xremote_scene_transmit.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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_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. furi_thread_flags_wait(0, FuriFlagWaitAny, app->ir_timing);
  60. xremote_scene_transmit_stop_ir_signal(app);
  61. }
  62. void xremote_scene_transmit_send_pause(XRemote* app, CrossRemoteItem* item) {
  63. app->transmitting = true;
  64. xremote_scene_ir_notification_message(app, PauseNotificationMessageBlinkStartSend);
  65. furi_thread_flags_wait(0, FuriFlagWaitAny, item->time * 1000);
  66. app->transmitting = false;
  67. xremote_scene_ir_notification_message(app, PauseNotificationMessageBlinkStop);
  68. }
  69. void xremote_scene_transmit_send_subghz(XRemote* app, CrossRemoteItem* item) {
  70. UNUSED(item);
  71. app->transmitting = true;
  72. xremote_scene_ir_notification_message(app, SubGhzNotificationMessageBlinkStartSend);
  73. // ADD SEND METHOD HERE
  74. furi_thread_flags_wait(0, FuriFlagWaitAny, 2000); //Remove later
  75. app->transmitting = false;
  76. xremote_scene_ir_notification_message(app, SubGhzNotificationMessageBlinkStop);
  77. }
  78. void xremote_scene_transmit_send_signal(void* context, CrossRemoteItem* item) {
  79. furi_assert(context);
  80. XRemote* app = context;
  81. CrossRemote* remote = app->cross_remote;
  82. if(app->transmitting) {
  83. return;
  84. }
  85. xremote_transmit_model_set_name(app->xremote_transmit, xremote_remote_item_get_name(item));
  86. xremote_transmit_model_set_type(app->xremote_transmit, item->type);
  87. if(item->type == XRemoteRemoteItemTypeInfrared) {
  88. xremote_scene_transmit_send_ir_signal(app, item);
  89. } else if(item->type == XRemoteRemoteItemTypePause) {
  90. xremote_scene_transmit_send_pause(app, item);
  91. } else if(item->type == XRemoteRemoteItemTypeSubGhz) {
  92. xremote_scene_transmit_send_subghz(app, item);
  93. }
  94. cross_remote_set_transmitting(remote, XRemoteTransmittingStop);
  95. }
  96. void xremote_scene_transmit_run_remote(void* context) {
  97. furi_assert(context);
  98. XRemote* app = context;
  99. CrossRemote* remote = app->cross_remote;
  100. size_t item_count = cross_remote_get_item_count(remote);
  101. for(size_t i = 0; i < item_count;) {
  102. if(cross_remote_get_transmitting(remote) == XRemoteTransmittingIdle) {
  103. cross_remote_set_transmitting(remote, XRemoteTransmittingStart);
  104. CrossRemoteItem* item = cross_remote_get_item(remote, i);
  105. xremote_scene_transmit_send_signal(app, item);
  106. //furi_thread_flags_wait(0, FuriFlagWaitAny, 2000);
  107. xremote_scene_ir_notification_message(app, InfraredNotificationMessageBlinkStartSend);
  108. } else if(cross_remote_get_transmitting(remote) == XRemoteTransmittingStop) {
  109. i++;
  110. cross_remote_set_transmitting(remote, XRemoteTransmittingIdle);
  111. }
  112. }
  113. xremote_scene_ir_notification_message(app, InfraredNotificationMessageBlinkStop);
  114. //scene_manager_next_scene(app->scene_manager, XRemoteSceneXrList);
  115. scene_manager_previous_scene(app->scene_manager);
  116. //xremote_transmit_model_set_name(app->xremote_transmit, cross_remote_get_name(remote));
  117. }
  118. void xremote_scene_transmit_on_enter(void* context) {
  119. furi_assert(context);
  120. XRemote* app = context;
  121. xremote_transmit_set_callback(app->xremote_transmit, xremote_transmit_callback, app);
  122. view_dispatcher_switch_to_view(app->view_dispatcher, XRemoteViewIdTransmit);
  123. xremote_scene_transmit_run_remote(app);
  124. }
  125. bool xremote_scene_transmit_on_event(void* context, SceneManagerEvent event) {
  126. XRemote* app = context;
  127. UNUSED(app);
  128. UNUSED(event);
  129. bool consumed = false;
  130. return consumed;
  131. }
  132. void xremote_scene_transmit_on_exit(void* context) {
  133. XRemote* app = context;
  134. UNUSED(app);
  135. }