flipper-zero-tutorials/gpio/wiegand/scenes/wiegand_main_menu.c

76 lines
2.6 KiB
C
Raw Normal View History

2023-04-13 22:45:31 +00:00
#include "../wiegand.h"
2023-04-07 03:46:18 +00:00
/*
Triggers a custom event that is handled in the main menu on_scene handler.
@param context Pointer to the application context.
@param index Index of the selected menu item to map to custom event.
*/
void wiegand_menu_callback(void* context, uint32_t index) {
App* app = context;
WiegandMainMenuEvent event = WiegandMainMenuUnknownEvent;
switch(index) {
case WiegandMainMenuInstructions:
event = WiegandMainMenuInstructionsEvent;
break;
case WiegandMainMenuRead:
event = WiegandMainMenuReadEvent;
break;
2023-09-14 02:56:30 +00:00
case WiegandMainMenuScan:
event = WiegandMainMenuScanEvent;
break;
2023-04-07 03:46:18 +00:00
case WiegandMainMenuLoad:
event = WiegandMainMenuLoadEvent;
break;
}
if(event != WiegandMainMenuUnknownEvent) {
scene_manager_handle_custom_event(app->scene_manager, event);
}
}
/*
Displays the main menu.
@param context Pointer to the application context.
*/
void wiegand_main_menu_scene_on_enter(void* context) {
App* app = context;
submenu_reset(app->submenu);
submenu_set_header(app->submenu, "Wiegand");
submenu_add_item(
app->submenu, "Instructions", WiegandMainMenuInstructions, wiegand_menu_callback, app);
submenu_add_item(app->submenu, "Read", WiegandMainMenuRead, wiegand_menu_callback, app);
2023-09-14 02:56:30 +00:00
submenu_add_item(
app->submenu, "Scan w/AutoSave", WiegandMainMenuScan, wiegand_menu_callback, app);
2023-04-07 03:46:18 +00:00
submenu_add_item(app->submenu, "Load", WiegandMainMenuLoad, wiegand_menu_callback, app);
view_dispatcher_switch_to_view(app->view_dispatcher, WiegandSubmenuView);
}
bool wiegand_main_menu_scene_on_event(void* context, SceneManagerEvent event) {
App* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case WiegandMainMenuInstructionsEvent:
scene_manager_next_scene(app->scene_manager, WiegandInstructionsScene);
consumed = true;
break;
case WiegandMainMenuReadEvent:
scene_manager_next_scene(app->scene_manager, WiegandReadScene);
consumed = true;
break;
2023-09-14 02:56:30 +00:00
case WiegandMainMenuScanEvent:
scene_manager_next_scene(app->scene_manager, WiegandScanScene);
consumed = true;
break;
2023-04-07 03:46:18 +00:00
case WiegandMainMenuLoadEvent:
scene_manager_next_scene(app->scene_manager, WiegandLoadScene);
consumed = true;
break;
default:
consumed = false;
break;
}
}
return consumed;
}