clarify this is viewport

This commit is contained in:
Derek Jamison 2024-01-28 11:27:45 -06:00
parent 97a19a32f6
commit dca8b03b8a
3 changed files with 47 additions and 27 deletions

View File

@ -1,31 +1,39 @@
# BASIC DEMO # 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 ## Installation Directions
This project is intended to be overlayed on top of an existing firmware repo. 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. - 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. - 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 ## 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. - Press the OK button on the flipper to pull up the main menu.
- Choose "Applications" from the menu. - Choose "Applications" from the menu.
- Choose "Misc" from the sub-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. - Press the BACK button to exit.
## How it works ## How it works
- application.fam - application.fam
- specifies the name of our application. - specifies the name of our application.
- specifies the entry point for our application. - specifies the entry point for our application.
- specifies we use the GUI. - 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. - specifies our application can be found in the "Misc" category.
- basic_demo.png - basic_demo.png
- The icon for our application. - The icon for our application.
- basic_demo_app.c - basic_demo_app.c
@ -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. - The message loop continues until processing is false.
- We release our application resources. - We release our application resources.
- We exit the program. - We exit the program.

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -32,6 +32,7 @@ typedef struct {
typedef struct { typedef struct {
FuriString* buffer; FuriString* buffer;
// You can add additional state here. // You can add additional state here.
int32_t counter;
} DemoData; } DemoData;
typedef struct { typedef struct {
@ -56,17 +57,23 @@ static void basic_demo_render_callback(Canvas* canvas, void* ctx) {
} }
DemoData* data = demo_context->data; DemoData* data = demo_context->data;
furi_string_printf(data->buffer, "Basic"); furi_string_printf(data->buffer, "Basic ViewPort demo");
furi_string_cat_printf(data->buffer, " demo");
canvas_set_font(canvas, FontPrimary); 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. // Release the context, so other threads can update the data.
furi_mutex_release(demo_context->mutex); furi_mutex_release(demo_context->mutex);
} }
int32_t basic_demo_app(void* p) { int32_t basic_view_port_demo_app(void* p) {
UNUSED(p); UNUSED(p);
// Configure our initial data. // Configure our initial data.
@ -91,16 +98,21 @@ int32_t basic_demo_app(void* p) {
DemoEvent event; DemoEvent event;
bool processing = true; bool processing = true;
do { 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); FURI_LOG_T(TAG, "Got event type: %d", event.type);
switch (event.type) { switch(event.type) {
case DemoEventTypeKey: case DemoEventTypeKey:
// Short press of back button exits the program. // Short press of back button exits the program.
if(event.input.type == InputTypeShort && event.input.key == InputKeyBack) { if(event.input.type == InputTypeShort && event.input.key == InputKeyBack) {
FURI_LOG_I(TAG, "Short-Back pressed. Exiting program."); FURI_LOG_I(TAG, "Short-Back pressed. Exiting program.");
processing = false; 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: default:
break; break;
} }
@ -111,7 +123,7 @@ int32_t basic_demo_app(void* p) {
// We had an issue getting message from the queue, so exit application. // We had an issue getting message from the queue, so exit application.
processing = false; processing = false;
} }
} while (processing); } while(processing);
// Free resources // Free resources
view_port_enabled_set(view_port, false); view_port_enabled_set(view_port, false);