2022-04-14 15:03:47 +03:00
|
|
|
#include "lfrfid_app_scene_read_menu.h"
|
2021-06-28 17:42:30 +03:00
|
|
|
|
|
|
|
typedef enum {
|
2022-04-06 21:34:51 +03:00
|
|
|
SubmenuSave,
|
2021-06-28 17:42:30 +03:00
|
|
|
SubmenuEmulate,
|
2022-04-22 22:01:21 +03:00
|
|
|
SubmenuWrite,
|
2021-06-28 17:42:30 +03:00
|
|
|
} SubmenuIndex;
|
|
|
|
|
2022-04-14 15:03:47 +03:00
|
|
|
void LfRfidAppSceneReadKeyMenu::on_enter(LfRfidApp* app, bool need_restore) {
|
2021-06-28 17:42:30 +03:00
|
|
|
auto submenu = app->view_controller.get<SubmenuVM>();
|
|
|
|
|
2022-04-06 21:34:51 +03:00
|
|
|
submenu->add_item("Save", SubmenuSave, submenu_callback, app);
|
2021-06-28 17:42:30 +03:00
|
|
|
submenu->add_item("Emulate", SubmenuEmulate, submenu_callback, app);
|
2022-04-22 22:01:21 +03:00
|
|
|
submenu->add_item("Write", SubmenuWrite, submenu_callback, app);
|
2021-06-28 17:42:30 +03:00
|
|
|
|
|
|
|
if(need_restore) {
|
|
|
|
submenu->set_selected_item(submenu_item_selected);
|
|
|
|
}
|
|
|
|
|
|
|
|
app->view_controller.switch_to<SubmenuVM>();
|
|
|
|
}
|
|
|
|
|
2022-04-14 15:03:47 +03:00
|
|
|
bool LfRfidAppSceneReadKeyMenu::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
|
2021-06-28 17:42:30 +03:00
|
|
|
bool consumed = false;
|
|
|
|
|
|
|
|
if(event->type == LfRfidApp::EventType::MenuSelected) {
|
|
|
|
submenu_item_selected = event->payload.menu_index;
|
|
|
|
switch(event->payload.menu_index) {
|
|
|
|
case SubmenuWrite:
|
|
|
|
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::Write);
|
|
|
|
break;
|
2022-04-06 21:34:51 +03:00
|
|
|
case SubmenuSave:
|
2021-06-28 17:42:30 +03:00
|
|
|
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::SaveName);
|
|
|
|
break;
|
|
|
|
case SubmenuEmulate:
|
|
|
|
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::Emulate);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
consumed = true;
|
|
|
|
} else if(event->type == LfRfidApp::EventType::Back) {
|
2022-04-14 15:03:47 +03:00
|
|
|
app->scene_controller.switch_to_previous_scene();
|
2021-06-28 17:42:30 +03:00
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
2022-04-14 15:03:47 +03:00
|
|
|
void LfRfidAppSceneReadKeyMenu::on_exit(LfRfidApp* app) {
|
2021-06-28 17:42:30 +03:00
|
|
|
app->view_controller.get<SubmenuVM>()->clean();
|
|
|
|
}
|
|
|
|
|
2022-04-14 15:03:47 +03:00
|
|
|
void LfRfidAppSceneReadKeyMenu::submenu_callback(void* context, uint32_t index) {
|
2021-06-28 17:42:30 +03:00
|
|
|
LfRfidApp* app = static_cast<LfRfidApp*>(context);
|
|
|
|
LfRfidApp::Event event;
|
|
|
|
|
|
|
|
event.type = LfRfidApp::EventType::MenuSelected;
|
|
|
|
event.payload.menu_index = index;
|
|
|
|
|
|
|
|
app->view_controller.send_event(&event);
|
|
|
|
}
|