diff --git a/Tactility/Source/app/alertdialog/AlertDialog.cpp b/Tactility/Source/app/alertdialog/AlertDialog.cpp index d1d457e8..979212df 100644 --- a/Tactility/Source/app/alertdialog/AlertDialog.cpp +++ b/Tactility/Source/app/alertdialog/AlertDialog.cpp @@ -52,9 +52,8 @@ class AlertDialogApp : public App { private: static void onButtonClickedCallback(lv_event_t* e) { - auto appContext = service::loader::getCurrentAppContext(); - assert(appContext != nullptr); - auto app = std::static_pointer_cast(appContext->getApp()); + auto app = std::static_pointer_cast(getCurrentApp()); + assert(app != nullptr); app->onButtonClicked(e); } diff --git a/Tactility/Source/app/gpio/Gpio.cpp b/Tactility/Source/app/gpio/Gpio.cpp index a9bb40bf..9adf4489 100644 --- a/Tactility/Source/app/gpio/Gpio.cpp +++ b/Tactility/Source/app/gpio/Gpio.cpp @@ -80,7 +80,7 @@ lv_obj_t* GpioApp::createGpioRowWrapper(lv_obj_t* parent) { // region Task void GpioApp::onTimer(TT_UNUSED std::shared_ptr context) { - auto appContext = service::loader::getCurrentAppContext(); + auto appContext = getCurrentAppContext(); if (appContext->getManifest().id == manifest.id) { auto app = std::static_pointer_cast(appContext->getApp()); if (app != nullptr) { diff --git a/Tactility/Source/app/i2cscanner/I2cScanner.cpp b/Tactility/Source/app/i2cscanner/I2cScanner.cpp index f356e41f..63e643df 100644 --- a/Tactility/Source/app/i2cscanner/I2cScanner.cpp +++ b/Tactility/Source/app/i2cscanner/I2cScanner.cpp @@ -72,7 +72,7 @@ public: /** Returns the app data if the app is active. Note that this could clash if the same app is started twice and a background thread is slow. */ std::shared_ptr _Nullable optApp() { - auto appContext = service::loader::getCurrentAppContext(); + auto appContext = getCurrentAppContext(); if (appContext != nullptr && appContext->getManifest().id == manifest.id) { return std::static_pointer_cast(appContext->getApp()); } else { diff --git a/Tactility/Source/app/inputdialog/InputDialog.cpp b/Tactility/Source/app/inputdialog/InputDialog.cpp index 9da57738..749b11a6 100644 --- a/Tactility/Source/app/inputdialog/InputDialog.cpp +++ b/Tactility/Source/app/inputdialog/InputDialog.cpp @@ -58,9 +58,8 @@ private: } static void onButtonClickedCallback(lv_event_t* e) { - auto appContext = service::loader::getCurrentAppContext(); - assert(appContext != nullptr); - auto app = std::static_pointer_cast(appContext->getApp()); + auto app = std::static_pointer_cast(getCurrentApp()); + assert(app != nullptr); app->onButtonClicked(e); } diff --git a/Tactility/Source/app/power/Power.cpp b/Tactility/Source/app/power/Power.cpp index 1a87201b..c2485a38 100644 --- a/Tactility/Source/app/power/Power.cpp +++ b/Tactility/Source/app/power/Power.cpp @@ -21,7 +21,7 @@ class PowerApp; /** Returns the app data if the app is active. Note that this could clash if the same app is started twice and a background thread is slow. */ std::shared_ptr _Nullable optApp() { - auto appContext = service::loader::getCurrentAppContext(); + auto appContext = getCurrentAppContext(); if (appContext != nullptr && appContext->getManifest().id == manifest.id) { return std::static_pointer_cast(appContext->getApp()); } else { diff --git a/Tactility/Source/app/screenshot/Screenshot.cpp b/Tactility/Source/app/screenshot/Screenshot.cpp index 1a7d1939..382c0b72 100644 --- a/Tactility/Source/app/screenshot/Screenshot.cpp +++ b/Tactility/Source/app/screenshot/Screenshot.cpp @@ -21,7 +21,7 @@ namespace tt::app::screenshot { extern const AppManifest manifest; -class ScreenshotApp : public App { +class ScreenshotApp final : public App { lv_obj_t* modeDropdown = nullptr; lv_obj_t* pathTextArea = nullptr; @@ -39,7 +39,7 @@ class ScreenshotApp : public App { public: ScreenshotApp(); - ~ScreenshotApp(); + ~ScreenshotApp() final; void onShow(AppContext& app, lv_obj_t* parent) override; void onStartPressed(); @@ -50,7 +50,7 @@ public: /** Returns the app data if the app is active. Note that this could clash if the same app is started twice and a background thread is slow. */ std::shared_ptr _Nullable optApp() { - auto appContext = service::loader::getCurrentAppContext(); + auto appContext = getCurrentAppContext(); if (appContext != nullptr && appContext->getManifest().id == manifest.id) { return std::static_pointer_cast(appContext->getApp()); } else { diff --git a/Tactility/Source/app/selectiondialog/SelectionDialog.cpp b/Tactility/Source/app/selectiondialog/SelectionDialog.cpp index 6b55575a..16c8bec4 100644 --- a/Tactility/Source/app/selectiondialog/SelectionDialog.cpp +++ b/Tactility/Source/app/selectiondialog/SelectionDialog.cpp @@ -49,9 +49,8 @@ class SelectionDialogApp : public App { private: static void onListItemSelectedCallback(lv_event_t* e) { - auto appContext = service::loader::getCurrentAppContext(); - assert(appContext != nullptr); - auto app = std::static_pointer_cast(appContext->getApp()); + auto app = std::static_pointer_cast(getCurrentApp()); + assert(app != nullptr); app->onListItemSelected(e); } diff --git a/Tactility/Source/app/timezone/TimeZone.cpp b/Tactility/Source/app/timezone/TimeZone.cpp index aa46cace..efc19ce3 100644 --- a/Tactility/Source/app/timezone/TimeZone.cpp +++ b/Tactility/Source/app/timezone/TimeZone.cpp @@ -93,11 +93,9 @@ private: static void onListItemSelectedCallback(lv_event_t* e) { auto index = reinterpret_cast(lv_event_get_user_data(e)); - auto appContext = service::loader::getCurrentAppContext(); - if (appContext != nullptr && appContext->getManifest().id == manifest.id) { - auto app = std::static_pointer_cast(appContext->getApp()); - app->onListItemSelected(index); - } + auto app = std::static_pointer_cast(getCurrentApp()); + assert(app != nullptr); + app->onListItemSelected(index); } void onListItemSelected(std::size_t index) { @@ -120,7 +118,7 @@ private: } static void updateTimerCallback(std::shared_ptr context) { - auto appContext = service::loader::getCurrentAppContext(); + auto appContext = getCurrentAppContext(); if (appContext != nullptr && appContext->getManifest().id == manifest.id) { auto app = std::static_pointer_cast(appContext->getApp()); app->updateList(); diff --git a/Tactility/Source/app/wifiapsettings/WifiApSettings.cpp b/Tactility/Source/app/wifiapsettings/WifiApSettings.cpp index 3cde25d4..a30e0d38 100644 --- a/Tactility/Source/app/wifiapsettings/WifiApSettings.cpp +++ b/Tactility/Source/app/wifiapsettings/WifiApSettings.cpp @@ -1,10 +1,11 @@ #include "Tactility/app/wifiapsettings/WifiApSettings.h" +#include "Tactility/app/App.h" #include "Tactility/app/AppContext.h" +#include "Tactility/app/AppManifest.h" #include "Tactility/app/alertdialog/AlertDialog.h" #include "Tactility/lvgl/Style.h" #include "Tactility/lvgl/Toolbar.h" -#include "Tactility/service/loader/Loader.h" #include #include @@ -17,20 +18,10 @@ namespace tt::app::wifiapsettings { extern const AppManifest manifest; -/** Returns the app data if the app is active. Note that this could clash if the same app is started twice and a background thread is slow. */ -const std::shared_ptr _Nullable optWifiApSettingsApp() { - auto app = service::loader::getCurrentAppContext(); - if (app != nullptr && app->getManifest().id == manifest.id) { - return app; - } else { - return nullptr; - } -} - void start(const std::string& ssid) { auto bundle = std::make_shared(); bundle->putString("ssid", ssid); - service::loader::startApp(manifest.id, bundle); + app::start(manifest.id, bundle); } static void onPressForget(TT_UNUSED lv_event_t* event) { @@ -44,11 +35,7 @@ static void onPressForget(TT_UNUSED lv_event_t* event) { static void onToggleAutoConnect(lv_event_t* event) { lv_event_code_t code = lv_event_get_code(event); - auto app = optWifiApSettingsApp(); - if (app == nullptr) { - return; - } - + auto app = getCurrentAppContext(); auto parameters = app->getParameters(); tt_check(parameters != nullptr, "Parameters missing"); @@ -125,31 +112,28 @@ class WifiApSettings : public App { } void onResult(TT_UNUSED AppContext& appContext, TT_UNUSED Result result, std::unique_ptr bundle) override { - auto index = alertdialog::getResultIndex(*bundle); - if (index == 0) { // Yes - auto app = optWifiApSettingsApp(); - if (app == nullptr) { - return; - } + if (result == Result::Ok && bundle != nullptr) { + auto index = alertdialog::getResultIndex(*bundle); + if (index == 0) { // Yes + auto parameters = appContext.getParameters(); + tt_check(parameters != nullptr, "Parameters missing"); - auto parameters = app->getParameters(); - tt_check(parameters != nullptr, "Parameters missing"); + std::string ssid = parameters->getString("ssid"); + if (service::wifi::settings::remove(ssid.c_str())) { + TT_LOG_I(TAG, "Removed SSID"); - std::string ssid = parameters->getString("ssid"); - if (service::wifi::settings::remove(ssid.c_str())) { - TT_LOG_I(TAG, "Removed SSID"); + if ( + service::wifi::getRadioState() == service::wifi::RadioState::ConnectionActive && + service::wifi::getConnectionTarget() == ssid + ) { + service::wifi::disconnect(); + } - if ( - service::wifi::getRadioState() == service::wifi::RadioState::ConnectionActive && - service::wifi::getConnectionTarget() == ssid - ) { - service::wifi::disconnect(); + // Stop self + app::stop(); + } else { + TT_LOG_E(TAG, "Failed to remove SSID"); } - - // Stop self - service::loader::stopApp(); - } else { - TT_LOG_E(TAG, "Failed to remove SSID"); } } } diff --git a/Tactility/Source/app/wificonnect/View.cpp b/Tactility/Source/app/wificonnect/View.cpp index db995f6f..d7bb08e1 100644 --- a/Tactility/Source/app/wificonnect/View.cpp +++ b/Tactility/Source/app/wificonnect/View.cpp @@ -25,7 +25,7 @@ void View::resetErrors() { } static void onConnect(TT_UNUSED lv_event_t* event) { - auto wifi = optWifiConnect(); + auto wifi = std::static_pointer_cast(getCurrentApp()); auto& view = wifi->getView(); wifi->getState().setConnectionError(false); diff --git a/Tactility/Source/app/wificonnect/WifiConnect.cpp b/Tactility/Source/app/wificonnect/WifiConnect.cpp index de6343a0..ff17d3bc 100644 --- a/Tactility/Source/app/wificonnect/WifiConnect.cpp +++ b/Tactility/Source/app/wificonnect/WifiConnect.cpp @@ -13,16 +13,6 @@ namespace tt::app::wificonnect { extern const AppManifest manifest; -/** Returns the app data if the app is active. Note that this could clash if the same app is started twice and a background thread is slow. */ -std::shared_ptr _Nullable optWifiConnect() { - auto appContext = service::loader::getCurrentAppContext(); - if (appContext != nullptr && appContext->getManifest().id == manifest.id) { - return std::static_pointer_cast(appContext->getApp()); - } else { - return nullptr; - } -} - static void eventCallback(const void* message, void* context) { auto* event = static_cast(message); auto* wifi = static_cast(context); diff --git a/Tactility/Source/app/wifimanage/View.cpp b/Tactility/Source/app/wifimanage/View.cpp index 0eeb7e16..b4a1d39d 100644 --- a/Tactility/Source/app/wifimanage/View.cpp +++ b/Tactility/Source/app/wifimanage/View.cpp @@ -36,7 +36,7 @@ static void on_enable_switch_changed(lv_event_t* event) { if (code == LV_EVENT_VALUE_CHANGED) { bool is_on = lv_obj_has_state(enable_switch, LV_STATE_CHECKED); - auto wifi = optWifiManage(); + auto wifi = std::static_pointer_cast(getCurrentApp()); auto bindings = wifi->getBindings(); bindings.onWifiToggled(is_on); diff --git a/Tactility/Source/app/wifimanage/WifiManage.cpp b/Tactility/Source/app/wifimanage/WifiManage.cpp index ad7ec6fc..5f914867 100644 --- a/Tactility/Source/app/wifimanage/WifiManage.cpp +++ b/Tactility/Source/app/wifimanage/WifiManage.cpp @@ -14,16 +14,6 @@ namespace tt::app::wifimanage { extern const AppManifest manifest; -/** Returns the app data if the app is active. Note that this could clash if the same app is started twice and a background thread is slow. */ -std::shared_ptr _Nullable optWifiManage() { - auto appContext = service::loader::getCurrentAppContext(); - if (appContext != nullptr && appContext->getManifest().id == manifest.id) { - return std::static_pointer_cast(appContext->getApp()); - } else { - return nullptr; - } -} - static void onConnect(const char* ssid) { service::wifi::settings::WifiApSettings settings; if (service::wifi::settings::load(ssid, &settings)) { diff --git a/Tactility/Source/lvgl/Statusbar.cpp b/Tactility/Source/lvgl/Statusbar.cpp index 5fd85c2f..a9f28109 100644 --- a/Tactility/Source/lvgl/Statusbar.cpp +++ b/Tactility/Source/lvgl/Statusbar.cpp @@ -66,7 +66,7 @@ static TickType_t getNextUpdateTime() { time_t now = ::time(nullptr); struct tm* tm_struct = localtime(&now); uint32_t seconds_to_wait = 60U - tm_struct->tm_sec; - TT_LOG_I(TAG, "Update in %lu s", seconds_to_wait); + TT_LOG_D(TAG, "Update in %lu s", seconds_to_wait); return pdMS_TO_TICKS(seconds_to_wait * 1000U); } @@ -109,7 +109,7 @@ static const lv_obj_class_t statusbar_class = { }; static void statusbar_pubsub_event(TT_UNUSED const void* message, void* obj) { - TT_LOG_I(TAG, "event"); + TT_LOG_D(TAG, "event"); auto* statusbar = static_cast(obj); if (lock(kernel::millisToTicks(100))) { update_main(statusbar); @@ -167,7 +167,7 @@ lv_obj_t* statusbar_create(lv_obj_t* parent) { lv_obj_set_width(obj, LV_PCT(100)); lv_obj_set_height(obj, STATUSBAR_HEIGHT); - obj_set_style_no_padding(obj); + lv_obj_set_style_pad_all(obj, 0, 0); lv_obj_center(obj); lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_ROW); lv_obj_set_flex_align(obj, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); @@ -186,7 +186,7 @@ lv_obj_t* statusbar_create(lv_obj_t* parent) { for (int i = 0; i < STATUSBAR_ICON_LIMIT; ++i) { auto* image = lv_image_create(obj); lv_obj_set_size(image, STATUSBAR_ICON_SIZE, STATUSBAR_ICON_SIZE); - obj_set_style_no_padding(image); + lv_obj_set_style_pad_all(image, 0, 0); obj_set_style_bg_blacken(image); statusbar->icons[i] = image; @@ -242,7 +242,7 @@ int8_t statusbar_icon_add(const std::string& image) { statusbar_data.icons[i].visible = !image.empty(); statusbar_data.icons[i].image = image; result = i; - TT_LOG_I(TAG, "id %d: added", i); + TT_LOG_D(TAG, "id %d: added", i); break; } } @@ -256,7 +256,7 @@ int8_t statusbar_icon_add() { } void statusbar_icon_remove(int8_t id) { - TT_LOG_I(TAG, "id %d: remove", id); + TT_LOG_D(TAG, "id %d: remove", id); tt_check(id >= 0 && id < STATUSBAR_ICON_LIMIT); statusbar_lock(); StatusbarIcon* icon = &statusbar_data.icons[id]; @@ -268,7 +268,7 @@ void statusbar_icon_remove(int8_t id) { } void statusbar_icon_set_image(int8_t id, const std::string& image) { - TT_LOG_I(TAG, "id %d: set image %s", id, image.empty() ? "(none)" : image.c_str()); + TT_LOG_D(TAG, "id %d: set image %s", id, image.empty() ? "(none)" : image.c_str()); tt_check(id >= 0 && id < STATUSBAR_ICON_LIMIT); if (statusbar_lock(50 / portTICK_PERIOD_MS)) { StatusbarIcon* icon = &statusbar_data.icons[id]; @@ -280,7 +280,7 @@ void statusbar_icon_set_image(int8_t id, const std::string& image) { } void statusbar_icon_set_visibility(int8_t id, bool visible) { - TT_LOG_I(TAG, "id %d: set visibility %d", id, visible); + TT_LOG_D(TAG, "id %d: set visibility %d", id, visible); tt_check(id >= 0 && id < STATUSBAR_ICON_LIMIT); if (statusbar_lock(50 / portTICK_PERIOD_MS)) { StatusbarIcon* icon = &statusbar_data.icons[id]; diff --git a/Tactility/Source/service/gui/Gui.cpp b/Tactility/Source/service/gui/Gui.cpp index 152b22ce..4460cd52 100644 --- a/Tactility/Source/service/gui/Gui.cpp +++ b/Tactility/Source/service/gui/Gui.cpp @@ -20,7 +20,7 @@ Gui* gui = nullptr; void onLoaderMessage(const void* message, TT_UNUSED void* context) { auto* event = static_cast(message); if (event->type == loader::LoaderEventTypeApplicationShowing) { - auto app_instance = service::loader::getCurrentAppContext(); + auto app_instance = app::getCurrentAppContext(); showApp(app_instance); } else if (event->type == loader::LoaderEventTypeApplicationHiding) { hideApp(); diff --git a/Tactility/Source/service/screenshot/ScreenshotTask.cpp b/Tactility/Source/service/screenshot/ScreenshotTask.cpp index ffbef833..a2d93bda 100644 --- a/Tactility/Source/service/screenshot/ScreenshotTask.cpp +++ b/Tactility/Source/service/screenshot/ScreenshotTask.cpp @@ -87,7 +87,7 @@ void ScreenshotTask::taskMain() { } } } else if (work.type == TASK_WORK_TYPE_APPS) { - auto appContext = loader::getCurrentAppContext(); + auto appContext = app::getCurrentAppContext(); if (appContext != nullptr) { const app::AppManifest& manifest = appContext->getManifest(); if (manifest.id != last_app_id) { diff --git a/TactilityC/Include/tt_app.h b/TactilityC/Include/tt_app.h index 413bdfda..b1e97bd2 100644 --- a/TactilityC/Include/tt_app.h +++ b/TactilityC/Include/tt_app.h @@ -29,6 +29,9 @@ bool tt_app_has_result(AppHandle handle); */ void tt_app_start(const char* appId); +/** Stop the currently running app */ +void tt_app_stop(); + /** * Start an app by id and bundle. * @param[in] appId the app manifest id diff --git a/TactilityC/Include/tt_service_loader.h b/TactilityC/Include/tt_service_loader.h deleted file mode 100644 index 688a2b68..00000000 --- a/TactilityC/Include/tt_service_loader.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include "tt_app.h" -#include "tt_bundle.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Start an application providing a manifest id and an optional bundle. - * Execution is always deferred. - * This function generally returns immediately unless the scheduler is blocked. - * @param[in] id application manifest id - * @param[in] bundle an allocated bundle (or NULL) of which the memory ownership is handed over to this function - */ -void tt_service_loader_start_app(const char* id, BundleHandle _Nullable bundle); - -/** - * Stop the currently active app. - * Execution is always deferred. - * This function generally returns immediately unless the scheduler is blocked. - */ -void tt_service_loader_stop_app(); - -/** - * Get the context handle of the app that is currently shown on the screen. - */ -AppHandle tt_service_loader_get_current_app(); - -#ifdef __cplusplus -} -#endif \ No newline at end of file diff --git a/TactilityC/Source/tt_app.cpp b/TactilityC/Source/tt_app.cpp index 44edc58a..bf770720 100644 --- a/TactilityC/Source/tt_app.cpp +++ b/TactilityC/Source/tt_app.cpp @@ -27,4 +27,8 @@ void tt_app_start_with_bundle(const char* appId, BundleHandle parameters) { tt::app::start(appId, std::shared_ptr((tt::Bundle*)parameters)); } +void tt_app_stop() { + tt::app::stop(); +} + } \ No newline at end of file diff --git a/TactilityC/Source/tt_service_loader.cpp b/TactilityC/Source/tt_service_loader.cpp deleted file mode 100644 index 92bfe6da..00000000 --- a/TactilityC/Source/tt_service_loader.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "tt_service_loader.h" -#include -#include - -extern "C" { - -void tt_service_loader_start_app(const char* id, BundleHandle _Nullable bundle) { - auto shared_bundle = std::shared_ptr((tt::Bundle*)bundle); - tt::service::loader::startApp(id, std::move(shared_bundle)); -} - -void tt_service_loader_stop_app() { - tt::service::loader::stopApp(); -} - -AppHandle tt_service_loader_get_current_app() { - return tt::service::loader::getCurrentAppContext().get(); -} - -} diff --git a/version.txt b/version.txt index 341cf11f..9325c3cc 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.2.0 \ No newline at end of file +0.3.0 \ No newline at end of file