subrem_scene_remote.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include "../subghz_remote_app_i.h"
  2. #include "../views/remote.h"
  3. #include <lib/subghz/protocols/raw.h>
  4. #define TAG "SubRemScenRemote"
  5. void subrem_scene_remote_callback(SubRemCustomEvent event, void* context) {
  6. furi_assert(context);
  7. SubGhzRemoteApp* app = context;
  8. view_dispatcher_send_custom_event(app->view_dispatcher, event);
  9. }
  10. void subrem_scene_remote_raw_callback_end_tx(void* context) {
  11. furi_assert(context);
  12. SubGhzRemoteApp* app = context;
  13. view_dispatcher_send_custom_event(app->view_dispatcher, SubRemCustomEventViewRemoteForcedStop);
  14. }
  15. static uint8_t subrem_scene_remote_event_to_index(SubRemCustomEvent event_id) {
  16. uint8_t ret = 0;
  17. if(event_id == SubRemCustomEventViewRemoteStartUP) {
  18. ret = SubRemSubKeyNameUp;
  19. } else if(event_id == SubRemCustomEventViewRemoteStartDOWN) {
  20. ret = SubRemSubKeyNameDown;
  21. } else if(event_id == SubRemCustomEventViewRemoteStartLEFT) {
  22. ret = SubRemSubKeyNameLeft;
  23. } else if(event_id == SubRemCustomEventViewRemoteStartRIGHT) {
  24. ret = SubRemSubKeyNameRight;
  25. } else if(event_id == SubRemCustomEventViewRemoteStartOK) {
  26. ret = SubRemSubKeyNameOk;
  27. }
  28. return ret;
  29. }
  30. void subrem_scene_remote_on_enter(void* context) {
  31. SubGhzRemoteApp* app = context;
  32. subrem_view_remote_update_data_labels(app->subrem_remote_view, app->map_preset->subs_preset);
  33. subrem_view_remote_set_radio(
  34. app->subrem_remote_view,
  35. subghz_txrx_radio_device_get(app->txrx) != SubGhzRadioDeviceTypeInternal);
  36. subrem_view_remote_set_callback(app->subrem_remote_view, subrem_scene_remote_callback, app);
  37. view_dispatcher_switch_to_view(app->view_dispatcher, SubRemViewIDRemote);
  38. }
  39. bool subrem_scene_remote_on_event(void* context, SceneManagerEvent event) {
  40. SubGhzRemoteApp* app = context;
  41. if(event.type == SceneManagerEventTypeCustom) {
  42. if(event.event == SubRemCustomEventViewRemoteBack) {
  43. if(!scene_manager_previous_scene(app->scene_manager)) {
  44. scene_manager_stop(app->scene_manager);
  45. view_dispatcher_stop(app->view_dispatcher);
  46. }
  47. return true;
  48. } else if(
  49. event.event == SubRemCustomEventViewRemoteStartUP ||
  50. event.event == SubRemCustomEventViewRemoteStartDOWN ||
  51. event.event == SubRemCustomEventViewRemoteStartLEFT ||
  52. event.event == SubRemCustomEventViewRemoteStartRIGHT ||
  53. event.event == SubRemCustomEventViewRemoteStartOK) {
  54. // Start sending sub
  55. subrem_tx_stop_sub(app, true);
  56. uint8_t chosen_sub = subrem_scene_remote_event_to_index(event.event);
  57. app->chosen_sub = chosen_sub;
  58. subrem_view_remote_set_state(
  59. app->subrem_remote_view, SubRemViewRemoteStateLoading, chosen_sub);
  60. if(subrem_tx_start_sub(app, app->map_preset->subs_preset[chosen_sub])) {
  61. if(app->map_preset->subs_preset[chosen_sub]->type == SubGhzProtocolTypeRAW) {
  62. subghz_txrx_set_raw_file_encoder_worker_callback_end(
  63. app->txrx, subrem_scene_remote_raw_callback_end_tx, app);
  64. }
  65. subrem_view_remote_set_state(
  66. app->subrem_remote_view, SubRemViewRemoteStateSending, chosen_sub);
  67. notification_message(app->notifications, &sequence_blink_start_magenta);
  68. } else {
  69. subrem_view_remote_set_state(
  70. app->subrem_remote_view, SubRemViewRemoteStateIdle, 0);
  71. notification_message(app->notifications, &sequence_blink_red_100);
  72. }
  73. return true;
  74. } else if(event.event == SubRemCustomEventViewRemoteForcedStop) {
  75. subrem_tx_stop_sub(app, true);
  76. subrem_view_remote_set_state(app->subrem_remote_view, SubRemViewRemoteStateIdle, 0);
  77. notification_message(app->notifications, &sequence_blink_stop);
  78. return true;
  79. } else if(event.event == SubRemCustomEventViewRemoteStop) {
  80. if(subrem_tx_stop_sub(app, false)) {
  81. subrem_view_remote_set_state(
  82. app->subrem_remote_view, SubRemViewRemoteStateIdle, 0);
  83. notification_message(app->notifications, &sequence_blink_stop);
  84. }
  85. return true;
  86. }
  87. }
  88. // } else if(event.type == SceneManagerEventTypeTick) {
  89. // }
  90. return false;
  91. }
  92. void subrem_scene_remote_on_exit(void* context) {
  93. SubGhzRemoteApp* app = context;
  94. subrem_tx_stop_sub(app, true);
  95. subrem_view_remote_set_state(app->subrem_remote_view, SubRemViewRemoteStateIdle, 0);
  96. notification_message(app->notifications, &sequence_blink_stop);
  97. }