Skip to content

Commit

Permalink
chore: add resources and demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex4386 committed May 25, 2024
1 parent e58afa6 commit f1813ba
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 32 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dist/*
.vscode
.clang-format
.editorconfig
.env
.ufbt
12 changes: 4 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,11 +37,16 @@
```
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.**

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)
35 changes: 25 additions & 10 deletions application.fam
Original file line number Diff line number Diff line change
@@ -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
)
12 changes: 0 additions & 12 deletions demo_app.c

This file was deleted.

File renamed without changes
File renamed without changes.
File renamed without changes
8 changes: 8 additions & 0 deletions src/entrypoint.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <furi.h>
#include "main.h"

int32_t main_entrypoint(void* p) {
UNUSED(p);
main();
return 0;
}
29 changes: 29 additions & 0 deletions src/events.c
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions src/events.h
Original file line number Diff line number Diff line change
@@ -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 changes: 27 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

int main();
37 changes: 37 additions & 0 deletions src/utils/gui.c
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions src/utils/gui.h
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit f1813ba

Please sign in to comment.