nfc_scene_set_uid.c 1.8 KB

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