Compare commits

..

No commits in common. "a9340ae345df0acfdda3b13b460f3d0f67c97a09" and "c5a8c99597410945f2360cb59983e943168a0029" have entirely different histories.

15 changed files with 31 additions and 236 deletions

View File

@ -67,11 +67,6 @@ static void create_gt911_touch(Device* i2c0) {
// Reset is pulsed via io_expander0 (detect.cpp's pulse_display_reset_pins), not a direct SoC GPIO. // Reset is pulsed via io_expander0 (detect.cpp's pulse_display_reset_pins), not a direct SoC GPIO.
.pin_reset = GPIO_PIN_SPEC_NONE, .pin_reset = GPIO_PIN_SPEC_NONE,
.pin_interrupt = GPIO_PIN_SPEC_NONE, .pin_interrupt = GPIO_PIN_SPEC_NONE,
.reset_pulses = 0, // no-op: pin_reset is NONE, so reset_controller_pin() skips anyway
.x_offset = 0,
.y_offset = 0,
.x_scale = 1000,
.y_scale = 1000,
}; };
gt911_device.config = &gt911_config; gt911_device.config = &gt911_config;

View File

@ -575,7 +575,6 @@ static error_t tab5_keyboard_read_key(Device* device, KeyboardKeyData* data) {
static const KeyboardApi tab5_keyboard_api = { static const KeyboardApi tab5_keyboard_api = {
.read_key = tab5_keyboard_read_key, .read_key = tab5_keyboard_read_key,
.is_present = tab5_keyboard_is_attached,
}; };
// Defined in module.cpp - this driver is registered directly by m5stack-tab5's own module, // Defined in module.cpp - this driver is registered directly by m5stack-tab5's own module,

View File

@ -231,16 +231,8 @@ error_t register_installed_app_locked(const std::string& app_dir_path, const App
.flags = 0, .flags = 0,
}; };
// Belt-and-braces: app_install()'s earlier app_manager_remove() call is meant to have
// already cleared any stale registration for this id (e.g. left over from
// app_manager_install_path_scan()'s separate registry), but that call happens before the
// tarball is even extracted - remove once more, right before add, so a duplicate id can
// never turn a filesystem-level install success into a reported failure.
app_manager_remove(record->id.c_str());
error_t add_result = app_manager_add(&record->manifest); error_t add_result = app_manager_add(&record->manifest);
if (add_result != ERROR_NONE) { if (add_result != ERROR_NONE) {
LOG_E(TAG, "Failed to register app '%s': %s", record->id.c_str(), error_to_string(add_result));
return add_result; return add_result;
} }
@ -370,9 +362,7 @@ error_t app_install(const char* source_path) {
// uninstall_locked() doesn't know about. Clear the app-manager registration unconditionally // uninstall_locked() doesn't know about. Clear the app-manager registration unconditionally
// too, or app_manager_add() below rejects the re-add as a duplicate. // too, or app_manager_add() below rejects the re-add as a duplicate.
uninstall_locked(metadata.app_id); uninstall_locked(metadata.app_id);
if (app_manager_remove(metadata.app_id) != ERROR_NONE) {
error_t remove_result = app_manager_remove(metadata.app_id);
if (remove_result != ERROR_NONE && remove_result != ERROR_NOT_FOUND) {
LOG_E(TAG, "Install failed: failed to remove existing installation"); LOG_E(TAG, "Install failed: failed to remove existing installation");
mutex_unlock(&registry.mutex); mutex_unlock(&registry.mutex);
delete_recursively(staging_path); delete_recursively(staging_path);

View File

@ -2,8 +2,7 @@
#include <app/event.h> #include <app/event.h>
#include <app/install.h> #include <app/install.h>
#include <app/manager.h> #include <app/manager.h>
#include <app/metadata.h> #include <app/module.h>
#include <app/paths.h>
#include <app/scheduler.h> #include <app/scheduler.h>
#include <service/manager.h> #include <service/manager.h>
@ -16,15 +15,13 @@ extern "C" {
extern ServiceManifest app_internal_loader_service_manifest; extern ServiceManifest app_internal_loader_service_manifest;
const ModuleSymbol app_module_symbols[] = { const ModuleSymbol app_module_symbols[] = {
// app/scheduler
DEFINE_MODULE_SYMBOL(app_scheduler_current_app_id),
// app/event // app/event
DEFINE_MODULE_SYMBOL(app_event_subscribe), DEFINE_MODULE_SYMBOL(app_event_subscribe),
DEFINE_MODULE_SYMBOL(app_event_unsubscribe), DEFINE_MODULE_SYMBOL(app_event_unsubscribe),
DEFINE_MODULE_SYMBOL(app_event_emit), DEFINE_MODULE_SYMBOL(app_event_emit),
DEFINE_MODULE_SYMBOL(app_event_await), DEFINE_MODULE_SYMBOL(app_event_await),
// app/install
DEFINE_MODULE_SYMBOL(app_get_install_path),
DEFINE_MODULE_SYMBOL(app_install),
DEFINE_MODULE_SYMBOL(app_uninstall),
// app/manager // app/manager
DEFINE_MODULE_SYMBOL(app_manager_start), DEFINE_MODULE_SYMBOL(app_manager_start),
DEFINE_MODULE_SYMBOL(app_manager_start_with_parameters), DEFINE_MODULE_SYMBOL(app_manager_start_with_parameters),
@ -40,15 +37,10 @@ const ModuleSymbol app_module_symbols[] = {
DEFINE_MODULE_SYMBOL(app_manager_get_topmost_app_id), DEFINE_MODULE_SYMBOL(app_manager_get_topmost_app_id),
DEFINE_MODULE_SYMBOL(app_manager_install_path_add), DEFINE_MODULE_SYMBOL(app_manager_install_path_add),
DEFINE_MODULE_SYMBOL(app_manager_install_path_scan), DEFINE_MODULE_SYMBOL(app_manager_install_path_scan),
// app/metadata // app/install
DEFINE_MODULE_SYMBOL(app_metadata_parse), DEFINE_MODULE_SYMBOL(app_get_install_path),
// app/paths DEFINE_MODULE_SYMBOL(app_install),
DEFINE_MODULE_SYMBOL(app_paths_get_user_data_directory), DEFINE_MODULE_SYMBOL(app_uninstall),
DEFINE_MODULE_SYMBOL(app_paths_get_user_data_path),
DEFINE_MODULE_SYMBOL(app_paths_get_assets_directory),
DEFINE_MODULE_SYMBOL(app_paths_get_assets_path),
// app/scheduler
DEFINE_MODULE_SYMBOL(app_scheduler_current_app_id),
// terminator // terminator
MODULE_SYMBOL_TERMINATOR MODULE_SYMBOL_TERMINATOR
}; };

View File

@ -106,11 +106,8 @@ bool lvgl_hardware_keyboard_is_available() {
return false; return false;
} }
// TODO: Refactor the driver subsystem to so it does proper probing/releasing of such devices
// This work-around exists for the Tab5 keyboard driver.
bool present = keyboard_is_present(keyboard_device);
device_put(keyboard_device); device_put(keyboard_device);
return present; return true;
} }
void lvgl_hardware_keyboard_add_custom(lv_indev_t* indev) { void lvgl_hardware_keyboard_add_custom(lv_indev_t* indev) {
@ -140,15 +137,9 @@ static void textarea_show_keyboard(lv_event_t* event) {
} }
static void textarea_hide_keyboard(lv_event_t* event) { static void textarea_hide_keyboard(lv_event_t* event) {
if (last_software_keyboard.object == nullptr) { if (last_software_keyboard.object != nullptr) {
return;
}
// Only hide if the keyboard is actually bound to the textarea that triggered this
lv_obj_t* target = lv_event_get_current_target_obj(event);
if (lv_keyboard_get_textarea(last_software_keyboard.object) != target) {
return;
}
lvgl_software_keyboard_hide(&last_software_keyboard); lvgl_software_keyboard_hide(&last_software_keyboard);
}
} }
void lvgl_software_keyboard_construct(LvglSoftwareKeyboard* keyboard, lv_obj_t* parent) { void lvgl_software_keyboard_construct(LvglSoftwareKeyboard* keyboard, lv_obj_t* parent) {
@ -196,7 +187,6 @@ void lvgl_keyboard_add_textarea(LvglSoftwareKeyboard* keyboard, lv_obj_t* textar
lv_obj_add_event_cb(textarea, textarea_show_keyboard, LV_EVENT_FOCUSED, nullptr); lv_obj_add_event_cb(textarea, textarea_show_keyboard, LV_EVENT_FOCUSED, nullptr);
lv_obj_add_event_cb(textarea, textarea_hide_keyboard, LV_EVENT_DEFOCUSED, nullptr); lv_obj_add_event_cb(textarea, textarea_hide_keyboard, LV_EVENT_DEFOCUSED, nullptr);
lv_obj_add_event_cb(textarea, textarea_hide_keyboard, LV_EVENT_READY, nullptr); lv_obj_add_event_cb(textarea, textarea_hide_keyboard, LV_EVENT_READY, nullptr);
lv_obj_add_event_cb(textarea, textarea_hide_keyboard, LV_EVENT_DELETE, nullptr);
} }
// lv_obj_t auto-remove themselves from the group when they are destroyed (last checked in LVGL 8.3) // lv_obj_t auto-remove themselves from the group when they are destroyed (last checked in LVGL 8.3)

View File

@ -210,45 +210,12 @@ error_t window_manager_start(void) {
return ERROR_RESOURCE; return ERROR_RESOURCE;
} }
// A previous stop() (see its comment) may have left window records behind for an app that's
// still running (as opposed to a real full shutdown, where every app has already removed its
// own window before this runs, leaving the list empty). Rebuild the topmost one now, exactly
// like window_manager_remove()'s resurface path does when a buried window becomes topmost -
// otherwise that app's task just sits blocked in its own event loop forever with no window
// and no way to know it needs to rebuild one.
WindowCreateWidgetsFn top_create_widgets = nullptr;
void* top_user_data = nullptr;
WindowId top_id = 0;
bool has_top = false;
mutex_lock(&s.mutex); mutex_lock(&s.mutex);
s.real_root_widget = real_widget; s.real_root_widget = real_widget;
s.content_root_widget = content_widget; s.content_root_widget = content_widget;
s.started = true; s.started = true;
if (!s.windows.empty()) {
top_create_widgets = s.windows.back().create_widgets;
top_user_data = s.windows.back().user_data;
top_id = s.windows.back().id;
has_top = true;
}
mutex_unlock(&s.mutex); mutex_unlock(&s.mutex);
if (has_top) {
lv_obj_t* new_widget = build_window_widget(content_widget, top_create_widgets, top_user_data);
mutex_lock(&s.mutex);
bool still_topmost = !s.windows.empty() && s.windows.back().id == top_id;
if (still_topmost) {
s.top_widget = new_widget;
new_widget = nullptr; // consumed
}
mutex_unlock(&s.mutex);
// Something else changed the window stack while we were building (e.g. a concurrent
// remove()) - discard what we just made.
delete_widget(new_widget);
}
mutex_unlock(&s.lifecycle_mutex); mutex_unlock(&s.lifecycle_mutex);
return ERROR_NONE; return ERROR_NONE;
} }
@ -267,8 +234,8 @@ error_t window_manager_stop(void) {
return ERROR_NONE; return ERROR_NONE;
} }
lv_obj_t* widget = s.real_root_widget; lv_obj_t* widget = s.real_root_widget;
// Claim every window's waiter before tearing down - normally at most the topmost window's // Claim every window's waiter before clearing - normally at most the topmost window's is
// is ever set, but every window's widget is being torn down here, so every one is checked. // ever set, but every window is being torn down here, so every one is checked.
std::vector<WindowWaitSignal*> waiters; std::vector<WindowWaitSignal*> waiters;
for (auto& window : s.windows) { for (auto& window : s.windows) {
if (auto* signal = claim_waiter_locked(window); signal != nullptr) { if (auto* signal = claim_waiter_locked(window); signal != nullptr) {
@ -278,15 +245,7 @@ error_t window_manager_stop(void) {
s.real_root_widget = nullptr; s.real_root_widget = nullptr;
s.content_root_widget = nullptr; s.content_root_widget = nullptr;
s.top_widget = nullptr; s.top_widget = nullptr;
// Deliberately NOT s.windows.clear(): this only tears down the LVGL widget tree, not the s.windows.clear();
// window records themselves. A real full shutdown (every app already removed its own window
// via window_manager_remove() before this runs) leaves the list empty anyway, so this is a
// no-op there. But a caller can also stop()/start() this module on its own, temporarily,
// while apps keep running underneath (e.g. an app borrowing the display/touch hardware
// directly) - those apps' tasks are still alive, blocked in their own event loops, with no
// way to know they need to call window_manager_create() again. Keeping the records lets
// window_manager_start() rebuild the topmost one automatically instead of leaving that app
// stuck with no window forever.
s.started = false; s.started = false;
mutex_unlock(&s.mutex); mutex_unlock(&s.mutex);

View File

@ -16,7 +16,6 @@
#include <tactility/drivers/wifi.h> #include <tactility/drivers/wifi.h>
#include <tactility/error_esp32.h> #include <tactility/error_esp32.h>
#include <tactility/log.h> #include <tactility/log.h>
#include <tactility/time.h>
#if defined(CONFIG_SLAVE_SOC_WIFI_SUPPORTED) #if defined(CONFIG_SLAVE_SOC_WIFI_SUPPORTED)
#include <tactility/drivers/esp32_esp_hosted_ota.h> #include <tactility/drivers/esp32_esp_hosted_ota.h>
@ -57,15 +56,6 @@ struct Esp32WifiCtx {
esp_event_handler_instance_t wifiEventHandler = nullptr; esp_event_handler_instance_t wifiEventHandler = nullptr;
esp_event_handler_instance_t ipEventHandler = nullptr; esp_event_handler_instance_t ipEventHandler = nullptr;
// Dedup for WIFI_EVENT/IP_EVENT notifications: on the esp_hosted/Wi-Fi Remote transport
// (e.g. Tab5's P4 host + C6 co-processor), the RPC layer has been observed delivering the
// exact same event twice in a row (same base, same event_id, same millisecond - not two
// genuinely separate occurrences). Native WiFi doesn't exhibit this, but the handler is
// shared, so the guard applies unconditionally; it's a no-op for well-separated real events.
esp_event_base_t lastEventBase = nullptr;
int32_t lastEventId = -1;
TickType_t lastEventTick = 0;
Mutex callbackMutex{}; Mutex callbackMutex{};
WifiCallbackEntry callbacks[WIFI_MAX_CALLBACKS] = {}; WifiCallbackEntry callbacks[WIFI_MAX_CALLBACKS] = {};
size_t callbackCount = 0; size_t callbackCount = 0;
@ -110,20 +100,6 @@ void fire_event(Esp32WifiCtx* ctx, WifiEvent event) {
void on_wifi_or_ip_event(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { void on_wifi_or_ip_event(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) {
auto* ctx = static_cast<Esp32WifiCtx*>(arg); auto* ctx = static_cast<Esp32WifiCtx*>(arg);
// See Esp32WifiCtx::lastEventBase/lastEventId/lastEventTick - collapse an immediate duplicate
// delivery of the same event (observed on the esp_hosted/Wi-Fi Remote transport) into one.
constexpr uint32_t DEDUP_WINDOW_MS = 50; // well under any real re-occurrence of the same event
TickType_t now = get_ticks();
bool is_duplicate = event_base == ctx->lastEventBase && event_id == ctx->lastEventId &&
(now - ctx->lastEventTick) <= millis_to_ticks(DEDUP_WINDOW_MS);
ctx->lastEventBase = event_base;
ctx->lastEventId = event_id;
ctx->lastEventTick = now;
if (is_duplicate) {
LOG_D(TAG, "Ignoring duplicate WiFi event %d", (int)event_id);
return;
}
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
mutex_lock(&ctx->mutex); mutex_lock(&ctx->mutex);
bool was_pending = ctx->stationState == WIFI_STATION_STATE_CONNECTION_PENDING; bool was_pending = ctx->stationState == WIFI_STATION_STATE_CONNECTION_PENDING;

View File

@ -42,7 +42,6 @@
#include <gps_meshtastic/module.h> #include <gps_meshtastic/module.h>
#include <crypt/module.h> #include <crypt/module.h>
#include <lvgl/devices/keyboard.h>
#include <lvgl/devices/pointer.h> #include <lvgl/devices/pointer.h>
#include <lvgl/lvgl.h> #include <lvgl/lvgl.h>
#include <lvgl/module.h> #include <lvgl/module.h>
@ -362,9 +361,6 @@ static void stopAppFromToolbar(lv_event_t*) {
app_event_emit(topmost, &event); app_event_emit(topmost, &event);
} }
// The on-screen keyboard widget itself, constructed during windowManagerScreenInit
static LvglSoftwareKeyboard softwareKeyboard { .object = nullptr };
static lv_obj_t* windowManagerScreenInit(lv_obj_t* root) { static lv_obj_t* windowManagerScreenInit(lv_obj_t* root) {
lv_obj_t* vertical_container = lv_obj_create(root); lv_obj_t* vertical_container = lv_obj_create(root);
lv_obj_set_size(vertical_container, LV_PCT(100), LV_PCT(100)); lv_obj_set_size(vertical_container, LV_PCT(100), LV_PCT(100));
@ -384,11 +380,6 @@ static lv_obj_t* windowManagerScreenInit(lv_obj_t* root) {
lv_obj_set_flex_grow(app_container, 1); lv_obj_set_flex_grow(app_container, 1);
lv_obj_set_flex_flow(app_container, LV_FLEX_FLOW_COLUMN); lv_obj_set_flex_flow(app_container, LV_FLEX_FLOW_COLUMN);
// Parented to root (not app_container/vertical_container) so it overlays on top of
// everything, including the statusbar, regardless of which app is showing. Hidden until a
// focused textarea shows it (see lvgl_keyboard_add_textarea()/textarea_show_keyboard()).
lvgl_software_keyboard_construct(&softwareKeyboard, root);
return app_container; return app_container;
} }
@ -449,10 +440,6 @@ static void onLvglStarted() {
} }
static void onLvglStopped() { static void onLvglStopped() {
if (softwareKeyboard.object != nullptr) {
lvgl_software_keyboard_destruct(&softwareKeyboard);
}
module_stop(&lvgl_window_manager_module); module_stop(&lvgl_window_manager_module);
lvgl::stopUsbHidInput(); lvgl::stopUsbHidInput();

View File

@ -175,25 +175,19 @@ int32_t appMain(uint32_t appInstanceId, int argc, char* argv[]) {
return 0; return 0;
} }
ctx.timer = std::make_unique<Timer>(Timer::Type::Periodic, pdMS_TO_TICKS(1000), [&ctx] {
if (lvgl_is_running()) {
lvgl_lock();
updateViewState(&ctx);
lvgl_unlock();
}
});
AppEventSubscription sub {}; AppEventSubscription sub {};
sub.app_instance_id = appInstanceId; sub.app_instance_id = appInstanceId;
app_event_subscribe(&sub); app_event_subscribe(&sub);
WindowId window = window_manager_create(appInstanceId, createWidgets, &ctx); WindowId window = window_manager_create(appInstanceId, createWidgets, &ctx);
ctx.timer = std::make_unique<Timer>(Timer::Type::Periodic, pdMS_TO_TICKS(1000), [&ctx, window] {
if (lvgl_is_running()) {
lvgl_lock();
// Widgets only exist while this window is topmost - skip otherwise. Another app
// (started non-modally, e.g. via app_manager_start()) can bury this window without
// stopping this instance or notifying it; window_manager deletes a buried window's
// widgets, so touching ctx->statusLabel here would use-after-free it.
if (window_manager_get_state(window) == WINDOW_STATE_GRANTED) {
updateViewState(&ctx);
}
lvgl_unlock();
}
});
ctx.timer->start(); ctx.timer->start();
bool shouldClose = false; bool shouldClose = false;

View File

@ -1,6 +1,5 @@
#include <tactility/device.h> #include <tactility/device.h>
#include <tactility/drivers/display.h> #include <tactility/drivers/display.h>
#include <tactility/drivers/sdcard.h>
#include <tactility/drivers/spi_controller.h> #include <tactility/drivers/spi_controller.h>
#include <tactility/filesystem/file_mutex.h> #include <tactility/filesystem/file_mutex.h>
#include <tactility/filesystem/file_system.h> #include <tactility/filesystem/file_system.h>
@ -76,29 +75,6 @@ void initFileMutexForLvgl() {
return true; return true;
}); });
// SDMMC-backed SD cards aren't parented under SPI_CONTROLLER_TYPE, so the pass above never
// sees them - but on some chips (classic ESP32) SDMMC and SPI still contend for DMA/bus
// access. Lock every SD card mount if a display exists anywhere, regardless of bus topology.
if (!device_exists_of_type(&DISPLAY_TYPE)) {
return;
}
file_system_for_each(nullptr, [](FileSystem* fs, void* context) {
char mount_path[64];
if (file_system_get_path(fs, mount_path, sizeof(mount_path)) != ERROR_NONE) {
return true;
}
auto* owner = file_system_get_owner(fs);
if (owner == nullptr || device_get_type(owner) != &SDCARD_TYPE) {
return true;
}
LOG_I(TAG, "Adding file mutex for %s (SD card) - a display is present and may contend for bus/DMA resources", mount_path);
file_mutex_register(&lvgl_mutex, mount_path);
return true;
});
} }
} }

View File

@ -1,8 +1,8 @@
#include <Tactility/LogMessages.h> #include <Tactility/LogMessages.h>
#include <Tactility/StringUtils.h> #include <Tactility/StringUtils.h>
#include <Tactility/file/File.h>
#include <Tactility/network/HttpdReq.h> #include <Tactility/network/HttpdReq.h>
#include <tactility/filesystem/file_mutex.h>
#include <tactility/log.h> #include <tactility/log.h>
#include <memory> #include <memory>
@ -186,59 +186,30 @@ size_t receiveFile(httpd_req_t* request, size_t length, const std::string& fileP
char buffer[BUFFER_SIZE]; char buffer[BUFFER_SIZE];
size_t bytes_received = 0; size_t bytes_received = 0;
// Locked only around each actual disk I/O call below, not across the httpd_req_recv() waits file::FileMutexGuard guard(filePath);
// in between - this file's mutex may resolve to lvgl_lock() (see FileMutexLvgl.cpp), and
// holding that for the whole (potentially multi-second) network transfer starves LVGL's own
// task for the entire upload instead of just for each brief write.
FileMutex mutex {};
file_mutex_get(&mutex, filePath.c_str());
file_mutex_lock(&mutex);
auto* file = fopen(filePath.c_str(), "wb"); auto* file = fopen(filePath.c_str(), "wb");
file_mutex_unlock(&mutex);
if (file == nullptr) { if (file == nullptr) {
LOG_E(TAG, "Failed to open file for writing: %s", filePath.c_str()); LOG_E(TAG, "Failed to open file for writing: %s", filePath.c_str());
return 0; return 0;
} }
constexpr int MAX_TIMEOUT_RETRIES = 5;
int timeout_retries = 0;
while (bytes_received < length) { while (bytes_received < length) {
auto expected_chunk_size = std::min<size_t>(BUFFER_SIZE, length - bytes_received); auto expected_chunk_size = std::min<size_t>(BUFFER_SIZE, length - bytes_received);
int received = httpd_req_recv(request, buffer, expected_chunk_size); size_t receive_chunk_size = httpd_req_recv(request, buffer, expected_chunk_size);
if (received == HTTPD_SOCK_ERR_TIMEOUT) { if (receive_chunk_size <= 0) {
// Timeout - retry with backoff, same as receiveByteArray(). A large file takes many
// more chunks (and much longer overall) than the small reads elsewhere in this file,
// so it's far more likely to hit at least one transient stall somewhere along the way.
timeout_retries++;
if (timeout_retries >= MAX_TIMEOUT_RETRIES) {
LOG_E(TAG, "Recv timeout after %d retries, wrote %zu/%zu bytes", timeout_retries, bytes_received, length);
break;
}
LOG_W(TAG, "Recv timeout, retry %d/%d", timeout_retries, MAX_TIMEOUT_RETRIES);
vTaskDelay(pdMS_TO_TICKS(100 * timeout_retries)); // Exponential backoff
continue;
}
if (received <= 0) {
LOG_E(TAG, "Receive failed, got 0 bytes but expected %zu more", length - bytes_received); LOG_E(TAG, "Receive failed, got 0 bytes but expected %zu more", length - bytes_received);
break; break;
} }
timeout_retries = 0; if (fwrite(buffer, 1, receive_chunk_size, file) != receive_chunk_size) {
size_t receive_chunk_size = (size_t)received;
file_mutex_lock(&mutex);
bool write_ok = fwrite(buffer, 1, receive_chunk_size, file) == receive_chunk_size;
file_mutex_unlock(&mutex);
if (!write_ok) {
LOG_E(TAG, "Failed to write all bytes"); LOG_E(TAG, "Failed to write all bytes");
break; break;
} }
bytes_received += receive_chunk_size; bytes_received += receive_chunk_size;
} }
file_mutex_lock(&mutex); // Write file
fclose(file); fclose(file);
file_mutex_unlock(&mutex);
return bytes_received; return bytes_received;
} }

View File

@ -113,7 +113,7 @@ esp_err_t DevelopmentService::handleAppRun(httpd_req_t* request) {
} }
} }
app_manager_start(id_key_pos->second.c_str(), &instance_id); app_manager_start(app_id, &instance_id);
LOG_I(TAG, "[200] /app/run %s", id_key_pos->second.c_str()); LOG_I(TAG, "[200] /app/run %s", id_key_pos->second.c_str());
httpd_resp_send(request, nullptr, 0); httpd_resp_send(request, nullptr, 0);
@ -193,7 +193,7 @@ esp_err_t DevelopmentService::handleAppInstall(httpd_req_t* request) {
LOG_W(TAG, "We have more bytes at the end of the request parsing?!"); LOG_W(TAG, "We have more bytes at the end of the request parsing?!");
} }
if (app_install(file_path.c_str()) != ERROR_NONE) { if (!app_install(file_path.c_str())) {
httpd_resp_send_err(request, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to install"); httpd_resp_send_err(request, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to install");
return ESP_FAIL; return ESP_FAIL;
} }
@ -231,7 +231,7 @@ esp_err_t DevelopmentService::handleAppUninstall(httpd_req_t* request) {
return ESP_OK; return ESP_OK;
} }
if (app_uninstall(id_key_pos->second.c_str()) == ERROR_NONE) { if (app_uninstall(id_key_pos->second.c_str())) {
LOG_I(TAG, "[200] /app/uninstall %s", id_key_pos->second.c_str()); LOG_I(TAG, "[200] /app/uninstall %s", id_key_pos->second.c_str());
httpd_resp_send(request, nullptr, 0); httpd_resp_send(request, nullptr, 0);
return ESP_OK; return ESP_OK;

View File

@ -138,24 +138,20 @@ bool contains(const std::string& ssid) {
bool load(const std::string& ssid, WifiApSettings& apSettings) { bool load(const std::string& ssid, WifiApSettings& apSettings) {
auto service_context = findServiceContext(); auto service_context = findServiceContext();
if (service_context == nullptr) { if (service_context == nullptr) {
LOG_E(TAG, "No service context");
return false; return false;
} }
const auto file_path = getApPropertiesFilePath(service_context->getPaths(), ssid); const auto file_path = getApPropertiesFilePath(service_context->getPaths(), ssid);
if (!file::isFile(file_path)) { if (!file::isFile(file_path)) {
LOG_E(TAG, "Not a file: %s", file_path.c_str());
return false; return false;
} }
std::map<std::string, std::string> map; std::map<std::string, std::string> map;
if (!file::loadPropertiesFile(file_path, map)) { if (!file::loadPropertiesFile(file_path, map)) {
LOG_E(TAG, "Failed to load properties from %s", file_path.c_str());
return false; return false;
} }
// SSID is required // SSID is required
if (!map.contains(AP_PROPERTIES_KEY_SSID)) { if (!map.contains(AP_PROPERTIES_KEY_SSID)) {
LOG_E(TAG, "File does not contain SSID: %s", file_path.c_str());
return false; return false;
} }
@ -170,7 +166,6 @@ bool load(const std::string& ssid, WifiApSettings& apSettings) {
} else if (decrypt(ssid, encrypted_password, password_decrypted)) { } else if (decrypt(ssid, encrypted_password, password_decrypted)) {
apSettings.password = password_decrypted; apSettings.password = password_decrypted;
} else { } else {
LOG_E(TAG, "Failed to decrypt password from %s", file_path.c_str());
return false; return false;
} }
} else { } else {

View File

@ -66,17 +66,6 @@ struct KeyboardApi {
* @retval ERROR_NOT_SUPPORTED when this device has no backlight * @retval ERROR_NOT_SUPPORTED when this device has no backlight
*/ */
error_t (*get_backlight)(struct Device* device, struct Device** backlight_device); error_t (*get_backlight)(struct Device* device, struct Device** backlight_device);
/**
* @brief Optional: reports whether the keyboard is physically present right now. Only
* meaningful for hot-pluggable/detachable keyboards (e.g. a removable accessory) whose
* kernel device is constructed and started once at boot regardless of physical attachment -
* leave NULL for a keyboard that's always physically present whenever its device is active
* (the common case; callers must treat NULL the same as "always present").
* @param[in] device the keyboard device
* @return true if physically attached/present
*/
bool (*is_present)(struct Device* device);
}; };
/** /**
@ -94,14 +83,6 @@ error_t keyboard_read_key(struct Device* device, struct KeyboardKeyData* data);
*/ */
error_t keyboard_get_backlight(struct Device* device, struct Device** backlight_device); error_t keyboard_get_backlight(struct Device* device, struct Device** backlight_device);
/**
* @brief Whether the keyboard device is physically present right now. True when the driver
* doesn't implement KeyboardApi::is_present (i.e. it's always physically present whenever its
* device is active) - see that field's doc comment.
* @param[in] device the keyboard device
*/
bool keyboard_is_present(struct Device* device);
extern const struct DeviceType KEYBOARD_TYPE; extern const struct DeviceType KEYBOARD_TYPE;
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -28,16 +28,6 @@ error_t keyboard_get_backlight(Device* device, Device** backlight_device) {
return KEYBOARD_DRIVER_API(driver)->get_backlight(device, backlight_device); return KEYBOARD_DRIVER_API(driver)->get_backlight(device, backlight_device);
} }
bool keyboard_is_present(Device* device) {
const auto* driver = device_get_driver(device);
if (KEYBOARD_DRIVER_API(driver)->is_present == nullptr) {
return true;
}
return KEYBOARD_DRIVER_API(driver)->is_present(device);
}
const DeviceType KEYBOARD_TYPE { const DeviceType KEYBOARD_TYPE {
.name = "keyboard" .name = "keyboard"
}; };