lfrfid_scene_rpc.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "../lfrfid_i.h"
  2. void lfrfid_scene_rpc_on_enter(void* context) {
  3. LfRfid* app = context;
  4. Popup* popup = app->popup;
  5. popup_set_header(popup, "LF RFID", 89, 42, AlignCenter, AlignBottom);
  6. popup_set_text(popup, "RPC mode", 89, 44, AlignCenter, AlignTop);
  7. popup_set_icon(popup, 0, 12, &I_RFIDDolphinSend_97x61);
  8. view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewPopup);
  9. notification_message(app->notifications, &sequence_display_backlight_on);
  10. app->rpc_state = LfRfidRpcStateIdle;
  11. }
  12. bool lfrfid_scene_rpc_on_event(void* context, SceneManagerEvent event) {
  13. LfRfid* app = context;
  14. Popup* popup = app->popup;
  15. UNUSED(event);
  16. bool consumed = false;
  17. if(event.type == SceneManagerEventTypeCustom) {
  18. consumed = true;
  19. if(event.event == LfRfidEventExit) {
  20. rpc_system_app_confirm(app->rpc_ctx, RpcAppEventAppExit, true);
  21. scene_manager_stop(app->scene_manager);
  22. view_dispatcher_stop(app->view_dispatcher);
  23. } else if(event.event == LfRfidEventRpcSessionClose) {
  24. scene_manager_stop(app->scene_manager);
  25. view_dispatcher_stop(app->view_dispatcher);
  26. } else if(event.event == LfRfidEventRpcLoadFile) {
  27. const char* arg = rpc_system_app_get_data(app->rpc_ctx);
  28. bool result = false;
  29. if(arg && (app->rpc_state == LfRfidRpcStateIdle)) {
  30. furi_string_set(app->file_path, arg);
  31. if(lfrfid_load_key_data(app, app->file_path, false)) {
  32. lfrfid_worker_start_thread(app->lfworker);
  33. lfrfid_worker_emulate_start(app->lfworker, (LFRFIDProtocol)app->protocol_id);
  34. app->rpc_state = LfRfidRpcStateEmulating;
  35. lfrfid_text_store_set(
  36. app, "emulating\n%s", furi_string_get_cstr(app->file_name));
  37. popup_set_text(popup, app->text_store, 89, 44, AlignCenter, AlignTop);
  38. notification_message(app->notifications, &sequence_blink_start_magenta);
  39. result = true;
  40. }
  41. }
  42. rpc_system_app_confirm(app->rpc_ctx, RpcAppEventLoadFile, result);
  43. }
  44. }
  45. return consumed;
  46. }
  47. void lfrfid_scene_rpc_on_exit(void* context) {
  48. LfRfid* app = context;
  49. Popup* popup = app->popup;
  50. if(app->rpc_state == LfRfidRpcStateEmulating) {
  51. lfrfid_worker_stop(app->lfworker);
  52. lfrfid_worker_stop_thread(app->lfworker);
  53. notification_message(app->notifications, &sequence_blink_stop);
  54. }
  55. popup_reset(popup);
  56. }