t5577_multiwriter_scene_write_second_key.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include "../t5577_multiwriter_i.h"
  2. #include "../protocols/EM41XX.h"
  3. #include "../t5577_multiwriter/helpers/t5577.h"
  4. static void
  5. t5577_multiwriter_write_second_key_callback(LFRFIDWorkerWriteResult result, void* context) {
  6. LfRfid* app = context;
  7. uint32_t event = 0;
  8. if(result == LFRFIDWorkerWriteOK) {
  9. event = LfRfidEventWriteOK;
  10. } else if(result == LFRFIDWorkerWriteProtocolCannotBeWritten) {
  11. event = LfRfidEventWriteProtocolCannotBeWritten;
  12. } else if(result == LFRFIDWorkerWriteFobCannotBeWritten) {
  13. event = LfRfidEventWriteFobCannotBeWritten;
  14. } else if(result == LFRFIDWorkerWriteTooLongToWrite) {
  15. event = LfRfidEventWriteTooLongToWrite;
  16. }
  17. view_dispatcher_send_custom_event(app->view_dispatcher, event);
  18. }
  19. void t5577_multiwriter_scene_write_second_key_on_enter(void* context) {
  20. LfRfid* app = context;
  21. Popup* popup = app->popup;
  22. popup_set_header(popup, "Writing", 89, 30, AlignCenter, AlignTop);
  23. if(!furi_string_empty(app->file_name)) {
  24. popup_set_text(popup, furi_string_get_cstr(app->file_name), 89, 43, AlignCenter, AlignTop);
  25. } else {
  26. popup_set_text(
  27. popup,
  28. protocol_dict_get_name(app->dict, app->protocol_id),
  29. 89,
  30. 43,
  31. AlignCenter,
  32. AlignTop);
  33. }
  34. popup_set_icon(popup, 0, 3, &I_RFIDDolphinSend_97x61);
  35. view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewPopup);
  36. notification_message(app->notifications, &sequence_blink_start_magenta);
  37. size_t size = protocol_dict_get_data_size(app->dict, app->protocol_id);
  38. uint8_t* data = (uint8_t*)malloc(size);
  39. protocol_dict_get_data(app->dict, app->protocol_id, data, size);
  40. uint64_t key = bytes2num(data, size);
  41. LFRFIDT5577Data data_to_write = {0};
  42. add_em41xx_data(&data_to_write, key, 3);
  43. set_em41xx_config(&data_to_write, 2);
  44. t5577_write_with_mask(&data_to_write);
  45. t5577_multiwriter_write_second_key_callback(LFRFIDWorkerWriteOK, context);
  46. }
  47. bool t5577_multiwriter_scene_write_second_key_on_event(void* context, SceneManagerEvent event) {
  48. LfRfid* app = context;
  49. Popup* popup = app->popup;
  50. bool consumed = false;
  51. if(event.type == SceneManagerEventTypeCustom) {
  52. if(event.event == LfRfidEventWriteOK) {
  53. notification_message(app->notifications, &sequence_success);
  54. scene_manager_next_scene(app->scene_manager, LfRfidSceneWriteSuccess);
  55. consumed = true;
  56. } else if(event.event == LfRfidEventWriteProtocolCannotBeWritten) {
  57. popup_set_icon(popup, 72, 17, &I_WarningDolphinFlip_45x42);
  58. popup_set_header(popup, "Error", 64, 3, AlignCenter, AlignTop);
  59. popup_set_text(popup, "This protocol\ncannot be written", 3, 17, AlignLeft, AlignTop);
  60. notification_message(app->notifications, &sequence_blink_start_red);
  61. consumed = true;
  62. } else if(
  63. (event.event == LfRfidEventWriteFobCannotBeWritten) ||
  64. (event.event == LfRfidEventWriteTooLongToWrite)) {
  65. popup_set_icon(popup, 72, 17, &I_WarningDolphinFlip_45x42);
  66. popup_set_header(popup, "Still trying to write...", 64, 3, AlignCenter, AlignTop);
  67. popup_set_text(
  68. popup,
  69. "Make sure this\ncard is writable\nand not\nprotected.",
  70. 3,
  71. 17,
  72. AlignLeft,
  73. AlignTop);
  74. notification_message(app->notifications, &sequence_blink_start_yellow);
  75. consumed = true;
  76. }
  77. }
  78. return consumed;
  79. }
  80. void t5577_multiwriter_scene_write_second_key_on_exit(void* context) {
  81. LfRfid* app = context;
  82. notification_message(app->notifications, &sequence_blink_stop);
  83. popup_reset(app->popup);
  84. size_t size = protocol_dict_get_data_size(app->dict, app->protocol_id);
  85. protocol_dict_set_data(app->dict, app->protocol_id, app->old_key_data, size);
  86. }