Просмотр исходного кода

Merge pull request #5 from jamisonderek/jamisonderek/always-rx

Always RX except when shooting
RocketGod 1 год назад
Родитель
Сommit
59b65a932c
2 измененных файлов с 26 добавлено и 5 удалено
  1. 22 5
      infrared_controller.c
  2. 4 0
      laser_tag_app.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;
 

+ 4 - 0
laser_tag_app.c

@@ -270,6 +270,10 @@ static bool laser_tag_app_enter_game_state(LaserTagApp* app) {
     laser_tag_view_update(app->view, app->game_state);
     FURI_LOG_D(TAG, "View updated with new game state");
 
+    if(app->ir_controller) {
+        infrared_controller_free(app->ir_controller);
+        app->ir_controller = NULL;
+    }
     app->ir_controller = infrared_controller_alloc();
     if(!app->ir_controller) {
         FURI_LOG_E(TAG, "Failed to allocate IR controller");