diff --git a/Data/system/app/Desktop/icon_apps.png b/Data/system/app/Launcher/icon_apps.png similarity index 100% rename from Data/system/app/Desktop/icon_apps.png rename to Data/system/app/Launcher/icon_apps.png diff --git a/Data/system/app/Desktop/icon_files.png b/Data/system/app/Launcher/icon_files.png similarity index 100% rename from Data/system/app/Desktop/icon_files.png rename to Data/system/app/Launcher/icon_files.png diff --git a/Data/system/app/Desktop/icon_settings.png b/Data/system/app/Launcher/icon_settings.png similarity index 100% rename from Data/system/app/Desktop/icon_settings.png rename to Data/system/app/Launcher/icon_settings.png diff --git a/Documentation/ideas.md b/Documentation/ideas.md index 578a8ae5..6e44d387 100644 --- a/Documentation/ideas.md +++ b/Documentation/ideas.md @@ -10,16 +10,12 @@ - Show error in WiFi screen (e.g. AlertDialog when SPI is not enabled and available memory is below a certain amount) - Clean up static_cast when casting to base class. - M5Stack CoreS3 SD card mounts, but cannot be read. There is currently a notice about it [here](https://github.com/espressif/esp-bsp/blob/master/bsp/m5stack_core_s3/README.md). -- SD card statusbar icon shows error when there's a read timeout on the SD card status. Don't show the error icon in this scenario. - EventFlag: Fix return value of set/get/wait (the errors are weirdly mixed in) -- getConfiguration() in TT headless is a reference, while in TT main project it's a pointer. Make it a pointer for headless too. +- Consistently use either ESP_TARGET or ESP_PLATFORM # TODOs -- Tactility.h config: List of apps and services can be a std::vector (get rid of TT_CONFIG_SERVICES_LIMIT and TT_CONFIG_APPS_LIMIT) - Boot hooks instead of a single boot method in config. Define different boot phases/levels in enum. -- Rename "Desktop" to "Launcher" because it more clearly communicates its purpose - Add toggle to Display app for sysmon overlay: https://docs.lvgl.io/master/API/others/sysmon/index.html -- Mutex: Cleanup deprecated methods - CrashHandler: use "corrupted" flag - CrashHandler: process other types of crashes (WDT?) - Call tt::lvgl::isSyncSet after HAL init and show error (and crash?) when it is not set. @@ -30,7 +26,6 @@ - Audio player app - Audio recording app - T-Deck: Use knob for UI selection -- Logging to disk/etc. - Crash monitoring: Keep track of which system phase the app crashed in (e.g. which app in which state) - AppContext's onResult should pass the app id (or launch request id!) that was started, so we can differentiate between multiple types of apps being launched - Loader: Use main dispatcher instead of Thread @@ -39,7 +34,6 @@ - Show a warning screen when a user plugs in the SD card on a device that only supports mounting at boot. - Localisation of texts (load in boot app from sd?) - Explore LVGL9's FreeRTOS functionality -- Replace M5Unified and M5GFX with custom drivers (so we can fix the Core2 SD card mounting bug, and so we regain some firmware space) - External app loading: Check version of Tactility and check ESP target hardware, to check for compatibility. - Scanning SD card for external apps and auto-register them (in a temporary register?) - tt::app::start() and similar functions as proxies for Loader app start/stop/etc. @@ -57,6 +51,7 @@ - Wrapper for Slider that shows "+" and "-" buttons, and also the value in a label. - Display app: Add toggle to display performance measurement overlay (consider showing FPS in statusbar!) - Files app: copy/paste actions +- On crash, try to save current log to flash or SD card? (this is risky, though, so ask in Discord first) # App Ideas - USB implementation to make device act as mass storage device. diff --git a/Tactility/Source/Tactility.cpp b/Tactility/Source/Tactility.cpp index 087f2799..966f6767 100644 --- a/Tactility/Source/Tactility.cpp +++ b/Tactility/Source/Tactility.cpp @@ -40,7 +40,6 @@ namespace app { namespace alertdialog { extern const AppManifest manifest; } namespace applist { extern const AppManifest manifest; } namespace boot { extern const AppManifest manifest; } - namespace desktop { extern const AppManifest manifest; } namespace files { extern const AppManifest manifest; } namespace gpio { extern const AppManifest manifest; } namespace display { extern const AppManifest manifest; } @@ -48,6 +47,7 @@ namespace app { namespace i2csettings { extern const AppManifest manifest; } namespace imageviewer { extern const AppManifest manifest; } namespace inputdialog { extern const AppManifest manifest; } + namespace launcher { extern const AppManifest manifest; } namespace log { extern const AppManifest manifest; } namespace power { extern const AppManifest manifest; } namespace selectiondialog { extern const AppManifest manifest; } @@ -74,7 +74,6 @@ static const std::vector system_apps = { &app::alertdialog::manifest, &app::applist::manifest, &app::boot::manifest, - &app::desktop::manifest, &app::display::manifest, &app::files::manifest, &app::gpio::manifest, @@ -82,6 +81,7 @@ static const std::vector system_apps = { &app::i2csettings::manifest, &app::imageviewer::manifest, &app::inputdialog::manifest, + &app::launcher::manifest, &app::log::manifest, &app::settings::manifest, &app::selectiondialog::manifest, @@ -104,7 +104,7 @@ static const std::vector system_apps = { static void register_system_apps() { TT_LOG_I(TAG, "Registering default apps"); - for (const auto& app_manifest: system_apps) { + for (const auto* app_manifest: system_apps) { addApp(app_manifest); } @@ -113,16 +113,11 @@ static void register_system_apps() { } } -static void register_user_apps(const app::AppManifest* const apps[TT_CONFIG_APPS_LIMIT]) { +static void register_user_apps(const std::vector& apps) { TT_LOG_I(TAG, "Registering user apps"); - for (size_t i = 0; i < TT_CONFIG_APPS_LIMIT; i++) { - const app::AppManifest* manifest = apps[i]; - if (manifest != nullptr) { - addApp(manifest); - } else { - // reached end of list - break; - } + for (auto* manifest : apps) { + assert(manifest != nullptr); + addApp(manifest); } } @@ -134,17 +129,12 @@ static void register_and_start_system_services() { } } -static void register_and_start_user_services(const service::ServiceManifest* const services[TT_CONFIG_SERVICES_LIMIT]) { +static void register_and_start_user_services(const std::vector& services) { TT_LOG_I(TAG, "Registering and starting user services"); - for (size_t i = 0; i < TT_CONFIG_SERVICES_LIMIT; i++) { - const service::ServiceManifest* manifest = services[i]; - if (manifest != nullptr) { - addService(manifest); - tt_check(service::startService(manifest->id)); - } else { - // reached end of list - break; - } + for (auto* manifest : services) { + assert(manifest != nullptr); + addService(manifest); + tt_check(service::startService(manifest->id)); } } diff --git a/Tactility/Source/Tactility.h b/Tactility/Source/Tactility.h index 12759aff..0bb65d63 100644 --- a/Tactility/Source/Tactility.h +++ b/Tactility/Source/Tactility.h @@ -14,9 +14,9 @@ struct Configuration { /** HAL configuration (drivers) */ const hal::Configuration* hardware; /** List of user applications */ - const app::AppManifest* const apps[TT_CONFIG_APPS_LIMIT] = {}; + const std::vector apps; /** List of user services */ - const service::ServiceManifest* const services[TT_CONFIG_SERVICES_LIMIT] = {}; + const std::vector services; /** Optional app to start automatically after the splash screen. */ const char* _Nullable autoStartAppId = nullptr; }; diff --git a/Tactility/Source/TactilityConfig.h b/Tactility/Source/TactilityConfig.h index d554942e..7d84071a 100644 --- a/Tactility/Source/TactilityConfig.h +++ b/Tactility/Source/TactilityConfig.h @@ -4,9 +4,6 @@ #include "sdkconfig.h" #endif -#include "TactilityHeadlessConfig.h" - -#define TT_CONFIG_APPS_LIMIT 32 #define TT_CONFIG_FORCE_ONSCREEN_KEYBOARD false // for development/debug purposes #define TT_SCREENSHOT_MODE false // for taking screenshots (e.g. forces SD card presence and Files tree on simulator) diff --git a/Tactility/Source/app/AppManifest.h b/Tactility/Source/app/AppManifest.h index 4c5e10ae..f8579111 100644 --- a/Tactility/Source/app/AppManifest.h +++ b/Tactility/Source/app/AppManifest.h @@ -15,8 +15,8 @@ class AppContext; enum Type { /** Boot screen, shown before desktop is launched. */ TypeBoot, - /** A desktop app sits at the root of the app stack managed by the Loader service */ - TypeDesktop, + /** A launcher app sits at the root of the app stack after the boot splash is finished */ + TypeLauncher, /** Apps that generally aren't started from the desktop (e.g. image viewer) */ TypeHidden, /** Standard apps, provided by the system. */ diff --git a/Tactility/Source/app/boot/Boot.cpp b/Tactility/Source/app/boot/Boot.cpp index a48ba056..36645524 100644 --- a/Tactility/Source/app/boot/Boot.cpp +++ b/Tactility/Source/app/boot/Boot.cpp @@ -1,8 +1,8 @@ -#include "Assets.h" #include "TactilityCore.h" #include "app/AppContext.h" #include "app/display/DisplaySettings.h" +#include "app/launcher/Launcher.h" #include "hal/Display.h" #include "service/loader/Loader.h" #include "lvgl/Style.h" @@ -14,6 +14,7 @@ #ifdef ESP_PLATFORM #include "kernel/PanicHandler.h" #include "sdkconfig.h" +#include "app/crashdiagnostics/CrashDiagnostics.h" #else #define CONFIG_TT_SPLASH_DURATION 0 #endif @@ -62,32 +63,29 @@ static int32_t bootThreadCallback(TT_UNUSED void* context) { return 0; } -static void startNextApp() { - auto config = tt::getConfiguration(); - std::string next_app; - if (config->autoStartAppId) { - TT_LOG_I(TAG, "init auto-starting %s", config->autoStartAppId); - next_app = config->autoStartAppId; - } else { - next_app = "Desktop"; - } +static void startNextApp() { #ifdef ESP_PLATFORM esp_reset_reason_t reason = esp_reset_reason(); if (reason == ESP_RST_PANIC) { - tt::service::loader::startApp("CrashDiagnostics"); - } else { - tt::service::loader::startApp(next_app); + app::crashdiagnostics::start(); + return; } -#else - tt::service::loader::startApp(next_app); #endif + + auto* config = tt::getConfiguration(); + if (config->autoStartAppId) { + TT_LOG_I(TAG, "init auto-starting %s", config->autoStartAppId); + tt::service::loader::startApp(config->autoStartAppId); + } else { + app::launcher::start(); + } } static void onShow(TT_UNUSED AppContext& app, lv_obj_t* parent) { auto data = std::static_pointer_cast(app.getData()); - lv_obj_t* image = lv_image_create(parent); + auto* image = lv_image_create(parent); lv_obj_set_size(image, LV_PCT(100), LV_PCT(100)); auto paths = app.getPaths(); diff --git a/Tactility/Source/app/crashdiagnostics/CrashDiagnostics.cpp b/Tactility/Source/app/crashdiagnostics/CrashDiagnostics.cpp index 31618d10..397a4fae 100644 --- a/Tactility/Source/app/crashdiagnostics/CrashDiagnostics.cpp +++ b/Tactility/Source/app/crashdiagnostics/CrashDiagnostics.cpp @@ -1,12 +1,12 @@ -#ifdef ESP_PLATFORM +#ifdef ESP_TARGET -#include #include "lvgl.h" #include "lvgl/Statusbar.h" -#include "service/loader/Loader.h" +#include "app/launcher/Launcher.h" #include "qrcode.h" #include "QrHelpers.h" #include "QrUrl.h" +#include "service/loader/Loader.h" #define TAG "crash_diagnostics" @@ -14,10 +14,10 @@ namespace tt::app::crashdiagnostics { void onContinuePressed(TT_UNUSED lv_event_t* event) { tt::service::loader::stopApp(); - tt::service::loader::startApp("Desktop"); + tt::app::launcher::start(); } -static void onShow(TT_UNUSED AppContext& app, lv_obj_t* parent) { +static void onShow(AppContext& app, lv_obj_t* parent) { auto* display = lv_obj_get_display(parent); int32_t parent_height = lv_display_get_vertical_resolution(display) - STATUSBAR_HEIGHT; @@ -116,6 +116,10 @@ extern const AppManifest manifest = { .onShow = onShow }; +void start() { + service::loader::startApp(manifest.id); +} + } // namespace #endif \ No newline at end of file diff --git a/Tactility/Source/app/crashdiagnostics/CrashDiagnostics.h b/Tactility/Source/app/crashdiagnostics/CrashDiagnostics.h new file mode 100644 index 00000000..ebea78e0 --- /dev/null +++ b/Tactility/Source/app/crashdiagnostics/CrashDiagnostics.h @@ -0,0 +1,11 @@ +#pragma once + +#ifdef ESP_TARGET + +namespace tt::app::crashdiagnostics { + +void start(); + +} + +#endif diff --git a/Tactility/Source/app/desktop/Desktop.cpp b/Tactility/Source/app/launcher/Launcher.cpp similarity index 92% rename from Tactility/Source/app/desktop/Desktop.cpp rename to Tactility/Source/app/launcher/Launcher.cpp index 8ca12a4e..d65927bb 100644 --- a/Tactility/Source/app/desktop/Desktop.cpp +++ b/Tactility/Source/app/launcher/Launcher.cpp @@ -5,7 +5,7 @@ #include "service/loader/Loader.h" #include "Assets.h" -namespace tt::app::desktop { +namespace tt::app::launcher { static void onAppPressed(TT_UNUSED lv_event_t* e) { auto* appId = (const char*)lv_event_get_user_data(e); @@ -33,6 +33,8 @@ static lv_obj_t* createAppButton(lv_obj_t* parent, const char* title, const char lv_obj_add_event_cb(apps_button, onAppPressed, LV_EVENT_SHORT_CLICKED, (void*)appId); lv_obj_set_style_image_recolor(button_image, lv_theme_get_color_primary(parent), 0); lv_obj_set_style_image_recolor_opa(button_image, LV_OPA_COVER, 0); + // Ensure buttons are still tappable when asset fails to load + lv_obj_set_size(button_image, 64, 64); auto* label = lv_label_create(wrapper); lv_label_set_text(label, title); @@ -73,10 +75,14 @@ static void onShow(TT_UNUSED AppContext& app, lv_obj_t* parent) { } extern const AppManifest manifest = { - .id = "Desktop", - .name = "Desktop", - .type = TypeDesktop, + .id = "Launcher", + .name = "Launcher", + .type = TypeLauncher, .onShow = onShow, }; +void start() { + service::loader::startApp(manifest.id); +} + } // namespace diff --git a/Tactility/Source/app/launcher/Launcher.h b/Tactility/Source/app/launcher/Launcher.h new file mode 100644 index 00000000..31e8d452 --- /dev/null +++ b/Tactility/Source/app/launcher/Launcher.h @@ -0,0 +1,7 @@ +#pragma once + +namespace tt::app::launcher { + +void start(); + +} diff --git a/Tactility/Source/app/screenshot/ScreenshotUi.cpp b/Tactility/Source/app/screenshot/ScreenshotUi.cpp index 07cc69b6..4ff85935 100644 --- a/Tactility/Source/app/screenshot/ScreenshotUi.cpp +++ b/Tactility/Source/app/screenshot/ScreenshotUi.cpp @@ -176,7 +176,7 @@ void ScreenshotUi::createFilePathWidgets(lv_obj_t* parent) { lv_textarea_set_one_line(pathTextArea, true); lv_obj_set_flex_grow(pathTextArea, 1); if (kernel::getPlatform() == kernel::PlatformEsp) { - auto sdcard = tt::hal::getConfiguration().sdcard; + auto sdcard = tt::hal::getConfiguration()->sdcard; if (sdcard != nullptr && sdcard->getState() == hal::SdCard::StateMounted) { lv_textarea_set_text(pathTextArea, "A:/sdcard"); } else { diff --git a/Tactility/Source/service/statusbar/Statusbar.cpp b/Tactility/Source/service/statusbar/Statusbar.cpp index 0ac2085b..a2d74695 100644 --- a/Tactility/Source/service/statusbar/Statusbar.cpp +++ b/Tactility/Source/service/statusbar/Statusbar.cpp @@ -132,20 +132,19 @@ static const char* getSdCardStatusIcon(hal::SdCard::State state) { } static void updateSdCardIcon(const service::Paths* paths, const std::shared_ptr& data) { - auto sdcard = tt::hal::getConfiguration().sdcard; + auto sdcard = tt::hal::getConfiguration()->sdcard; if (sdcard != nullptr) { auto state = sdcard->getState(); - const char* desired_icon = getSdCardStatusIcon(state); - if (data->sdcard_last_icon != desired_icon) { - if (desired_icon != nullptr) { + if (state != hal::SdCard::StateUnknown) { + auto* desired_icon = getSdCardStatusIcon(state); + if (data->sdcard_last_icon != desired_icon) { auto icon_path = paths->getSystemPathLvgl(desired_icon); lvgl::statusbar_icon_set_image(data->sdcard_icon_id, icon_path); lvgl::statusbar_icon_set_visibility(data->sdcard_icon_id, true); - } else { - lvgl::statusbar_icon_set_visibility(data->sdcard_icon_id, false); + data->sdcard_last_icon = desired_icon; } - data->sdcard_last_icon = desired_icon; } + // TODO: Consider tracking how long the SD card has been in unknown status and then show error } } diff --git a/TactilityCore/Source/Mutex.cpp b/TactilityCore/Source/Mutex.cpp index 031ecabc..1f170e4a 100644 --- a/TactilityCore/Source/Mutex.cpp +++ b/TactilityCore/Source/Mutex.cpp @@ -106,24 +106,4 @@ ThreadId Mutex::getOwner() const { return (ThreadId)xSemaphoreGetMutexHolder(semaphore); } -Mutex* tt_mutex_alloc(Mutex::Type type) { - return new Mutex(type); -} - -void tt_mutex_free(Mutex* mutex) { - delete mutex; -} - -TtStatus tt_mutex_acquire(Mutex* mutex, TickType_t timeout) { - return mutex-> acquire(timeout); -} - -TtStatus tt_mutex_release(Mutex* mutex) { - return mutex->release(); -} - -ThreadId tt_mutex_get_owner(Mutex* mutex) { - return mutex->getOwner(); -} - } // namespace diff --git a/TactilityCore/Source/Mutex.h b/TactilityCore/Source/Mutex.h index a7410637..4109d1ab 100644 --- a/TactilityCore/Source/Mutex.h +++ b/TactilityCore/Source/Mutex.h @@ -62,40 +62,4 @@ public: ThreadId getOwner() const; }; -/** Allocate Mutex - * @param[in] type The mutex type - * @return pointer to Mutex instance - */ - -[[deprecated("use class")]] -Mutex* tt_mutex_alloc(Mutex::Type type); - -/** Free Mutex - * @param[in] mutex The Mutex instance - */ -[[deprecated("use class")]] -void tt_mutex_free(Mutex* mutex); - -/** Acquire mutex - * @param[in] mutex - * @param[in] timeout - * @return the status result - */ -[[deprecated("use class")]] -TtStatus tt_mutex_acquire(Mutex* mutex, TickType_t timeout); - -/** Release mutex - * @param[in] mutex The Mutex instance - * @return the status result - */ -[[deprecated("use class")]] -TtStatus tt_mutex_release(Mutex* mutex); - -/** Get mutex owner thread id - * @param[in] mutex The Mutex instance - * @return The thread identifier. - */ -[[deprecated("use class")]] -ThreadId tt_mutex_get_owner(Mutex* mutex); - } // namespace diff --git a/TactilityHeadless/Source/TactilityHeadless.cpp b/TactilityHeadless/Source/TactilityHeadless.cpp index 3ad9a787..6926cf21 100644 --- a/TactilityHeadless/Source/TactilityHeadless.cpp +++ b/TactilityHeadless/Source/TactilityHeadless.cpp @@ -50,9 +50,8 @@ Dispatcher& getMainDispatcher() { namespace hal { -const Configuration& getConfiguration() { - tt_assert(hardwareConfig != nullptr); - return *hardwareConfig; +const Configuration* getConfiguration() { + return hardwareConfig; } } // namespace hal diff --git a/TactilityHeadless/Source/TactilityHeadless.h b/TactilityHeadless/Source/TactilityHeadless.h index b4528b50..dc87924d 100644 --- a/TactilityHeadless/Source/TactilityHeadless.h +++ b/TactilityHeadless/Source/TactilityHeadless.h @@ -2,7 +2,6 @@ #include "TactilityCore.h" #include "hal/Configuration.h" -#include "TactilityHeadlessConfig.h" #include "Dispatcher.h" namespace tt { @@ -20,7 +19,7 @@ Dispatcher& getMainDispatcher(); namespace tt::hal { -/** Can be called after initHeadless() is called. Will crash otherwise. */ -const Configuration& getConfiguration(); +/** While technically this configuration is nullable, it's never null after initHeadless() is called. */ +const Configuration* _Nullable getConfiguration(); } // namespace diff --git a/TactilityHeadless/Source/TactilityHeadlessConfig.h b/TactilityHeadless/Source/TactilityHeadlessConfig.h deleted file mode 100644 index 7b1dd854..00000000 --- a/TactilityHeadless/Source/TactilityHeadlessConfig.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#define TT_CONFIG_SERVICES_LIMIT 32 \ No newline at end of file diff --git a/TactilityHeadless/Source/TactilityHeadlessEsp.cpp b/TactilityHeadless/Source/TactilityHeadlessEsp.cpp index e27b35ae..3fe800a6 100644 --- a/TactilityHeadless/Source/TactilityHeadlessEsp.cpp +++ b/TactilityHeadless/Source/TactilityHeadlessEsp.cpp @@ -1,4 +1,5 @@ #ifdef ESP_TARGET + #include "TactilityCore.h" #include "EspPartitions_i.h" diff --git a/TactilityHeadless/Source/hal/usb/Usb.cpp b/TactilityHeadless/Source/hal/usb/Usb.cpp index f4edfcd4..a48ae9bc 100644 --- a/TactilityHeadless/Source/hal/usb/Usb.cpp +++ b/TactilityHeadless/Source/hal/usb/Usb.cpp @@ -20,7 +20,7 @@ static Mode currentMode = ModeDefault; static RTC_NOINIT_ATTR BootMode bootMode; sdmmc_card_t* _Nullable getCard() { - auto sdcard = getConfiguration().sdcard; + auto sdcard = getConfiguration()->sdcard; if (sdcard == nullptr) { TT_LOG_W(TAG, "No SD card configuration found"); return nullptr; diff --git a/TactilityHeadless/Source/service/sdcard/Sdcard.cpp b/TactilityHeadless/Source/service/sdcard/Sdcard.cpp index be1b7c79..46dcf03a 100644 --- a/TactilityHeadless/Source/service/sdcard/Sdcard.cpp +++ b/TactilityHeadless/Source/service/sdcard/Sdcard.cpp @@ -30,7 +30,7 @@ struct ServiceData { static void onUpdate(std::shared_ptr context) { - auto sdcard = tt::hal::getConfiguration().sdcard; + auto sdcard = tt::hal::getConfiguration()->sdcard; if (sdcard == nullptr) { return; } @@ -57,7 +57,7 @@ static void onUpdate(std::shared_ptr context) { } static void onStart(ServiceContext& service) { - if (hal::getConfiguration().sdcard != nullptr) { + if (hal::getConfiguration()->sdcard != nullptr) { auto data = std::make_shared(); service.setData(data); diff --git a/TactilityHeadless/Source/service/wifi/WifiMock.cpp b/TactilityHeadless/Source/service/wifi/WifiMock.cpp index 3f907651..b2fc87cd 100644 --- a/TactilityHeadless/Source/service/wifi/WifiMock.cpp +++ b/TactilityHeadless/Source/service/wifi/WifiMock.cpp @@ -8,8 +8,6 @@ #include "Mutex.h" #include "Pubsub.h" #include "service/ServiceContext.h" -#include -#include namespace tt::service::wifi { @@ -17,25 +15,23 @@ namespace tt::service::wifi { #define WIFI_CONNECTED_BIT BIT0 #define WIFI_FAIL_BIT BIT1 -typedef struct { +struct Wifi { + Wifi() = default; + ~Wifi() = default; + /** @brief Locking mechanism for modifying the Wifi instance */ - Mutex* mutex; + Mutex mutex = Mutex(Mutex::TypeRecursive); /** @brief The public event bus */ - std::shared_ptr pubsub; + std::shared_ptr pubsub = std::make_shared(); /** @brief The internal message queue */ - MessageQueue queue; - bool scan_active; - bool secure_connection; - WifiRadioState radio_state; -} Wifi; + bool scan_active = false; + bool secure_connection = false; + WifiRadioState radio_state = WIFI_RADIO_CONNECTION_ACTIVE; +}; static Wifi* wifi = nullptr; -// Forward declarations -static void wifi_lock(Wifi* wifi); -static void wifi_unlock(Wifi* wifi); - // region Static static void publish_event_simple(Wifi* wifi, WifiEventType type) { @@ -45,25 +41,6 @@ static void publish_event_simple(Wifi* wifi, WifiEventType type) { // endregion Static -// region Alloc - -static Wifi* wifi_alloc() { - auto* instance = static_cast(malloc(sizeof(Wifi))); - instance->mutex = tt_mutex_alloc(Mutex::TypeRecursive); - instance->pubsub = std::make_shared(); - instance->scan_active = false; - instance->radio_state = WIFI_RADIO_CONNECTION_ACTIVE; - instance->secure_connection = false; - return instance; -} - -static void wifi_free(Wifi* instance) { - tt_mutex_free(instance->mutex); - free(instance); -} - -// endregion Alloc - // region Public functions std::shared_ptr getPubsub() { @@ -160,29 +137,14 @@ int getRssi() { // endregion Public functions -static void lock(Wifi* wifi) { - tt_crash("this fails for now"); - tt_assert(wifi); - tt_assert(wifi->mutex); - tt_mutex_acquire(wifi->mutex, 100); -} - -static void unlock(Wifi* wifi) { - tt_assert(wifi); - tt_assert(wifi->mutex); - tt_mutex_release(wifi->mutex); -} - - static void service_start(TT_UNUSED ServiceContext& service) { tt_check(wifi == nullptr); - wifi = wifi_alloc(); + wifi = new Wifi(); } static void service_stop(TT_UNUSED ServiceContext& service) { tt_check(wifi != nullptr); - - wifi_free(wifi); + delete wifi; wifi = nullptr; } diff --git a/Tests/TactilityCore/MutexTest.cpp b/Tests/TactilityCore/MutexTest.cpp index 3e3203f4..f9e852b5 100644 --- a/Tests/TactilityCore/MutexTest.cpp +++ b/Tests/TactilityCore/MutexTest.cpp @@ -4,33 +4,31 @@ using namespace tt; -static int thread_with_mutex_parameter(void* parameter) { +static int32_t thread_with_mutex_parameter(void* parameter) { auto* mutex = (Mutex*)parameter; - tt_mutex_acquire(mutex, TtWaitForever); + mutex->lock(portMAX_DELAY); return 0; } TEST_CASE("a mutex can block a thread") { - auto* mutex = tt_mutex_alloc(Mutex::TypeNormal); - tt_mutex_acquire(mutex, TtWaitForever); + auto mutex = Mutex(Mutex::TypeNormal); + mutex.lock(portMAX_DELAY); - Thread* thread = new Thread( + Thread thread = Thread( "thread", 1024, &thread_with_mutex_parameter, - mutex + &mutex ); - thread->start(); + thread.start(); kernel::delayMillis(5); - CHECK_EQ(thread->getState(), Thread::StateRunning); + CHECK_EQ(thread.getState(), Thread::StateRunning); - tt_mutex_release(mutex); + mutex.unlock(); kernel::delayMillis(5); - CHECK_EQ(thread->getState(), Thread::StateStopped); + CHECK_EQ(thread.getState(), Thread::StateStopped); - thread->join(); - delete thread; - tt_mutex_free(mutex); + thread.join(); }