lfrfid_app_scene_rpc.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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, &(app->worker.key), false)) {
  35. app->worker.start_emulate();
  36. emulating = true;
  37. auto popup = app->view_controller.get<PopupVM>();
  38. app->text_store.set("emulating\n%s", app->worker.key.get_name());
  39. popup->set_text(app->text_store.text, 89, 44, AlignCenter, AlignTop);
  40. notification_message(app->notification, &sequence_blink_start_magenta);
  41. result = true;
  42. }
  43. }
  44. rpc_system_app_confirm(app->rpc_ctx, RpcAppEventLoadFile, result);
  45. }
  46. return consumed;
  47. }
  48. void LfRfidAppSceneRpc::on_exit(LfRfidApp* app) {
  49. if(emulating) {
  50. app->worker.stop_emulate();
  51. notification_message(app->notification, &sequence_blink_stop);
  52. }
  53. app->view_controller.get<PopupVM>()->clean();
  54. }