xremote_scene_transmit.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. // ADD SEND METHOD HERE
  78. subghz_send(app, furi_string_get_cstr(item->filename)); //currently crashes, null pointer
  79. //furi_thread_flags_wait(0, FuriFlagWaitAny, 2000); //Remove later
  80. //app->transmitting = false;
  81. //xremote_scene_ir_notification_message(app, SubGhzNotificationMessageBlinkStop);
  82. }
  83. void xremote_scene_transmit_send_signal(void* context, CrossRemoteItem* item) {
  84. furi_assert(context);
  85. XRemote* app = context;
  86. CrossRemote* remote = app->cross_remote;
  87. if(app->transmitting) {
  88. return;
  89. }
  90. xremote_transmit_model_set_name(app->xremote_transmit, xremote_cross_remote_item_get_name(item));
  91. xremote_transmit_model_set_type(app->xremote_transmit, item->type);
  92. if(item->type == XRemoteRemoteItemTypeInfrared) {
  93. xremote_scene_transmit_send_ir_signal(app, item);
  94. xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingStop);
  95. } else if(item->type == XRemoteRemoteItemTypePause) {
  96. xremote_scene_transmit_send_pause(app, item);
  97. xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingStop);
  98. } else if(item->type == XRemoteRemoteItemTypeSubGhz) {
  99. xremote_scene_transmit_send_subghz(app, item);
  100. }
  101. //xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingStop);
  102. }
  103. void xremote_scene_transmit_run_remote(void* context) {
  104. furi_assert(context);
  105. XRemote* app = context;
  106. CrossRemote* remote = app->cross_remote;
  107. size_t item_count = xremote_cross_remote_get_item_count(remote);
  108. for(size_t i = 0; i < item_count;) {
  109. if(xremote_cross_remote_get_transmitting(remote) == XRemoteTransmittingIdle) {
  110. xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingStart);
  111. CrossRemoteItem* item = xremote_cross_remote_get_item(remote, i);
  112. xremote_scene_transmit_send_signal(app, item);
  113. //furi_thread_flags_wait(0, FuriFlagWaitAny, 2000);
  114. //furi_thread_flags_wait(0, FuriFlagWaitAny, 1000);
  115. //xremote_scene_ir_notification_message(app, InfraredNotificationMessageBlinkStartSend);
  116. } else if(xremote_cross_remote_get_transmitting(remote) == XRemoteTransmittingStopSubghz) {
  117. i++;
  118. app->state_notifications = SubGhzNotificationStateIDLE;
  119. subghz_txrx_stop(app->subghz->txrx);
  120. app->transmitting = false;
  121. xremote_scene_ir_notification_message(app, SubGhzNotificationMessageBlinkStop);
  122. xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingIdle);
  123. //furi_thread_flags_wait(0, FuriFlagWaitAny, 1000);
  124. } else if(xremote_cross_remote_get_transmitting(remote) == XRemoteTransmittingStop) {
  125. i++;
  126. xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingIdle);
  127. }
  128. }
  129. xremote_scene_ir_notification_message(app, InfraredNotificationMessageBlinkStop);
  130. //scene_manager_next_scene(app->scene_manager, XRemoteSceneXrList);
  131. scene_manager_previous_scene(app->scene_manager);
  132. //xremote_transmit_model_set_name(app->xremote_transmit, xremote_cross_remote_get_name(remote));
  133. }
  134. void xremote_scene_transmit_on_enter(void* context) {
  135. furi_assert(context);
  136. XRemote* app = context;
  137. xremote_transmit_set_callback(app->xremote_transmit, xremote_transmit_callback, app);
  138. view_dispatcher_switch_to_view(app->view_dispatcher, XRemoteViewIdTransmit);
  139. xremote_scene_transmit_run_remote(app);
  140. }
  141. bool xremote_scene_transmit_on_event(void* context, SceneManagerEvent event) {
  142. XRemote* app = context;
  143. bool consumed = false;
  144. if(event.type == SceneManagerEventTypeCustom) {
  145. FURI_LOG_D(TAG, "Custom Event");
  146. switch(event.event) {
  147. case XRemoteCustomEventViewTransmitterSendStop:
  148. FURI_LOG_D("SUBGHZ", "stop event");
  149. //app->stop_transmit = true;
  150. app->state_notifications = SubGhzNotificationStateIDLE;
  151. subghz_txrx_stop(app->subghz->txrx);
  152. app->transmitting = false;
  153. xremote_scene_ir_notification_message(app, SubGhzNotificationMessageBlinkStop);
  154. xremote_cross_remote_set_transmitting(app->cross_remote, XRemoteTransmittingStop);
  155. break;
  156. default:
  157. break;
  158. }
  159. } else if(event.type == SceneManagerEventTypeTick) {
  160. FURI_LOG_D(TAG, "Tick Event");
  161. if (app->state_notifications == SubGhzNotificationStateTx && app->led == 1) {
  162. //blink for subghz
  163. }
  164. }
  165. return consumed;
  166. }
  167. void xremote_scene_transmit_on_exit(void* context) {
  168. XRemote* app = context;
  169. app->transmitting = false;
  170. subghz_txrx_stop(app->subghz->txrx);
  171. app->state_notifications = SubGhzNotificationStateIDLE;
  172. //xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingIdle);
  173. }