MCPcopy Create free account
hub / github.com/DroomOne/Flipper-Plugin-Tutorial / hello_world_app

Function hello_world_app

hello_world.c:48–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48int32_t hello_world_app() {
49 FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
50
51 PluginState* plugin_state = malloc(sizeof(PluginState));
52
53 hello_world_state_init(plugin_state);
54
55 ValueMutex state_mutex;
56 if(!init_mutex(&state_mutex, plugin_state, sizeof(PluginState))) {
57 FURI_LOG_E("Hello_world", "cannot create mutex\r\n");
58 free(plugin_state);
59 return 255;
60 }
61
62 // Set system callbacks
63 ViewPort* view_port = view_port_alloc();
64 view_port_draw_callback_set(view_port, render_callback, &state_mutex);
65 view_port_input_callback_set(view_port, input_callback, event_queue);
66
67 // Open GUI and register view_port
68 Gui* gui = furi_record_open("gui");
69 gui_add_view_port(gui, view_port, GuiLayerFullscreen);
70
71 PluginEvent event;
72 for(bool processing = true; processing;) {
73 FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
74
75 PluginState* plugin_state = (PluginState*)acquire_mutex_block(&state_mutex);
76
77 if(event_status == FuriStatusOk) {
78 // press events
79 if(event.type == EventTypeKey) {
80 if(event.input.type == InputTypePress) {
81 switch(event.input.key) {
82 case InputKeyUp:
83 plugin_state->y--;
84 break;
85 case InputKeyDown:
86 plugin_state->y++;
87 break;
88 case InputKeyRight:
89 plugin_state->x++;
90 break;
91 case InputKeyLeft:
92 plugin_state->x--;
93 break;
94 case InputKeyOk:
95 case InputKeyBack:
96 processing = false;
97 break;
98 default:
99 break;
100 }
101 }
102 }
103 } else {
104 FURI_LOG_D("Hello_world", "FuriMessageQueue: event timeout");
105 // event timeout

Callers

nothing calls this directly

Calls 1

hello_world_state_initFunction · 0.85

Tested by

no test coverage detected