From f1813ba454d96753febaa1acfa7320d41674bb58 Mon Sep 17 00:00:00 2001 From: Alex4386 Date: Sat, 25 May 2024 15:52:54 +0000 Subject: [PATCH] chore: add resources and demo app --- .gitignore | 6 +++++ CHANGELOG.md | 12 +++------ README.md | 10 ++++++-- application.fam | 35 ++++++++++++++++++-------- demo_app.c | 12 --------- demo_app.png => icon.png | Bin {images => icons}/.gitkeep | 0 {images => icons}/dolphin_71x25.png | Bin src/entrypoint.c | 8 ++++++ src/events.c | 29 ++++++++++++++++++++++ src/events.h | 7 ++++++ src/main.c | 27 ++++++++++++++++++++ src/main.h | 3 +++ src/utils/gui.c | 37 ++++++++++++++++++++++++++++ src/utils/gui.h | 11 +++++++++ 15 files changed, 165 insertions(+), 32 deletions(-) create mode 100644 .gitignore delete mode 100644 demo_app.c rename demo_app.png => icon.png (100%) rename {images => icons}/.gitkeep (100%) rename {images => icons}/dolphin_71x25.png (100%) create mode 100644 src/entrypoint.c create mode 100644 src/events.c create mode 100644 src/events.h create mode 100644 src/main.c create mode 100644 src/main.h create mode 100644 src/utils/gui.c create mode 100644 src/utils/gui.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..81a8981 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +dist/* +.vscode +.clang-format +.editorconfig +.env +.ufbt diff --git a/CHANGELOG.md b/CHANGELOG.md index acc8a3d..b34d0dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,5 @@ -v0.5: - * added images - -v0.4: - * added changelog +v1.0: + * The first release of the plugin -older: - * various - * fixes \ No newline at end of file +v0.5: + * this is the example of the changelog diff --git a/README.md b/README.md index 55e4394..657300e 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,8 @@ |:-------------:|:-------------:| | ![Nightly Build](https://github.com/Alex4386/f0-template/actions/workflows/nightly.yml/badge.svg) | ![Release Build](https://github.com/Alex4386/f0-template/actions/workflows/release.yml/badge.svg) | -## Build Instruction +## Setup Build environment +### Build Instruction 1. Install `ufbt`: ```bash pip3 install ufbt @@ -36,7 +37,7 @@ ``` 5. Compiled binary is now available at `./dist/` directory. -## Setup Visual Studio Code +### Setup Visual Studio Code > [!WARNING] > This command will overwrite your `.vscode` directory and `.gitignore` on your root directory. > **Make sure to backup your changes before running this command.** @@ -44,3 +45,8 @@ 1. Suppose your build environment is ready. 2. Run `ufbt vscode_dist` to generate Visual Studio Code config. +## Developer Resources +Here are the resources for developing applications for Flipper Zero: +- [Flipper Zero Firmware Docs](https://developer.flipper.net/flipperzero/doxygen/) + - [`struct` list](https://developer.flipper.net/flipperzero/doxygen/annotated.html) [index](https://developer.flipper.net/flipperzero/doxygen/classes.html) +- [Flipper Zero code examples](https://github.com/m1ch3al/flipper-zero-dev-tutorial) diff --git a/application.fam b/application.fam index 9bd66d4..b1cff73 100644 --- a/application.fam +++ b/application.fam @@ -1,17 +1,32 @@ -# For details & more options, see documentation/AppManifests.md in firmware repo +# Please refer to: +# https://developer.flipper.net/flipperzero/doxygen/app_manifests.html App( appid="demo_app", # Must be unique - name="App demo_app", # Displayed in UI + name="Demo Application", # Displayed in UI apptype=FlipperAppType.EXTERNAL, - entry_point="demo_app_app", - stack_size=2 * 1024, + entry_point="main_entrypoint", + stack_size=2 * 1024, # size of memory stack it will allocate + + # source code settings + sources=["src/*.c*", "src/*/*.c*"], # Due to limitation of the fbt, + # you need to specify nested directories + # manually since it doesn't support + # recurse globbing such as "src/**/*.c*" + + # Dependencies + requires=[ + "gui", # allows to use GUI functions + + ], + + # FAP Settings fap_category="Tools", - # Optional values - fap_description="A simple app", + fap_description="A simple app for demonstration", fap_version="1.0", # (major, minor) - fap_icon="demo_app.png", # 10x10 1-bit PNG - # fap_author="J. Doe", - # fap_weburl="https://github.com/user/demo_app", - fap_icon_assets="images", # Image assets to compile for this application + fap_icon="icon.png", # 10x10 1-bit PNG + fap_author="Alex4386", + fap_weburl="https://github.com/Alex4386/f0-template", + fap_icon_assets="icons", # Image assets to compile for this application + # available as {appid}_icons.h in the source code ) diff --git a/demo_app.c b/demo_app.c deleted file mode 100644 index b895c87..0000000 --- a/demo_app.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -/* generated by fbt from .png files in images folder */ -#include - -int32_t demo_app_app(void* p) { - UNUSED(p); - FURI_LOG_I("TEST", "Hello world"); - FURI_LOG_I("TEST", "I'm demo_app!"); - - return 0; -} diff --git a/demo_app.png b/icon.png similarity index 100% rename from demo_app.png rename to icon.png diff --git a/images/.gitkeep b/icons/.gitkeep similarity index 100% rename from images/.gitkeep rename to icons/.gitkeep diff --git a/images/dolphin_71x25.png b/icons/dolphin_71x25.png similarity index 100% rename from images/dolphin_71x25.png rename to icons/dolphin_71x25.png diff --git a/src/entrypoint.c b/src/entrypoint.c new file mode 100644 index 0000000..5353df6 --- /dev/null +++ b/src/entrypoint.c @@ -0,0 +1,8 @@ +#include +#include "main.h" + +int32_t main_entrypoint(void* p) { + UNUSED(p); + main(); + return 0; +} diff --git a/src/events.c b/src/events.c new file mode 100644 index 0000000..1e3101e --- /dev/null +++ b/src/events.c @@ -0,0 +1,29 @@ +#include +#include + +void on_draw(Canvas* canvas, void* context) { + UNUSED(context); + + // clear canvas + canvas_clear(canvas); + + // Set the font + canvas_set_font(canvas, FontPrimary); + canvas_draw_str(canvas, 32, 13, "Hello, World!"); + + // draw dolphin first + canvas_draw_icon(canvas, 32, 34, &I_dolphin_71x25); + + // write press back + canvas_set_font(canvas, FontSecondary); + canvas_draw_str(canvas, 15, 26, " press back to exit FAP"); + + canvas_draw_line(canvas, 2, 16, 126, 16); +} + +void on_input(InputEvent* event, void* context) { + furi_assert(context); + FuriMessageQueue* msg_queue = (FuriMessageQueue*)context; + + furi_message_queue_put(msg_queue, event, FuriWaitForever); +} diff --git a/src/events.h b/src/events.h new file mode 100644 index 0000000..67dd32b --- /dev/null +++ b/src/events.h @@ -0,0 +1,7 @@ +#pragma once +#include +#include +#include + +void on_draw(Canvas* canvas, void* context); +void on_input(InputEvent* event, void* context); diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..f848f48 --- /dev/null +++ b/src/main.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include "events.h" +#include "utils/gui.h" + +int main() { + // 1. Provision the InputHandlers + // Handle input event + InputEvent event; + GUISetupData* gui_setup = setup_gui(on_draw, on_input); + + // 2. Main EventLoop + while(true) { + // 4.1. Read input event from the message queue + furi_check( + furi_message_queue_get(gui_setup->msg_queue, &event, FuriWaitForever) == FuriStatusOk); + + // 4.2. check if the event is a quit event + if(event.key == InputKeyBack) { + break; + } + } + + // 3. Free the resources + free_gui(gui_setup); +} diff --git a/src/main.h b/src/main.h new file mode 100644 index 0000000..9595166 --- /dev/null +++ b/src/main.h @@ -0,0 +1,3 @@ +#pragma once + +int main(); diff --git a/src/utils/gui.c b/src/utils/gui.c new file mode 100644 index 0000000..871a747 --- /dev/null +++ b/src/utils/gui.c @@ -0,0 +1,37 @@ +#include +#include +#include "gui.h" + +GUISetupData* setup_gui(ViewPortDrawCallback on_draw, ViewPortInputCallback on_input) { + GUISetupData* data = malloc(sizeof(GUISetupData)); + + data->msg_queue = furi_message_queue_alloc(8, sizeof(InputEvent)); + data->viewport = view_port_alloc(); + + view_port_draw_callback_set(data->viewport, on_draw, NULL); + view_port_input_callback_set(data->viewport, on_input, data->msg_queue); + data->gui = furi_record_open(RECORD_GUI); + gui_add_view_port(data->gui, data->viewport, GuiLayerFullscreen); + return data; +} + +void free_gui(GUISetupData* data) { + // nullguard! + if(data == NULL) return; + + if(data->msg_queue != NULL) { + furi_message_queue_free(data->msg_queue); + } + + if(data->viewport != NULL) { + if(data->gui != NULL) { + gui_remove_view_port(data->gui, data->viewport); + } + + view_port_enabled_set(data->viewport, false); + view_port_free(data->viewport); + } + + furi_record_close(RECORD_GUI); + free(data); +} \ No newline at end of file diff --git a/src/utils/gui.h b/src/utils/gui.h new file mode 100644 index 0000000..1926408 --- /dev/null +++ b/src/utils/gui.h @@ -0,0 +1,11 @@ +#pragma once +#include + +typedef struct GUISetupData { + FuriMessageQueue* msg_queue; + ViewPort* viewport; + Gui* gui; +} GUISetupData; + +GUISetupData* setup_gui(ViewPortDrawCallback on_draw, ViewPortInputCallback on_input); +void free_gui(GUISetupData* data);