lfrfid_scene_rpc.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. string_set_str(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(app, "emulating\n%s", string_get_cstr(app->file_name));
  36. popup_set_text(popup, app->text_store, 89, 44, AlignCenter, AlignTop);
  37. notification_message(app->notifications, &sequence_blink_start_magenta);
  38. result = true;
  39. }
  40. }
  41. rpc_system_app_confirm(app->rpc_ctx, RpcAppEventLoadFile, result);
  42. }
  43. }
  44. return consumed;
  45. }
  46. void lfrfid_scene_rpc_on_exit(void* context) {
  47. LfRfid* app = context;
  48. Popup* popup = app->popup;
  49. if(app->rpc_state == LfRfidRpcStateEmulating) {
  50. lfrfid_worker_stop(app->lfworker);
  51. lfrfid_worker_stop_thread(app->lfworker);
  52. notification_message(app->notifications, &sequence_blink_stop);
  53. }
  54. popup_reset(popup);
  55. }