From 2d47104aa92f02bd9d8ae45f4df150eafb112c05 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Thu, 28 Dec 2023 01:11:52 +0100 Subject: [PATCH] improved hello world readability --- main/src/hello_world/hello_world.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/main/src/hello_world/hello_world.c b/main/src/hello_world/hello_world.c index 3fd1cd6d..fddcf83b 100644 --- a/main/src/hello_world/hello_world.c +++ b/main/src/hello_world/hello_world.c @@ -1,8 +1,6 @@ #include "hello_world.h" -#include "core_defines.h" #include "record.h" #include "nb_lvgl.h" -#include "nb_hardware.h" #include "applications/services/gui/gui.h" #include "esp_lvgl_port.h" #include "esp_log.h" @@ -11,7 +9,7 @@ static const char* TAG = "app_helloworld"; ViewPort* view_port = NULL; -static void prv_on_button_click(lv_event_t _Nonnull* event) { +static void on_button_click(lv_event_t _Nonnull* event) { ESP_LOGI(TAG, "button clicked"); FURI_RECORD_TRANSACTION(RECORD_GUI, gui, { @@ -21,7 +19,8 @@ static void prv_on_button_click(lv_event_t _Nonnull* event) { }); } -static void prv_hello_world_lvgl(lv_obj_t* parent, void* context) { +// Main entry point for LVGL widget creation +static void app_lvgl(lv_obj_t* parent, void* context) { lvgl_port_lock(0); lv_obj_t* label = lv_label_create(parent); @@ -35,18 +34,20 @@ static void prv_hello_world_lvgl(lv_obj_t* parent, void* context) { label = lv_label_create(btn); lv_label_set_text_static(label, "Exit"); lv_obj_align(btn, LV_ALIGN_CENTER, 0, 30); - lv_obj_add_event_cb(btn, prv_on_button_click, LV_EVENT_CLICKED, NULL); + lv_obj_add_event_cb(btn, on_button_click, LV_EVENT_CLICKED, NULL); lvgl_port_unlock(); } -static int32_t prv_hello_world_main(void* param) { +// Main entry point for the app +static int32_t app_main(void* param) { UNUSED(param); - // Configure view port + // Configure view port to enable UI with LVGL view_port = view_port_alloc(); - view_port_draw_callback_set(view_port, &prv_hello_world_lvgl, view_port); + view_port_draw_callback_set(view_port, &app_lvgl, view_port); + // The transaction automatically calls furi_record_open() and furi_record_close() FURI_RECORD_TRANSACTION(RECORD_GUI, gui, { gui_add_view_port(gui, view_port, GuiLayerFullscreen); }) @@ -58,7 +59,7 @@ const NbApp hello_world_app = { .id = "helloworld", .name = "Hello World", .type = USER, - .entry_point = &prv_hello_world_main, + .entry_point = &app_main, .stack_size = NB_TASK_STACK_SIZE_DEFAULT, .priority = NB_TASK_PRIORITY_DEFAULT };