lfrfid_app_scene_read.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include "lfrfid_app_scene_read.h"
  2. #include <dolphin/dolphin.h>
  3. static void lfrfid_read_callback(LFRFIDWorkerReadResult result, ProtocolId protocol, void* ctx) {
  4. LfRfidApp* app = static_cast<LfRfidApp*>(ctx);
  5. LfRfidApp::Event event;
  6. switch(result) {
  7. case LFRFIDWorkerReadSenseStart:
  8. event.type = LfRfidApp::EventType::ReadEventSenseStart;
  9. break;
  10. case LFRFIDWorkerReadSenseEnd:
  11. event.type = LfRfidApp::EventType::ReadEventSenseEnd;
  12. break;
  13. case LFRFIDWorkerReadSenseCardStart:
  14. event.type = LfRfidApp::EventType::ReadEventSenseCardStart;
  15. break;
  16. case LFRFIDWorkerReadSenseCardEnd:
  17. event.type = LfRfidApp::EventType::ReadEventSenseCardEnd;
  18. break;
  19. case LFRFIDWorkerReadDone:
  20. event.type = LfRfidApp::EventType::ReadEventDone;
  21. break;
  22. case LFRFIDWorkerReadStartASK:
  23. event.type = LfRfidApp::EventType::ReadEventStartASK;
  24. break;
  25. case LFRFIDWorkerReadStartPSK:
  26. event.type = LfRfidApp::EventType::ReadEventStartPSK;
  27. break;
  28. }
  29. event.payload.signed_int = protocol;
  30. app->view_controller.send_event(&event);
  31. }
  32. void LfRfidAppSceneRead::on_enter(LfRfidApp* app, bool /* need_restore */) {
  33. auto popup = app->view_controller.get<PopupVM>();
  34. DOLPHIN_DEED(DolphinDeedRfidRead);
  35. if(app->read_type == LFRFIDWorkerReadTypePSKOnly) {
  36. popup->set_header("Reading\nLF RFID\nPSK", 89, 30, AlignCenter, AlignTop);
  37. } else {
  38. popup->set_header("Reading\nLF RFID\nASK", 89, 30, AlignCenter, AlignTop);
  39. }
  40. popup->set_icon(0, 3, &I_RFIDDolphinReceive_97x61);
  41. app->view_controller.switch_to<PopupVM>();
  42. lfrfid_worker_start_thread(app->lfworker);
  43. lfrfid_worker_read_start(app->lfworker, app->read_type, lfrfid_read_callback, app);
  44. notification_message(app->notification, &sequence_blink_start_cyan);
  45. }
  46. bool LfRfidAppSceneRead::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
  47. bool consumed = true;
  48. auto popup = app->view_controller.get<PopupVM>();
  49. switch(event->type) {
  50. case LfRfidApp::EventType::ReadEventSenseStart:
  51. notification_message(app->notification, &sequence_blink_stop);
  52. notification_message(app->notification, &sequence_blink_start_yellow);
  53. break;
  54. case LfRfidApp::EventType::ReadEventSenseCardStart:
  55. notification_message(app->notification, &sequence_blink_stop);
  56. notification_message(app->notification, &sequence_blink_start_green);
  57. break;
  58. case LfRfidApp::EventType::ReadEventSenseEnd:
  59. case LfRfidApp::EventType::ReadEventSenseCardEnd:
  60. notification_message(app->notification, &sequence_blink_stop);
  61. notification_message(app->notification, &sequence_blink_start_cyan);
  62. break;
  63. case LfRfidApp::EventType::ReadEventDone:
  64. app->protocol_id = event->payload.signed_int;
  65. DOLPHIN_DEED(DolphinDeedRfidReadSuccess);
  66. notification_message(app->notification, &sequence_success);
  67. string_reset(app->file_name);
  68. app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::ReadSuccess);
  69. break;
  70. case LfRfidApp::EventType::ReadEventStartPSK:
  71. popup->set_header("Reading\nLF RFID\nPSK", 89, 30, AlignCenter, AlignTop);
  72. break;
  73. case LfRfidApp::EventType::ReadEventStartASK:
  74. popup->set_header("Reading\nLF RFID\nASK", 89, 30, AlignCenter, AlignTop);
  75. break;
  76. default:
  77. consumed = false;
  78. break;
  79. }
  80. return consumed;
  81. }
  82. void LfRfidAppSceneRead::on_exit(LfRfidApp* app) {
  83. notification_message(app->notification, &sequence_blink_stop);
  84. app->view_controller.get<PopupVM>()->clean();
  85. lfrfid_worker_stop(app->lfworker);
  86. lfrfid_worker_stop_thread(app->lfworker);
  87. }