From dca8b03b8abe534ea9f937b75b8d042ecc8390cc Mon Sep 17 00:00:00 2001 From: Derek Jamison Date: Sun, 28 Jan 2024 11:27:45 -0600 Subject: [PATCH] clarify this is viewport --- plugins/basic/README.md | 30 +++++++----- ...asic_demo.png => basic_view_port_demo.png} | Bin ..._demo_app.c => basic_view_port_demo_app.c} | 44 +++++++++++------- 3 files changed, 47 insertions(+), 27 deletions(-) rename plugins/basic/{basic_demo.png => basic_view_port_demo.png} (100%) rename plugins/basic/{basic_demo_app.c => basic_view_port_demo_app.c} (70%) diff --git a/plugins/basic/README.md b/plugins/basic/README.md index 671ec9f..30f49e2 100644 --- a/plugins/basic/README.md +++ b/plugins/basic/README.md @@ -1,31 +1,39 @@ # BASIC DEMO -## Introduction -This is a basic application for the Flipper Zero. The goal of this project is to use it as a starting point for other applications. +## Introduction + +This is a basic ViewPort application for the Flipper Zero. The goal of this project is to use it as a starting point for other applications. When creating a UI for the Flipper Zero, you can choose from three techniques: + +- "ViewPort" (single view that does all the rendering & input handling) +- "ViewDispatcher" (multiple views, single back button is handled for you) +- "SceneManager" (multiple views, back button history is handled for you) ## Installation Directions + This project is intended to be overlayed on top of an existing firmware repo. -- Clone, Build & Deploy an existing flipper zero firmware repo. See this [tutorial](/firmware/updating/README.md) for updating firmware. + +- Clone, Build & Deploy an existing flipper zero firmware repo. See this [tutorial](/firmware/updating/README.md) for updating firmware. - Copy the "basic_demo" [folder](..) to the \applications\plugins\basic_demo folder in your firmware. -- Build & deploy the firmware. See this [tutorial](/firmware/updating/README.md) for updating firmware. +- Build & deploy the firmware. See this [tutorial](/firmware/updating/README.md) for updating firmware. - NOTE: You can also extract the basic_demo.FAP from resources.tar file and use qFlipper to copy the file to the SD Card/apps/Misc folder. - ## Running the updated firmware -These directions assume you are starting at the flipper desktop. If not, please press the back button until you are at the desktop. + +These directions assume you are starting at the flipper desktop. If not, please press the back button until you are at the desktop. - Press the OK button on the flipper to pull up the main menu. - Choose "Applications" from the menu. - Choose "Misc" from the sub-menu. -- Choose "Basic Demo" +- Choose "Basic Viewport Demo" -- The flipper should say "Basic Demo". +- The flipper should say "Basic Viewport Demo". - Press the BACK button to exit. - ## How it works + - application.fam + - specifies the name of our application. - specifies the entry point for our application. - specifies we use the GUI. @@ -33,6 +41,7 @@ These directions assume you are starting at the flipper desktop. If not, please - specifies our application can be found in the "Misc" category. - basic_demo.png + - The icon for our application. - basic_demo_app.c @@ -45,7 +54,7 @@ These directions assume you are starting at the flipper desktop. If not, please - We create a basic_demo_render_callback(...) method that does the screen rendering. - We acquire the mutex, so that no other thread can modify the data. - If unsuccessful, we don't render anything this frame. - - We select the Primary font. We render the text "Basic Demo". + - We select the Primary font. We render the text "Basic Demo". - We release the mutex, so other threads may modify the data. - We create the entrypoint basic_demo_app(...) method - We configure our initial data state @@ -60,4 +69,3 @@ These directions assume you are starting at the flipper desktop. If not, please - The message loop continues until processing is false. - We release our application resources. - We exit the program. - \ No newline at end of file diff --git a/plugins/basic/basic_demo.png b/plugins/basic/basic_view_port_demo.png similarity index 100% rename from plugins/basic/basic_demo.png rename to plugins/basic/basic_view_port_demo.png diff --git a/plugins/basic/basic_demo_app.c b/plugins/basic/basic_view_port_demo_app.c similarity index 70% rename from plugins/basic/basic_demo_app.c rename to plugins/basic/basic_view_port_demo_app.c index 87237a4..acb03ec 100644 --- a/plugins/basic/basic_demo_app.c +++ b/plugins/basic/basic_view_port_demo_app.c @@ -25,13 +25,14 @@ typedef enum { typedef struct { DemoEventType type; // The reason for this event. - InputEvent input; // This data is specific to keypress data. + InputEvent input; // This data is specific to keypress data. // You can add additional data that is helpful for your events. } DemoEvent; typedef struct { FuriString* buffer; // You can add additional state here. + int32_t counter; } DemoData; typedef struct { @@ -56,17 +57,23 @@ static void basic_demo_render_callback(Canvas* canvas, void* ctx) { } DemoData* data = demo_context->data; - furi_string_printf(data->buffer, "Basic"); - furi_string_cat_printf(data->buffer, " demo"); + furi_string_printf(data->buffer, "Basic ViewPort demo"); canvas_set_font(canvas, FontPrimary); - canvas_draw_str_aligned(canvas, 45, 30, AlignLeft, AlignTop, furi_string_get_cstr(data->buffer)); + canvas_draw_str_aligned( + canvas, 15, 25, AlignLeft, AlignTop, furi_string_get_cstr(data->buffer)); + + furi_string_printf(data->buffer, "OK pressed"); + furi_string_cat_printf(data->buffer, " %ld times.", data->counter); + canvas_set_font(canvas, FontSecondary); + canvas_draw_str_aligned( + canvas, 15, 40, AlignLeft, AlignTop, furi_string_get_cstr(data->buffer)); // Release the context, so other threads can update the data. furi_mutex_release(demo_context->mutex); } -int32_t basic_demo_app(void* p) { +int32_t basic_view_port_demo_app(void* p) { UNUSED(p); // Configure our initial data. @@ -91,18 +98,23 @@ int32_t basic_demo_app(void* p) { DemoEvent event; bool processing = true; do { - if (furi_message_queue_get(demo_context->queue, &event, FuriWaitForever) == FuriStatusOk) { + if(furi_message_queue_get(demo_context->queue, &event, FuriWaitForever) == FuriStatusOk) { FURI_LOG_T(TAG, "Got event type: %d", event.type); - switch (event.type) { - case DemoEventTypeKey: - // Short press of back button exits the program. - if(event.input.type == InputTypeShort && event.input.key == InputKeyBack) { - FURI_LOG_I(TAG, "Short-Back pressed. Exiting program."); - processing = false; + switch(event.type) { + case DemoEventTypeKey: + // Short press of back button exits the program. + if(event.input.type == InputTypeShort && event.input.key == InputKeyBack) { + FURI_LOG_I(TAG, "Short-Back pressed. Exiting program."); + processing = false; + } else if(event.input.type == InputTypeShort && event.input.key == InputKeyOk) { + FURI_LOG_I(TAG, "Short-OK pressed."); + if(furi_mutex_acquire(demo_context->mutex, FuriWaitForever) == FuriStatusOk) { + demo_context->data->counter++; + furi_mutex_release(demo_context->mutex); } - break; - default: - break; + } + default: + break; } // Send signal to update the screen (callback will get invoked at some point later.) @@ -111,7 +123,7 @@ int32_t basic_demo_app(void* p) { // We had an issue getting message from the queue, so exit application. processing = false; } - } while (processing); + } while(processing); // Free resources view_port_enabled_set(view_port, false);