mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-12-24 03:33:08 +00:00
8cfd0eab9e
* rfal: add state changed callback * furi_hal_nfc: add NFC-A emulation API * nfc: add emulation logger, refactor scenes * elements: fix text_box element * gui: fix text box module * nfc: remove unnecessary buffers * nfc: introduce emulation callback concept * nfc: format sources * bt settings: fix incorrect scene switch * bt settings: format sources * Debug: fix x2d import for python 3 * Gui: rename method name widget_clear to widget_reset * nfc: add nfca emulation handler * nfc: add global custom events enum * nfc: UID emulation Data -> Log * furi_hal_nfc: fix incorrect timings * u2f, badusb: widget_clear() -> widget_reset() Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
94 lines
3.2 KiB
C++
Executable file
94 lines
3.2 KiB
C++
Executable file
#include "ibutton_scene_delete_confirm.h"
|
|
#include "../ibutton_app.h"
|
|
#include "../ibutton_view_manager.h"
|
|
#include "../ibutton_event.h"
|
|
#include <callback-connector.h>
|
|
|
|
void iButtonSceneDeleteConfirm::on_enter(iButtonApp* app) {
|
|
iButtonAppViewManager* view_manager = app->get_view_manager();
|
|
Widget* widget = view_manager->get_widget();
|
|
auto callback = cbc::obtain_connector(this, &iButtonSceneDeleteConfirm::widget_callback);
|
|
|
|
iButtonKey* key = app->get_key();
|
|
uint8_t* key_data = key->get_data();
|
|
|
|
app->set_text_store("\e#Delete %s?\e#", key->get_name());
|
|
widget_add_text_box_element(
|
|
widget, 0, 0, 128, 27, AlignCenter, AlignCenter, app->get_text_store());
|
|
widget_add_button_element(widget, GuiButtonTypeLeft, "Back", callback, app);
|
|
widget_add_button_element(widget, GuiButtonTypeRight, "Delete", callback, app);
|
|
|
|
switch(key->get_key_type()) {
|
|
case iButtonKeyType::KeyDallas:
|
|
app->set_text_store(
|
|
"%02X %02X %02X %02X %02X %02X %02X %02X",
|
|
key_data[0],
|
|
key_data[1],
|
|
key_data[2],
|
|
key_data[3],
|
|
key_data[4],
|
|
key_data[5],
|
|
key_data[6],
|
|
key_data[7]);
|
|
widget_add_string_element(
|
|
widget, 64, 45, AlignCenter, AlignBottom, FontSecondary, "Dallas");
|
|
break;
|
|
case iButtonKeyType::KeyCyfral:
|
|
app->set_text_store("%02X %02X", key_data[0], key_data[1]);
|
|
widget_add_string_element(
|
|
widget, 64, 45, AlignCenter, AlignBottom, FontSecondary, "Cyfral");
|
|
break;
|
|
case iButtonKeyType::KeyMetakom:
|
|
app->set_text_store(
|
|
"%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], key_data[3]);
|
|
widget_add_string_element(
|
|
widget, 64, 45, AlignCenter, AlignBottom, FontSecondary, "Metakom");
|
|
break;
|
|
}
|
|
widget_add_string_element(
|
|
widget, 64, 33, AlignCenter, AlignBottom, FontSecondary, app->get_text_store());
|
|
|
|
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewWidget);
|
|
}
|
|
|
|
bool iButtonSceneDeleteConfirm::on_event(iButtonApp* app, iButtonEvent* event) {
|
|
bool consumed = false;
|
|
|
|
if(event->type == iButtonEvent::Type::EventTypeWidgetButtonResult) {
|
|
if(event->payload.widget_button_result == GuiButtonTypeRight) {
|
|
if(app->delete_key()) {
|
|
app->switch_to_next_scene(iButtonApp::Scene::SceneDeleteSuccess);
|
|
}
|
|
} else {
|
|
app->switch_to_previous_scene();
|
|
}
|
|
|
|
consumed = true;
|
|
}
|
|
|
|
return consumed;
|
|
}
|
|
|
|
void iButtonSceneDeleteConfirm::on_exit(iButtonApp* app) {
|
|
iButtonAppViewManager* view_manager = app->get_view_manager();
|
|
Widget* widget = view_manager->get_widget();
|
|
|
|
app->set_text_store("");
|
|
|
|
widget_reset(widget);
|
|
}
|
|
|
|
void iButtonSceneDeleteConfirm::widget_callback(
|
|
GuiButtonType result,
|
|
InputType type,
|
|
void* context) {
|
|
iButtonApp* app = static_cast<iButtonApp*>(context);
|
|
iButtonEvent event;
|
|
|
|
if(type == InputTypeShort) {
|
|
event.type = iButtonEvent::Type::EventTypeWidgetButtonResult;
|
|
event.payload.widget_button_result = result;
|
|
}
|
|
|
|
app->get_view_manager()->send_event(&event);
|
|
}
|