lfrfid_app_scene_rpc.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "lfrfid_app_scene_rpc.h"
  2. #include <core/common_defines.h>
  3. #include <dolphin/dolphin.h>
  4. #include <rpc/rpc_app.h>
  5. static const NotificationSequence sequence_blink_start_magenta = {
  6. &message_blink_start_10,
  7. &message_blink_set_color_magenta,
  8. &message_do_not_reset,
  9. NULL,
  10. };
  11. static const NotificationSequence sequence_blink_stop = {
  12. &message_blink_stop,
  13. NULL,
  14. };
  15. void LfRfidAppSceneRpc::on_enter(LfRfidApp* app, bool /* need_restore */) {
  16. auto popup = app->view_controller.get<PopupVM>();
  17. popup->set_header("LF RFID", 89, 30, AlignCenter, AlignTop);
  18. popup->set_text("RPC mode", 89, 43, AlignCenter, AlignTop);
  19. popup->set_icon(0, 3, &I_RFIDDolphinSend_97x61);
  20. app->view_controller.switch_to<PopupVM>();
  21. notification_message(app->notification, &sequence_display_backlight_on);
  22. }
  23. bool LfRfidAppSceneRpc::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
  24. UNUSED(app);
  25. UNUSED(event);
  26. bool consumed = false;
  27. if(event->type == LfRfidApp::EventType::Exit) {
  28. consumed = true;
  29. LfRfidApp::Event view_event;
  30. view_event.type = LfRfidApp::EventType::Back;
  31. app->view_controller.send_event(&view_event);
  32. rpc_system_app_confirm(app->rpc_ctx, RpcAppEventAppExit, true);
  33. } else if(event->type == LfRfidApp::EventType::RpcSessionClose) {
  34. // Detach RPC
  35. rpc_system_app_set_callback(app->rpc_ctx, NULL, NULL);
  36. app->rpc_ctx = NULL;
  37. consumed = true;
  38. LfRfidApp::Event view_event;
  39. view_event.type = LfRfidApp::EventType::Back;
  40. app->view_controller.send_event(&view_event);
  41. } else if(event->type == LfRfidApp::EventType::EmulateStart) {
  42. auto popup = app->view_controller.get<PopupVM>();
  43. consumed = true;
  44. emulating = true;
  45. app->text_store.set("emulating\n%s", app->worker.key.get_name());
  46. popup->set_text(app->text_store.text, 89, 43, AlignCenter, AlignTop);
  47. notification_message(app->notification, &sequence_blink_start_magenta);
  48. } else if(event->type == LfRfidApp::EventType::RpcLoadFile) {
  49. const char* arg = rpc_system_app_get_data(app->rpc_ctx);
  50. bool result = false;
  51. if(arg) {
  52. string_set_str(app->file_path, arg);
  53. if(app->load_key_data(app->file_path, &(app->worker.key), false)) {
  54. LfRfidApp::Event event;
  55. event.type = LfRfidApp::EventType::EmulateStart;
  56. app->view_controller.send_event(&event);
  57. app->worker.start_emulate();
  58. result = true;
  59. }
  60. }
  61. rpc_system_app_confirm(app->rpc_ctx, RpcAppEventLoadFile, result);
  62. }
  63. return consumed;
  64. }
  65. void LfRfidAppSceneRpc::on_exit(LfRfidApp* app) {
  66. if(emulating) {
  67. app->worker.stop_emulate();
  68. notification_message(app->notification, &sequence_blink_stop);
  69. }
  70. app->view_controller.get<PopupVM>()->clean();
  71. }