ibutton_scene_rpc.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "../ibutton_i.h"
  2. #include <toolbox/path.h>
  3. #include <rpc/rpc_app.h>
  4. void ibutton_scene_rpc_on_enter(void* context) {
  5. iButton* ibutton = context;
  6. Popup* popup = ibutton->popup;
  7. popup_set_header(popup, "iButton", 82, 28, AlignCenter, AlignBottom);
  8. popup_set_text(popup, "RPC mode", 82, 32, AlignCenter, AlignTop);
  9. popup_set_icon(popup, 2, 14, &I_iButtonKey_49x44);
  10. view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewPopup);
  11. notification_message(ibutton->notifications, &sequence_display_backlight_on);
  12. }
  13. bool ibutton_scene_rpc_on_event(void* context, SceneManagerEvent event) {
  14. UNUSED(context);
  15. UNUSED(event);
  16. iButton* ibutton = context;
  17. Popup* popup = ibutton->popup;
  18. bool consumed = false;
  19. if(event.type == SceneManagerEventTypeCustom) {
  20. consumed = true;
  21. if(event.event == iButtonCustomEventRpcLoad) {
  22. const char* arg = rpc_system_app_get_data(ibutton->rpc_ctx);
  23. bool result = false;
  24. if(arg && (furi_string_empty(ibutton->file_path))) {
  25. furi_string_set(ibutton->file_path, arg);
  26. if(ibutton_load_key_data(ibutton, ibutton->file_path, false)) {
  27. ibutton_worker_emulate_start(ibutton->key_worker, ibutton->key);
  28. FuriString* key_name;
  29. key_name = furi_string_alloc();
  30. if(furi_string_end_with(ibutton->file_path, IBUTTON_APP_EXTENSION)) {
  31. path_extract_filename(ibutton->file_path, key_name, true);
  32. }
  33. if(!furi_string_empty(key_name)) {
  34. ibutton_text_store_set(
  35. ibutton, "emulating\n%s", furi_string_get_cstr(key_name));
  36. } else {
  37. ibutton_text_store_set(ibutton, "emulating");
  38. }
  39. popup_set_text(popup, ibutton->text_store, 82, 32, AlignCenter, AlignTop);
  40. ibutton_notification_message(ibutton, iButtonNotificationMessageEmulateStart);
  41. furi_string_free(key_name);
  42. result = true;
  43. } else {
  44. furi_string_reset(ibutton->file_path);
  45. }
  46. }
  47. rpc_system_app_confirm(ibutton->rpc_ctx, RpcAppEventLoadFile, result);
  48. } else if(event.event == iButtonCustomEventRpcExit) {
  49. rpc_system_app_confirm(ibutton->rpc_ctx, RpcAppEventAppExit, true);
  50. scene_manager_stop(ibutton->scene_manager);
  51. view_dispatcher_stop(ibutton->view_dispatcher);
  52. } else if(event.event == iButtonCustomEventRpcSessionClose) {
  53. scene_manager_stop(ibutton->scene_manager);
  54. view_dispatcher_stop(ibutton->view_dispatcher);
  55. }
  56. }
  57. return consumed;
  58. }
  59. void ibutton_scene_rpc_on_exit(void* context) {
  60. iButton* ibutton = context;
  61. Popup* popup = ibutton->popup;
  62. popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
  63. popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
  64. popup_set_icon(popup, 0, 0, NULL);
  65. ibutton_notification_message(ibutton, iButtonNotificationMessageBlinkStop);
  66. }