Просмотр исходного кода

chore: add resources and demo app

Alex4386 1 год назад
Родитель
Сommit
f1813ba454
15 измененных файлов с 165 добавлено и 32 удалено
  1. 6 0
      .gitignore
  2. 4 8
      CHANGELOG.md
  3. 8 2
      README.md
  4. 25 10
      application.fam
  5. 0 12
      demo_app.c
  6. 0 0
      icon.png
  7. 0 0
      icons/.gitkeep
  8. 0 0
      icons/dolphin_71x25.png
  9. 8 0
      src/entrypoint.c
  10. 29 0
      src/events.c
  11. 7 0
      src/events.h
  12. 27 0
      src/main.c
  13. 3 0
      src/main.h
  14. 37 0
      src/utils/gui.c
  15. 11 0
      src/utils/gui.h

+ 6 - 0
.gitignore

@@ -0,0 +1,6 @@
+dist/*
+.vscode
+.clang-format
+.editorconfig
+.env
+.ufbt

+ 4 - 8
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
+v0.5:
+ * this is the example of the changelog

+ 8 - 2
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)

+ 25 - 10
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
 )

+ 0 - 12
demo_app.c

@@ -1,12 +0,0 @@
-#include <furi.h>
-
-/* generated by fbt from .png files in images folder */
-#include <demo_app_icons.h>
-
-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;
-}

+ 0 - 0
demo_app.png → icon.png


+ 0 - 0
images/.gitkeep → icons/.gitkeep


+ 0 - 0
images/dolphin_71x25.png → icons/dolphin_71x25.png


+ 8 - 0
src/entrypoint.c

@@ -0,0 +1,8 @@
+#include <furi.h>
+#include "main.h"
+
+int32_t main_entrypoint(void* p) {
+    UNUSED(p);
+    main();
+    return 0;
+}

+ 29 - 0
src/events.c

@@ -0,0 +1,29 @@
+#include <gui/gui.h>
+#include <demo_app_icons.h>
+
+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);
+}

+ 7 - 0
src/events.h

@@ -0,0 +1,7 @@
+#pragma once
+#include <stdio.h>
+#include <furi.h>
+#include <gui/gui.h>
+
+void on_draw(Canvas* canvas, void* context);
+void on_input(InputEvent* event, void* context);

+ 27 - 0
src/main.c

@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <furi.h>
+#include <gui/gui.h>
+#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);
+}

+ 3 - 0
src/main.h

@@ -0,0 +1,3 @@
+#pragma once
+
+int main();

+ 37 - 0
src/utils/gui.c

@@ -0,0 +1,37 @@
+#include <furi.h>
+#include <gui/gui.h>
+#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);
+}

+ 11 - 0
src/utils/gui.h

@@ -0,0 +1,11 @@
+#pragma once
+#include <gui/gui.h>
+
+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);