Headless improvements (#58)

- Refactored headless init
- Cleanup of statusbar updater
This commit is contained in:
Ken Van Hoeylandt 2024-09-23 21:46:29 +02:00 committed by GitHub
parent fd27799826
commit a67ae35aae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 58 additions and 27 deletions

View File

@ -1,14 +1,42 @@
#include "tactility_headless.h" #include "tactility_headless.h"
#include "hardware_config.h" #include "hardware_config.h"
#include "hardware_i.h" #include "hardware_i.h"
#include "service_manifest.h"
#include "service_registry.h" #include "service_registry.h"
#ifdef ESP_PLATFORM
#include "esp_init.h"
#endif
#define TAG "tactility"
extern const ServiceManifest sdcard_service;
extern const ServiceManifest wifi_service;
static const ServiceManifest* const system_services[] = {
&sdcard_service,
&wifi_service
};
static const HardwareConfig* hardwareConfig = NULL; static const HardwareConfig* hardwareConfig = NULL;
void tt_tactility_headless_init(const HardwareConfig* config, const ServiceManifest* const services[32]) { static void register_and_start_system_services() {
TT_LOG_I(TAG, "Registering and starting system services");
int app_count = sizeof(system_services) / sizeof(ServiceManifest*);
for (int i = 0; i < app_count; ++i) {
tt_service_registry_add(system_services[i]);
tt_check(tt_service_registry_start(system_services[i]->id));
}
}
void tt_headless_init(const HardwareConfig* config) {
#ifdef ESP_PLATFORM
tt_esp_init();
#endif
hardwareConfig = config;
tt_service_registry_init(); tt_service_registry_init();
tt_hardware_init(config); tt_hardware_init(config);
hardwareConfig = config; register_and_start_system_services();
} }
const HardwareConfig* tt_get_hardware_config() { const HardwareConfig* tt_get_hardware_config() {

View File

@ -1,14 +1,13 @@
#pragma once #pragma once
#include "hardware_config.h" #include "hardware_config.h"
#include "service_manifest.h"
#include "tactility_headless_config.h" #include "tactility_headless_config.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void tt_tactility_headless_init(const HardwareConfig* config, const ServiceManifest* const services[32]); void tt_headless_init(const HardwareConfig* config);
const HardwareConfig* tt_get_hardware_config(); const HardwareConfig* tt_get_hardware_config();

View File

@ -1,13 +1,12 @@
#include "mutex.h" #include "mutex.h"
#include "service.h" #include "service.h"
#include "ui/statusbar.h" #include "ui/statusbar.h"
#define TAG "wifi_statusbar_service"
#include "assets.h" #include "assets.h"
#include "sdcard.h" #include "sdcard.h"
#include "services/wifi/wifi.h" #include "services/wifi/wifi.h"
#define TAG "statusbar_service"
typedef struct { typedef struct {
Mutex* mutex; Mutex* mutex;
Thread* thread; Thread* thread;
@ -18,6 +17,8 @@ typedef struct {
const char* sdcard_last_icon; const char* sdcard_last_icon;
} ServiceData; } ServiceData;
// region wifi
const char* wifi_get_status_icon_for_rssi(int rssi, bool secured) { const char* wifi_get_status_icon_for_rssi(int rssi, bool secured) {
if (rssi > 0) { if (rssi > 0) {
return TT_ASSETS_ICON_WIFI_CONNECTION_ISSUE; return TT_ASSETS_ICON_WIFI_CONNECTION_ISSUE;
@ -50,6 +51,20 @@ static const char* wifi_get_status_icon(WifiRadioState state, bool secure) {
} }
} }
static void update_wifi_icon(ServiceData* data) {
WifiRadioState radio_state = wifi_get_radio_state();
bool is_secure = wifi_is_connection_secure();
const char* desired_icon = wifi_get_status_icon(radio_state, is_secure);
if (data->wifi_last_icon != desired_icon) {
tt_statusbar_icon_set_image(data->wifi_icon_id, desired_icon);
data->wifi_last_icon = desired_icon;
}
}
// endregion wifi
// region sdcard
static _Nullable const char* sdcard_get_status_icon(SdcardState state) { static _Nullable const char* sdcard_get_status_icon(SdcardState state) {
switch (state) { switch (state) {
case SdcardStateMounted: case SdcardStateMounted:
@ -62,16 +77,6 @@ static _Nullable const char* sdcard_get_status_icon(SdcardState state) {
} }
} }
static void update_wifi_icon(ServiceData* data) {
WifiRadioState radio_state = wifi_get_radio_state();
bool is_secure = wifi_is_connection_secure();
const char* desired_icon = wifi_get_status_icon(radio_state, is_secure);
if (data->wifi_last_icon != desired_icon) {
tt_statusbar_icon_set_image(data->wifi_icon_id, desired_icon);
data->wifi_last_icon = desired_icon;
}
}
static void update_sdcard_icon(ServiceData* data) { static void update_sdcard_icon(ServiceData* data) {
SdcardState state = tt_sdcard_get_state(); SdcardState state = tt_sdcard_get_state();
const char* desired_icon = sdcard_get_status_icon(state); const char* desired_icon = sdcard_get_status_icon(state);
@ -82,6 +87,10 @@ static void update_sdcard_icon(ServiceData* data) {
} }
} }
// endregion sdcard
// region service
static ServiceData* service_data_alloc() { static ServiceData* service_data_alloc() {
ServiceData* data = malloc(sizeof(ServiceData)); ServiceData* data = malloc(sizeof(ServiceData));
*data = (ServiceData) { *data = (ServiceData) {
@ -135,7 +144,7 @@ static void on_start(Service service) {
tt_thread_set_callback(data->thread, service_main); tt_thread_set_callback(data->thread, service_main);
tt_thread_set_current_priority(ThreadPriorityLow); tt_thread_set_current_priority(ThreadPriorityLow);
tt_thread_set_stack_size(data->thread, 2048); // 2048 was the minimum when last tested tt_thread_set_stack_size(data->thread, 3000);
tt_thread_set_context(data->thread, data); tt_thread_set_context(data->thread, data);
tt_thread_start(data->thread); tt_thread_start(data->thread);
} }
@ -158,3 +167,5 @@ const ServiceManifest statusbar_updater_service = {
.on_start = &on_start, .on_start = &on_start,
.on_stop = &on_stop .on_stop = &on_stop
}; };
// endregion service

View File

@ -1,7 +1,6 @@
#include "tactility.h" #include "tactility.h"
#include "app_manifest_registry.h" #include "app_manifest_registry.h"
#include "esp_init.h"
#include "lvgl_init_i.h" #include "lvgl_init_i.h"
#include "service_registry.h" #include "service_registry.h"
#include "services/loader/loader.h" #include "services/loader/loader.h"
@ -26,8 +25,6 @@ static const ServiceManifest* const system_services[] = {
#ifndef ESP_PLATFORM // Screenshots don't work yet on ESP32 #ifndef ESP_PLATFORM // Screenshots don't work yet on ESP32
&screenshot_service, &screenshot_service,
#endif #endif
&sdcard_service,
&wifi_service,
&statusbar_updater_service &statusbar_updater_service
}; };
@ -109,25 +106,21 @@ static void register_and_start_user_services(const ServiceManifest* const servic
} }
} }
} }
void tt_init(const Config* config) { void tt_init(const Config* config) {
TT_LOG_I(TAG, "tt_init started"); TT_LOG_I(TAG, "tt_init started");
#ifdef ESP_PLATFORM
tt_esp_init();
#endif
// Assign early so starting services can use it // Assign early so starting services can use it
config_instance = config; config_instance = config;
tt_tactility_headless_init(config->hardware, config->services); tt_headless_init(config->hardware);
tt_lvgl_init(config->hardware); tt_lvgl_init(config->hardware);
tt_app_manifest_registry_init(); tt_app_manifest_registry_init();
// Note: the order of starting apps and services is critical! // Note: the order of starting apps and services is critical!
// System services are registered first so the apps below can use them // System services are registered first so the apps below can find them if needed
register_and_start_system_services(); register_and_start_system_services();
// Then we register system apps. They are not used/started yet. // Then we register system apps. They are not used/started yet.
register_system_apps(); register_system_apps();