infrared_scene_rpc.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "../infrared_i.h"
  2. #include "gui/canvas.h"
  3. void infrared_scene_rpc_on_enter(void* context) {
  4. Infrared* infrared = context;
  5. Popup* popup = infrared->popup;
  6. popup_set_header(popup, "Infrared", 82, 28, AlignCenter, AlignBottom);
  7. popup_set_text(popup, "RPC mode", 82, 32, AlignCenter, AlignTop);
  8. popup_set_icon(popup, 2, 14, &I_Warning_30x23); // TODO: icon
  9. popup_set_context(popup, context);
  10. popup_set_callback(popup, infrared_popup_closed_callback);
  11. view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewPopup);
  12. notification_message(infrared->notifications, &sequence_display_backlight_on);
  13. }
  14. bool infrared_scene_rpc_on_event(void* context, SceneManagerEvent event) {
  15. Infrared* infrared = context;
  16. bool consumed = false;
  17. if(event.type == SceneManagerEventTypeCustom) {
  18. consumed = true;
  19. if(event.event == InfraredCustomEventTypeBackPressed) {
  20. view_dispatcher_stop(infrared->view_dispatcher);
  21. } else if(event.event == InfraredCustomEventTypePopupClosed) {
  22. view_dispatcher_stop(infrared->view_dispatcher);
  23. } else if(event.event == InfraredCustomEventTypeRpcLoad) {
  24. bool result = false;
  25. const char* arg = rpc_system_app_get_data(infrared->rpc_ctx);
  26. if(arg) {
  27. string_set_str(infrared->file_path, arg);
  28. result = infrared_remote_load(infrared->remote, infrared->file_path);
  29. infrared_worker_tx_set_get_signal_callback(
  30. infrared->worker, infrared_worker_tx_get_signal_steady_callback, infrared);
  31. infrared_worker_tx_set_signal_sent_callback(
  32. infrared->worker, infrared_signal_sent_callback, infrared);
  33. }
  34. const char* remote_name = infrared_remote_get_name(infrared->remote);
  35. infrared_text_store_set(infrared, 0, "loaded\n%s", remote_name);
  36. popup_set_text(
  37. infrared->popup, infrared->text_store[0], 82, 32, AlignCenter, AlignTop);
  38. rpc_system_app_confirm(infrared->rpc_ctx, RpcAppEventLoadFile, result);
  39. } else if(event.event == InfraredCustomEventTypeRpcButtonPress) {
  40. bool result = false;
  41. const char* arg = rpc_system_app_get_data(infrared->rpc_ctx);
  42. if(arg) {
  43. size_t button_index = 0;
  44. if(infrared_remote_find_button_by_name(infrared->remote, arg, &button_index)) {
  45. infrared_tx_start_button_index(infrared, button_index);
  46. result = true;
  47. }
  48. }
  49. rpc_system_app_confirm(infrared->rpc_ctx, RpcAppEventButtonRelease, result);
  50. } else if(event.event == InfraredCustomEventTypeRpcButtonRelease) {
  51. infrared_tx_stop(infrared);
  52. rpc_system_app_confirm(infrared->rpc_ctx, RpcAppEventButtonRelease, true);
  53. } else if(event.event == InfraredCustomEventTypeRpcExit) {
  54. view_dispatcher_stop(infrared->view_dispatcher);
  55. rpc_system_app_confirm(infrared->rpc_ctx, RpcAppEventAppExit, true);
  56. } else if(event.event == InfraredCustomEventTypeRpcSessionClose) {
  57. rpc_system_app_set_callback(infrared->rpc_ctx, NULL, NULL);
  58. infrared->rpc_ctx = NULL;
  59. view_dispatcher_stop(infrared->view_dispatcher);
  60. }
  61. }
  62. return consumed;
  63. }
  64. void infrared_scene_rpc_on_exit(void* context) {
  65. Infrared* infrared = context;
  66. popup_reset(infrared->popup);
  67. }