Viewport code example.
This commit is contained in:
40
plugins/minimal_viewport/README.md
Normal file
40
plugins/minimal_viewport/README.md
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# BASIC DEMO
|
||||||
|
## Introduction
|
||||||
|
This is a minimal Hello World application for the Flipper Zero using the Viewport. The goal of this project is to use it as a starting point for other applications.
|
||||||
|
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
- Copy the "minimal_viewport" [folder](..) to the \applications\plugins\minimal_viewport folder in your 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.
|
||||||
|
|
||||||
|
- 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 "Minimal Viewport Demo"
|
||||||
|
|
||||||
|
- The flipper should say "Hello World!"
|
||||||
|
|
||||||
|
- 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.
|
||||||
|
- specifies our icon is the minimal_viewport.png file.
|
||||||
|
- specifies our application can be found in the "Misc" category.
|
||||||
|
|
||||||
|
- minimal_viewport.png
|
||||||
|
- The icon for our application.
|
||||||
|
|
||||||
|
- minimal_viewport_app.c
|
||||||
|
- We #include the libraries we referece.
|
||||||
|
|
||||||
10
plugins/minimal_viewport/application.fam
Normal file
10
plugins/minimal_viewport/application.fam
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
App(
|
||||||
|
appid="Minimal_Viewport_Demo",
|
||||||
|
name="Minimal Viewport Demo",
|
||||||
|
apptype=FlipperAppType.EXTERNAL,
|
||||||
|
entry_point="minimal_viewport_demo_app",
|
||||||
|
requires=["gui"],
|
||||||
|
stack_size=2 * 1024,
|
||||||
|
fap_icon="minimal_viewport.png",
|
||||||
|
fap_category="Misc",
|
||||||
|
)
|
||||||
BIN
plugins/minimal_viewport/minimal_viewport.png
Normal file
BIN
plugins/minimal_viewport/minimal_viewport.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
43
plugins/minimal_viewport/minimal_viewport_app.c
Normal file
43
plugins/minimal_viewport/minimal_viewport_app.c
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#include <furi.h>
|
||||||
|
#include <gui/gui.h>
|
||||||
|
typedef struct {
|
||||||
|
int type;
|
||||||
|
InputEvent input;
|
||||||
|
} AppEvent;
|
||||||
|
static void input_callback(InputEvent* input_event, void* ctx) {
|
||||||
|
FuriMessageQueue* queue = ctx;
|
||||||
|
AppEvent event = {
|
||||||
|
.type = input_event->type,
|
||||||
|
.input = *input_event,
|
||||||
|
};
|
||||||
|
furi_message_queue_put(queue, &event, FuriWaitForever);
|
||||||
|
}
|
||||||
|
static void render_callback(Canvas* canvas, void* ctx) {
|
||||||
|
UNUSED(ctx);
|
||||||
|
canvas_set_font(canvas, FontPrimary);
|
||||||
|
canvas_draw_str_aligned(canvas, 15, 30, AlignLeft, AlignTop, "HELLO WORLD!");
|
||||||
|
}
|
||||||
|
//static ViewPort* view_port = view_port_alloc();
|
||||||
|
int32_t minimal_viewport_demo_app(void* p) {
|
||||||
|
UNUSED(p);
|
||||||
|
FuriMessageQueue* queue = furi_message_queue_alloc(8, sizeof(AppEvent));
|
||||||
|
ViewPort* view_port = view_port_alloc();
|
||||||
|
view_port_input_callback_set(view_port, input_callback, queue);
|
||||||
|
view_port_draw_callback_set(view_port, render_callback, NULL);
|
||||||
|
Gui* gui = furi_record_open(RECORD_GUI);
|
||||||
|
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
||||||
|
bool processing = true;
|
||||||
|
AppEvent event;
|
||||||
|
do {
|
||||||
|
if(furi_message_queue_get(queue, &event, FuriWaitForever) == FuriStatusOk) {
|
||||||
|
if(event.input.type == InputTypeShort && event.input.key == InputKeyBack) {
|
||||||
|
processing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while(processing);
|
||||||
|
view_port_enabled_set(view_port, false);
|
||||||
|
gui_remove_view_port(gui, view_port);
|
||||||
|
view_port_free(view_port);
|
||||||
|
furi_record_close(RECORD_GUI);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user