diff --git a/tactility-headless/src/sdcard.c b/tactility-headless/src/sdcard.c index d2b6a867..9811998a 100644 --- a/tactility-headless/src/sdcard.c +++ b/tactility-headless/src/sdcard.c @@ -46,11 +46,7 @@ bool tt_sdcard_mount(const SdCard* sdcard) { .sdcard = sdcard }; sdcard_unlock(); - if (data.context != NULL) { - return true; - } else { - return false; - } + return (data.context != NULL); } else { TT_LOG_E(TAG, "Failed to lock"); return false; diff --git a/tactility/src/apps/gpio/gpio.c b/tactility/src/apps/gpio/gpio.c index dbef9a73..88520b07 100644 --- a/tactility/src/apps/gpio/gpio.c +++ b/tactility/src/apps/gpio/gpio.c @@ -39,9 +39,10 @@ static void update_pin_widgets(Gpio* gpio) { for (int j = 0; j < GPIO_NUM_MAX; ++j) { int level = gpio->pin_states[j]; lv_obj_t* label = gpio->lv_pins[j]; - // user_data stores the state, so we can avoid unnecessary updates - if ((void*)level != label->user_data) { - label->user_data = (void*)level; + void* label_user_data = lv_obj_get_user_data(label); + // The user data stores the state, so we can avoid unnecessary updates + if ((void*)level != label_user_data) { + lv_obj_set_user_data(label, (void*)level); if (level == 0) { lv_obj_set_style_text_color(label, lv_color_black(), 0); } else { diff --git a/tactility/src/apps/screenshot/screenshot_ui.c b/tactility/src/apps/screenshot/screenshot_ui.c index 874cb532..400053c6 100644 --- a/tactility/src/apps/screenshot/screenshot_ui.c +++ b/tactility/src/apps/screenshot/screenshot_ui.c @@ -25,12 +25,12 @@ static void update_mode(ScreenshotUi* ui) { } static void on_mode_set(lv_event_t* event) { - ScreenshotUi* ui = (ScreenshotUi*)event->user_data; + ScreenshotUi* ui = (ScreenshotUi*)lv_event_get_user_data(event); update_mode(ui); } static void on_start_pressed(lv_event_t* event) { - ScreenshotUi* ui = event->user_data; + ScreenshotUi* ui = lv_event_get_user_data(event); if (tt_screenshot_is_started()) { TT_LOG_I(TAG, "Stop screenshot"); diff --git a/tactility/src/apps/system/files/files.c b/tactility/src/apps/system/files/files.c index a617643a..17abebc2 100644 --- a/tactility/src/apps/system/files/files.c +++ b/tactility/src/apps/system/files/files.c @@ -47,7 +47,7 @@ static bool is_image_file(const char* filename) { static void update_views(FilesData* data); static void on_navigate_up_pressed(lv_event_t* event) { - FilesData* files_data = (FilesData*)event->user_data; + FilesData* files_data = (FilesData*)lv_event_get_user_data(event); if (strcmp(files_data->current_path, "/") != 0) { TT_LOG_I(TAG, "Navigating upwards"); char new_absolute_path[MAX_PATH_LENGTH]; @@ -62,13 +62,13 @@ static void on_exit_app_pressed(TT_UNUSED lv_event_t* event) { loader_stop_app(); } -static void on_file_pressed(lv_event_t* e) { - lv_event_code_t code = lv_event_get_code(e); +static void on_file_pressed(lv_event_t* event) { + lv_event_code_t code = lv_event_get_code(event); if (code == LV_EVENT_CLICKED) { - lv_obj_t* button = e->current_target; + lv_obj_t* button = lv_event_get_current_target_obj(event); FilesData* files_data = lv_obj_get_user_data(button); - struct dirent* dir_entry = e->user_data; + struct dirent* dir_entry = lv_event_get_user_data(event); TT_LOG_I(TAG, "Pressed %s %d", dir_entry->d_name, dir_entry->d_type); switch (dir_entry->d_type) { diff --git a/tactility/src/apps/wifi_connect/wifi_connect_view.c b/tactility/src/apps/wifi_connect/wifi_connect_view.c index fe1e57c4..d7968087 100644 --- a/tactility/src/apps/wifi_connect/wifi_connect_view.c +++ b/tactility/src/apps/wifi_connect/wifi_connect_view.c @@ -14,7 +14,7 @@ #define TAG "wifi_connect" static void on_connect(lv_event_t* event) { - WifiConnect* wifi = (WifiConnect*)event->user_data; + WifiConnect* wifi = (WifiConnect*)lv_event_get_user_data(event); WifiConnectView* view = &wifi->view; const char* ssid = lv_textarea_get_text(view->ssid_textarea); const char* password = lv_textarea_get_text(view->password_textarea); diff --git a/tactility/src/apps/wifi_manage/wifi_manage_view.c b/tactility/src/apps/wifi_manage/wifi_manage_view.c index b921b533..a304e3a0 100644 --- a/tactility/src/apps/wifi_manage/wifi_manage_view.c +++ b/tactility/src/apps/wifi_manage/wifi_manage_view.c @@ -15,27 +15,27 @@ static void on_enable_switch_changed(lv_event_t* event) { lv_obj_t* enable_switch = lv_event_get_target(event); if (code == LV_EVENT_VALUE_CHANGED) { bool is_on = lv_obj_has_state(enable_switch, LV_STATE_CHECKED); - WifiManageBindings* bindings = (WifiManageBindings*)event->user_data; + WifiManageBindings* bindings = (WifiManageBindings*)lv_event_get_user_data(event); bindings->on_wifi_toggled(is_on); } } static void on_disconnect_pressed(lv_event_t* event) { - WifiManageBindings* bindings = (WifiManageBindings*)event->user_data; + WifiManageBindings* bindings = (WifiManageBindings*)lv_event_get_user_data(event); bindings->on_disconnect(); } // region Secondary updates static void connect(lv_event_t* event) { - lv_obj_t* button = event->current_target; + lv_obj_t* button = lv_event_get_current_target_obj(event); // Assumes that the second child of the button is a label ... risky lv_obj_t* label = lv_obj_get_child(button, 1); // We get the SSID from the button label because it's safer than alloc'ing // our own and passing it as the event data const char* ssid = lv_label_get_text(label); TT_LOG_I(TAG, "Clicked AP: %s", ssid); - WifiManageBindings* bindings = (WifiManageBindings*)event->user_data; + WifiManageBindings* bindings = (WifiManageBindings*)lv_event_get_user_data(event); bindings->on_connect_ssid(ssid); } diff --git a/tactility/src/services/gui/gui.c b/tactility/src/services/gui/gui.c index 1a951489..548d55d9 100644 --- a/tactility/src/services/gui/gui.c +++ b/tactility/src/services/gui/gui.c @@ -25,7 +25,7 @@ void gui_loader_callback(const void* message, void* context) { LoaderEvent* event = (LoaderEvent*)message; if (event->type == LoaderEventTypeApplicationShowing) { App* app = event->app_showing.app; - AppManifest* app_manifest = tt_app_get_manifest(app); + const AppManifest* app_manifest = tt_app_get_manifest(app); gui_show_app(app, app_manifest->on_show, app_manifest->on_hide); } else if (event->type == LoaderEventTypeApplicationHiding) { gui_hide_app(); diff --git a/tactility/src/services/gui/gui_keyboard.c b/tactility/src/services/gui/gui_keyboard.c index dd239780..cc853b96 100644 --- a/tactility/src/services/gui/gui_keyboard.c +++ b/tactility/src/services/gui/gui_keyboard.c @@ -7,8 +7,9 @@ extern Gui* gui; static void show_keyboard(lv_event_t* event) { - gui_keyboard_show(event->current_target); - lv_obj_scroll_to_view(event->current_target, LV_ANIM_ON); + lv_obj_t* target = lv_event_get_current_target_obj(event); + gui_keyboard_show(target); + lv_obj_scroll_to_view(target, LV_ANIM_ON); } static void hide_keyboard(TT_UNUSED lv_event_t* event) { diff --git a/tactility/src/services/loader/loader.c b/tactility/src/services/loader/loader.c index f91e7580..5871eb6b 100644 --- a/tactility/src/services/loader/loader.c +++ b/tactility/src/services/loader/loader.c @@ -262,7 +262,7 @@ static void loader_do_stop_app() { // Stop current app App app_to_stop = loader_singleton->app_stack[current_app_index]; - AppManifest* manifest = tt_app_get_manifest(app_to_stop); + const AppManifest* manifest = tt_app_get_manifest(app_to_stop); app_transition_to_state(app_to_stop, AppStateHiding); app_transition_to_state(app_to_stop, AppStateStopped); diff --git a/tactility/src/services/loader/loader.h b/tactility/src/services/loader/loader.h index 2827a2d1..35cff42d 100644 --- a/tactility/src/services/loader/loader.h +++ b/tactility/src/services/loader/loader.h @@ -39,7 +39,7 @@ typedef struct { } LoaderEventAppHiding; typedef struct { - AppManifest* manifest; + const AppManifest* manifest; } LoaderEventAppStopped; typedef struct { diff --git a/tactility/src/ui/statusbar.c b/tactility/src/ui/statusbar.c index 016831db..0779d26f 100644 --- a/tactility/src/ui/statusbar.c +++ b/tactility/src/ui/statusbar.c @@ -1,3 +1,4 @@ +#define LV_USE_PRIVATE_API 1 // For actual lv_obj_t declaration #include "statusbar.h" #include "mutex.h" diff --git a/tactility/src/ui/toolbar.c b/tactility/src/ui/toolbar.c index 28bc4b47..2df623e9 100644 --- a/tactility/src/ui/toolbar.c +++ b/tactility/src/ui/toolbar.c @@ -1,10 +1,19 @@ +#define LV_USE_PRIVATE_API 1 // For actual lv_obj_t declaration #include "toolbar.h" #include "services/loader/loader.h" #include "ui/spacer.h" #include "ui/style.h" -#include "lvgl.h" +typedef struct { + lv_obj_t obj; + lv_obj_t* title_label; + lv_obj_t* close_button; + lv_obj_t* close_button_image; + lv_obj_t* action_container; + ToolbarAction* action_array[TOOLBAR_ACTION_LIMIT]; + uint8_t action_count; +} Toolbar; static void toolbar_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj); diff --git a/tactility/src/ui/toolbar.h b/tactility/src/ui/toolbar.h index 7d873f52..bfb72583 100644 --- a/tactility/src/ui/toolbar.h +++ b/tactility/src/ui/toolbar.h @@ -20,16 +20,6 @@ typedef struct { void* _Nullable callback_context; } ToolbarAction; -typedef struct { - lv_obj_t obj; - lv_obj_t* title_label; - lv_obj_t* close_button; - lv_obj_t* close_button_image; - lv_obj_t* action_container; - ToolbarAction* action_array[TOOLBAR_ACTION_LIMIT]; - uint8_t action_count; -} Toolbar; - lv_obj_t* tt_toolbar_create(lv_obj_t* parent, const char* title); lv_obj_t* tt_toolbar_create_for_app(lv_obj_t* parent, App app); void tt_toolbar_set_title(lv_obj_t* obj, const char* title);