lfrfid_app_scene_rpc.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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, 42, AlignCenter, AlignBottom);
  8. popup->set_text("RPC mode", 89, 44, AlignCenter, AlignTop);
  9. popup->set_icon(0, 12, &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. consumed = true;
  25. LfRfidApp::Event view_event;
  26. view_event.type = LfRfidApp::EventType::Back;
  27. app->view_controller.send_event(&view_event);
  28. } else if(event->type == LfRfidApp::EventType::RpcLoadFile) {
  29. const char* arg = rpc_system_app_get_data(app->rpc_ctx);
  30. consumed = true;
  31. bool result = false;
  32. if(arg && !emulating) {
  33. string_set_str(app->file_path, arg);
  34. if(app->load_key_data(app->file_path, false)) {
  35. lfrfid_worker_start_thread(app->lfworker);
  36. lfrfid_worker_emulate_start(app->lfworker, (LFRFIDProtocol)app->protocol_id);
  37. emulating = true;
  38. auto popup = app->view_controller.get<PopupVM>();
  39. app->text_store.set("emulating\n%s", string_get_cstr(app->file_name));
  40. popup->set_text(app->text_store.text, 89, 44, AlignCenter, AlignTop);
  41. notification_message(app->notification, &sequence_blink_start_magenta);
  42. result = true;
  43. }
  44. }
  45. rpc_system_app_confirm(app->rpc_ctx, RpcAppEventLoadFile, result);
  46. }
  47. return consumed;
  48. }
  49. void LfRfidAppSceneRpc::on_exit(LfRfidApp* app) {
  50. if(emulating) {
  51. lfrfid_worker_stop(app->lfworker);
  52. lfrfid_worker_stop_thread(app->lfworker);
  53. notification_message(app->notification, &sequence_blink_stop);
  54. }
  55. app->view_controller.get<PopupVM>()->clean();
  56. }