Refactor LVGL code into kernel module (#472)
* **New Features** * Added a standalone LVGL module and enabled LVGL support in the simulator for richer local UI testing. * **Refactor** * HAL and LVGL split into distinct modules; startup and device attach/detach flows reorganized for clearer lifecycle management. * Public APIs tightened with clearer nullability/documentation. * **Bug Fixes** * More consistent LVGL start/stop and device attach/detach behavior for improved stability.
This commit is contained in:
committed by
GitHub
parent
3fe1dc0312
commit
9f721e6655
@@ -8,8 +8,8 @@ if (DEFINED ENV{ESP_IDF_VERSION})
|
||||
PlatformEsp32
|
||||
TactilityCore
|
||||
TactilityFreeRtos
|
||||
hal-device
|
||||
lvgl
|
||||
hal-device-module
|
||||
lvgl-module
|
||||
driver
|
||||
elf_loader
|
||||
lv_screenshot
|
||||
@@ -17,7 +17,6 @@ if (DEFINED ENV{ESP_IDF_VERSION})
|
||||
esp_http_server
|
||||
esp_http_client
|
||||
esp-tls
|
||||
esp_lvgl_port
|
||||
esp_wifi
|
||||
json
|
||||
minitar
|
||||
@@ -63,16 +62,14 @@ else()
|
||||
PUBLIC Include/
|
||||
)
|
||||
|
||||
add_definitions(-D_Nullable=)
|
||||
add_definitions(-D_Nonnull=)
|
||||
|
||||
target_link_libraries(Tactility PUBLIC
|
||||
cJSON
|
||||
TactilityFreeRtos
|
||||
TactilityCore
|
||||
TactilityKernel
|
||||
PlatformPosix
|
||||
hal-device
|
||||
hal-device-module
|
||||
lvgl-module
|
||||
freertos_kernel
|
||||
lvgl
|
||||
lv_screenshot
|
||||
|
||||
@@ -27,9 +27,10 @@ void run(const Configuration& config, Module* platformModule, Module* deviceModu
|
||||
|
||||
/**
|
||||
* While technically nullable, this instance is always set if tt_init() succeeds.
|
||||
* Could return nullptr if init was not called.
|
||||
* @return the Configuration instance that was passed on to tt_init() if init is successful
|
||||
*/
|
||||
const Configuration* _Nullable getConfiguration();
|
||||
const Configuration* getConfiguration();
|
||||
|
||||
/** Provides access to the dispatcher that runs on the main task.
|
||||
* @warning This dispatcher is used for WiFi and might block for some time during WiFi connection.
|
||||
@@ -40,7 +41,7 @@ Dispatcher& getMainDispatcher();
|
||||
namespace hal {
|
||||
|
||||
/** While technically this configuration is nullable, it's never null after initHeadless() is called. */
|
||||
const Configuration* _Nullable getConfiguration();
|
||||
const Configuration* getConfiguration();
|
||||
|
||||
} // namespace hal
|
||||
|
||||
|
||||
@@ -44,7 +44,8 @@ public:
|
||||
virtual void onDestroy(AppContext& appContext) {}
|
||||
virtual void onShow(AppContext& appContext, lv_obj_t* parent) {}
|
||||
virtual void onHide(AppContext& appContext) {}
|
||||
virtual void onResult(AppContext& appContext, LaunchId launchId, Result result, std::unique_ptr<Bundle> _Nullable resultData) {}
|
||||
/** resultData could be null */
|
||||
virtual void onResult(AppContext& appContext, LaunchId launchId, Result result, std::unique_ptr<Bundle> resultData) {}
|
||||
|
||||
Mutex& getMutex() { return mutex; }
|
||||
|
||||
@@ -81,9 +82,9 @@ std::shared_ptr<App> create() { return std::shared_ptr<T>(new T); }
|
||||
/**
|
||||
* @brief Start an app
|
||||
* @param[in] id application name or id
|
||||
* @param[in] parameters optional parameters to pass onto the application
|
||||
* @param[in] parameters optional parameters to pass onto the application. can be nullptr.
|
||||
*/
|
||||
LaunchId start(const std::string& id, std::shared_ptr<const Bundle> _Nullable parameters = nullptr);
|
||||
LaunchId start(const std::string& id, std::shared_ptr<const Bundle> parameters = nullptr);
|
||||
|
||||
/** @brief Stop the currently showing app. Show the previous app if any app was still running. */
|
||||
void stop();
|
||||
@@ -103,10 +104,10 @@ void stopAll(const std::string& id);
|
||||
bool isRunning(const std::string& id);
|
||||
|
||||
/** @return the currently running app context (it is only ever null before the splash screen is shown) */
|
||||
std::shared_ptr<AppContext> _Nullable getCurrentAppContext();
|
||||
std::shared_ptr<AppContext> getCurrentAppContext();
|
||||
|
||||
/** @return the currently running app (it is only ever null before the splash screen is shown) */
|
||||
std::shared_ptr<App> _Nullable getCurrentApp();
|
||||
std::shared_ptr<App> getCurrentApp();
|
||||
|
||||
bool install(const std::string& path);
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ bool removeAppManifest(const std::string& id);
|
||||
* @param[in] id the manifest id
|
||||
* @return the application manifest if it was found
|
||||
*/
|
||||
_Nullable std::shared_ptr<AppManifest> findAppManifestById(const std::string& id);
|
||||
std::shared_ptr<AppManifest> findAppManifestById(const std::string& id);
|
||||
|
||||
/** @return a list of all registered apps. This includes user and system apps. */
|
||||
std::vector<std::shared_ptr<AppManifest>> getAppManifests();
|
||||
|
||||
@@ -8,20 +8,26 @@ namespace tt::app {
|
||||
|
||||
typedef void* (*CreateData)();
|
||||
typedef void (*DestroyData)(void* data);
|
||||
typedef void (*OnCreate)(void* appContext, void* _Nullable data);
|
||||
typedef void (*OnDestroy)(void* appContext, void* _Nullable data);
|
||||
typedef void (*OnShow)(void* appContext, void* _Nullable data, lv_obj_t* parent);
|
||||
typedef void (*OnHide)(void* appContext, void* _Nullable data);
|
||||
typedef void (*OnResult)(void* appContext, void* _Nullable data, LaunchId launchId, Result result, Bundle* resultData);
|
||||
/** data is nullable */
|
||||
typedef void (*OnCreate)(void* appContext, void* data);
|
||||
/** data is nullable */
|
||||
typedef void (*OnDestroy)(void* appContext, void* data);
|
||||
/** data is nullable */
|
||||
typedef void (*OnShow)(void* appContext, void* data, lv_obj_t* parent);
|
||||
/** data is nullable */
|
||||
typedef void (*OnHide)(void* appContext, void* data);
|
||||
/** data is nullable, resultData is nullable. */
|
||||
typedef void (*OnResult)(void* appContext, void* data, LaunchId launchId, Result result, Bundle* resultData);
|
||||
|
||||
/** All fields are nullable */
|
||||
void setElfAppParameters(
|
||||
CreateData _Nullable createData,
|
||||
DestroyData _Nullable destroyData,
|
||||
OnCreate _Nullable onCreate,
|
||||
OnDestroy _Nullable onDestroy,
|
||||
OnShow _Nullable onShow,
|
||||
OnHide _Nullable onHide,
|
||||
OnResult _Nullable onResult
|
||||
CreateData createData,
|
||||
DestroyData destroyData,
|
||||
OnCreate onCreate,
|
||||
OnDestroy onDestroy,
|
||||
OnShow onShow,
|
||||
OnHide onHide,
|
||||
OnResult onResult
|
||||
);
|
||||
|
||||
std::shared_ptr<App> createElfApp(const std::shared_ptr<AppManifest>& manifest);
|
||||
|
||||
@@ -15,6 +15,6 @@ namespace tt::file {
|
||||
* @param[in] path the path to find a lock for
|
||||
* @return a lock instance when a lock was found, otherwise nullptr
|
||||
*/
|
||||
std::shared_ptr<Lock> _Nullable findLock(const std::string& path);
|
||||
std::shared_ptr<Lock> findLock(const std::string& path);
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ struct Configuration {
|
||||
* Called before I2C/SPI/etc is initialized.
|
||||
* Used for powering on the peripherals manually.
|
||||
*/
|
||||
const InitBoot _Nullable initBoot = nullptr;
|
||||
const InitBoot initBoot = nullptr;
|
||||
|
||||
/** Init behaviour: default (esp_lvgl_port for ESP32, nothing for PC) or None (nothing on any platform). Only used in Tactility, not in TactilityHeadless. */
|
||||
const LvglInit lvglInit = LvglInit::Default;
|
||||
|
||||
@@ -26,7 +26,8 @@ public:
|
||||
virtual bool isPoweredOn() const { return true; }
|
||||
virtual bool supportsPowerControl() const { return false; }
|
||||
|
||||
virtual std::shared_ptr<touch::TouchDevice> _Nullable getTouchDevice() = 0;
|
||||
/** Could return nullptr if not started */
|
||||
virtual std::shared_ptr<touch::TouchDevice> getTouchDevice() = 0;
|
||||
|
||||
/** Set a value in the range [0, 255] */
|
||||
virtual void setBacklightDuty(uint8_t backlightDuty) { /* NO-OP */ }
|
||||
@@ -40,10 +41,12 @@ public:
|
||||
virtual bool startLvgl() = 0;
|
||||
virtual bool stopLvgl() = 0;
|
||||
|
||||
virtual lv_display_t* _Nullable getLvglDisplay() const = 0;
|
||||
/** Could return nullptr if not started */
|
||||
virtual lv_display_t* getLvglDisplay() const = 0;
|
||||
|
||||
virtual bool supportsDisplayDriver() const = 0;
|
||||
virtual std::shared_ptr<DisplayDriver> _Nullable getDisplayDriver() = 0;
|
||||
/** Could return nullptr if not supported */
|
||||
virtual std::shared_ptr<DisplayDriver> getDisplayDriver() = 0;
|
||||
};
|
||||
|
||||
} // namespace tt::hal::display
|
||||
|
||||
@@ -17,7 +17,8 @@ public:
|
||||
virtual bool startLvgl(lv_display_t* display) = 0;
|
||||
virtual bool stopLvgl() = 0;
|
||||
|
||||
virtual lv_indev_t* _Nullable getLvglIndev() = 0;
|
||||
/** Could return nullptr if not started */
|
||||
virtual lv_indev_t* getLvglIndev() = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ private:
|
||||
|
||||
const GpsConfiguration configuration;
|
||||
RecursiveMutex mutex;
|
||||
std::unique_ptr<Thread> _Nullable thread;
|
||||
std::unique_ptr<Thread> thread;
|
||||
bool threadInterrupted = false;
|
||||
std::vector<GgaSubscription> ggaSubscriptions;
|
||||
std::vector<RmcSubscription> rmcSubscriptions;
|
||||
|
||||
@@ -20,7 +20,8 @@ public:
|
||||
/** @return true when the keyboard currently is physically attached */
|
||||
virtual bool isAttached() const = 0;
|
||||
|
||||
virtual lv_indev_t* _Nullable getLvglIndev() = 0;
|
||||
/** Could return nullptr if not started */
|
||||
virtual lv_indev_t* getLvglIndev() = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -67,8 +67,8 @@ public:
|
||||
bool isMounted(TickType_t timeout = kernel::MAX_TICKS) const { return getState(timeout) == State::Mounted; }
|
||||
};
|
||||
|
||||
/** Return the SdCard device if the path is within the SdCard mounted path (path std::string::starts_with() check)*/
|
||||
std::shared_ptr<SdCardDevice> _Nullable find(const std::string& path);
|
||||
/** Return the SdCard device if the path is within the SdCard mounted path (path std::string::starts_with() check), otherwise return nullptr */
|
||||
std::shared_ptr<SdCardDevice> find(const std::string& path);
|
||||
|
||||
/**
|
||||
* Attempt to find an SD card that the specified belongs to,
|
||||
|
||||
@@ -82,7 +82,8 @@ public:
|
||||
|
||||
State getState(TickType_t timeout) const override;
|
||||
|
||||
sdmmc_card_t* _Nullable getCard() { return card; }
|
||||
/** return card when mounted, otherwise return nullptr */
|
||||
sdmmc_card_t* getCard() { return card; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
gpio_num_t spiPinInt,
|
||||
MountBehaviour mountBehaviourAtBoot,
|
||||
/** When customLock is a nullptr, use the SPI default one */
|
||||
std::shared_ptr<Lock> _Nullable customLock = nullptr,
|
||||
std::shared_ptr<Lock> customLock = nullptr,
|
||||
std::vector<gpio_num_t> csPinWorkAround = std::vector<gpio_num_t>(),
|
||||
spi_host_device_t spiHost = SPI2_HOST,
|
||||
int spiFrequencyKhz = SDMMC_FREQ_DEFAULT
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
gpio_num_t spiPinWp; // Write-protect
|
||||
gpio_num_t spiPinInt; // Interrupt
|
||||
MountBehaviour mountBehaviourAtBoot;
|
||||
std::shared_ptr<Lock> _Nullable customLock;
|
||||
std::shared_ptr<Lock> customLock; // can be nullptr
|
||||
std::vector<gpio_num_t> csPinWorkAround;
|
||||
spi_host_device_t spiHost;
|
||||
bool formatOnMountFailed = false;
|
||||
@@ -91,7 +91,8 @@ public:
|
||||
|
||||
State getState(TickType_t timeout) const override;
|
||||
|
||||
sdmmc_card_t* _Nullable getCard() { return card; }
|
||||
/** return card when mounted, otherwise return nullptr */
|
||||
sdmmc_card_t* getCard() { return card; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ struct Configuration {
|
||||
/** Whether configuration can be changed. */
|
||||
bool isMutable;
|
||||
/** Optional custom lock - otherwise creates one internally */
|
||||
std::shared_ptr<Lock> _Nullable lock;
|
||||
std::shared_ptr<Lock> lock;
|
||||
};
|
||||
|
||||
enum class Status {
|
||||
|
||||
@@ -22,11 +22,13 @@ public:
|
||||
virtual bool startLvgl(lv_display_t* display) = 0;
|
||||
virtual bool stopLvgl() = 0;
|
||||
|
||||
virtual lv_indev_t* _Nullable getLvglIndev() = 0;
|
||||
/** Could return nullptr if not started */
|
||||
virtual lv_indev_t* getLvglIndev() = 0;
|
||||
|
||||
virtual bool supportsTouchDriver() = 0;
|
||||
|
||||
virtual std::shared_ptr<TouchDriver> _Nullable getTouchDriver() = 0;
|
||||
/** Could return nullptr if not supported */
|
||||
virtual std::shared_ptr<TouchDriver> getTouchDriver() = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ public:
|
||||
*
|
||||
* @param[in] x array of X coordinates
|
||||
* @param[in] y array of Y coordinates
|
||||
* @param[in] strength optional array of strengths
|
||||
* @param[in] strength optional array of strengths (nullable)
|
||||
* @param[in] pointCount the number of points currently touched on the screen
|
||||
* @param[in] maxPointCount the maximum number of points that can be touched at once
|
||||
*
|
||||
* @return true when touched and coordinates are available
|
||||
*/
|
||||
virtual bool getTouchedPoints(uint16_t* x, uint16_t* y, uint16_t* _Nullable strength, uint8_t* pointCount, uint8_t maxPointCount) = 0;
|
||||
virtual bool getTouchedPoints(uint16_t* x, uint16_t* y, uint16_t* strength, uint8_t* pointCount, uint8_t maxPointCount) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,11 +12,6 @@ enum class SystemEvent {
|
||||
/** Gained IP address */
|
||||
NetworkConnected,
|
||||
NetworkDisconnected,
|
||||
/** LVGL devices are initialized and usable */
|
||||
LvglStarted,
|
||||
/** LVGL devices were removed and not usable anymore */
|
||||
LvglStopped,
|
||||
/** An important system time-related event, such as NTP update or time-zone change */
|
||||
Time,
|
||||
};
|
||||
|
||||
|
||||
@@ -8,23 +8,13 @@ namespace tt::lvgl {
|
||||
|
||||
constexpr TickType_t defaultLockTime = 500 / portTICK_PERIOD_MS;
|
||||
|
||||
/**
|
||||
* LVGL locking function
|
||||
* @param[in] timeoutMillis timeout in milliseconds. waits forever when 0 is passed.
|
||||
* @warning this works with milliseconds, as opposed to every other FreeRTOS function that works in 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
|
||||
*/
|
||||
typedef bool (*LvglLock)(uint32_t timeoutMillis);
|
||||
typedef void (*LvglUnlock)();
|
||||
|
||||
void syncSet(LvglLock lock, LvglUnlock unlock);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
bool lock(TickType_t timeout);
|
||||
bool lock(TickType_t timeout = portMAX_DELAY);
|
||||
|
||||
void unlock();
|
||||
|
||||
std::shared_ptr<Lock> getSyncLock();
|
||||
|
||||
@@ -40,26 +40,26 @@ State getState(const std::string& id);
|
||||
* @param[in] id the id as defined in the manifest
|
||||
* @return the matching manifest or nullptr when it wasn't found
|
||||
*/
|
||||
std::shared_ptr<const ServiceManifest> _Nullable findManifestById(const std::string& id);
|
||||
std::shared_ptr<const ServiceManifest> findManifestById(const std::string& id);
|
||||
|
||||
/** Find a ServiceContext by its manifest id.
|
||||
* @param[in] id the id as defined in the manifest
|
||||
* @return the service context or nullptr when it wasn't found
|
||||
*/
|
||||
std::shared_ptr<ServiceContext> _Nullable findServiceContextById(const std::string& id);
|
||||
std::shared_ptr<ServiceContext> findServiceContextById(const std::string& id);
|
||||
|
||||
/** Find a Service by its manifest id.
|
||||
* @param[in] id the id as defined in the manifest
|
||||
* @return the service context or nullptr when it wasn't found
|
||||
*/
|
||||
std::shared_ptr<Service> _Nullable findServiceById(const std::string& id);
|
||||
std::shared_ptr<Service> findServiceById(const std::string& id);
|
||||
|
||||
/** Find a Service by its manifest id.
|
||||
* @param[in] id the id as defined in the manifest
|
||||
* @return the service context or nullptr when it wasn't found
|
||||
*/
|
||||
template <typename T>
|
||||
std::shared_ptr<T> _Nullable findServiceById(const std::string& id) {
|
||||
std::shared_ptr<T> findServiceById(const std::string& id) {
|
||||
return std::static_pointer_cast<T>(findServiceById(id));
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,8 @@ class GpsService final : public Service {
|
||||
bool startGpsDevice(GpsDeviceRecord& deviceRecord);
|
||||
static bool stopGpsDevice(GpsDeviceRecord& deviceRecord);
|
||||
|
||||
GpsDeviceRecord* _Nullable findGpsRecord(const std::shared_ptr<hal::gps::GpsDevice>& record);
|
||||
/** return nullptr when not found */
|
||||
GpsDeviceRecord* findGpsRecord(const std::shared_ptr<hal::gps::GpsDevice>& record);
|
||||
|
||||
void onGgaSentence(hal::Device::Id deviceId, const minmea_sentence_gga& gga);
|
||||
void onRmcSentence(hal::Device::Id deviceId, const minmea_sentence_rmc& rmc);
|
||||
|
||||
@@ -62,10 +62,10 @@ public:
|
||||
/**
|
||||
* @brief Start an app given an app id and an optional bundle with parameters
|
||||
* @param id the app identifier
|
||||
* @param parameters optional parameter bundle
|
||||
* @param parameters optional parameter bundle (nullable)
|
||||
* @return the launch id
|
||||
*/
|
||||
app::LaunchId start(const std::string& id, std::shared_ptr<const Bundle> _Nullable parameters);
|
||||
app::LaunchId start(const std::string& id, std::shared_ptr<const Bundle> parameters);
|
||||
|
||||
/**
|
||||
* @brief Stops the top-most app (the one that is currently active shown to the user
|
||||
@@ -85,8 +85,8 @@ public:
|
||||
*/
|
||||
void stopAll(const std::string& id);
|
||||
|
||||
/** @return the AppContext of the top-most application */
|
||||
std::shared_ptr<app::AppContext> _Nullable getCurrentAppContext();
|
||||
/** @return the AppContext of the top-most application, or nullptr if no app is running. */
|
||||
std::shared_ptr<app::AppContext> getCurrentAppContext();
|
||||
|
||||
/** @return true if the app is running anywhere in the app stack (the app does not have to be the top-most one for this to return true) */
|
||||
bool isRunning(const std::string& id) const;
|
||||
@@ -95,6 +95,7 @@ public:
|
||||
std::shared_ptr<PubSub<Event>> getPubsub() const { return pubsubExternal; }
|
||||
};
|
||||
|
||||
std::shared_ptr<LoaderService> _Nullable findLoaderService();
|
||||
/** return the service or nullptr if it's not running */
|
||||
std::shared_ptr<LoaderService> findLoaderService();
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -36,7 +36,7 @@ class AppInstance : public AppContext {
|
||||
* When these are stored in the app struct, the struct takes ownership.
|
||||
* Do not mutate after app creation.
|
||||
*/
|
||||
std::shared_ptr<const Bundle> _Nullable parameters;
|
||||
std::shared_ptr<const Bundle> parameters;
|
||||
|
||||
std::shared_ptr<App> app;
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
namespace tt::lvgl {
|
||||
|
||||
bool initEspLvglPort();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,9 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
#include <Tactility/lvgl/Lvgl.h>
|
||||
|
||||
namespace tt::lvgl {
|
||||
|
||||
void init(const hal::Configuration& config);
|
||||
void attachDevices();
|
||||
|
||||
} // namespace
|
||||
void detachDevices();
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class GuiService final : public Service {
|
||||
// App-specific
|
||||
std::shared_ptr<app::AppInstance> appToRender = nullptr;
|
||||
|
||||
lv_obj_t* _Nullable keyboard = nullptr;
|
||||
lv_obj_t* keyboard = nullptr;
|
||||
lv_group_t* keyboardGroup = nullptr;
|
||||
|
||||
bool isStarted = false;
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
void stop();
|
||||
};
|
||||
|
||||
std::shared_ptr<ScreenshotService> _Nullable optScreenshotService();
|
||||
std::shared_ptr<ScreenshotService> optScreenshotService();
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
#include <sdkconfig.h>
|
||||
#endif
|
||||
|
||||
#include <format>
|
||||
#include <map>
|
||||
|
||||
#include <Tactility/Tactility.h>
|
||||
#include <Tactility/TactilityConfig.h>
|
||||
|
||||
#include <Tactility/app/AppManifestParsing.h>
|
||||
#include <Tactility/app/AppRegistration.h>
|
||||
#include <Tactility/CpuAffinity.h>
|
||||
#include <Tactility/DispatcherThread.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/file/FileLock.h>
|
||||
@@ -19,14 +23,12 @@
|
||||
#include <Tactility/network/NtpPrivate.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
#include <Tactility/service/loader/Loader.h>
|
||||
#include <Tactility/settings/TimePrivate.h>
|
||||
|
||||
#include <tactility/concurrent/thread.h>
|
||||
#include <tactility/kernel_init.h>
|
||||
#include <tactility/hal_device_module.h>
|
||||
|
||||
#include <map>
|
||||
#include <format>
|
||||
#include <tactility/lvgl_module.h>
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <Tactility/InitEsp.h>
|
||||
@@ -336,8 +338,9 @@ void run(const Configuration& config, Module* platformModule, Module* deviceModu
|
||||
return;
|
||||
}
|
||||
|
||||
// HAL compatibility module: it creates kernel driver wrappers for tt::hal::Device
|
||||
// Module parent
|
||||
check(module_parent_construct(&tactility_module_parent) == ERROR_NONE);
|
||||
// hal-device-module
|
||||
check(module_set_parent(&hal_device_module, &tactility_module_parent) == ERROR_NONE);
|
||||
check(module_start(&hal_device_module) == ERROR_NONE);
|
||||
|
||||
@@ -355,7 +358,22 @@ void run(const Configuration& config, Module* platformModule, Module* deviceModu
|
||||
network::ntp::init();
|
||||
|
||||
registerAndStartPrimaryServices();
|
||||
lvgl::init(hardware);
|
||||
|
||||
lvgl_module_configure((LvglModuleConfig) {
|
||||
.on_start = lvgl::attachDevices,
|
||||
.on_stop = lvgl::detachDevices,
|
||||
.task_priority = THREAD_PRIORITY_HIGHER,
|
||||
/** Minimum seems to be about 3500. In some scenarios, the WiFi app crashes at 8192,
|
||||
* so we now have 9120 to run in a stable manner. We should figure out a way to avoid this.
|
||||
* Perhaps we can give apps their own stack space and deal with lvgl callback handlers in a clever way. */
|
||||
.task_stack_size = 9120,
|
||||
#ifdef ESP_PLATFORM
|
||||
.task_affinity = getCpuAffinityConfiguration().graphics
|
||||
#endif
|
||||
});
|
||||
check(module_set_parent(&lvgl_module, &tactility_module_parent) == ERROR_NONE);
|
||||
lvgl::start();
|
||||
|
||||
registerAndStartSecondaryServices();
|
||||
|
||||
LOGGER.info("Core systems ready");
|
||||
@@ -371,7 +389,8 @@ void run(const Configuration& config, Module* platformModule, Module* deviceModu
|
||||
}
|
||||
}
|
||||
|
||||
const Configuration* _Nullable getConfiguration() {
|
||||
/** return the configuration or nullptr if it's not initialized */
|
||||
const Configuration* getConfiguration() {
|
||||
return config_instance;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace tt::app {
|
||||
|
||||
constexpr auto* TAG = "App";
|
||||
|
||||
LaunchId start(const std::string& id, std::shared_ptr<const Bundle> _Nullable parameters) {
|
||||
LaunchId start(const std::string& id, std::shared_ptr<const Bundle> parameters) {
|
||||
const auto service = service::loader::findLoaderService();
|
||||
assert(service != nullptr);
|
||||
return service->start(id, std::move(parameters));
|
||||
@@ -35,15 +35,15 @@ bool isRunning(const std::string& id) {
|
||||
return service->isRunning(id);
|
||||
}
|
||||
|
||||
std::shared_ptr<AppContext> _Nullable getCurrentAppContext() {
|
||||
std::shared_ptr<AppContext> getCurrentAppContext() {
|
||||
const auto service = service::loader::findLoaderService();
|
||||
assert(service != nullptr);
|
||||
return service->getCurrentAppContext();
|
||||
}
|
||||
|
||||
std::shared_ptr<App> _Nullable getCurrentApp() {
|
||||
std::shared_ptr<App> getCurrentApp() {
|
||||
const auto app_context = getCurrentAppContext();
|
||||
return (app_context != nullptr) ? app_context->getApp() : nullptr;
|
||||
return (app_context != nullptr) ? app_context->getApp() : nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ bool removeAppManifest(const std::string& id) {
|
||||
return app_manifest_map.erase(id) == 1;
|
||||
}
|
||||
|
||||
_Nullable std::shared_ptr<AppManifest> findAppManifestById(const std::string& id) {
|
||||
std::shared_ptr<AppManifest> findAppManifestById(const std::string& id) {
|
||||
hash_mutex.lock();
|
||||
auto result = app_manifest_map.find(id);
|
||||
hash_mutex.unlock();
|
||||
|
||||
@@ -34,13 +34,13 @@ class ElfApp final : public App {
|
||||
public:
|
||||
|
||||
struct Parameters {
|
||||
CreateData _Nullable createData = nullptr;
|
||||
DestroyData _Nullable destroyData = nullptr;
|
||||
OnCreate _Nullable onCreate = nullptr;
|
||||
OnDestroy _Nullable onDestroy = nullptr;
|
||||
OnShow _Nullable onShow = nullptr;
|
||||
OnHide _Nullable onHide = nullptr;
|
||||
OnResult _Nullable onResult = nullptr;
|
||||
CreateData createData = nullptr;
|
||||
DestroyData destroyData = nullptr;
|
||||
OnCreate onCreate = nullptr;
|
||||
OnDestroy onDestroy = nullptr;
|
||||
OnShow onShow = nullptr;
|
||||
OnHide onHide = nullptr;
|
||||
OnResult onResult = nullptr;
|
||||
};
|
||||
|
||||
static void setParameters(const Parameters& parameters) {
|
||||
@@ -202,13 +202,13 @@ size_t ElfApp::staticParametersSetCount = 0;
|
||||
std::shared_ptr<Lock> ElfApp::staticParametersLock = std::make_shared<Mutex>();
|
||||
|
||||
void setElfAppParameters(
|
||||
CreateData _Nullable createData,
|
||||
DestroyData _Nullable destroyData,
|
||||
OnCreate _Nullable onCreate,
|
||||
OnDestroy _Nullable onDestroy,
|
||||
OnShow _Nullable onShow,
|
||||
OnHide _Nullable onHide,
|
||||
OnResult _Nullable onResult
|
||||
CreateData createData,
|
||||
DestroyData destroyData,
|
||||
OnCreate onCreate,
|
||||
OnDestroy onDestroy,
|
||||
OnShow onShow,
|
||||
OnHide onHide,
|
||||
OnResult onResult
|
||||
) {
|
||||
ElfApp::setParameters({
|
||||
.createData = createData,
|
||||
|
||||
@@ -30,7 +30,7 @@ class AppHubApp final : public App {
|
||||
std::vector<AppHubEntry> entries;
|
||||
Mutex mutex;
|
||||
|
||||
static std::shared_ptr<AppHubApp> _Nullable findAppInstance() {
|
||||
static std::shared_ptr<AppHubApp> findAppInstance() {
|
||||
auto app_context = getCurrentAppContext();
|
||||
if (app_context->getManifest().appId != manifest.appId) {
|
||||
return nullptr;
|
||||
|
||||
@@ -71,7 +71,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<I2cScannerApp> _Nullable optApp() {
|
||||
std::shared_ptr<I2cScannerApp> optApp() {
|
||||
auto appContext = getCurrentAppContext();
|
||||
if (appContext != nullptr && appContext->getManifest().appId == manifest.appId) {
|
||||
return std::static_pointer_cast<I2cScannerApp>(appContext->getApp());
|
||||
|
||||
@@ -20,7 +20,7 @@ extern const AppManifest manifest;
|
||||
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<PowerApp> _Nullable optApp() {
|
||||
std::shared_ptr<PowerApp> optApp() {
|
||||
auto appContext = getCurrentAppContext();
|
||||
if (appContext != nullptr && appContext->getManifest().appId == manifest.appId) {
|
||||
return std::static_pointer_cast<PowerApp>(appContext->getApp());
|
||||
|
||||
@@ -49,7 +49,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<ScreenshotApp> _Nullable optApp() {
|
||||
std::shared_ptr<ScreenshotApp> optApp() {
|
||||
auto appContext = getCurrentAppContext();
|
||||
if (appContext != nullptr && appContext->getManifest().appId == manifest.appId) {
|
||||
return std::static_pointer_cast<ScreenshotApp>(appContext->getApp());
|
||||
|
||||
@@ -274,7 +274,7 @@ extern const AppManifest manifest;
|
||||
|
||||
class SystemInfoApp;
|
||||
|
||||
static std::shared_ptr<SystemInfoApp> _Nullable optApp() {
|
||||
static std::shared_ptr<SystemInfoApp> optApp() {
|
||||
auto appContext = getCurrentAppContext();
|
||||
if (appContext != nullptr && appContext->getManifest().appId == manifest.appId) {
|
||||
return std::static_pointer_cast<SystemInfoApp>(appContext->getApp());
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace tt::app::wifimanage {
|
||||
|
||||
static const auto LOGGER = Logger("WifiManageView");
|
||||
|
||||
std::shared_ptr<WifiManage> _Nullable optWifiManage();
|
||||
std::shared_ptr<WifiManage> optWifiManage();
|
||||
|
||||
static uint8_t mapRssiToPercentage(int rssi) {
|
||||
auto abs_rssi = std::abs(rssi);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
namespace tt::file {
|
||||
|
||||
std::shared_ptr<Lock> _Nullable findLock(const std::string& path) {
|
||||
std::shared_ptr<Lock> findLock(const std::string& path) {
|
||||
return hal::sdcard::findSdCardLock(path);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
namespace tt::hal::sdcard {
|
||||
|
||||
std::shared_ptr<SdCardDevice> _Nullable find(const std::string& path) {
|
||||
std::shared_ptr<SdCardDevice> find(const std::string& path) {
|
||||
auto sdcards = findDevices<SdCardDevice>(Device::Type::SdCard);
|
||||
for (auto& sdcard : sdcards) {
|
||||
if (sdcard->isMounted() && path.starts_with(sdcard->getMountPath())) {
|
||||
|
||||
@@ -20,7 +20,7 @@ struct BootModeData {
|
||||
static Mode currentMode = Mode::Default;
|
||||
static RTC_NOINIT_ATTR BootModeData bootModeData;
|
||||
|
||||
sdmmc_card_t* _Nullable getCard() {
|
||||
sdmmc_card_t* getCard() {
|
||||
auto sdcards = findDevices<sdcard::SpiSdCardDevice>(Device::Type::SdCard);
|
||||
|
||||
std::shared_ptr<sdcard::SpiSdCardDevice> usable_sdcard;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
static const auto LOGGER = tt::Logger("USB");
|
||||
|
||||
namespace tt::hal::usb {
|
||||
extern sdmmc_card_t* _Nullable getCard();
|
||||
extern sdmmc_card_t* getCard();
|
||||
}
|
||||
|
||||
enum {
|
||||
|
||||
@@ -34,10 +34,6 @@ static const char* getEventName(SystemEvent event) {
|
||||
return TT_STRINGIFY(NetworkConnected);
|
||||
case NetworkDisconnected:
|
||||
return TT_STRINGIFY(NetworkDisconnected);
|
||||
case LvglStarted:
|
||||
return TT_STRINGIFY(LvglStarted);
|
||||
case LvglStopped:
|
||||
return TT_STRINGIFY(LvglStopped);
|
||||
case Time:
|
||||
return TT_STRINGIFY(Time);
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
#include <Tactility/Thread.h>
|
||||
#include <Tactility/CpuAffinity.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/Mutex.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
|
||||
#include <esp_lvgl_port.h>
|
||||
|
||||
namespace tt::lvgl {
|
||||
|
||||
// LVGL
|
||||
// The minimum task stack seems to be about 3500, but that crashes the wifi app in some scenarios
|
||||
// At 8192, it sometimes crashes when wifi-auto enables and is busy connecting and then you open WifiManage
|
||||
constexpr auto LVGL_TASK_STACK_DEPTH = 9216;
|
||||
|
||||
static const auto LOGGER = Logger("EspLvglPort");
|
||||
|
||||
bool initEspLvglPort() {
|
||||
LOGGER.debug("Init");
|
||||
const lvgl_port_cfg_t lvgl_cfg = {
|
||||
.task_priority = static_cast<UBaseType_t>(Thread::Priority::Critical),
|
||||
.task_stack = LVGL_TASK_STACK_DEPTH,
|
||||
.task_affinity = getCpuAffinityConfiguration().graphics,
|
||||
.task_max_sleep_ms = 500,
|
||||
.timer_period_ms = 5
|
||||
};
|
||||
|
||||
if (lvgl_port_init(&lvgl_cfg) != ESP_OK) {
|
||||
LOGGER.error("Init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
syncSet(&lvgl_port_lock, &lvgl_port_unlock);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace tt::lvgl
|
||||
|
||||
#endif
|
||||
@@ -7,47 +7,24 @@
|
||||
#include <Tactility/lvgl/Keyboard.h>
|
||||
#include <Tactility/lvgl/Lvgl.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/kernel/SystemEvents.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
#include <Tactility/settings/DisplaySettings.h>
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <Tactility/lvgl/EspLvglPort.h>
|
||||
#endif
|
||||
#include <tactility/lvgl_module.h>
|
||||
#include <tactility/module.h>
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
namespace tt::lvgl {
|
||||
|
||||
static const auto LOGGER = Logger("Lvgl");
|
||||
|
||||
static bool started = false;
|
||||
|
||||
void init(const hal::Configuration& config) {
|
||||
LOGGER.info("Init started");
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
if (config.lvglInit == hal::LvglInit::Default && !initEspLvglPort()) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
start();
|
||||
|
||||
LOGGER.info("Init finished");
|
||||
}
|
||||
static const auto LOGGER = Logger("LVGL");
|
||||
|
||||
bool isStarted() {
|
||||
return started;
|
||||
return module_is_started(&lvgl_module);
|
||||
}
|
||||
|
||||
void start() {
|
||||
LOGGER.info("Start LVGL");
|
||||
|
||||
if (started) {
|
||||
LOGGER.warn("Can't start LVGL twice");
|
||||
return;
|
||||
}
|
||||
void attachDevices() {
|
||||
LOGGER.info("Adding devices");
|
||||
|
||||
auto lock = getSyncLock()->asScopedLock();
|
||||
lock.lock();
|
||||
@@ -56,7 +33,7 @@ void start() {
|
||||
|
||||
LOGGER.info("Start displays");
|
||||
auto displays = hal::findDevices<hal::display::DisplayDevice>(hal::Device::Type::Display);
|
||||
for (const auto& display : displays) {
|
||||
for (const auto& display: displays) {
|
||||
if (display->supportsLvgl()) {
|
||||
if (display->startLvgl()) {
|
||||
LOGGER.info("Started {}", display->getName());
|
||||
@@ -82,7 +59,7 @@ void start() {
|
||||
if (primary_display != nullptr) {
|
||||
LOGGER.info("Start touch devices");
|
||||
auto touch_devices = hal::findDevices<hal::touch::TouchDevice>(hal::Device::Type::Touch);
|
||||
for (const auto& touch_device : touch_devices) {
|
||||
for (const auto& touch_device: touch_devices) {
|
||||
// Start any touch devices that haven't been started yet
|
||||
if (touch_device->supportsLvgl() && touch_device->getLvglIndev() == nullptr) {
|
||||
if (touch_device->startLvgl(primary_display->getLvglDisplay())) {
|
||||
@@ -96,7 +73,7 @@ void start() {
|
||||
// Start keyboards
|
||||
LOGGER.info("Start keyboards");
|
||||
auto keyboards = hal::findDevices<hal::keyboard::KeyboardDevice>(hal::Device::Type::Keyboard);
|
||||
for (const auto& keyboard : keyboards) {
|
||||
for (const auto& keyboard: keyboards) {
|
||||
if (keyboard->isAttached()) {
|
||||
if (keyboard->startLvgl(primary_display->getLvglDisplay())) {
|
||||
lv_indev_t* keyboard_indev = keyboard->getLvglIndev();
|
||||
@@ -111,7 +88,7 @@ void start() {
|
||||
// Start encoders
|
||||
LOGGER.info("Start encoders");
|
||||
auto encoders = hal::findDevices<hal::encoder::EncoderDevice>(hal::Device::Type::Encoder);
|
||||
for (const auto& encoder : encoders) {
|
||||
for (const auto& encoder: encoders) {
|
||||
if (encoder->startLvgl(primary_display->getLvglDisplay())) {
|
||||
LOGGER.info("Started {}", encoder->getName());
|
||||
} else {
|
||||
@@ -141,21 +118,10 @@ void start() {
|
||||
LOGGER.error("Statusbar service is not in Stopped state");
|
||||
}
|
||||
}
|
||||
|
||||
// Finalize
|
||||
|
||||
kernel::publishSystemEvent(kernel::SystemEvent::LvglStarted);
|
||||
|
||||
started = true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
LOGGER.info("Stopping LVGL");
|
||||
|
||||
if (!started) {
|
||||
LOGGER.warn("Can't stop LVGL: not started");
|
||||
return;
|
||||
}
|
||||
void detachDevices() {
|
||||
LOGGER.info("Removing devices");
|
||||
|
||||
auto lock = getSyncLock()->asScopedLock();
|
||||
lock.lock();
|
||||
@@ -169,7 +135,7 @@ void stop() {
|
||||
|
||||
LOGGER.info("Stopping keyboards");
|
||||
auto keyboards = hal::findDevices<hal::keyboard::KeyboardDevice>(hal::Device::Type::Keyboard);
|
||||
for (auto keyboard : keyboards) {
|
||||
for (auto keyboard: keyboards) {
|
||||
if (keyboard->getLvglIndev() != nullptr) {
|
||||
keyboard->stopLvgl();
|
||||
}
|
||||
@@ -180,7 +146,7 @@ void stop() {
|
||||
LOGGER.info("Stopping touch");
|
||||
// The display generally stops their own touch devices, but we'll clean up anything that didn't
|
||||
auto touch_devices = hal::findDevices<hal::touch::TouchDevice>(hal::Device::Type::Touch);
|
||||
for (auto touch_device : touch_devices) {
|
||||
for (auto touch_device: touch_devices) {
|
||||
if (touch_device->getLvglIndev() != nullptr) {
|
||||
touch_device->stopLvgl();
|
||||
}
|
||||
@@ -191,7 +157,7 @@ void stop() {
|
||||
LOGGER.info("Stopping encoders");
|
||||
// The display generally stops their own touch devices, but we'll clean up anything that didn't
|
||||
auto encoder_devices = hal::findDevices<hal::encoder::EncoderDevice>(hal::Device::Type::Encoder);
|
||||
for (auto encoder_device : encoder_devices) {
|
||||
for (auto encoder_device: encoder_devices) {
|
||||
if (encoder_device->getLvglIndev() != nullptr) {
|
||||
encoder_device->stopLvgl();
|
||||
}
|
||||
@@ -200,17 +166,19 @@ void stop() {
|
||||
|
||||
LOGGER.info("Stopping displays");
|
||||
auto displays = hal::findDevices<hal::display::DisplayDevice>(hal::Device::Type::Display);
|
||||
for (auto display : displays) {
|
||||
for (auto display: displays) {
|
||||
if (display->supportsLvgl() && display->getLvglDisplay() != nullptr && !display->stopLvgl()) {
|
||||
LOGGER.error("Failed to detach display from LVGL");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
started = false;
|
||||
void start() {
|
||||
check(module_start(&lvgl_module) == ERROR_NONE);
|
||||
}
|
||||
|
||||
kernel::publishSystemEvent(kernel::SystemEvent::LvglStopped);
|
||||
|
||||
LOGGER.info("Stopped LVGL");
|
||||
void stop() {
|
||||
check(module_stop(&lvgl_module) == ERROR_NONE);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -1,39 +1,16 @@
|
||||
#include "Tactility/lvgl/LvglSync.h"
|
||||
|
||||
#include <Tactility/Mutex.h>
|
||||
#include <tactility/lvgl_module.h>
|
||||
|
||||
namespace tt::lvgl {
|
||||
|
||||
static Mutex lockMutex;
|
||||
|
||||
static bool defaultLock(uint32_t timeoutMillis) {
|
||||
return lockMutex.lock(timeoutMillis);
|
||||
}
|
||||
|
||||
static void defaultUnlock() {
|
||||
lockMutex.unlock();
|
||||
}
|
||||
|
||||
static LvglLock lock_singleton = defaultLock;
|
||||
static LvglUnlock unlock_singleton = defaultUnlock;
|
||||
|
||||
void syncSet(LvglLock lock, LvglUnlock unlock) {
|
||||
auto old_lock = lock_singleton;
|
||||
auto old_unlock = unlock_singleton;
|
||||
|
||||
// Ensure the old lock is not engaged when changing locks
|
||||
old_lock((uint32_t)kernel::MAX_TICKS);
|
||||
lock_singleton = lock;
|
||||
unlock_singleton = unlock;
|
||||
old_unlock();
|
||||
}
|
||||
|
||||
bool lock(TickType_t timeout) {
|
||||
return lock_singleton(pdMS_TO_TICKS(timeout == 0 ? kernel::MAX_TICKS : timeout));
|
||||
return lvgl_try_lock_timed(timeout);
|
||||
}
|
||||
|
||||
void unlock() {
|
||||
unlock_singleton();
|
||||
lvgl_unlock();
|
||||
}
|
||||
|
||||
class LvglSync : public Lock {
|
||||
@@ -41,11 +18,11 @@ public:
|
||||
~LvglSync() override = default;
|
||||
|
||||
bool lock(TickType_t timeoutTicks) const override {
|
||||
return lvgl::lock(timeoutTicks);
|
||||
return lvgl_try_lock_timed(timeoutTicks);
|
||||
}
|
||||
|
||||
void unlock() const override {
|
||||
lvgl::unlock();
|
||||
lvgl_unlock();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ void addService(const ServiceManifest& manifest, bool autoStart) {
|
||||
addService(std::make_shared<const ServiceManifest>(manifest), autoStart);
|
||||
}
|
||||
|
||||
std::shared_ptr<const ServiceManifest> _Nullable findManifestById(const std::string& id) {
|
||||
std::shared_ptr<const ServiceManifest> findManifestById(const std::string& id) {
|
||||
manifest_mutex.lock();
|
||||
auto iterator = service_manifest_map.find(id);
|
||||
auto manifest = iterator != service_manifest_map.end() ? iterator->second : nullptr;
|
||||
@@ -52,7 +52,7 @@ std::shared_ptr<const ServiceManifest> _Nullable findManifestById(const std::str
|
||||
return manifest;
|
||||
}
|
||||
|
||||
static std::shared_ptr<ServiceInstance> _Nullable findServiceInstanceById(const std::string& id) {
|
||||
static std::shared_ptr<ServiceInstance> findServiceInstanceById(const std::string& id) {
|
||||
manifest_mutex.lock();
|
||||
auto iterator = service_instance_map.find(id);
|
||||
auto service = iterator != service_instance_map.end() ? iterator->second : nullptr;
|
||||
@@ -92,11 +92,11 @@ bool startService(const std::string& id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<ServiceContext> _Nullable findServiceContextById(const std::string& id) {
|
||||
std::shared_ptr<ServiceContext> findServiceContextById(const std::string& id) {
|
||||
return findServiceInstanceById(id);
|
||||
}
|
||||
|
||||
std::shared_ptr<Service> _Nullable findServiceById(const std::string& id) {
|
||||
std::shared_ptr<Service> findServiceById(const std::string& id) {
|
||||
auto instance = findServiceInstanceById(id);
|
||||
return instance != nullptr ? instance->getService() : nullptr;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ constexpr bool hasTimeElapsed(TickType_t now, TickType_t timeInThePast, TickType
|
||||
return (now - timeInThePast) >= expireTimeInTicks;
|
||||
}
|
||||
|
||||
GpsService::GpsDeviceRecord* _Nullable GpsService::findGpsRecord(const std::shared_ptr<GpsDevice>& device) {
|
||||
GpsService::GpsDeviceRecord* GpsService::findGpsRecord(const std::shared_ptr<GpsDevice>& device) {
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
|
||||
@@ -40,6 +40,47 @@ void GuiService::onLoaderEvent(LoaderService::Event event) {
|
||||
int32_t GuiService::guiMain() {
|
||||
auto service = findServiceById<GuiService>(manifest.id);
|
||||
|
||||
if (!lvgl::lock(5000)) {
|
||||
LOGGER.error("LVGL guiMain start failed as LVGL couldn't be locked");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The screen root is created in the main task instead of during onStart because
|
||||
// it allows onStart() to succeed faster and allows widget creation to happen in the background
|
||||
|
||||
auto* screen_root = lv_screen_active();
|
||||
if (screen_root == nullptr) {
|
||||
LOGGER.error("No display found, exiting GUI task");
|
||||
lvgl::unlock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
service->keyboardGroup = lv_group_create();
|
||||
lv_obj_set_style_border_width(screen_root, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_pad_all(screen_root, 0, LV_STATE_DEFAULT);
|
||||
|
||||
lv_obj_t* vertical_container = lv_obj_create(screen_root);
|
||||
lv_obj_set_size(vertical_container, LV_PCT(100), LV_PCT(100));
|
||||
lv_obj_set_flex_flow(vertical_container, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_style_pad_all(vertical_container, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_pad_gap(vertical_container, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_bg_color(vertical_container, lv_color_black(), LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_border_width(vertical_container, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_radius(vertical_container, 0, LV_STATE_DEFAULT);
|
||||
|
||||
service->statusbarWidget = lvgl::statusbar_create(vertical_container);
|
||||
|
||||
auto* app_container = lv_obj_create(vertical_container);
|
||||
lv_obj_set_style_pad_all(app_container, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_border_width(app_container, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_width(app_container, LV_PCT(100));
|
||||
lv_obj_set_flex_grow(app_container, 1);
|
||||
lv_obj_set_flex_flow(app_container, LV_FLEX_FLOW_COLUMN);
|
||||
|
||||
service->appRootWidget = app_container;
|
||||
|
||||
lvgl::unlock();
|
||||
|
||||
while (true) {
|
||||
uint32_t flags = 0;
|
||||
if (service->threadFlags.wait(GUI_THREAD_FLAG_ALL, false, true, &flags, portMAX_DELAY)) {
|
||||
@@ -62,6 +103,9 @@ int32_t GuiService::guiMain() {
|
||||
}
|
||||
}
|
||||
|
||||
service->appRootWidget = nullptr;
|
||||
service->statusbarWidget = nullptr;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -87,6 +131,12 @@ void GuiService::redraw() {
|
||||
// Lock GUI and LVGL
|
||||
lock();
|
||||
|
||||
if (appRootWidget == nullptr) {
|
||||
LOGGER.warn("No root widget");
|
||||
unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
if (lvgl::lock(1000)) {
|
||||
lv_obj_clean(appRootWidget);
|
||||
|
||||
@@ -113,7 +163,7 @@ void GuiService::redraw() {
|
||||
lv_obj_t* container = createAppViews(appRootWidget);
|
||||
appToRender->getApp()->onShow(*appToRender, container);
|
||||
} else {
|
||||
LOGGER.warn("nothing to draw");
|
||||
LOGGER.warn("Nothing to draw");
|
||||
}
|
||||
|
||||
// Unlock GUI and LVGL
|
||||
@@ -126,18 +176,11 @@ void GuiService::redraw() {
|
||||
}
|
||||
|
||||
bool GuiService::onStart(ServiceContext& service) {
|
||||
auto* screen_root = lv_screen_active();
|
||||
if (screen_root == nullptr) {
|
||||
LOGGER.error("No display found");
|
||||
return false;
|
||||
}
|
||||
|
||||
thread = new Thread(
|
||||
GUI_TASK_NAME,
|
||||
4096, // Last known minimum was 2800 for launching desktop
|
||||
[]() { return guiMain(); }
|
||||
guiMain
|
||||
);
|
||||
|
||||
thread->setPriority(THREAD_PRIORITY_SERVICE);
|
||||
|
||||
const auto loader = findLoaderService();
|
||||
@@ -146,37 +189,8 @@ bool GuiService::onStart(ServiceContext& service) {
|
||||
onLoaderEvent(event);
|
||||
});
|
||||
|
||||
lvgl::lock(portMAX_DELAY);
|
||||
|
||||
keyboardGroup = lv_group_create();
|
||||
lv_obj_set_style_border_width(screen_root, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_pad_all(screen_root, 0, LV_STATE_DEFAULT);
|
||||
|
||||
lv_obj_t* vertical_container = lv_obj_create(screen_root);
|
||||
lv_obj_set_size(vertical_container, LV_PCT(100), LV_PCT(100));
|
||||
lv_obj_set_flex_flow(vertical_container, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_style_pad_all(vertical_container, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_pad_gap(vertical_container, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_bg_color(vertical_container, lv_color_black(), LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_border_width(vertical_container, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_radius(vertical_container, 0, LV_STATE_DEFAULT);
|
||||
|
||||
statusbarWidget = lvgl::statusbar_create(vertical_container);
|
||||
|
||||
auto* app_container = lv_obj_create(vertical_container);
|
||||
lv_obj_set_style_pad_all(app_container, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_border_width(app_container, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_width(app_container, LV_PCT(100));
|
||||
lv_obj_set_flex_grow(app_container, 1);
|
||||
lv_obj_set_flex_flow(app_container, LV_FLEX_FLOW_COLUMN);
|
||||
|
||||
appRootWidget = app_container;
|
||||
|
||||
lvgl::unlock();
|
||||
|
||||
isStarted = true;
|
||||
|
||||
thread->setPriority(THREAD_PRIORITY_SERVICE);
|
||||
thread->start();
|
||||
|
||||
return true;
|
||||
@@ -192,20 +206,24 @@ void GuiService::onStop(ServiceContext& service) {
|
||||
appToRender = nullptr;
|
||||
isStarted = false;
|
||||
|
||||
auto task_handle = thread->getTaskHandle();
|
||||
threadFlags.set(GUI_THREAD_FLAG_EXIT);
|
||||
thread->join();
|
||||
delete thread;
|
||||
|
||||
unlock();
|
||||
thread->join();
|
||||
|
||||
check(lvgl::lock(1000 / portTICK_PERIOD_MS));
|
||||
lv_group_delete(keyboardGroup);
|
||||
lvgl::unlock();
|
||||
if (lvgl::lock()) {
|
||||
if (keyboardGroup != nullptr) {
|
||||
lv_group_delete(keyboardGroup);
|
||||
keyboardGroup = nullptr;
|
||||
}
|
||||
lvgl::unlock();
|
||||
} else {
|
||||
LOGGER.error("Failed to lock LVGL during GUI stop");
|
||||
}
|
||||
|
||||
delete thread;
|
||||
}
|
||||
|
||||
void GuiService::requestDraw() {
|
||||
auto task_handle = thread->getTaskHandle();
|
||||
threadFlags.set(GUI_THREAD_FLAG_DRAW);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
namespace tt::service::loader {
|
||||
|
||||
static const auto LOGGER = Logger("Boot");
|
||||
static const auto LOGGER = Logger("Loader");
|
||||
|
||||
constexpr auto LOADER_TIMEOUT = (100 / portTICK_PERIOD_MS);
|
||||
|
||||
@@ -297,7 +297,7 @@ void LoaderService::stopAll(const std::string& id) {
|
||||
});
|
||||
}
|
||||
|
||||
std::shared_ptr<app::AppContext> _Nullable LoaderService::getCurrentAppContext() {
|
||||
std::shared_ptr<app::AppContext> LoaderService::getCurrentAppContext() {
|
||||
const auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
if (appStack.empty()) {
|
||||
@@ -318,7 +318,7 @@ bool LoaderService::isRunning(const std::string& id) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<LoaderService> _Nullable findLoaderService() {
|
||||
std::shared_ptr<LoaderService> findLoaderService() {
|
||||
return service::findServiceById<LoaderService>(manifest.id);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ static const auto LOGGER = Logger("ScreenshotService");
|
||||
|
||||
extern const ServiceManifest manifest;
|
||||
|
||||
std::shared_ptr<ScreenshotService> _Nullable optScreenshotService() {
|
||||
std::shared_ptr<ScreenshotService> optScreenshotService() {
|
||||
return service::findServiceById<ScreenshotService>(manifest.id);
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ static const char* getSdCardStatusIcon(hal::sdcard::SdCardDevice::State state) {
|
||||
}
|
||||
}
|
||||
|
||||
static _Nullable const char* getPowerStatusIcon() {
|
||||
static const char* getPowerStatusIcon() {
|
||||
// TODO: Support multiple power devices?
|
||||
std::shared_ptr<hal::power::PowerDevice> power;
|
||||
hal::findDevices<hal::power::PowerDevice>(hal::Device::Type::Power, [&power](const auto& device) {
|
||||
|
||||
@@ -62,9 +62,9 @@ public:
|
||||
// for example: when scanning and you turn off the radio, the scan should probably stop or turning off
|
||||
// the radio should disable the on/off button in the app as it is pending.
|
||||
/** @brief The network interface when wifi is started */
|
||||
esp_netif_t* _Nullable netif = nullptr;
|
||||
esp_netif_t* netif = nullptr;
|
||||
/** @brief Scanning results */
|
||||
wifi_ap_record_t* _Nullable scan_list = nullptr;
|
||||
wifi_ap_record_t* scan_list = nullptr;
|
||||
/** @brief The current item count in scan_list (-1 when scan_list is NULL) */
|
||||
uint16_t scan_list_count = 0;
|
||||
/** @brief Maximum amount of records to scan (value > 0) */
|
||||
|
||||
Reference in New Issue
Block a user