ibutton_scene_rpc.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "../ibutton_i.h"
  2. #include <toolbox/path.h>
  3. void ibutton_scene_rpc_on_enter(void* context) {
  4. iButton* ibutton = context;
  5. Popup* popup = ibutton->popup;
  6. popup_set_header(popup, "iButton", 82, 28, AlignCenter, AlignBottom);
  7. popup_set_text(popup, "RPC mode", 82, 32, AlignCenter, AlignTop);
  8. popup_set_icon(popup, 2, 14, &I_iButtonKey_49x44);
  9. view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewPopup);
  10. notification_message(ibutton->notifications, &sequence_display_backlight_on);
  11. }
  12. bool ibutton_scene_rpc_on_event(void* context, SceneManagerEvent event) {
  13. UNUSED(context);
  14. UNUSED(event);
  15. iButton* ibutton = context;
  16. Popup* popup = ibutton->popup;
  17. bool consumed = false;
  18. if(event.type == SceneManagerEventTypeCustom) {
  19. consumed = true;
  20. if(event.event == iButtonCustomEventRpcLoad) {
  21. string_t key_name;
  22. string_init(key_name);
  23. if(string_end_with_str_p(ibutton->file_path, IBUTTON_APP_EXTENSION)) {
  24. path_extract_filename(ibutton->file_path, key_name, true);
  25. }
  26. if(!string_empty_p(key_name)) {
  27. ibutton_text_store_set(ibutton, "emulating\n%s", string_get_cstr(key_name));
  28. } else {
  29. ibutton_text_store_set(ibutton, "emulating");
  30. }
  31. popup_set_text(popup, ibutton->text_store, 82, 32, AlignCenter, AlignTop);
  32. ibutton_notification_message(ibutton, iButtonNotificationMessageEmulateStart);
  33. string_clear(key_name);
  34. } else if(event.event == iButtonCustomEventRpcExit) {
  35. ibutton_notification_message(ibutton, iButtonNotificationMessageBlinkStop);
  36. view_dispatcher_stop(ibutton->view_dispatcher);
  37. }
  38. }
  39. return consumed;
  40. }
  41. void ibutton_scene_rpc_on_exit(void* context) {
  42. iButton* ibutton = context;
  43. Popup* popup = ibutton->popup;
  44. popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
  45. popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
  46. popup_set_icon(popup, 0, 0, NULL);
  47. ibutton_notification_message(ibutton, iButtonNotificationMessageBlinkStop);
  48. }