nfc_maker_scene_save_uid.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "../nfc_maker.h"
  2. enum ByteInputResult {
  3. ByteInputResultOk,
  4. };
  5. static void nfc_maker_scene_save_uid_byte_input_callback(void* context) {
  6. NfcMaker* app = context;
  7. size_t uid_len;
  8. nfc_device_get_uid(app->nfc_device, &uid_len);
  9. bool uid_valid = nfc_device_set_uid(app->nfc_device, app->uid_buf, uid_len);
  10. if(uid_valid) {
  11. view_dispatcher_send_custom_event(app->view_dispatcher, ByteInputResultOk);
  12. } else {
  13. byte_input_set_header_text(app->byte_input, "Invalid UID!");
  14. }
  15. }
  16. static void nfc_maker_scene_save_uid_byte_input_changed(void* context) {
  17. NfcMaker* app = context;
  18. byte_input_set_header_text(app->byte_input, "Change UID:");
  19. }
  20. void nfc_maker_scene_save_uid_on_enter(void* context) {
  21. NfcMaker* app = context;
  22. ByteInput* byte_input = app->byte_input;
  23. byte_input_set_header_text(byte_input, "(Optional) Change UID:");
  24. size_t uid_len;
  25. const uint8_t* uid = nfc_device_get_uid(app->nfc_device, &uid_len);
  26. memcpy(app->uid_buf, uid, uid_len);
  27. byte_input_set_result_callback(
  28. byte_input,
  29. nfc_maker_scene_save_uid_byte_input_callback,
  30. nfc_maker_scene_save_uid_byte_input_changed,
  31. app,
  32. app->uid_buf,
  33. uid_len);
  34. view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewByteInput);
  35. }
  36. bool nfc_maker_scene_save_uid_on_event(void* context, SceneManagerEvent event) {
  37. NfcMaker* app = context;
  38. bool consumed = false;
  39. if(event.type == SceneManagerEventTypeCustom) {
  40. consumed = true;
  41. switch(event.event) {
  42. case ByteInputResultOk:
  43. scene_manager_next_scene(app->scene_manager, NfcMakerSceneSaveName);
  44. break;
  45. default:
  46. break;
  47. }
  48. }
  49. return consumed;
  50. }
  51. void nfc_maker_scene_save_uid_on_exit(void* context) {
  52. NfcMaker* app = context;
  53. byte_input_set_result_callback(app->byte_input, NULL, NULL, NULL, NULL, 0);
  54. byte_input_set_header_text(app->byte_input, "");
  55. }