unleashed-firmware/applications/ibutton/scene/ibutton_scene_add_value.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

52 lines
1.7 KiB
C++
Executable File

#include "ibutton_scene_add_value.h"
#include "../ibutton_app.h"
#include <dolphin/dolphin.h>
static void byte_input_callback(void* context) {
iButtonApp* app = static_cast<iButtonApp*>(context);
iButtonEvent event;
event.type = iButtonEvent::Type::EventTypeByteEditResult;
app->get_view_manager()->send_event(&event);
}
void iButtonSceneAddValue::on_enter(iButtonApp* app) {
iButtonAppViewManager* view_manager = app->get_view_manager();
ByteInput* byte_input = view_manager->get_byte_input();
iButtonKey* key = app->get_key();
memcpy(this->new_key_data, ibutton_key_get_data_p(key), ibutton_key_get_data_size(key));
byte_input_set_result_callback(
byte_input,
byte_input_callback,
NULL,
app,
this->new_key_data,
ibutton_key_get_data_size(key));
byte_input_set_header_text(byte_input, "Enter the key");
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewByteInput);
}
bool iButtonSceneAddValue::on_event(iButtonApp* app, iButtonEvent* event) {
bool consumed = false;
if(event->type == iButtonEvent::Type::EventTypeByteEditResult) {
ibutton_key_set_data(app->get_key(), this->new_key_data, IBUTTON_KEY_DATA_SIZE);
DOLPHIN_DEED(DolphinDeedIbuttonAdd);
app->switch_to_next_scene(iButtonApp::Scene::SceneSaveName);
consumed = true;
}
return consumed;
}
void iButtonSceneAddValue::on_exit(iButtonApp* app) {
iButtonAppViewManager* view_manager = app->get_view_manager();
ByteInput* byte_input = view_manager->get_byte_input();
byte_input_set_result_callback(byte_input, NULL, NULL, NULL, NULL, 0);
byte_input_set_header_text(byte_input, {0});
}