ibutton_scene_add_value.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "ibutton_scene_add_value.h"
  2. #include "../ibutton_app.h"
  3. #include <dolphin/dolphin.h>
  4. static void byte_input_callback(void* context) {
  5. furi_assert(context);
  6. iButtonApp* app = static_cast<iButtonApp*>(context);
  7. iButtonEvent event;
  8. event.type = iButtonEvent::Type::EventTypeByteEditResult;
  9. app->get_view_manager()->send_event(&event);
  10. }
  11. void iButtonSceneAddValue::on_enter(iButtonApp* app) {
  12. iButtonAppViewManager* view_manager = app->get_view_manager();
  13. ByteInput* byte_input = view_manager->get_byte_input();
  14. iButtonKey* key = app->get_key();
  15. memcpy(this->new_key_data, ibutton_key_get_data_p(key), ibutton_key_get_data_size(key));
  16. byte_input_set_result_callback(
  17. byte_input,
  18. byte_input_callback,
  19. NULL,
  20. app,
  21. this->new_key_data,
  22. ibutton_key_get_data_size(key));
  23. byte_input_set_header_text(byte_input, "Enter the key");
  24. view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewByteInput);
  25. }
  26. bool iButtonSceneAddValue::on_event(iButtonApp* app, iButtonEvent* event) {
  27. bool consumed = false;
  28. if(event->type == iButtonEvent::Type::EventTypeByteEditResult) {
  29. ibutton_key_set_data(app->get_key(), this->new_key_data, IBUTTON_KEY_DATA_SIZE);
  30. DOLPHIN_DEED(DolphinDeedIbuttonAdd);
  31. app->switch_to_next_scene(iButtonApp::Scene::SceneSaveName);
  32. consumed = true;
  33. }
  34. return consumed;
  35. }
  36. void iButtonSceneAddValue::on_exit(iButtonApp* app) {
  37. iButtonAppViewManager* view_manager = app->get_view_manager();
  38. ByteInput* byte_input = view_manager->get_byte_input();
  39. byte_input_set_result_callback(byte_input, NULL, NULL, NULL, NULL, 0);
  40. byte_input_set_header_text(byte_input, {0});
  41. }