nfc_scene_set_uid.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "../nfc_i.h"
  2. void nfc_scene_set_uid_byte_input_callback(void* context) {
  3. Nfc* nfc = context;
  4. view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventByteInputDone);
  5. }
  6. void nfc_scene_set_uid_on_enter(void* context) {
  7. Nfc* nfc = context;
  8. // Setup view
  9. ByteInput* byte_input = nfc->byte_input;
  10. byte_input_set_header_text(byte_input, "Enter UID in hex");
  11. nfc->dev_edit_data = nfc->dev->dev_data.nfc_data;
  12. byte_input_set_result_callback(
  13. byte_input,
  14. nfc_scene_set_uid_byte_input_callback,
  15. NULL,
  16. nfc,
  17. nfc->dev_edit_data.uid,
  18. nfc->dev_edit_data.uid_len);
  19. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewByteInput);
  20. }
  21. bool nfc_scene_set_uid_on_event(void* context, SceneManagerEvent event) {
  22. Nfc* nfc = (Nfc*)context;
  23. bool consumed = false;
  24. if(event.type == SceneManagerEventTypeCustom) {
  25. if(event.event == NfcCustomEventByteInputDone) {
  26. if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneSavedMenu)) {
  27. nfc->dev->dev_data.nfc_data = nfc->dev_edit_data;
  28. if(nfc_save_file(nfc)) {
  29. scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveSuccess);
  30. consumed = true;
  31. }
  32. } else {
  33. scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveName);
  34. consumed = true;
  35. }
  36. }
  37. }
  38. return consumed;
  39. }
  40. void nfc_scene_set_uid_on_exit(void* context) {
  41. Nfc* nfc = context;
  42. // Clear view
  43. byte_input_set_result_callback(nfc->byte_input, NULL, NULL, NULL, NULL, 0);
  44. byte_input_set_header_text(nfc->byte_input, "");
  45. }