xremote_scene_transmit.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. #include "../xremote.h"
  2. #include "../views/xremote_transmit.h"
  3. #include "../models/infrared/xremote_ir_signal.h"
  4. #include "../helpers/subghz/subghz.h"
  5. static const NotificationSequence* xremote_notification_sequences[] = {
  6. &sequence_success,
  7. &sequence_set_only_green_255,
  8. &sequence_reset_green,
  9. &sequence_solid_yellow,
  10. &sequence_reset_rgb,
  11. &sequence_blink_start_cyan,
  12. &sequence_blink_start_magenta,
  13. &sequence_blink_stop,
  14. &sequence_blink_start_yellow,
  15. &sequence_blink_stop,
  16. &sequence_blink_start_blue,
  17. &sequence_blink_stop,
  18. };
  19. void xremote_transmit_callback(XRemoteCustomEvent event, void* context) {
  20. furi_assert(context);
  21. XRemote* app = context;
  22. view_dispatcher_send_custom_event(app->view_dispatcher, event);
  23. }
  24. void xremote_scene_ir_notification_message(XRemote* app, uint32_t message) {
  25. if(app->led == 1) {
  26. notification_message(app->notification, xremote_notification_sequences[message]);
  27. }
  28. }
  29. bool xremote_scene_ir_signal_is_raw(InfraredSignal* signal) {
  30. if(signal->is_raw) {
  31. return true;
  32. }
  33. return false;
  34. }
  35. void xremote_scene_transmit_stop_ir_signal(XRemote* app) {
  36. if(!app->transmitting) {
  37. return;
  38. }
  39. app->transmitting = false;
  40. infrared_worker_tx_stop(app->ir_worker);
  41. infrared_worker_tx_set_get_signal_callback(app->ir_worker, NULL, NULL);
  42. xremote_scene_ir_notification_message(app, InfraredNotificationMessageBlinkStop);
  43. }
  44. void xremote_scene_transmit_send_ir_signal(XRemote* app, CrossRemoteItem* item) {
  45. InfraredSignal* signal = xremote_cross_remote_item_get_ir_signal(item);
  46. dolphin_deed(DolphinDeedIrSend);
  47. xremote_scene_ir_notification_message(app, InfraredNotificationMessageBlinkStartSend);
  48. if(xremote_scene_ir_signal_is_raw(signal)) {
  49. InfraredRawSignal* raw = xremote_ir_signal_get_raw_signal(signal);
  50. infrared_worker_set_raw_signal(
  51. app->ir_worker, raw->timings, raw->timings_size, raw->frequency, raw->duty_cycle);
  52. } else {
  53. InfraredMessage* message = xremote_ir_signal_get_message(signal);
  54. infrared_worker_set_decoded_signal(app->ir_worker, message);
  55. }
  56. infrared_worker_tx_set_get_signal_callback(
  57. app->ir_worker, infrared_worker_tx_get_signal_steady_callback, app);
  58. infrared_worker_tx_start(app->ir_worker);
  59. app->transmitting = true;
  60. uint32_t time = app->ir_timing;
  61. if (item->time > 0) {
  62. time = item->time;
  63. }
  64. furi_thread_flags_wait(0, FuriFlagWaitAny, time);
  65. xremote_scene_transmit_stop_ir_signal(app);
  66. }
  67. void xremote_scene_transmit_send_pause(XRemote* app, CrossRemoteItem* item) {
  68. app->transmitting = true;
  69. xremote_scene_ir_notification_message(app, PauseNotificationMessageBlinkStartSend);
  70. furi_thread_flags_wait(0, FuriFlagWaitAny, item->time * 1000);
  71. app->transmitting = false;
  72. xremote_scene_ir_notification_message(app, PauseNotificationMessageBlinkStop);
  73. }
  74. void xremote_scene_transmit_send_subghz(XRemote* app, CrossRemoteItem* item) {
  75. app->transmitting = true;
  76. xremote_scene_ir_notification_message(app, SubGhzNotificationMessageBlinkStartSend);
  77. subghz_send(app, furi_string_get_cstr(item->filename));
  78. //furi_thread_flags_wait(0, FuriFlagWaitAny, 2000);
  79. }
  80. void xremote_scene_transmit_send_signal(void* context, CrossRemoteItem* item) {
  81. furi_assert(context);
  82. XRemote* app = context;
  83. CrossRemote* remote = app->cross_remote;
  84. if(app->transmitting) {
  85. return;
  86. }
  87. xremote_transmit_model_set_name(app->xremote_transmit, xremote_cross_remote_item_get_name(item));
  88. xremote_transmit_model_set_type(app->xremote_transmit, item->type);
  89. if(item->type == XRemoteRemoteItemTypeInfrared) {
  90. xremote_scene_transmit_send_ir_signal(app, item);
  91. xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingStop);
  92. } else if(item->type == XRemoteRemoteItemTypePause) {
  93. xremote_scene_transmit_send_pause(app, item);
  94. xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingStop);
  95. } else if(item->type == XRemoteRemoteItemTypeSubGhz) {
  96. xremote_scene_transmit_send_subghz(app, item);
  97. }
  98. }
  99. void xremote_scene_transmit_run_remote(void* context) {
  100. furi_assert(context);
  101. XRemote* app = context;
  102. CrossRemote* remote = app->cross_remote;
  103. size_t item_count = xremote_cross_remote_get_item_count(remote);
  104. for(size_t i = 0; i < item_count;) {
  105. if(xremote_cross_remote_get_transmitting(remote) == XRemoteTransmittingIdle) {
  106. xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingStart);
  107. CrossRemoteItem* item = xremote_cross_remote_get_item(remote, i);
  108. xremote_scene_transmit_send_signal(app, item);
  109. //furi_thread_flags_wait(0, FuriFlagWaitAny, 1000);
  110. } else if(xremote_cross_remote_get_transmitting(remote) == XRemoteTransmittingStopSubghz) {
  111. i++;
  112. app->state_notifications = SubGhzNotificationStateIDLE;
  113. app->transmitting = false;
  114. subghz_txrx_stop(app->subghz->txrx);
  115. xremote_scene_ir_notification_message(app, SubGhzNotificationMessageBlinkStop);
  116. xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingIdle);
  117. //furi_thread_flags_wait(0, FuriFlagWaitAny, 1000);
  118. } else if(xremote_cross_remote_get_transmitting(remote) == XRemoteTransmittingStop) {
  119. i++;
  120. xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingIdle);
  121. }
  122. }
  123. xremote_scene_ir_notification_message(app, InfraredNotificationMessageBlinkStop);
  124. scene_manager_previous_scene(app->scene_manager);
  125. //xremote_transmit_model_set_name(app->xremote_transmit, xremote_cross_remote_get_name(remote));
  126. }
  127. void xremote_scene_transmit_on_enter(void* context) {
  128. furi_assert(context);
  129. XRemote* app = context;
  130. xremote_transmit_set_callback(app->xremote_transmit, xremote_transmit_callback, app);
  131. view_dispatcher_switch_to_view(app->view_dispatcher, XRemoteViewIdTransmit);
  132. xremote_scene_transmit_run_remote(app);
  133. }
  134. bool xremote_scene_transmit_on_event(void* context, SceneManagerEvent event) {
  135. XRemote* app = context;
  136. bool consumed = false;
  137. if(event.type == SceneManagerEventTypeCustom) {
  138. FURI_LOG_D(TAG, "Custom Event");
  139. switch(event.event) {
  140. case XRemoteCustomEventViewTransmitterSendStop:
  141. FURI_LOG_D("SUBGHZ", "stop event");
  142. //app->stop_transmit = true;
  143. app->state_notifications = SubGhzNotificationStateIDLE;
  144. app->transmitting = false;
  145. subghz_txrx_stop(app->subghz->txrx);
  146. xremote_scene_ir_notification_message(app, SubGhzNotificationMessageBlinkStop);
  147. xremote_cross_remote_set_transmitting(app->cross_remote, XRemoteTransmittingStop);
  148. break;
  149. default:
  150. break;
  151. }
  152. } else if(event.type == SceneManagerEventTypeTick) {
  153. FURI_LOG_D(TAG, "Tick Event");
  154. if (app->state_notifications == SubGhzNotificationStateTx && app->led == 1) {
  155. //blink for subghz
  156. }
  157. }
  158. return consumed;
  159. }
  160. void xremote_scene_transmit_on_exit(void* context) {
  161. XRemote* app = context;
  162. app->transmitting = false;
  163. app->state_notifications = SubGhzNotificationStateIDLE;
  164. subghz_txrx_stop(app->subghz->txrx);
  165. //xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingIdle);
  166. }