Explorar o código

Always RX except when shooting

Derek Jamison hai 1 ano
pai
achega
6a56928d36
Modificáronse 1 ficheiros con 22 adicións e 5 borrados
  1. 22 5
      infrared_controller.c

+ 22 - 5
infrared_controller.c

@@ -18,6 +18,7 @@ const NotificationSequence sequence_hit = {
 struct InfraredController {
     LaserTagTeam team;
     InfraredWorker* worker;
+    bool worker_rx_active;
     InfraredSignal* signal;
     NotificationApp* notification;
     bool hit_received;
@@ -104,6 +105,11 @@ void infrared_controller_free(InfraredController* controller) {
     FURI_LOG_I(TAG, "Freeing InfraredController");
 
     if(controller) {
+        if(controller->worker_rx_active) {
+            FURI_LOG_I(TAG, "Stopping RX worker");
+            infrared_worker_rx_stop(controller->worker);
+        }
+
         FURI_LOG_I(TAG, "Freeing InfraredWorker and InfraredSignal");
         infrared_worker_free(controller->worker);
         infrared_signal_free(controller->signal);
@@ -139,12 +145,23 @@ void infrared_controller_send(InfraredController* controller) {
         (unsigned long)message.address,
         (unsigned long)message.command);
 
+    if(controller->worker_rx_active) {
+        FURI_LOG_I(TAG, "Stopping RX worker");
+        infrared_worker_rx_stop(controller->worker);
+        controller->worker_rx_active = false;
+    }
+
     FURI_LOG_I(TAG, "Setting message for infrared signal");
     infrared_signal_set_message(controller->signal, &message);
 
     FURI_LOG_I(TAG, "Starting infrared signal transmission");
     infrared_signal_transmit(controller->signal);
 
+    if(!controller->worker_rx_active) {
+        infrared_worker_rx_start(controller->worker);
+        controller->worker_rx_active = true;
+    }
+
     FURI_LOG_I(TAG, "Infrared signal transmission completed");
 }
 
@@ -156,11 +173,11 @@ bool infrared_controller_receive(InfraredController* controller) {
         return false;
     }
 
-    infrared_worker_rx_start(controller->worker);
-
-    furi_delay_ms(250);
-
-    infrared_worker_rx_stop(controller->worker);
+    if(!controller->worker_rx_active) {
+        infrared_worker_rx_start(controller->worker);
+        controller->worker_rx_active = true;
+        furi_delay_ms(250);
+    }
 
     bool hit = controller->hit_received;