tuanchris 3 месяцев назад
Родитель
Сommit
3ef6306535
2 измененных файлов с 15 добавлено и 6 удалено
  1. 5 4
      modules/core/pattern_manager.py
  2. 10 2
      modules/led/ball_tracking_manager.py

+ 5 - 4
modules/core/pattern_manager.py

@@ -691,13 +691,14 @@ async def run_theta_rho_file(file_path, is_playlist=False):
             state.ball_tracking_manager._update_count = 0
             state.ball_tracking_manager._skipped_updates = 0
 
-        if state.ball_tracking_mode == "playing_only" and state.ball_tracking_manager:
-            logger.info("Starting ball tracking (playing_only mode)")
+        # Start ball tracking for both "playing_only" and "enabled" modes during pattern execution
+        if state.ball_tracking_mode in ["playing_only", "enabled"] and state.ball_tracking_manager:
+            logger.info(f"Starting ball tracking ({state.ball_tracking_mode} mode)")
             state.ball_tracking_manager.start()
             ball_tracking_active = True
 
-        # Notify ball tracking that pattern is starting (for both "playing_only" and "enabled" modes)
-        if state.ball_tracking_manager and (ball_tracking_active or state.ball_tracking_mode == "enabled"):
+        # Notify ball tracking that pattern is starting
+        if state.ball_tracking_manager and ball_tracking_active:
             state.ball_tracking_manager.set_pattern_running(True)
 
         # Set LED effect

+ 10 - 2
modules/led/ball_tracking_manager.py

@@ -126,12 +126,13 @@ class BallTrackingManager:
         Args:
             is_running: True if pattern is executing, False otherwise
         """
+        logger.info(f"set_pattern_running called: is_running={is_running}, active={self._active}")
         self._is_pattern_running = is_running
 
         if is_running and self._active:
             # Pattern started, begin polling
             self._start_polling()
-            logger.info("Pattern started - beginning position polling")
+            logger.info(f"Pattern started - beginning position polling (interval={self._poll_interval}s)")
         else:
             # Pattern stopped, stop polling
             self._stop_polling()
@@ -153,6 +154,7 @@ class BallTrackingManager:
     def _poll_position(self):
         """Poll current position from state and update LEDs if needed"""
         if not self._active or not self._is_pattern_running:
+            logger.debug(f"Polling stopped: active={self._active}, pattern_running={self._is_pattern_running}")
             self._poll_timer = None
             return
 
@@ -164,11 +166,13 @@ class BallTrackingManager:
             theta = state.current_theta
             rho = state.current_rho
 
+            logger.debug(f"Polling position: theta={theta:.1f}°, rho={rho:.2f}, last_led={self._last_led_index}")
+
             # Update position (this will skip if LED zone hasn't changed)
             self._update_leds_optimized(theta, rho)
 
         except Exception as e:
-            logger.error(f"Error polling position: {e}")
+            logger.error(f"Error polling position: {e}", exc_info=True)
 
         # Schedule next poll
         if self._active and self._is_pattern_running:
@@ -187,12 +191,14 @@ class BallTrackingManager:
             current_rho: Most recent rho value
         """
         if not self._active:
+            logger.debug("Update skipped: not active")
             return
 
         # If using lookback buffer, get the delayed position
         if self._use_buffer:
             position = self._get_tracked_position()
             if position is None:
+                logger.debug("Update skipped: no position in buffer")
                 return
             theta, rho, _ = position
         else:
@@ -208,9 +214,11 @@ class BallTrackingManager:
             if new_led_index == self._last_led_index:
                 # LED zone hasn't changed, skip update
                 self._skipped_updates += 1
+                logger.debug(f"LED zone unchanged: {new_led_index}")
                 return
 
             # LED zone changed, update it
+            logger.info(f"LED zone changed: {self._last_led_index} → {new_led_index} (theta={theta:.1f}°)")
             self._last_led_index = new_led_index
 
     def _update_leds(self):