ソースを参照

change run_theta_rho_file logic

now if another pattern is requested, the current one will be stopped, and the new pattern will begin once the serial lock has been released
Fabio De Simone 1 年間 前
コミット
53d283be1e
1 ファイル変更11 行追加7 行削除
  1. 11 7
      app.py

+ 11 - 7
app.py

@@ -334,10 +334,7 @@ def schedule_checker(schedule_hours):
 
 def run_theta_rho_file(file_path, schedule_hours=None):
     """Run a theta-rho file by sending data in optimized batches with tqdm ETA tracking."""
-    global stop_requested, current_playing_file, execution_progress, serial_lock
-    stop_requested = False
-    current_playing_file = file_path  # Track current playing file
-    execution_progress = (0, 0, None)  # Reset progress (ETA starts as None)
+    global stop_requested, current_playing_file, execution_progress
 
     coordinates = parse_theta_rho_file(file_path)
     total_coordinates = len(coordinates)
@@ -350,13 +347,20 @@ def run_theta_rho_file(file_path, schedule_hours=None):
 
     execution_progress = (0, total_coordinates, None)  # Initialize progress with ETA as None
     batch_size = 10  # Smaller batches may smooth movement further
+    
+    # before trying to acuire the lock we send the stop command
+    # so then we will just wait for the lock to be released so we can use the serial
+    stop_actions()
     with serial_lock:
-        print(serial_lock)
-        print(type(serial_lock))
-        with tqdm(total=total_coordinates, unit="coords", desc="Executing Pattern", dynamic_ncols=True, disable=None) as pbar:
+        current_playing_file = file_path  # Track current playing file
+        execution_progress = (0, 0, None)  # Reset progress (ETA starts as None)
+        stop_requested = False
+        with tqdm(total=total_coordinates, unit="coords", desc=f"Executing Pattern {file_path}", dynamic_ncols=True, disable=None) as pbar:
             for i in range(0, total_coordinates, batch_size):
                 if stop_requested:
                     print("Execution stopped by user after completing the current batch.")
+                    # after stopping we free the stop rquest "lock"
+                    stop_requested= False
                     break
 
                 with pause_condition: