mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-11-28 02:45:45 +03:00
8f9b2513ff
* SYSTEM: tickless mode with deep sleep. * Move FreeRTOS ticks to lptim2 * API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source. * API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode. * NFC: support for tickless mode. * API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications. * BLE: prevent sleep while core2 starting * HAL: nap while in insomnia mode * init records work * try to implement record delete * tests and flapp * flapp subsystem * new core functions to get app stat, simplify core code * fix thread termination * add strdup to core * fix tests * Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage * Refactoring: update furi record api usage, cleanup code * Fix broken merge for freertos apps * Core, Target: fix compilation warnings * Drop firmware target local * HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode. * SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial. * delete old app example-ipc * delete old app fatfs list * fix strobe app, add input header * delete old display driver * comment old app qr-code * fix sd-card test, add forced widget update * remove unused new core test * increase heap to 128k * comment and assert old core tests * fix syntax Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
102 lines
2.5 KiB
C++
102 lines
2.5 KiB
C++
#include <furi.h>
|
|
#include "app-template.h"
|
|
|
|
/*
|
|
To use this example you need to rename
|
|
AppExampleState - class to hold app state
|
|
AppExampleEvent - class to hold app event
|
|
AppExample - app class
|
|
app_cpp_example - function that launch app
|
|
*/
|
|
|
|
// event enumeration type
|
|
typedef uint8_t event_t;
|
|
|
|
// app state class
|
|
class AppExampleState {
|
|
public:
|
|
// state data
|
|
uint8_t example_data;
|
|
|
|
// state initializer
|
|
AppExampleState() {
|
|
example_data = 0;
|
|
}
|
|
};
|
|
|
|
// app events class
|
|
class AppExampleEvent {
|
|
public:
|
|
// events enum
|
|
static const event_t EventTypeTick = 0;
|
|
static const event_t EventTypeKey = 1;
|
|
|
|
// payload
|
|
union {
|
|
InputEvent input;
|
|
} value;
|
|
|
|
// event type
|
|
event_t type;
|
|
};
|
|
|
|
// our app derived from base AppTemplate class
|
|
// with template variables <state, events>
|
|
class AppExample : public AppTemplate<AppExampleState, AppExampleEvent> {
|
|
public:
|
|
void run();
|
|
void render(Canvas* canvas);
|
|
};
|
|
|
|
// start app
|
|
void AppExample::run() {
|
|
// here we dont need to acquire or release state
|
|
// because before we call app_ready our application is "single threaded"
|
|
state.example_data = 12;
|
|
|
|
// signal that we ready to render and ipc
|
|
app_ready();
|
|
|
|
// from here, any data that pass in render function must be guarded
|
|
// by calling acquire_state and release_state
|
|
|
|
AppExampleEvent event;
|
|
while(1) {
|
|
if(get_event(&event, 1000)) {
|
|
if(event.type == AppExampleEvent::EventTypeKey) {
|
|
// press events
|
|
if(event.value.input.state && event.value.input.input == InputBack) {
|
|
printf("bye!\n");
|
|
exit();
|
|
}
|
|
|
|
if(event.value.input.state && event.value.input.input == InputUp) {
|
|
// to read or write state you need to execute
|
|
// acquire modify release state
|
|
acquire_state();
|
|
state.example_data = 24;
|
|
release_state();
|
|
}
|
|
}
|
|
}
|
|
|
|
// signal to force gui update
|
|
update_gui();
|
|
};
|
|
}
|
|
|
|
// render app
|
|
void AppExample::render(Canvas* canvas) {
|
|
// here you dont need to call acquire_state or release_state
|
|
// to read or write app state, that already handled by caller
|
|
canvas_set_color(canvas, ColorBlack);
|
|
canvas_set_font(canvas, FontPrimary);
|
|
canvas_draw_str(canvas, 2, state.example_data, "Example app");
|
|
}
|
|
|
|
// app enter function
|
|
extern "C" void app_cpp_example(void* p) {
|
|
AppExample* app = new AppExample();
|
|
app->run();
|
|
}
|