xremote_scene_transmit.c 5.8 KB

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