xremote_scene_transmit.c 6.1 KB

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