infrared_scene_rpc.c 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. }
  32. const char* remote_name = infrared_remote_get_name(infrared->remote);
  33. infrared_text_store_set(infrared, 0, "loaded\n%s", remote_name);
  34. popup_set_text(
  35. infrared->popup, infrared->text_store[0], 82, 32, AlignCenter, AlignTop);
  36. rpc_system_app_confirm(infrared->rpc_ctx, RpcAppEventLoadFile, result);
  37. } else if(event.event == InfraredCustomEventTypeRpcButtonPress) {
  38. bool result = false;
  39. const char* arg = rpc_system_app_get_data(infrared->rpc_ctx);
  40. if(arg) {
  41. size_t button_index = 0;
  42. if(infrared_remote_find_button_by_name(infrared->remote, arg, &button_index)) {
  43. infrared_tx_start_button_index(infrared, button_index);
  44. result = true;
  45. }
  46. }
  47. rpc_system_app_confirm(infrared->rpc_ctx, RpcAppEventButtonRelease, result);
  48. } else if(event.event == InfraredCustomEventTypeRpcButtonRelease) {
  49. infrared_tx_stop(infrared);
  50. rpc_system_app_confirm(infrared->rpc_ctx, RpcAppEventButtonRelease, true);
  51. } else if(event.event == InfraredCustomEventTypeRpcExit) {
  52. view_dispatcher_stop(infrared->view_dispatcher);
  53. rpc_system_app_confirm(infrared->rpc_ctx, RpcAppEventAppExit, true);
  54. } else if(event.event == InfraredCustomEventTypeRpcSessionClose) {
  55. rpc_system_app_set_callback(infrared->rpc_ctx, NULL, NULL);
  56. infrared->rpc_ctx = NULL;
  57. view_dispatcher_stop(infrared->view_dispatcher);
  58. }
  59. }
  60. return consumed;
  61. }
  62. void infrared_scene_rpc_on_exit(void* context) {
  63. Infrared* infrared = context;
  64. infrared_tx_stop(infrared);
  65. popup_reset(infrared->popup);
  66. }