2022-05-24 14:00:15 +00:00
|
|
|
#include "../nfc_i.h"
|
|
|
|
|
|
|
|
enum SubmenuIndex {
|
|
|
|
SubmenuIndexSave,
|
|
|
|
SubmenuIndexEmulate,
|
|
|
|
};
|
|
|
|
|
2022-07-26 15:30:49 +00:00
|
|
|
void nfc_scene_mf_classic_menu_submenu_callback(void* context, uint32_t index) {
|
2022-05-24 14:00:15 +00:00
|
|
|
Nfc* nfc = context;
|
|
|
|
|
|
|
|
view_dispatcher_send_custom_event(nfc->view_dispatcher, index);
|
|
|
|
}
|
|
|
|
|
2022-07-26 15:30:49 +00:00
|
|
|
void nfc_scene_mf_classic_menu_on_enter(void* context) {
|
2022-05-24 14:00:15 +00:00
|
|
|
Nfc* nfc = context;
|
|
|
|
Submenu* submenu = nfc->submenu;
|
|
|
|
|
|
|
|
submenu_add_item(
|
2022-07-26 15:30:49 +00:00
|
|
|
submenu, "Save", SubmenuIndexSave, nfc_scene_mf_classic_menu_submenu_callback, nfc);
|
2022-05-24 14:00:15 +00:00
|
|
|
submenu_add_item(
|
2022-07-26 15:30:49 +00:00
|
|
|
submenu, "Emulate", SubmenuIndexEmulate, nfc_scene_mf_classic_menu_submenu_callback, nfc);
|
2022-05-24 14:00:15 +00:00
|
|
|
submenu_set_selected_item(
|
2022-07-26 15:30:49 +00:00
|
|
|
nfc->submenu, scene_manager_get_scene_state(nfc->scene_manager, NfcSceneMfClassicMenu));
|
2022-05-24 14:00:15 +00:00
|
|
|
|
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewMenu);
|
|
|
|
}
|
|
|
|
|
2022-07-26 15:30:49 +00:00
|
|
|
bool nfc_scene_mf_classic_menu_on_event(void* context, SceneManagerEvent event) {
|
2022-05-24 14:00:15 +00:00
|
|
|
Nfc* nfc = context;
|
|
|
|
bool consumed = false;
|
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
|
|
|
if(event.event == SubmenuIndexSave) {
|
|
|
|
scene_manager_set_scene_state(
|
2022-07-26 15:30:49 +00:00
|
|
|
nfc->scene_manager, NfcSceneMfClassicMenu, SubmenuIndexSave);
|
2022-05-24 14:00:15 +00:00
|
|
|
nfc->dev->format = NfcDeviceSaveFormatMifareClassic;
|
|
|
|
// Clear device name
|
|
|
|
nfc_device_set_name(nfc->dev, "");
|
|
|
|
scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveName);
|
|
|
|
consumed = true;
|
|
|
|
} else if(event.event == SubmenuIndexEmulate) {
|
|
|
|
scene_manager_set_scene_state(
|
2022-07-26 15:30:49 +00:00
|
|
|
nfc->scene_manager, NfcSceneMfClassicMenu, SubmenuIndexEmulate);
|
|
|
|
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfClassicEmulate);
|
2022-05-24 14:00:15 +00:00
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
} else if(event.type == SceneManagerEventTypeBack) {
|
|
|
|
consumed =
|
|
|
|
scene_manager_search_and_switch_to_previous_scene(nfc->scene_manager, NfcSceneStart);
|
|
|
|
}
|
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
2022-07-26 15:30:49 +00:00
|
|
|
void nfc_scene_mf_classic_menu_on_exit(void* context) {
|
2022-05-24 14:00:15 +00:00
|
|
|
Nfc* nfc = context;
|
|
|
|
|
|
|
|
// Clear view
|
|
|
|
submenu_reset(nfc->submenu);
|
|
|
|
}
|