diff --git a/Devices/lilygo-tdeck/source/module.cpp b/Devices/lilygo-tdeck/source/module.cpp index 500926424..5916a8447 100644 --- a/Devices/lilygo-tdeck/source/module.cpp +++ b/Devices/lilygo-tdeck/source/module.cpp @@ -1,13 +1,12 @@ #include - #include #include + #include #include #include #include -#include #include #include diff --git a/Modules/lvgl-module/include/lvgl/lvgl.h b/Modules/lvgl-module/include/lvgl/lvgl.h index 1aabbfad8..fee5541f7 100644 --- a/Modules/lvgl-module/include/lvgl/lvgl.h +++ b/Modules/lvgl-module/include/lvgl/lvgl.h @@ -4,6 +4,9 @@ #include #include +// Official LVGL library header +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/Tactility/Include/Tactility/lvgl/LvglSync.h b/Tactility/Include/Tactility/lvgl/LvglSync.h deleted file mode 100644 index f6f7dd687..000000000 --- a/Tactility/Include/Tactility/lvgl/LvglSync.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include - -#include - -namespace tt::lvgl { - -constexpr TickType_t defaultLockTime = 500 / portTICK_PERIOD_MS; - -/** - * LVGL locking function - * @param[in] timeout as ticks - * @warning when passing zero, we wait forever, as this is the default behaviour for esp_lvgl_port, and we want it to remain consistent - * @deprecated Use lvgl_lock() or lvgl_try_lock() from lvgl-module instead. - */ -bool lock(TickType_t timeout = portMAX_DELAY) __attribute__((deprecated("Use lvgl_lock() from lvgl-module"))); - -/** @deprecated Use lvgl_unlock() from lvgl-module instead. */ -void unlock() __attribute__((deprecated("Use lvgl_unlock() from lvgl-module"))); - -std::shared_ptr getSyncLock() __attribute__((deprecated("Use lvgl locking functions from lvgl-module"))); - -} // namespace diff --git a/Tactility/Private/Tactility/service/gui/GuiService.h b/Tactility/Private/Tactility/service/gui/GuiService.h index 25f878995..220eb18bc 100644 --- a/Tactility/Private/Tactility/service/gui/GuiService.h +++ b/Tactility/Private/Tactility/service/gui/GuiService.h @@ -3,7 +3,6 @@ #include #include #include -#include #include #include @@ -11,7 +10,6 @@ #include -#include #include namespace tt::service::gui { diff --git a/Tactility/Source/app/appdetails/AppDetails.cpp b/Tactility/Source/app/appdetails/AppDetails.cpp index 96bb0c090..88257d6f5 100644 --- a/Tactility/Source/app/appdetails/AppDetails.cpp +++ b/Tactility/Source/app/appdetails/AppDetails.cpp @@ -1,18 +1,18 @@ -#include "Tactility/lvgl/LvglSync.h" - #include #include #include #include -#include #include -#include - -#include -#include #include #include +#include + +#include +#include + +#include + namespace tt::app::appdetails { extern const AppManifest manifest; diff --git a/Tactility/Source/app/apphub/AppHubApp.cpp b/Tactility/Source/app/apphub/AppHubApp.cpp index d6a0145fd..e1c43a321 100644 --- a/Tactility/Source/app/apphub/AppHubApp.cpp +++ b/Tactility/Source/app/apphub/AppHubApp.cpp @@ -1,20 +1,21 @@ +#include #include #include #include #include -#include -#include #include #include -#include #include #include +#include + #include +#include +#include + #include #include -#include -#include namespace tt::app::apphub { @@ -58,20 +59,16 @@ class AppHubApp final : public App { void onRefreshSuccess() { LOG_I(TAG, "Request success"); - auto lockable = lvgl::getSyncLock(); - auto lock = lockable->asScopedLock(); - lock.lock(); - + lvgl_lock(); showApps(); + lvgl_unlock(); } void onRefreshError(const char* error) { LOG_E(TAG, "Request failed: %s", error); - auto lockable = lvgl::getSyncLock(); - auto lock = lockable->asScopedLock(); - lock.lock(); - + lvgl_lock(); showRefreshFailedError("Cannot reach server"); + lvgl_unlock(); } static void createAppWidget(const std::shared_ptr& manifest, lv_obj_t* list) { diff --git a/Tactility/Source/app/apphubdetails/AppHubDetailsApp.cpp b/Tactility/Source/app/apphubdetails/AppHubDetailsApp.cpp index 16b977d4a..20611476d 100644 --- a/Tactility/Source/app/apphubdetails/AppHubDetailsApp.cpp +++ b/Tactility/Source/app/apphubdetails/AppHubDetailsApp.cpp @@ -1,17 +1,18 @@ +#include +#include +#include #include #include #include -#include #include -#include -#include #include -#include #include -#include -#include +#include +#include + #include + #include namespace tt::app::apphubdetails { @@ -87,15 +88,15 @@ class AppHubDetailsApp final : public App { void uninstallApp() { LOG_I(TAG, "Uninstall"); - lvgl::getSyncLock()->lock(); + lvgl_lock(); lv_obj_remove_flag(spinner, LV_OBJ_FLAG_HIDDEN); - lvgl::getSyncLock()->unlock(); + lvgl_unlock(); uninstall(entry.appId); - lvgl::getSyncLock()->lock(); + lvgl_lock(); updateViews(); - lvgl::getSyncLock()->unlock(); + lvgl_unlock(); } void doInstall() { @@ -115,9 +116,9 @@ class AppHubDetailsApp final : public App { LOG_I(TAG, "Deleted temporary file %s", temp_file_path.c_str()); } - lvgl::getSyncLock()->lock(); + lvgl_lock(); updateViews(); - lvgl::getSyncLock()->unlock(); + lvgl_unlock(); }, [temp_file_path](const char* errorMessage) { LOG_E(TAG, "Download failed: %s", errorMessage); @@ -133,9 +134,9 @@ class AppHubDetailsApp final : public App { void installApp() { LOG_I(TAG, "Install"); - lvgl::getSyncLock()->lock(); + lvgl_lock(); lv_obj_remove_flag(spinner, LV_OBJ_FLAG_HIDDEN); - lvgl::getSyncLock()->unlock(); + lvgl_unlock(); doInstall(); } @@ -143,9 +144,9 @@ class AppHubDetailsApp final : public App { void updateApp() { LOG_I(TAG, "Update"); - lvgl::getSyncLock()->lock(); + lvgl_lock(); lv_obj_remove_flag(spinner, LV_OBJ_FLAG_HIDDEN); - lvgl::getSyncLock()->unlock(); + lvgl_unlock(); LOG_I(TAG, "Removing previous version"); uninstall(entry.appId); diff --git a/Tactility/Source/app/audiosettings/AudioSettings.cpp b/Tactility/Source/app/audiosettings/AudioSettings.cpp index ec48d6c5a..f5cbc8f37 100644 --- a/Tactility/Source/app/audiosettings/AudioSettings.cpp +++ b/Tactility/Source/app/audiosettings/AudioSettings.cpp @@ -1,16 +1,12 @@ #include - -#include - #include #include -#include #include #include -#include -#include +#include #include +#include namespace tt::app::audiosettings { @@ -161,10 +157,9 @@ public: refresh(); audioSubscription = service::audio::getPubsub()->subscribe([this](auto) { - if (lvgl::lock(lvgl::defaultLockTime)) { - refresh(); - lvgl::unlock(); - } + lvgl_lock(); + refresh(); + lvgl_unlock(); }); } diff --git a/Tactility/Source/app/btmanage/BtManage.cpp b/Tactility/Source/app/btmanage/BtManage.cpp index 537e59a23..4b4e152c7 100644 --- a/Tactility/Source/app/btmanage/BtManage.cpp +++ b/Tactility/Source/app/btmanage/BtManage.cpp @@ -1,11 +1,11 @@ +#include + #include #include -#include #include #include #include -#include #include #include @@ -79,12 +79,9 @@ void BtManage::unlock() { void BtManage::requestViewUpdate() { lock(); if (isViewEnabled) { - if (lvgl::lock(1000)) { - view.update(); - lvgl::unlock(); - } else { - LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL"); - } + lvgl_lock(); + view.update(); + lvgl_unlock(); } unlock(); } diff --git a/Tactility/Source/app/btpeersettings/BtPeerSettings.cpp b/Tactility/Source/app/btpeersettings/BtPeerSettings.cpp index d4c792a7f..2e769acf2 100644 --- a/Tactility/Source/app/btpeersettings/BtPeerSettings.cpp +++ b/Tactility/Source/app/btpeersettings/BtPeerSettings.cpp @@ -1,23 +1,21 @@ #include -#include "tactility/device.h" +#include +#include -#include #include #include #include #include #include #include -#include #include -#include + #include +#include #include #include -#include - namespace tt::app::btpeersettings { constexpr auto* TAG = "BtPeerSettings"; @@ -84,12 +82,9 @@ class BtPeerSettings : public App { void requestViewUpdate() const { if (viewEnabled) { - if (lvgl::lock(1000)) { - updateViews(); - lvgl::unlock(); - } else { - LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL"); - } + lvgl_lock(); + updateViews(); + lvgl_unlock(); } } diff --git a/Tactility/Source/app/chat/ChatApp.cpp b/Tactility/Source/app/chat/ChatApp.cpp index 5ad89c4c9..e06a845dc 100644 --- a/Tactility/Source/app/chat/ChatApp.cpp +++ b/Tactility/Source/app/chat/ChatApp.cpp @@ -6,15 +6,16 @@ #include #include - #include -#include + +#include #include +#include + #include #include #include -#include #include namespace tt::app::chat { @@ -83,12 +84,9 @@ void ChatApp::onReceive(const esp_now_recv_info_t* receiveInfo, const uint8_t* d state.addMessage(msg); - { - auto lockable = lvgl::getSyncLock(); - auto lock = lockable->asScopedLock(); - lock.lock(); - view.displayMessage(msg); - } + lvgl_lock(); + view.displayMessage(msg); + lvgl_unlock(); } void ChatApp::sendMessage(const std::string& text) { @@ -115,12 +113,9 @@ void ChatApp::sendMessage(const std::string& text) { state.addMessage(msg); - { - auto lockable = lvgl::getSyncLock(); - auto lock = lockable->asScopedLock(); - lock.lock(); - view.displayMessage(msg); - } + lvgl_lock(); + view.displayMessage(msg); + lvgl_unlock(); } void ChatApp::applySettings(const std::string& nickname, const std::string& keyHex) { @@ -173,12 +168,9 @@ void ChatApp::switchChannel(const std::string& chatChannel) { settings.chatChannel = trimmedChannel; saveSettings(settings); - { - auto lockable = lvgl::getSyncLock(); - auto lock = lockable->asScopedLock(); - lock.lock(); - view.refreshMessageList(); - } + lvgl_lock(); + view.refreshMessageList(); + lvgl_unlock(); } extern const AppManifest manifest = { diff --git a/Tactility/Source/app/development/Development.cpp b/Tactility/Source/app/development/Development.cpp index e7ecf8df8..782c03ab7 100644 --- a/Tactility/Source/app/development/Development.cpp +++ b/Tactility/Source/app/development/Development.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -11,12 +10,12 @@ #include #include -#include -#include #include +#include +#include + #include -#include namespace tt::app::development { diff --git a/Tactility/Source/app/files/View.cpp b/Tactility/Source/app/files/View.cpp index b019a809a..4beef3a13 100644 --- a/Tactility/Source/app/files/View.cpp +++ b/Tactility/Source/app/files/View.cpp @@ -1,6 +1,5 @@ #include #include - #include #include #include @@ -9,14 +8,15 @@ #include #include #include -#include #include -#include +#include #include #include #include +#include + #include #include #include @@ -450,9 +450,7 @@ void View::onEjectPressed() { void View::update(size_t start_index) { const bool is_root = (state->getCurrentPath() == "/"); - auto sync_lockable = lvgl::getSyncLock(); - auto scoped_lockable = sync_lockable->asScopedLock(); - if (!scoped_lockable.lock(lvgl::defaultLockTime)) { + if (!lvgl_try_lock(500 / portTICK_PERIOD_MS)) { LOG_E(TAG, "Mutex acquisition timeout (%s)", "lvgl"); return; } @@ -516,6 +514,8 @@ void View::update(size_t start_index) { } else { lv_obj_add_flag(lv_obj_get_parent(paste_button), LV_OBJ_FLAG_HIDDEN); } + + lvgl_unlock(); } void View::init(const AppContext& appContext, lv_obj_t* parent) { @@ -551,18 +551,16 @@ void View::init(const AppContext& appContext, lv_obj_t* parent) { } void View::onDirEntryListScrollBegin() { - auto sync_lockable = lvgl::getSyncLock(); - auto scoped_lockable = sync_lockable->asScopedLock(); - if (scoped_lockable.lock(lvgl::defaultLockTime)) { + if (lvgl_try_lock(500 / portTICK_PERIOD_MS)) { lv_obj_add_flag(action_list, LV_OBJ_FLAG_HIDDEN); + lvgl_unlock(); } } void View::onNavigate() { - auto sync_lockable = lvgl::getSyncLock(); - auto scoped_lockable = sync_lockable->asScopedLock(); - if (scoped_lockable.lock(lvgl::defaultLockTime)) { + if (lvgl_try_lock(500 / portTICK_PERIOD_MS)) { lv_obj_add_flag(action_list, LV_OBJ_FLAG_HIDDEN); + lvgl_unlock(); } } diff --git a/Tactility/Source/app/fileselection/View.cpp b/Tactility/Source/app/fileselection/View.cpp index e4342fbf9..c51d30363 100644 --- a/Tactility/Source/app/fileselection/View.cpp +++ b/Tactility/Source/app/fileselection/View.cpp @@ -1,16 +1,16 @@ #include - -#include +#include #include #include #include #include -#include -#include -#include + #include #include +#include +#include + #include #include @@ -155,26 +155,27 @@ void View::onNavigateUpPressed() { } void View::update() { - auto sync_lockable = lvgl::getSyncLock(); - auto scoped_lockable = sync_lockable->asScopedLock(); - if (scoped_lockable.lock(lvgl::defaultLockTime)) { - lv_obj_clean(dir_entry_list); - - state->withEntries([this](const std::vector& entries) { - for (auto entry : entries) { - LOG_D(TAG, "Entry: %s %d", entry.d_name, (int)entry.d_type); - createDirEntryWidget(dir_entry_list, entry); - } - }); - - if (state->getCurrentPath() == "/") { - lv_obj_add_flag(navigate_up_button, LV_OBJ_FLAG_HIDDEN); - } else { - lv_obj_remove_flag(navigate_up_button, LV_OBJ_FLAG_HIDDEN); - } - } else { + if (!lvgl_try_lock(500 / portTICK_PERIOD_MS)) { LOG_E(TAG, "Mutex acquisition timeout (%s)", "lvgl"); + return; } + + lv_obj_clean(dir_entry_list); + + state->withEntries([this](const std::vector& entries) { + for (auto entry : entries) { + LOG_D(TAG, "Entry: %s %d", entry.d_name, (int)entry.d_type); + createDirEntryWidget(dir_entry_list, entry); + } + }); + + if (state->getCurrentPath() == "/") { + lv_obj_add_flag(navigate_up_button, LV_OBJ_FLAG_HIDDEN); + } else { + lv_obj_remove_flag(navigate_up_button, LV_OBJ_FLAG_HIDDEN); + } + + lvgl_unlock(); } void View::init(lv_obj_t* parent, Mode mode) { diff --git a/Tactility/Source/app/i2cscanner/I2cScanner.cpp b/Tactility/Source/app/i2cscanner/I2cScanner.cpp index 471fb71c8..a08dbcb73 100644 --- a/Tactility/Source/app/i2cscanner/I2cScanner.cpp +++ b/Tactility/Source/app/i2cscanner/I2cScanner.cpp @@ -1,20 +1,20 @@ -#include #include - +#include #include #include #include #include #include -#include #include #include + #include +#include #include +#include #include -#include namespace tt::app::i2cscanner { @@ -367,12 +367,9 @@ void I2cScannerApp::updateViews() { } void I2cScannerApp::updateViewsSafely() { - if (lvgl::lock(200 / portTICK_PERIOD_MS)) { - updateViews(); - lvgl::unlock(); - } else { - LOG_W(TAG, "Mutex acquisition timeout (%s)", "updateViewsSafely"); - } + lvgl_lock(); + updateViews(); + lvgl_unlock(); } void I2cScannerApp::onScanTimerFinished() { diff --git a/Tactility/Source/app/notes/Notes.cpp b/Tactility/Source/app/notes/Notes.cpp index 5591c6235..5914b7e95 100644 --- a/Tactility/Source/app/notes/Notes.cpp +++ b/Tactility/Source/app/notes/Notes.cpp @@ -1,10 +1,9 @@ +#include "lvgl/lvgl.h" + #include #include #include #include -#include -#include - #include #include @@ -42,16 +41,16 @@ class NotesApp final : public App { break; case 1: // Save if (!filePath.empty()) { - lvgl::getSyncLock()->lock(); + lvgl_lock(); saveBuffer = lv_textarea_get_text(uiNoteText); - lvgl::getSyncLock()->unlock(); + lvgl_unlock(); saveFile(filePath); } break; case 2: // Save as... - lvgl::getSyncLock()->lock(); + lvgl_lock(); saveBuffer = lv_textarea_get_text(uiNoteText); - lvgl::getSyncLock()->unlock(); + lvgl_unlock(); saveFileLaunchId = fileselection::startForExistingOrNewFile(); LOG_I(TAG, "launched with id %u", saveFileLaunchId); break; @@ -87,13 +86,12 @@ class NotesApp final : public App { file::getLock(path)->withLock([this, path] { auto data = file::readString(path); if (data != nullptr) { - auto lockable = lvgl::getSyncLock(); - auto lock = lockable->asScopedLock(); - lock.lock(); - lv_textarea_set_text(uiNoteText, reinterpret_cast(data.get())); - lv_label_set_text(uiCurrentFileName, path.c_str()); - filePath = path; - LOG_I(TAG, "Loaded from %s", path.c_str()); + lvgl_lock(); + lv_textarea_set_text(uiNoteText, reinterpret_cast(data.get())); + lv_label_set_text(uiCurrentFileName, path.c_str()); + lvgl_unlock(); + filePath = path; + LOG_I(TAG, "Loaded from %s", path.c_str()); } }); } diff --git a/Tactility/Source/app/power/Power.cpp b/Tactility/Source/app/power/Power.cpp index e2ccf4896..09a863353 100644 --- a/Tactility/Source/app/power/Power.cpp +++ b/Tactility/Source/app/power/Power.cpp @@ -1,16 +1,14 @@ #include -#include #include #include #include - #include -#include #include #include -#include +#include +#include #include @@ -136,7 +134,7 @@ class PowerApp : public App { return; } - lvgl::lock(kernel::millisToTicks(1000)); + lvgl_lock(); for (auto& entry : entries) { if (entry.enableSwitch != nullptr) { @@ -155,7 +153,7 @@ class PowerApp : public App { } } - lvgl::unlock(); + lvgl_unlock(); } public: diff --git a/Tactility/Source/app/screenshot/Screenshot.cpp b/Tactility/Source/app/screenshot/Screenshot.cpp index 80c6ee599..0d2d50b7d 100644 --- a/Tactility/Source/app/screenshot/Screenshot.cpp +++ b/Tactility/Source/app/screenshot/Screenshot.cpp @@ -7,16 +7,16 @@ #include #include #include -#include #include #include - #include #include -#include #include +#include +#include + namespace tt::app::screenshot { constexpr auto* TAG = "Screenshot"; @@ -87,10 +87,9 @@ ScreenshotApp::~ScreenshotApp() { } void ScreenshotApp::onTimerTick() { - auto lockable = lvgl::getSyncLock(); - auto lock = lockable->asScopedLock(); - if (lock.lock(lvgl::defaultLockTime)) { + if (lvgl_try_lock(500 / portTICK_PERIOD_MS)) { updateScreenshotMode(); + lvgl_unlock(); } } diff --git a/Tactility/Source/app/setup/Setup.cpp b/Tactility/Source/app/setup/Setup.cpp index 44ac8b0bf..05d39265f 100644 --- a/Tactility/Source/app/setup/Setup.cpp +++ b/Tactility/Source/app/setup/Setup.cpp @@ -4,12 +4,10 @@ #include #include #include - #include #include #include #include -#include #include #include diff --git a/Tactility/Source/app/systeminfo/SystemInfo.cpp b/Tactility/Source/app/systeminfo/SystemInfo.cpp index b6b567d84..fabade818 100644 --- a/Tactility/Source/app/systeminfo/SystemInfo.cpp +++ b/Tactility/Source/app/systeminfo/SystemInfo.cpp @@ -1,14 +1,12 @@ #include -#include #include #include #include - #include + #include #include #include -#include #include #include @@ -247,20 +245,18 @@ class SystemInfoApp final : public App { Timer memoryTimer = Timer(Timer::Type::Periodic, kernel::millisToTicks(10000), [] { auto app = optApp(); if (app) { - auto lockable = lvgl::getSyncLock(); - auto lock = lockable->asScopedLock(); - lock.lock(); + lvgl_lock(); app->updateMemory(); + lvgl_unlock(); } }); Timer tasksTimer = Timer(Timer::Type::Periodic, kernel::millisToTicks(15000), [] { auto app = optApp(); if (app) { - auto lockable = lvgl::getSyncLock(); - auto lock = lockable->asScopedLock(); - lock.lock(); + lvgl_lock(); app->updateTasks(); + lvgl_unlock(); } }); diff --git a/Tactility/Source/app/timedatesettings/TimeDateSettings.cpp b/Tactility/Source/app/timedatesettings/TimeDateSettings.cpp index ce04d3b53..c90d0cdb5 100644 --- a/Tactility/Source/app/timedatesettings/TimeDateSettings.cpp +++ b/Tactility/Source/app/timedatesettings/TimeDateSettings.cpp @@ -1,20 +1,16 @@ -#include - - #include #include #include -#include #include #include #include #include -#include - -#include #include +#include +#include + namespace tt::app::timedatesettings { constexpr auto* TAG = "TimeDate"; diff --git a/Tactility/Source/app/timezone/TimeZone.cpp b/Tactility/Source/app/timezone/TimeZone.cpp index 01d2e8f95..37ba02aa5 100644 --- a/Tactility/Source/app/timezone/TimeZone.cpp +++ b/Tactility/Source/app/timezone/TimeZone.cpp @@ -1,21 +1,20 @@ -#include -#include - #include #include #include - #include #include #include #include -#include #include #include #include + #include -#include +#include +#include +#include + #include namespace tt::app::timezone { @@ -166,16 +165,16 @@ class TimeZoneApp final : public App { } void updateList() { - if (lvgl::lock(200 / portTICK_PERIOD_MS)) { + if (lvgl_try_lock(200 / portTICK_PERIOD_MS)) { std::string filter = string::lowercase(std::string(lv_textarea_get_text(filterTextareaWidget))); - lvgl::unlock(); + lvgl_unlock(); readTimeZones(filter); } else { LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "TimeZone LVGL"); return; } - if (lvgl::lock(200 / portTICK_PERIOD_MS)) { + if (lvgl_try_lock(200 / portTICK_PERIOD_MS)) { if (mutex.lock(100 / portTICK_PERIOD_MS)) { lv_obj_clean(listWidget); @@ -188,7 +187,7 @@ class TimeZoneApp final : public App { mutex.unlock(); } - lvgl::unlock(); + lvgl_unlock(); } else { LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "TimeZone LVGL"); } diff --git a/Tactility/Source/app/webserversettings/WebServerSettings.cpp b/Tactility/Source/app/webserversettings/WebServerSettings.cpp index 030c2a9f6..f217955c3 100644 --- a/Tactility/Source/app/webserversettings/WebServerSettings.cpp +++ b/Tactility/Source/app/webserversettings/WebServerSettings.cpp @@ -2,22 +2,17 @@ #include #include -#include -#include -#include -#include -#include #include -#include +#include +#include + +#include #include -#include -#include +#include #include #include -#include -#include namespace tt::app::webserversettings { @@ -47,10 +42,9 @@ class WebServerSettingsApp final : public App { app->wsSettings.wifiMode = static_cast(index); app->updated = true; app->wifiSettingsChanged = true; - if (lvgl::lock(100)) { - app->updateUrlDisplay(); - lvgl::unlock(); - } + lvgl_lock(); + app->updateUrlDisplay(); + lvgl_unlock(); }); } @@ -60,10 +54,9 @@ class WebServerSettingsApp final : public App { getMainDispatcher().dispatch([app, enabled] { app->wsSettings.webServerEnabled = enabled; app->updated = true; - if (lvgl::lock(100)) { - app->updateUrlDisplay(); - lvgl::unlock(); - } + lvgl_lock(); + app->updateUrlDisplay(); + lvgl_unlock(); // Apply immediately instead of waiting for app exit const auto copy = app->wsSettings; diff --git a/Tactility/Source/app/wifiapsettings/WifiApSettings.cpp b/Tactility/Source/app/wifiapsettings/WifiApSettings.cpp index 052e86b6d..fc6aad7ac 100644 --- a/Tactility/Source/app/wifiapsettings/WifiApSettings.cpp +++ b/Tactility/Source/app/wifiapsettings/WifiApSettings.cpp @@ -1,20 +1,17 @@ -#include "Tactility/lvgl/LvglSync.h" - -#include #include #include #include #include #include -#include #include #include +#include +#include + #include #include -#include - namespace tt::app::wifiapsettings { constexpr auto* TAG = "WifiApSettings"; @@ -88,12 +85,9 @@ class WifiApSettings : public App { void requestViewUpdate() const { if (viewEnabled) { - if (lvgl::lock(1000)) { - updateViews(); - lvgl::unlock(); - } else { - LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL"); - } + lvgl_lock(); + updateViews(); + lvgl_unlock(); } } diff --git a/Tactility/Source/app/wificonnect/WifiConnect.cpp b/Tactility/Source/app/wificonnect/WifiConnect.cpp index eca5e4d05..89c998b41 100644 --- a/Tactility/Source/app/wificonnect/WifiConnect.cpp +++ b/Tactility/Source/app/wificonnect/WifiConnect.cpp @@ -1,12 +1,10 @@ #include -#include #include -#include #include #include -#include +#include namespace tt::app::wificonnect { @@ -68,12 +66,9 @@ void WifiConnect::unlock() { void WifiConnect::requestViewUpdate() { lock(); if (viewEnabled) { - if (lvgl::lock(1000)) { - view.update(); - lvgl::unlock(); - } else { - LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL"); - } + lvgl_lock(); + view.update(); + lvgl_unlock(); } unlock(); } diff --git a/Tactility/Source/app/wifimanage/WifiManage.cpp b/Tactility/Source/app/wifimanage/WifiManage.cpp index 0554b7344..77ea5c627 100644 --- a/Tactility/Source/app/wifimanage/WifiManage.cpp +++ b/Tactility/Source/app/wifimanage/WifiManage.cpp @@ -1,16 +1,16 @@ -#include #include +#include -#include #include #include #include -#include #include -#include #include +#include +#include + namespace tt::app::wifimanage { constexpr auto* TAG = "WifiManage"; @@ -65,12 +65,9 @@ void WifiManage::unlock() { void WifiManage::requestViewUpdate() { lock(); if (isViewEnabled) { - if (lvgl::lock(1000)) { - view.update(); - lvgl::unlock(); - } else { - LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL"); - } + lvgl_lock(); + view.update(); + lvgl_unlock(); } unlock(); } diff --git a/Tactility/Source/bluetooth/BluetoothHidHost.cpp b/Tactility/Source/bluetooth/BluetoothHidHost.cpp index e621ea0c9..07e7eef5b 100644 --- a/Tactility/Source/bluetooth/BluetoothHidHost.cpp +++ b/Tactility/Source/bluetooth/BluetoothHidHost.cpp @@ -11,7 +11,8 @@ #include #include #include -#include + +#include #include #include @@ -20,8 +21,8 @@ #include #include #include -#include -#include + +#include #include #include @@ -226,7 +227,7 @@ static void hidHostHandleMouseReport(const uint8_t* data, uint16_t len) { if (hid_host_ctx && hid_host_ctx->mouseIndev == nullptr) { getMainDispatcher().dispatch([] { if (!hid_host_ctx || hid_host_ctx->mouseIndev != nullptr) return; - if (!tt::lvgl::lock(1000)) { LOG_W(TAG, "LVGL lock failed for mouse indev"); return; } + if (!lvgl_try_lock(1000)) { LOG_W(TAG, "LVGL lock failed for mouse indev"); return; } auto* ms = lv_indev_create(); lv_indev_set_type(ms, LV_INDEV_TYPE_POINTER); lv_indev_set_read_cb(ms, hidHostMouseReadCb); @@ -237,7 +238,7 @@ static void hidHostHandleMouseReport(const uint8_t* data, uint16_t len) { lv_indev_set_cursor(ms, cur); hid_host_ctx->mouseIndev = ms; hid_host_ctx->mouseCursor = cur; - tt::lvgl::unlock(); + lvgl_unlock(); LOG_I(TAG, "Mouse indev registered"); }); } @@ -468,13 +469,13 @@ static void hidHostSubscribeNext(HidHostCtx& ctx) { } getMainDispatcher().dispatch([] { if (!hid_host_ctx || hid_host_ctx->kbIndev != nullptr) return; - if (!tt::lvgl::lock(1000)) { LOG_W(TAG, "LVGL lock failed for kb indev"); return; } + if (!lvgl_try_lock(1000)) { LOG_W(TAG, "LVGL lock failed for kb indev"); return; } auto* kb = lv_indev_create(); lv_indev_set_type(kb, LV_INDEV_TYPE_KEYPAD); lv_indev_set_read_cb(kb, hidHostKeyboardReadCb); hid_host_ctx->kbIndev = kb; - tt::lvgl::hardware_keyboard_set_indev(kb); - tt::lvgl::unlock(); + lvgl::hardware_keyboard_set_indev(kb); + lvgl_unlock(); LOG_I(TAG, "Keyboard indev registered"); }); @@ -694,18 +695,18 @@ static int hidHostGapCb(struct ble_gap_event* event, void* /*arg*/) { } getMainDispatcher().dispatch([saved_kb, saved_mouse, saved_cursor, saved_queue] { - if (!tt::lvgl::lock(1000)) { + if (!lvgl_try_lock(1000)) { LOG_W(TAG, "Failed to acquire LVGL lock for indev cleanup"); if (saved_queue) vQueueDelete(saved_queue); return; } if (saved_kb) { - tt::lvgl::hardware_keyboard_set_indev(nullptr); + lvgl::hardware_keyboard_set_indev(nullptr); lv_indev_delete(saved_kb); } if (saved_mouse) lv_indev_delete(saved_mouse); if (saved_cursor) lv_obj_delete(saved_cursor); - tt::lvgl::unlock(); + lvgl_unlock(); if (saved_queue) vQueueDelete(saved_queue); }); break; diff --git a/Tactility/Source/lvgl/LvglSync.cpp b/Tactility/Source/lvgl/LvglSync.cpp deleted file mode 100644 index 72d6c59af..000000000 --- a/Tactility/Source/lvgl/LvglSync.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "Tactility/lvgl/LvglSync.h" - -#include -#include - -namespace tt::lvgl { - -bool lock(TickType_t timeout) { - return lvgl_try_lock(timeout); -} - -void unlock() { - lvgl_unlock(); -} - -class LvglSync : public Lock { -public: - ~LvglSync() override = default; - - bool lock(TickType_t timeoutTicks) const override { - return lvgl_try_lock(timeoutTicks); - } - - void unlock() const override { - lvgl_unlock(); - } -}; - -static std::shared_ptr lvglSync = std::make_shared(); - -std::shared_ptr getSyncLock() { - return lvglSync; -} - -} // namespace diff --git a/Tactility/Source/lvgl/Statusbar.cpp b/Tactility/Source/lvgl/Statusbar.cpp index febd3b0f7..0d964eecd 100644 --- a/Tactility/Source/lvgl/Statusbar.cpp +++ b/Tactility/Source/lvgl/Statusbar.cpp @@ -5,17 +5,16 @@ #include #include #include -#include #include #include #include -#include -#include #include #include -#include +#include +#include + #include namespace tt::lvgl { @@ -106,10 +105,10 @@ static lv_obj_class_t statusbar_class = { static void statusbar_pubsub_event(Statusbar* statusbar) { LOG_D(TAG, "Update event"); - if (lock(defaultLockTime)) { + if (lvgl_try_lock(500 / portTICK_PERIOD_MS)) { update_main(statusbar); lv_obj_invalidate(&statusbar->obj); - unlock(); + lvgl_unlock(); } else { LOG_W(TAG, "Mutex acquisition timeout (%s)", "Statusbar"); } diff --git a/Tactility/Source/lvgl/UsbHidInput.cpp b/Tactility/Source/lvgl/UsbHidInput.cpp index dae388b09..5f2b6f6d8 100644 --- a/Tactility/Source/lvgl/UsbHidInput.cpp +++ b/Tactility/Source/lvgl/UsbHidInput.cpp @@ -2,10 +2,8 @@ #ifdef ESP_PLATFORM -#include #include #include -#include #include #include @@ -16,7 +14,9 @@ #include #include -#include +#include + +#include namespace tt::lvgl { @@ -148,33 +148,31 @@ static void usbHidInputTask(void* arg) { auto* ctx = static_cast(arg); LOG_I(TAG, "started"); + // TODO: Implement time-out while (!lv_is_initialized()) { vTaskDelay(pdMS_TO_TICKS(100)); } - if (lock()) { - ctx->mouse_cursor = lv_image_create(lv_layer_sys()); - lv_obj_remove_flag(ctx->mouse_cursor, LV_OBJ_FLAG_CLICKABLE); - lv_image_set_src(ctx->mouse_cursor, TT_ASSETS_UI_CURSOR); - lv_obj_add_flag(ctx->mouse_cursor, LV_OBJ_FLAG_HIDDEN); + lvgl_lock(); - ctx->mouse_indev = lv_indev_create(); - lv_indev_set_type(ctx->mouse_indev, LV_INDEV_TYPE_POINTER); - lv_indev_set_read_cb(ctx->mouse_indev, mouse_read_cb); - lv_indev_set_user_data(ctx->mouse_indev, ctx); - lv_indev_set_cursor(ctx->mouse_indev, ctx->mouse_cursor); + ctx->mouse_cursor = lv_image_create(lv_layer_sys()); + lv_obj_remove_flag(ctx->mouse_cursor, LV_OBJ_FLAG_CLICKABLE); + lv_image_set_src(ctx->mouse_cursor, TT_ASSETS_UI_CURSOR); + lv_obj_add_flag(ctx->mouse_cursor, LV_OBJ_FLAG_HIDDEN); - ctx->kb_indev = lv_indev_create(); - lv_indev_set_type(ctx->kb_indev, LV_INDEV_TYPE_KEYPAD); - lv_indev_set_read_cb(ctx->kb_indev, keyboard_read_cb); - lv_indev_set_user_data(ctx->kb_indev, ctx); - lv_indev_set_group(ctx->kb_indev, lv_group_get_default()); + ctx->mouse_indev = lv_indev_create(); + lv_indev_set_type(ctx->mouse_indev, LV_INDEV_TYPE_POINTER); + lv_indev_set_read_cb(ctx->mouse_indev, mouse_read_cb); + lv_indev_set_user_data(ctx->mouse_indev, ctx); + lv_indev_set_cursor(ctx->mouse_indev, ctx->mouse_cursor); - unlock(); - LOG_I(TAG, "LVGL input devices registered"); - } else { - LOG_W(TAG, "could not acquire LVGL lock for indev registration"); - } + ctx->kb_indev = lv_indev_create(); + lv_indev_set_type(ctx->kb_indev, LV_INDEV_TYPE_KEYPAD); + lv_indev_set_read_cb(ctx->kb_indev, keyboard_read_cb); + lv_indev_set_user_data(ctx->kb_indev, ctx); + lv_indev_set_group(ctx->kb_indev, lv_group_get_default()); + + lvgl_unlock(); // Drain the HID event queue and route events to the appropriate destinations while (ctx->running) { @@ -228,29 +226,29 @@ static void usbHidInputTask(void* arg) { break; } case USB_HID_EVENT_KEYBOARD_CONNECTED: - if (ctx->kb_indev && lock(pdMS_TO_TICKS(200))) { + if (ctx->kb_indev && lvgl_try_lock(pdMS_TO_TICKS(200))) { hardware_keyboard_set_indev(ctx->kb_indev); - unlock(); + lvgl_unlock(); } break; case USB_HID_EVENT_KEYBOARD_DISCONNECTED: - if (lock(pdMS_TO_TICKS(200))) { + if (lvgl_try_lock(pdMS_TO_TICKS(200))) { hardware_keyboard_set_indev(nullptr); - unlock(); + lvgl_unlock(); } break; case USB_HID_EVENT_MOUSE_CONNECTED: ctx->mouse_connected = true; - if (ctx->mouse_cursor && lock(pdMS_TO_TICKS(200))) { + if (ctx->mouse_cursor && lvgl_try_lock(pdMS_TO_TICKS(200))) { lv_obj_remove_flag(ctx->mouse_cursor, LV_OBJ_FLAG_HIDDEN); - unlock(); + lvgl_unlock(); } break; case USB_HID_EVENT_MOUSE_DISCONNECTED: ctx->mouse_connected = false; - if (ctx->mouse_cursor && lock(pdMS_TO_TICKS(200))) { + if (ctx->mouse_cursor && lvgl_try_lock(pdMS_TO_TICKS(200))) { lv_obj_add_flag(ctx->mouse_cursor, LV_OBJ_FLAG_HIDDEN); - unlock(); + lvgl_unlock(); } break; default: @@ -258,16 +256,15 @@ static void usbHidInputTask(void* arg) { } } - if (lock()) { - if (ctx->mouse_indev) { lv_indev_delete(ctx->mouse_indev); ctx->mouse_indev = nullptr; } - if (ctx->mouse_cursor) { lv_obj_delete(ctx->mouse_cursor); ctx->mouse_cursor = nullptr; } - if (ctx->kb_indev) { - hardware_keyboard_set_indev(nullptr); - lv_indev_delete(ctx->kb_indev); - ctx->kb_indev = nullptr; - } - unlock(); + lvgl_lock(); + if (ctx->mouse_indev) { lv_indev_delete(ctx->mouse_indev); ctx->mouse_indev = nullptr; } + if (ctx->mouse_cursor) { lv_obj_delete(ctx->mouse_cursor); ctx->mouse_cursor = nullptr; } + if (ctx->kb_indev) { + hardware_keyboard_set_indev(nullptr); + lv_indev_delete(ctx->kb_indev); + ctx->kb_indev = nullptr; } + lvgl_unlock(); LOG_I(TAG, "stopped"); xSemaphoreGive(ctx->task_done); @@ -334,7 +331,7 @@ void stopUsbHidInput() { vTaskDelete(ctx->task); // Task was killed before it could clean up LVGL objects; do it here to // prevent mouse_read_cb / keyboard_read_cb from running with a freed ctx. - if (lock(pdMS_TO_TICKS(200))) { + if (lvgl_try_lock(pdMS_TO_TICKS(200))) { if (ctx->mouse_indev) { lv_indev_delete(ctx->mouse_indev); ctx->mouse_indev = nullptr; } if (ctx->mouse_cursor) { lv_obj_delete(ctx->mouse_cursor); ctx->mouse_cursor = nullptr; } if (ctx->kb_indev) { @@ -342,7 +339,7 @@ void stopUsbHidInput() { lv_indev_delete(ctx->kb_indev); ctx->kb_indev = nullptr; } - unlock(); + lvgl_unlock(); } } ctx->task = nullptr; diff --git a/Tactility/Source/service/gui/GuiService.cpp b/Tactility/Source/service/gui/GuiService.cpp index b1029693e..2fe0a1896 100644 --- a/Tactility/Source/service/gui/GuiService.cpp +++ b/Tactility/Source/service/gui/GuiService.cpp @@ -1,19 +1,18 @@ #include - -#include - #include #include #include -#include #include #include #include #include #include + #include +#include + namespace tt::service::gui { extern const ServiceManifest manifest; diff --git a/Tactility/Source/service/gui/Keyboard.cpp b/Tactility/Source/service/gui/Keyboard.cpp index e2d58423a..4ba60c229 100644 --- a/Tactility/Source/service/gui/Keyboard.cpp +++ b/Tactility/Source/service/gui/Keyboard.cpp @@ -1,11 +1,12 @@ -#include "Tactility/lvgl/Keyboard.h" -#include "Tactility/lvgl/LvglSync.h" -#include "Tactility/service/gui/GuiService.h" - -#include +#include +#include #include #include +#include + +#include + namespace tt::service::gui { static void show_keyboard(lv_event_t* event) { @@ -53,7 +54,7 @@ void GuiService::keyboardAddTextArea(lv_obj_t* textarea) { lock(); if (isStarted) { - check(lvgl::lock(0), "lvgl should already be locked before calling this method"); + check(lvgl_try_lock(0), "lvgl should already be locked before calling this method"); if (softwareKeyboardIsEnabled()) { lv_obj_add_event_cb(textarea, show_keyboard, LV_EVENT_FOCUSED, nullptr); @@ -66,7 +67,7 @@ void GuiService::keyboardAddTextArea(lv_obj_t* textarea) { lvgl::software_keyboard_activate(keyboardGroup); } - lvgl::unlock(); + lvgl_unlock(); } unlock(); diff --git a/Tactility/Source/service/screenshot/ScreenshotTask.cpp b/Tactility/Source/service/screenshot/ScreenshotTask.cpp index 93d23381f..b91b088da 100644 --- a/Tactility/Source/service/screenshot/ScreenshotTask.cpp +++ b/Tactility/Source/service/screenshot/ScreenshotTask.cpp @@ -5,16 +5,17 @@ #include #include #include -#include #include #include +#include + +#include + #include #include -#include - namespace tt::service::screenshot { constexpr auto* TAG = "ScreenshotTask"; @@ -50,13 +51,13 @@ void ScreenshotTask::setFinished() { } static void makeScreenshot(const std::string& filename) { - if (lvgl::lock(50 / portTICK_PERIOD_MS)) { + if (lvgl_try_lock(50 / portTICK_PERIOD_MS)) { if (lv_screenshot_create(lv_scr_act(), LV_100ASK_SCREENSHOT_SV_PNG, filename.c_str())) { LOG_I(TAG, "Screenshot saved to %s", filename.c_str()); } else { LOG_E(TAG, "Screenshot not saved to %s", filename.c_str()); } - lvgl::unlock(); + lvgl_unlock(); } else { LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL"); } diff --git a/Tactility/Source/service/statusbar/Statusbar.cpp b/Tactility/Source/service/statusbar/Statusbar.cpp index 72ee15d17..ac0f3fa4f 100644 --- a/Tactility/Source/service/statusbar/Statusbar.cpp +++ b/Tactility/Source/service/statusbar/Statusbar.cpp @@ -3,11 +3,11 @@ #include #include #include -#include #include #include #include #include + #include #include #include @@ -18,7 +18,6 @@ #include #include #include - #include #include diff --git a/Tactility/Source/service/webserver/WebServerService.cpp b/Tactility/Source/service/webserver/WebServerService.cpp index a5ddfc877..6c6a62c11 100644 --- a/Tactility/Source/service/webserver/WebServerService.cpp +++ b/Tactility/Source/service/webserver/WebServerService.cpp @@ -1,8 +1,6 @@ #ifdef ESP_PLATFORM -#include #include -#include #include #include #include @@ -10,28 +8,29 @@ #include #include +#include + #include #include #include #include #include -#include #include #include #include -#include #include #include -#include #include +#include + +#include +#include #if TT_FEATURE_SCREENSHOT_ENABLED #include #endif -#include - #include #include #include @@ -42,16 +41,16 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include -#include - namespace tt::service::webserver { constexpr auto* TAG = "WebServerService"; @@ -1477,9 +1476,9 @@ esp_err_t WebServerService::handleApiScreenshot(httpd_req_t* request) { std::string lvgl_screenshot_path = lvgl::PATH_PREFIX + screenshot_path; // Capture screenshot using LVGL - if (lvgl::lock(pdMS_TO_TICKS(100))) { + if (lvgl_try_lock(pdMS_TO_TICKS(100))) { bool success = lv_screenshot_create(lv_scr_act(), LV_100ASK_SCREENSHOT_SV_PNG, lvgl_screenshot_path.c_str()); - lvgl::unlock(); + lvgl_unlock(); if (!success) { LOG_E(TAG, "lv_screenshot_create failed for path: %s", lvgl_screenshot_path.c_str());