Applications: unified entry point naming scheme, drop dead code, cleanup. (#628)
This commit is contained in:
@@ -1,97 +0,0 @@
|
||||
#include <furi.h>
|
||||
#include <api-hal.h>
|
||||
|
||||
#include <gui/gui.h>
|
||||
#include <input/input.h>
|
||||
|
||||
#include <notification/notification-messages.h>
|
||||
|
||||
#define BLINK_COLOR_COUNT 7
|
||||
|
||||
typedef enum {
|
||||
EventTypeTick,
|
||||
EventTypeKey,
|
||||
} EventType;
|
||||
|
||||
typedef struct {
|
||||
EventType type;
|
||||
InputEvent input;
|
||||
} BlinkEvent;
|
||||
|
||||
void blink_update(void* ctx) {
|
||||
furi_assert(ctx);
|
||||
osMessageQueueId_t event_queue = ctx;
|
||||
|
||||
BlinkEvent event = {.type = EventTypeTick};
|
||||
osMessageQueuePut(event_queue, &event, 0, 0);
|
||||
}
|
||||
|
||||
void blink_draw_callback(Canvas* canvas, void* ctx) {
|
||||
canvas_clear(canvas);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 2, 10, "Blink application");
|
||||
}
|
||||
|
||||
void blink_input_callback(InputEvent* input_event, void* ctx) {
|
||||
furi_assert(ctx);
|
||||
osMessageQueueId_t event_queue = ctx;
|
||||
|
||||
BlinkEvent event = {.type = EventTypeKey, .input = *input_event};
|
||||
osMessageQueuePut(event_queue, &event, 0, 0);
|
||||
}
|
||||
|
||||
int32_t application_blink(void* p) {
|
||||
osMessageQueueId_t event_queue = osMessageQueueNew(8, sizeof(BlinkEvent), NULL);
|
||||
|
||||
// Configure view port
|
||||
ViewPort* view_port = view_port_alloc();
|
||||
furi_check(view_port);
|
||||
view_port_draw_callback_set(view_port, blink_draw_callback, NULL);
|
||||
view_port_input_callback_set(view_port, blink_input_callback, event_queue);
|
||||
osTimerId_t timer = osTimerNew(blink_update, osTimerPeriodic, event_queue, NULL);
|
||||
osTimerStart(timer, 1000);
|
||||
|
||||
// Register view port in GUI
|
||||
Gui* gui = furi_record_open("gui");
|
||||
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
||||
|
||||
NotificationApp* notifications = furi_record_open("notification");
|
||||
|
||||
const NotificationSequence* colors[BLINK_COLOR_COUNT] = {
|
||||
&sequence_blink_red_100,
|
||||
&sequence_blink_green_100,
|
||||
&sequence_blink_blue_100,
|
||||
&sequence_blink_yellow_100,
|
||||
&sequence_blink_cyan_100,
|
||||
&sequence_blink_magenta_100,
|
||||
&sequence_blink_white_100,
|
||||
};
|
||||
|
||||
uint8_t state = 0;
|
||||
BlinkEvent event;
|
||||
|
||||
while(1) {
|
||||
furi_check(osMessageQueueGet(event_queue, &event, NULL, osWaitForever) == osOK);
|
||||
if(event.type == EventTypeKey) {
|
||||
if((event.input.type == InputTypeShort) && (event.input.key == InputKeyBack)) {
|
||||
furi_record_close("notification");
|
||||
view_port_enabled_set(view_port, false);
|
||||
gui_remove_view_port(gui, view_port);
|
||||
view_port_free(view_port);
|
||||
osMessageQueueDelete(event_queue);
|
||||
osTimerDelete(timer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
notification_message(notifications, colors[state]);
|
||||
|
||||
state++;
|
||||
if(state >= BLINK_COLOR_COUNT) {
|
||||
state = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,100 +0,0 @@
|
||||
#include <furi.h>
|
||||
#include <api-hal.h>
|
||||
#include <stdio.h>
|
||||
#include <gui/gui.h>
|
||||
#include <input/input.h>
|
||||
|
||||
typedef struct {
|
||||
InputEvent input;
|
||||
} InputDumpEvent;
|
||||
|
||||
void input_dump_draw_callback(Canvas* canvas, void* ctx) {
|
||||
canvas_clear(canvas);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 2, 10, "Input dump application");
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str(canvas, 2, 22, "Press long back to exit");
|
||||
}
|
||||
|
||||
void input_dump_input_callback(InputEvent* input_event, void* ctx) {
|
||||
furi_assert(ctx);
|
||||
osMessageQueueId_t event_queue = ctx;
|
||||
InputDumpEvent event = {.input = *input_event};
|
||||
osMessageQueuePut(event_queue, &event, 0, 0);
|
||||
}
|
||||
|
||||
static const char* input_dump_get_key_name(InputKey key) {
|
||||
switch(key) {
|
||||
case InputKeyOk:
|
||||
return "Ok";
|
||||
case InputKeyBack:
|
||||
return "Back";
|
||||
case InputKeyLeft:
|
||||
return "Left";
|
||||
case InputKeyRight:
|
||||
return "Right";
|
||||
case InputKeyUp:
|
||||
return "Up";
|
||||
case InputKeyDown:
|
||||
return "Down";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
static const char* input_dump_get_type_name(InputType type) {
|
||||
switch(type) {
|
||||
case InputTypePress:
|
||||
return "Press";
|
||||
case InputTypeRelease:
|
||||
return "Release";
|
||||
case InputTypeShort:
|
||||
return "Short";
|
||||
case InputTypeLong:
|
||||
return "Long";
|
||||
case InputTypeRepeat:
|
||||
return "Repeat";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
int32_t application_input_dump(void* p) {
|
||||
osMessageQueueId_t event_queue = osMessageQueueNew(8, sizeof(InputDumpEvent), NULL);
|
||||
|
||||
// Configure view port
|
||||
ViewPort* view_port = view_port_alloc();
|
||||
furi_check(view_port);
|
||||
view_port_draw_callback_set(view_port, input_dump_draw_callback, NULL);
|
||||
view_port_input_callback_set(view_port, input_dump_input_callback, event_queue);
|
||||
|
||||
// Register view port in GUI
|
||||
Gui* gui = furi_record_open("gui");
|
||||
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
||||
|
||||
FURI_LOG_I("INPUT DUMP", "waiting for input events");
|
||||
InputDumpEvent event;
|
||||
|
||||
while(1) {
|
||||
furi_check(osMessageQueueGet(event_queue, &event, NULL, osWaitForever) == osOK);
|
||||
|
||||
FURI_LOG_I(
|
||||
"INPUT DUMP",
|
||||
"key: %s type: %s",
|
||||
input_dump_get_key_name(event.input.key),
|
||||
input_dump_get_type_name(event.input.type));
|
||||
|
||||
if(event.input.type == InputTypeLong && event.input.key == InputKeyBack) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
FURI_LOG_I("INPUT DUMP", "shutting down, byebye!");
|
||||
|
||||
view_port_enabled_set(view_port, false);
|
||||
gui_remove_view_port(gui, view_port);
|
||||
view_port_free(view_port);
|
||||
osMessageQueueDelete(event_queue);
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,189 +0,0 @@
|
||||
#include <furi.h>
|
||||
#include <gui/gui.h>
|
||||
#include <input/input.h>
|
||||
|
||||
extern TIM_HandleTypeDef SPEAKER_TIM;
|
||||
|
||||
typedef struct {
|
||||
bool press[5];
|
||||
uint16_t up;
|
||||
uint16_t down;
|
||||
uint16_t left;
|
||||
uint16_t right;
|
||||
uint16_t ok;
|
||||
} State;
|
||||
|
||||
typedef enum {
|
||||
EventTypeTick,
|
||||
EventTypeKey,
|
||||
} EventType;
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
InputEvent input;
|
||||
} value;
|
||||
EventType type;
|
||||
} AppEvent;
|
||||
|
||||
static void reset_state(State* state) {
|
||||
state->left = 0;
|
||||
state->right = 0;
|
||||
state->up = 0;
|
||||
state->down = 0;
|
||||
state->ok = 0;
|
||||
}
|
||||
|
||||
static void render_callback(Canvas* canvas, void* ctx) {
|
||||
State* state = (State*)acquire_mutex((ValueMutex*)ctx, 25);
|
||||
canvas_clear(canvas);
|
||||
char strings[5][20];
|
||||
|
||||
sprintf(strings[0], "Ok: %d", state->ok);
|
||||
sprintf(strings[1], "L: %d", state->left);
|
||||
sprintf(strings[2], "R: %d", state->right);
|
||||
sprintf(strings[3], "U: %d", state->up);
|
||||
sprintf(strings[4], "D: %d", state->down);
|
||||
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 0, 10, "Keypad test");
|
||||
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str(canvas, 0, 24, strings[1]);
|
||||
canvas_draw_str(canvas, 35, 24, strings[2]);
|
||||
canvas_draw_str(canvas, 0, 36, strings[3]);
|
||||
canvas_draw_str(canvas, 35, 36, strings[4]);
|
||||
canvas_draw_str(canvas, 0, 48, strings[0]);
|
||||
canvas_draw_circle(canvas, 100, 26, 25);
|
||||
|
||||
if(state->press[0]) canvas_draw_disc(canvas, 118, 26, 5);
|
||||
if(state->press[1]) canvas_draw_disc(canvas, 82, 26, 5);
|
||||
if(state->press[2]) canvas_draw_disc(canvas, 100, 8, 5);
|
||||
if(state->press[3]) canvas_draw_disc(canvas, 100, 44, 5);
|
||||
if(state->press[4]) canvas_draw_disc(canvas, 100, 26, 5);
|
||||
|
||||
canvas_draw_str(canvas, 10, 63, "[back] - reset, hold to exit");
|
||||
|
||||
release_mutex((ValueMutex*)ctx, state);
|
||||
}
|
||||
|
||||
static void input_callback(InputEvent* input_event, void* ctx) {
|
||||
osMessageQueueId_t event_queue = ctx;
|
||||
|
||||
AppEvent event;
|
||||
event.type = EventTypeKey;
|
||||
event.value.input = *input_event;
|
||||
osMessageQueuePut(event_queue, &event, 0, 0);
|
||||
}
|
||||
|
||||
int32_t keypad_test(void* p) {
|
||||
osMessageQueueId_t event_queue = osMessageQueueNew(8, sizeof(AppEvent), NULL);
|
||||
furi_check(event_queue);
|
||||
|
||||
State _state = {{false, false, false, false, false}, 0, 0, 0, 0, 0};
|
||||
|
||||
ValueMutex state_mutex;
|
||||
if(!init_mutex(&state_mutex, &_state, sizeof(State))) {
|
||||
printf("[keypad_test] cannot create mutex\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ViewPort* view_port = view_port_alloc();
|
||||
|
||||
view_port_draw_callback_set(view_port, render_callback, &state_mutex);
|
||||
view_port_input_callback_set(view_port, input_callback, event_queue);
|
||||
|
||||
// Open GUI and register view_port
|
||||
Gui* gui = furi_record_open("gui");
|
||||
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
||||
|
||||
AppEvent event;
|
||||
while(1) {
|
||||
osStatus_t event_status = osMessageQueueGet(event_queue, &event, NULL, osWaitForever);
|
||||
State* state = (State*)acquire_mutex_block(&state_mutex);
|
||||
|
||||
if(event_status == osOK) {
|
||||
if(event.type == EventTypeKey) {
|
||||
if(event.value.input.type == InputTypeLong &&
|
||||
event.value.input.key == InputKeyBack) {
|
||||
printf("[keypad test] bye!\r\n");
|
||||
release_mutex(&state_mutex, state);
|
||||
break;
|
||||
}
|
||||
|
||||
if(event.value.input.type == InputTypeShort &&
|
||||
event.value.input.key == InputKeyBack) {
|
||||
reset_state(state);
|
||||
}
|
||||
|
||||
if(event.value.input.key == InputKeyRight) {
|
||||
if(event.value.input.type == InputTypePress) {
|
||||
state->press[0] = true;
|
||||
} else if(event.value.input.type == InputTypeRelease) {
|
||||
state->press[0] = false;
|
||||
}
|
||||
|
||||
if(event.value.input.type == InputTypeShort) {
|
||||
++state->right;
|
||||
}
|
||||
}
|
||||
|
||||
if(event.value.input.key == InputKeyLeft) {
|
||||
if(event.value.input.type == InputTypePress) {
|
||||
state->press[1] = true;
|
||||
} else if(event.value.input.type == InputTypeRelease) {
|
||||
state->press[1] = false;
|
||||
}
|
||||
|
||||
if(event.value.input.type == InputTypeShort) {
|
||||
++state->left;
|
||||
}
|
||||
}
|
||||
|
||||
if(event.value.input.key == InputKeyUp) {
|
||||
if(event.value.input.type == InputTypePress) {
|
||||
state->press[2] = true;
|
||||
} else if(event.value.input.type == InputTypeRelease) {
|
||||
state->press[2] = false;
|
||||
}
|
||||
|
||||
if(event.value.input.type == InputTypeShort) {
|
||||
++state->up;
|
||||
}
|
||||
}
|
||||
|
||||
if(event.value.input.key == InputKeyDown) {
|
||||
if(event.value.input.type == InputTypePress) {
|
||||
state->press[3] = true;
|
||||
} else if(event.value.input.type == InputTypeRelease) {
|
||||
state->press[3] = false;
|
||||
}
|
||||
|
||||
if(event.value.input.type == InputTypeShort) {
|
||||
++state->down;
|
||||
}
|
||||
}
|
||||
|
||||
if(event.value.input.key == InputKeyOk) {
|
||||
if(event.value.input.type == InputTypePress) {
|
||||
state->press[4] = true;
|
||||
} else if(event.value.input.type == InputTypeRelease) {
|
||||
state->press[4] = false;
|
||||
}
|
||||
|
||||
if(event.value.input.type == InputTypeShort) {
|
||||
++state->ok;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
view_port_update(view_port);
|
||||
release_mutex(&state_mutex, state);
|
||||
}
|
||||
// remove & free all stuff created by app
|
||||
gui_remove_view_port(gui, view_port);
|
||||
view_port_free(view_port);
|
||||
osMessageQueueDelete(event_queue);
|
||||
delete_mutex(&state_mutex);
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
#include "u8g2/u8g2.h"
|
||||
#include <furi.h>
|
||||
|
||||
int32_t u8g2_example(void* p) {
|
||||
// open record
|
||||
u8g2_t* fb = furi_record_open("u8g2_fb");
|
||||
u8g2_SetFont(fb, u8g2_font_6x10_mf);
|
||||
u8g2_SetDrawColor(fb, 1);
|
||||
u8g2_SetFontMode(fb, 1);
|
||||
u8g2_DrawStr(fb, 2, 12, "hello world!");
|
||||
furi_record_close("u8g2_fb");
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,76 +0,0 @@
|
||||
#include "u8g2/u8g2.h"
|
||||
#include "qrcode/qrcode.h"
|
||||
#include <furi.h>
|
||||
|
||||
/*
|
||||
TODO: rework with new app api
|
||||
|
||||
void u8g2_DrawPixelSize(u8g2_t* u8g2, uint8_t x, uint8_t y, uint8_t size) {
|
||||
for(uint8_t px = 0; px < size; px++) {
|
||||
for(uint8_t py = 0; py < size; py++) {
|
||||
u8g2_DrawPixel(u8g2, x + px, y + py);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t u8g2_qrcode(void* p) {
|
||||
// open record
|
||||
FuriRecordSubscriber* fb_record =
|
||||
furi_open_deprecated("u8g2_fb", false, false, NULL, NULL, NULL);
|
||||
|
||||
// Allocate a chunk of memory to store the QR code
|
||||
// https://github.com/ricmoo/QRCode
|
||||
// we init version 1, 21x21 px, 16 alphanumeric chars with
|
||||
// QUARTILE error correction
|
||||
const uint8_t qr_version = 1;
|
||||
const uint8_t qr_error_correction = ECC_QUARTILE;
|
||||
|
||||
const uint8_t qr_x = 32;
|
||||
const uint8_t qr_y = 0;
|
||||
const uint8_t qr_size = 3;
|
||||
|
||||
// The structure to manage the QR code
|
||||
QRCode qrcode;
|
||||
|
||||
// QR Code init
|
||||
uint8_t qrcodeBytes[qrcode_getBufferSize(qr_version)];
|
||||
qrcode_initText(&qrcode, qrcodeBytes, qr_version, qr_error_correction, "HELLO FLIPPER");
|
||||
|
||||
if(fb_record == NULL) {
|
||||
printf("[view_port] cannot create fb record\r\n");
|
||||
return 255;
|
||||
}
|
||||
|
||||
u8g2_t* fb = furi_take(fb_record);
|
||||
|
||||
// clear display
|
||||
if(fb != NULL) {
|
||||
u8g2_ClearBuffer(fb);
|
||||
}
|
||||
|
||||
while(1) {
|
||||
if(fb != NULL) {
|
||||
// draw qr code
|
||||
for(uint8_t y = 0; y < qrcode.size; y++) {
|
||||
for(uint8_t x = 0; x < qrcode.size; x++) {
|
||||
if(qrcode_getModule(&qrcode, x, y)) {
|
||||
u8g2_SetDrawColor(fb, 1);
|
||||
u8g2_DrawPixelSize(fb, qr_x + x * qr_size, qr_y + y * qr_size, qr_size);
|
||||
} else {
|
||||
u8g2_SetDrawColor(fb, 0);
|
||||
u8g2_DrawPixelSize(fb, qr_x + x * qr_size, qr_y + y * qr_size, qr_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return 255;
|
||||
}
|
||||
|
||||
furi_commit(fb_record);
|
||||
|
||||
delay(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
@@ -1,35 +0,0 @@
|
||||
#include <furi.h>
|
||||
#include <api-hal.h>
|
||||
#include <string.h>
|
||||
|
||||
int32_t application_uart_write(void* p) {
|
||||
// Red led for showing progress
|
||||
GpioPin led = {.pin = GPIO_PIN_8, .port = GPIOA};
|
||||
// TODO open record
|
||||
GpioPin* led_record = &led;
|
||||
|
||||
hal_gpio_init(led_record, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
// create buffer
|
||||
const char test_string[] = "test\n";
|
||||
printf(test_string);
|
||||
|
||||
// for example, create counter and show its value
|
||||
uint8_t counter = 0;
|
||||
|
||||
while(1) {
|
||||
// continously write it to UART
|
||||
printf("counter: %d\n", counter);
|
||||
counter++;
|
||||
|
||||
// flash at every send
|
||||
hal_gpio_write(led_record, false);
|
||||
delay(50);
|
||||
hal_gpio_write(led_record, true);
|
||||
|
||||
// delay with overall perion of 1s
|
||||
delay(950);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,103 +0,0 @@
|
||||
#include <furi.h>
|
||||
#include <gui/gui.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/modules/submenu.h>
|
||||
|
||||
static ViewDispatcher* view_dispatcher;
|
||||
static osMessageQueueId_t event_queue;
|
||||
|
||||
typedef enum {
|
||||
EventTypeGoAway,
|
||||
EventTypeGoToMainMenu,
|
||||
EventTypeSwitchToVertical,
|
||||
EventTypeSwitchToHorizontal,
|
||||
} EventType;
|
||||
|
||||
// Nothing dangerous in settings some vars and flags inside callback
|
||||
static void submenu_callback(void* context, uint32_t index) {
|
||||
EventType event = EventTypeGoAway;
|
||||
switch(index) {
|
||||
case 1:
|
||||
event = EventTypeSwitchToVertical;
|
||||
break;
|
||||
case 2:
|
||||
event = EventTypeSwitchToHorizontal;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
osMessageQueuePut(event_queue, &event, 0, 0);
|
||||
}
|
||||
|
||||
uint32_t previous_exit_callback(void* context) {
|
||||
EventType event = EventTypeGoAway;
|
||||
osMessageQueuePut(event_queue, &event, 0, 0);
|
||||
return VIEW_IGNORE;
|
||||
}
|
||||
|
||||
uint32_t previous_callback(void* context) {
|
||||
EventType event = EventTypeGoToMainMenu;
|
||||
osMessageQueuePut(event_queue, &event, 0, 0);
|
||||
return VIEW_IGNORE;
|
||||
}
|
||||
|
||||
int32_t application_vertical_screen(void* p) {
|
||||
event_queue = osMessageQueueNew(8, sizeof(EventType), NULL);
|
||||
|
||||
view_dispatcher = view_dispatcher_alloc();
|
||||
Gui* gui = furi_record_open("gui");
|
||||
view_dispatcher_attach_to_gui(view_dispatcher, gui, ViewDispatcherTypeFullscreen);
|
||||
|
||||
Submenu* submenu = submenu_alloc();
|
||||
View* submenu_view = submenu_get_view(submenu);
|
||||
view_set_previous_callback(submenu_view, previous_exit_callback);
|
||||
view_set_orientation(submenu_view, ViewOrientationVertical);
|
||||
submenu_add_item(submenu, "VerSubm", 1, submenu_callback, view_dispatcher);
|
||||
submenu_add_item(submenu, "HorSubm", 2, submenu_callback, view_dispatcher);
|
||||
view_dispatcher_add_view(view_dispatcher, 1, submenu_view);
|
||||
|
||||
Submenu* submenu_vertical = submenu_alloc();
|
||||
View* submenu_vertical_view = submenu_get_view(submenu_vertical);
|
||||
view_set_previous_callback(submenu_vertical_view, previous_callback);
|
||||
view_set_orientation(submenu_vertical_view, ViewOrientationVertical);
|
||||
submenu_add_item(submenu_vertical, "Vert1", 1, NULL, view_dispatcher);
|
||||
submenu_add_item(submenu_vertical, "Vert2", 2, NULL, view_dispatcher);
|
||||
view_dispatcher_add_view(view_dispatcher, 2, submenu_vertical_view);
|
||||
|
||||
Submenu* submenu_horizontal = submenu_alloc();
|
||||
View* submenu_horizontal_view = submenu_get_view(submenu_horizontal);
|
||||
view_set_previous_callback(submenu_horizontal_view, previous_callback);
|
||||
view_set_orientation(submenu_horizontal_view, ViewOrientationHorizontal);
|
||||
submenu_add_item(submenu_horizontal, "Horiz1", 1, NULL, view_dispatcher);
|
||||
submenu_add_item(submenu_horizontal, "Horiz2", 2, NULL, view_dispatcher);
|
||||
view_dispatcher_add_view(view_dispatcher, 3, submenu_horizontal_view);
|
||||
|
||||
view_dispatcher_switch_to_view(view_dispatcher, 1);
|
||||
|
||||
while(1) {
|
||||
EventType event;
|
||||
furi_check(osMessageQueueGet(event_queue, &event, NULL, osWaitForever) == osOK);
|
||||
if(event == EventTypeGoAway) {
|
||||
break;
|
||||
} else if(event == EventTypeGoToMainMenu) {
|
||||
view_dispatcher_switch_to_view(view_dispatcher, 1);
|
||||
} else if(event == EventTypeSwitchToVertical) {
|
||||
view_dispatcher_switch_to_view(view_dispatcher, 2);
|
||||
} else if(event == EventTypeSwitchToHorizontal) {
|
||||
view_dispatcher_switch_to_view(view_dispatcher, 3);
|
||||
}
|
||||
}
|
||||
|
||||
view_dispatcher_remove_view(view_dispatcher, 1);
|
||||
view_dispatcher_remove_view(view_dispatcher, 2);
|
||||
view_dispatcher_remove_view(view_dispatcher, 3);
|
||||
submenu_free(submenu);
|
||||
submenu_free(submenu_vertical);
|
||||
submenu_free(submenu_horizontal);
|
||||
view_dispatcher_free(view_dispatcher);
|
||||
osMessageQueueDelete(event_queue);
|
||||
furi_record_close("gui");
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,72 +0,0 @@
|
||||
#include <furi.h>
|
||||
#include <api-hal.h>
|
||||
|
||||
#include <gui/gui.h>
|
||||
#include <input/input.h>
|
||||
#include <notification/notification-messages.h>
|
||||
|
||||
typedef struct {
|
||||
InputEvent input;
|
||||
} VibroEvent;
|
||||
|
||||
void vibro_draw_callback(Canvas* canvas, void* ctx) {
|
||||
canvas_clear(canvas);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 2, 10, "Vibro application");
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str(canvas, 2, 22, "Press OK turns on vibro");
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str(canvas, 2, 34, "Release OK turns off vibro");
|
||||
}
|
||||
|
||||
void vibro_input_callback(InputEvent* input_event, void* ctx) {
|
||||
furi_assert(ctx);
|
||||
osMessageQueueId_t event_queue = ctx;
|
||||
|
||||
VibroEvent event = {.input = *input_event};
|
||||
osMessageQueuePut(event_queue, &event, 0, 0);
|
||||
}
|
||||
|
||||
int32_t application_vibro(void* p) {
|
||||
osMessageQueueId_t event_queue = osMessageQueueNew(8, sizeof(VibroEvent), NULL);
|
||||
|
||||
// Configure view port
|
||||
ViewPort* view_port = view_port_alloc();
|
||||
furi_check(view_port);
|
||||
view_port_draw_callback_set(view_port, vibro_draw_callback, NULL);
|
||||
view_port_input_callback_set(view_port, vibro_input_callback, event_queue);
|
||||
|
||||
// Register view port in GUI
|
||||
Gui* gui = furi_record_open("gui");
|
||||
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
||||
|
||||
NotificationApp* notification = furi_record_open("notification");
|
||||
|
||||
VibroEvent event;
|
||||
|
||||
while(1) {
|
||||
furi_check(osMessageQueueGet(event_queue, &event, NULL, osWaitForever) == osOK);
|
||||
if(event.input.type == InputTypeShort && event.input.key == InputKeyBack) {
|
||||
notification_message(notification, &sequence_reset_vibro);
|
||||
notification_message(notification, &sequence_reset_green);
|
||||
furi_record_close("notification");
|
||||
view_port_enabled_set(view_port, false);
|
||||
gui_remove_view_port(gui, view_port);
|
||||
view_port_free(view_port);
|
||||
osMessageQueueDelete(event_queue);
|
||||
|
||||
return 0;
|
||||
}
|
||||
if(event.input.key == InputKeyOk) {
|
||||
if(event.input.type == InputTypePress) {
|
||||
notification_message(notification, &sequence_set_vibro_on);
|
||||
notification_message(notification, &sequence_set_green_255);
|
||||
} else if(event.input.type == InputTypeRelease) {
|
||||
notification_message(notification, &sequence_reset_vibro);
|
||||
notification_message(notification, &sequence_reset_green);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user