ibutton_scene_add_value.cpp 1.7 KB

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