nfc_scene_set_uid.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <nfc/scenes/nfc_scene_set_uid.h>
  2. #include <furi.h>
  3. #include "../nfc_i.h"
  4. #include <gui/view_dispatcher.h>
  5. #define SCENE_SET_UID_CUSTOM_EVENT (0UL)
  6. void nfc_scene_set_uid_byte_input_callback(void* context) {
  7. Nfc* nfc = (Nfc*)context;
  8. view_dispatcher_send_custom_event(nfc->nfc_common.view_dispatcher, SCENE_SET_UID_CUSTOM_EVENT);
  9. }
  10. const void nfc_scene_set_uid_on_enter(void* context) {
  11. Nfc* nfc = (Nfc*)context;
  12. // Setup view
  13. ByteInput* byte_input = nfc->byte_input;
  14. byte_input_set_header_text(byte_input, "Enter uid in hex");
  15. byte_input_set_result_callback(
  16. byte_input,
  17. nfc_scene_set_uid_byte_input_callback,
  18. NULL,
  19. nfc,
  20. nfc->device.data.uid,
  21. nfc->device.data.uid_len);
  22. view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewByteInput);
  23. }
  24. const bool nfc_scene_set_uid_on_event(void* context, uint32_t event) {
  25. Nfc* nfc = (Nfc*)context;
  26. if(event == SCENE_SET_UID_CUSTOM_EVENT) {
  27. view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_save_name);
  28. view_dispatcher_send_navigation_event(
  29. nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
  30. return true;
  31. }
  32. return false;
  33. }
  34. const void nfc_scene_set_uid_on_exit(void* context) {
  35. Nfc* nfc = (Nfc*)context;
  36. // Clear view
  37. byte_input_set_result_callback(nfc->byte_input, NULL, NULL, NULL, NULL, 0);
  38. byte_input_set_header_text(nfc->byte_input, "");
  39. }
  40. AppScene* nfc_scene_set_uid_alloc() {
  41. AppScene* scene = furi_alloc(sizeof(AppScene));
  42. scene->id = NfcSceneSetUid;
  43. scene->on_enter = nfc_scene_set_uid_on_enter;
  44. scene->on_event = nfc_scene_set_uid_on_event;
  45. scene->on_exit = nfc_scene_set_uid_on_exit;
  46. return scene;
  47. }
  48. void nfc_scene_set_uid_free(AppScene* scene) {
  49. free(scene);
  50. }