ibutton_scene_rpc.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "../ibutton_i.h"
  2. void ibutton_scene_rpc_on_enter(void* context) {
  3. iButton* ibutton = context;
  4. Popup* popup = ibutton->popup;
  5. popup_set_header(popup, "iButton", 82, 28, AlignCenter, AlignBottom);
  6. popup_set_text(popup, "RPC mode", 82, 32, AlignCenter, AlignTop);
  7. popup_set_icon(popup, 2, 14, &I_iButtonKey_49x44);
  8. view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewPopup);
  9. notification_message(ibutton->notifications, &sequence_display_backlight_on);
  10. }
  11. bool ibutton_scene_rpc_on_event(void* context, SceneManagerEvent event) {
  12. iButton* ibutton = context;
  13. Popup* popup = ibutton->popup;
  14. bool consumed = false;
  15. if(event.type == SceneManagerEventTypeCustom) {
  16. consumed = true;
  17. if(event.event == iButtonCustomEventRpcLoad) {
  18. bool result = false;
  19. const char* file_path = rpc_system_app_get_data(ibutton->rpc);
  20. if(file_path && (furi_string_empty(ibutton->file_path))) {
  21. furi_string_set(ibutton->file_path, file_path);
  22. if(ibutton_load_key(ibutton)) {
  23. popup_set_text(popup, ibutton->key_name, 82, 32, AlignCenter, AlignTop);
  24. view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewPopup);
  25. ibutton_notification_message(ibutton, iButtonNotificationMessageEmulateStart);
  26. ibutton_worker_emulate_start(ibutton->worker, ibutton->key);
  27. result = true;
  28. }
  29. }
  30. rpc_system_app_confirm(ibutton->rpc, RpcAppEventLoadFile, result);
  31. } else if(event.event == iButtonCustomEventRpcExit) {
  32. rpc_system_app_confirm(ibutton->rpc, RpcAppEventAppExit, true);
  33. scene_manager_stop(ibutton->scene_manager);
  34. view_dispatcher_stop(ibutton->view_dispatcher);
  35. } else if(event.event == iButtonCustomEventRpcSessionClose) {
  36. scene_manager_stop(ibutton->scene_manager);
  37. view_dispatcher_stop(ibutton->view_dispatcher);
  38. }
  39. }
  40. return consumed;
  41. }
  42. void ibutton_scene_rpc_on_exit(void* context) {
  43. iButton* ibutton = context;
  44. Popup* popup = ibutton->popup;
  45. popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
  46. popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
  47. popup_set_icon(popup, 0, 0, NULL);
  48. ibutton_notification_message(ibutton, iButtonNotificationMessageBlinkStop);
  49. }