flipperzero-firmware/applications/ibutton/scene/ibutton_scene_saved_key_menu.cpp
SG bdba15b366
[FL-2393][FL-2381] iButton, OneWire: move to plain C (#1068)
* iButton: getting started on the worker concept
* Hal delay: added global instructions_per_us variable
* iButton: one wire slave
* iButton: ibutton key setter
* iButton: one wire host, use ibutton_hal
* iButton\RFID: common pulse decoder concept
* iButton: cyfral decoder
* iButton: worker thread concept
* iButton: metakom decoder
* iButton: write key through worker
* iButton: worker mode holder
* iButton: worker improvements
* iButton: Cyfral encoder
* iButton: Metakom encoder
* lib: pulse protocol helpers
* iButton: Metakom decoder
* iButton: Cyfral decoder
* iButton worker: separate modes
* iButton: libs documentation
* HAL: iButton gpio modes
* iButton worker: rename modes file
* iButton worker, hal: move to LL
* iButton CLI: worker for reading and emulation commands
* iButton HAL: correct init and emulation sequence
* iButton cli: moved to plain C
* iButton: move to worker, small step to plain C
* Libs, one wire: move to plain C
* Libs: added forgotten files to compilation
* iButton writer: get rid of manual disable/enable irq
2022-03-29 16:01:56 +03:00

73 lines
2.5 KiB
C++

#include "ibutton_scene_saved_key_menu.h"
#include "../ibutton_app.h"
#include <callback-connector.h>
typedef enum {
SubmenuIndexEmulate,
SubmenuIndexWrite,
SubmenuIndexEdit,
SubmenuIndexDelete,
SubmenuIndexInfo,
} SubmenuIndex;
static void submenu_callback(void* context, uint32_t index) {
iButtonApp* app = static_cast<iButtonApp*>(context);
iButtonEvent event;
event.type = iButtonEvent::Type::EventTypeMenuSelected;
event.payload.menu_index = index;
app->get_view_manager()->send_event(&event);
}
void iButtonSceneSavedKeyMenu::on_enter(iButtonApp* app) {
iButtonAppViewManager* view_manager = app->get_view_manager();
Submenu* submenu = view_manager->get_submenu();
submenu_add_item(submenu, "Emulate", SubmenuIndexEmulate, submenu_callback, app);
if(ibutton_key_get_type(app->get_key()) == iButtonKeyDS1990) {
submenu_add_item(submenu, "Write", SubmenuIndexWrite, submenu_callback, app);
}
submenu_add_item(submenu, "Edit", SubmenuIndexEdit, submenu_callback, app);
submenu_add_item(submenu, "Delete", SubmenuIndexDelete, submenu_callback, app);
submenu_add_item(submenu, "Info", SubmenuIndexInfo, submenu_callback, app);
submenu_set_selected_item(submenu, submenu_item_selected);
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewSubmenu);
}
bool iButtonSceneSavedKeyMenu::on_event(iButtonApp* app, iButtonEvent* event) {
bool consumed = false;
if(event->type == iButtonEvent::Type::EventTypeMenuSelected) {
submenu_item_selected = event->payload.menu_index;
switch(event->payload.menu_index) {
case SubmenuIndexWrite:
app->switch_to_next_scene(iButtonApp::Scene::SceneWrite);
break;
case SubmenuIndexEmulate:
app->switch_to_next_scene(iButtonApp::Scene::SceneEmulate);
break;
case SubmenuIndexEdit:
app->switch_to_next_scene(iButtonApp::Scene::SceneAddValue);
break;
case SubmenuIndexDelete:
app->switch_to_next_scene(iButtonApp::Scene::SceneDeleteConfirm);
break;
case SubmenuIndexInfo:
app->switch_to_next_scene(iButtonApp::Scene::SceneInfo);
break;
}
consumed = true;
}
return consumed;
}
void iButtonSceneSavedKeyMenu::on_exit(iButtonApp* app) {
iButtonAppViewManager* view = app->get_view_manager();
Submenu* submenu = view->get_submenu();
submenu_reset(submenu);
}