2022-05-24 14:00:15 +00:00
|
|
|
#include "../nfc_i.h"
|
2022-10-11 16:54:35 +00:00
|
|
|
#include <dolphin/dolphin.h>
|
2022-05-24 14:00:15 +00:00
|
|
|
|
|
|
|
enum SubmenuIndex {
|
|
|
|
SubmenuIndexSave,
|
|
|
|
SubmenuIndexEmulate,
|
2022-11-29 13:10:02 +00:00
|
|
|
SubmenuIndexDetectReader,
|
2022-08-07 15:18:39 +00:00
|
|
|
SubmenuIndexInfo,
|
2022-05-24 14:00:15 +00:00
|
|
|
};
|
|
|
|
|
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-11-29 13:10:02 +00:00
|
|
|
if(!mf_classic_is_card_read(&nfc->dev->dev_data.mf_classic_data)) {
|
|
|
|
submenu_add_item(
|
|
|
|
submenu,
|
2023-03-08 11:27:21 +00:00
|
|
|
"Detect Reader",
|
2022-11-29 13:10:02 +00:00
|
|
|
SubmenuIndexDetectReader,
|
|
|
|
nfc_scene_mf_classic_menu_submenu_callback,
|
|
|
|
nfc);
|
|
|
|
}
|
2022-08-07 15:18:39 +00:00
|
|
|
submenu_add_item(
|
|
|
|
submenu, "Info", SubmenuIndexInfo, 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) {
|
2022-11-29 13:10:02 +00:00
|
|
|
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneMfClassicMenu, event.event);
|
2022-05-24 14:00:15 +00:00
|
|
|
if(event.event == SubmenuIndexSave) {
|
|
|
|
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) {
|
2022-07-26 15:30:49 +00:00
|
|
|
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfClassicEmulate);
|
2022-10-28 07:18:41 +00:00
|
|
|
if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneSetType)) {
|
|
|
|
DOLPHIN_DEED(DolphinDeedNfcAddEmulate);
|
|
|
|
} else {
|
|
|
|
DOLPHIN_DEED(DolphinDeedNfcEmulate);
|
|
|
|
}
|
2022-05-24 14:00:15 +00:00
|
|
|
consumed = true;
|
2022-11-29 13:10:02 +00:00
|
|
|
} else if(event.event == SubmenuIndexDetectReader) {
|
|
|
|
scene_manager_next_scene(nfc->scene_manager, NfcSceneDetectReader);
|
|
|
|
DOLPHIN_DEED(DolphinDeedNfcDetectReader);
|
|
|
|
consumed = true;
|
2022-08-07 15:18:39 +00:00
|
|
|
} else if(event.event == SubmenuIndexInfo) {
|
2022-08-17 15:08:13 +00:00
|
|
|
scene_manager_next_scene(nfc->scene_manager, NfcSceneNfcDataInfo);
|
2022-08-07 15:18:39 +00:00
|
|
|
consumed = true;
|
2022-05-24 14:00:15 +00:00
|
|
|
}
|
|
|
|
} else if(event.type == SceneManagerEventTypeBack) {
|
2022-07-26 17:28:37 +00:00
|
|
|
consumed = scene_manager_previous_scene(nfc->scene_manager);
|
2022-05-24 14:00:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|