lfrfid_app_scene_rpc.cpp 2.6 KB

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