From 7563a8c587d1a953ac21c386263a28bb6adc3757 Mon Sep 17 00:00:00 2001 From: Maddox Werts Date: Tue, 27 Aug 2024 00:37:32 -0400 Subject: [PATCH] Updated GUI system --- project/app.h | 8 ++++++++ project/flippypass.c | 24 ++++++++++++++++++------ project/ui.c | 28 ++++++++++++++++++++++++++++ project/ui.h | 8 ++++++++ 4 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 project/app.h diff --git a/project/app.h b/project/app.h new file mode 100644 index 0000000..83c8b23 --- /dev/null +++ b/project/app.h @@ -0,0 +1,8 @@ +// Define once +#ifndef H_APP +#define H_APP + +// Constants +#define TAG "FlippyPass" + +#endif \ No newline at end of file diff --git a/project/flippypass.c b/project/flippypass.c index 8bb9231..fe02b21 100644 --- a/project/flippypass.c +++ b/project/flippypass.c @@ -10,17 +10,29 @@ int32_t flippypass_app(void* p) { // Creating the UI struct uiManager* ui = ui_create(); - // Timer - int alive_timer = 0; - // Drawwing the UI + InputEvent event; while(ui->running) { + // Getting the input event + FuriStatus status = furi_message_queue_get(ui->event_queue, &event, 100); + furi_mutex_acquire(ui->mutex, FuriWaitForever); + + if (status == FuriStatusOk) { + if (event.key == InputKeyBack) { + ui->running = false; + return 0; + } + } else { + FURI_LOG_D(TAG, "Event Timeout"); + } + // Updating canvas view_port_update(ui->canvas); - - alive_timer += 1; - if (alive_timer > 10000000) {ui->running = false; break;} + furi_mutex_release(ui->mutex); } + + // Cleanup + ui_delete(ui); // Exit App return 0; diff --git a/project/ui.c b/project/ui.c index 6df9825..d634f88 100644 --- a/project/ui.c +++ b/project/ui.c @@ -10,15 +10,33 @@ uiManager* ui_create() { result->running = true; result->page = 0; + // Creating a GUI + result->gui = furi_record_open(RECORD_GUI); + // Creating a canvas result->canvas = view_port_alloc(); view_port_draw_callback_set(result->canvas, ui_draw, result); + gui_add_view_port(result->gui, result->canvas, GuiLayerFullscreen); + + // Creating mutex + result->mutex = furi_mutex_alloc(FuriMutexTypeNormal); + if (!result->mutex) { + FURI_LOG_E(TAG, "Failed to create Mutex\r\n"); + free(result); + return NULL; + } + + // Creating event queue + result->event_queue = furi_message_queue_alloc(8, sizeof(InputEvent)); // Returning the UI Manager return result; } void ui_draw(Canvas* canvas, void* ctx) { + // Showing the Main Menu + ui_p_mainmenu(canvas); + // Context into Result uiManager* manager = (uiManager*)ctx; @@ -46,4 +64,14 @@ void ui_p_mainmenu(Canvas* canvas) { canvas_set_font(canvas, FontSecondary); canvas_draw_str(canvas, 22, 32, "View Archive"); +} + +void ui_delete(uiManager* manager) { + furi_message_queue_free(manager->event_queue); + view_port_enabled_set(manager->canvas, false); + gui_remove_view_port(manager->gui, manager->canvas); + view_port_free(manager->canvas); + furi_record_close(RECORD_GUI); + furi_mutex_free(manager->mutex); + free(manager); } \ No newline at end of file diff --git a/project/ui.h b/project/ui.h index 0b79d00..e0444f0 100644 --- a/project/ui.h +++ b/project/ui.h @@ -5,10 +5,14 @@ // Libraries #include #include +#include "app.h" // Structures typedef struct { + FuriMessageQueue* event_queue; + FuriMutex* mutex; ViewPort* canvas; + Gui* gui; int page; bool running; @@ -18,7 +22,11 @@ typedef struct { uiManager* ui_create(); // Functions +void ui_timer(void* event_queue); + void ui_draw(Canvas* canvas, void* ctx); void ui_p_mainmenu(Canvas* canvas); +void ui_delete(uiManager* manager); + #endif \ No newline at end of file