13
13
app = Flask (__name__ )
14
14
app .secret_key = '--'
15
15
16
- lsl_process = None # Process for LSL
16
+ lsl_process = None # Process Variable for LSL
17
17
lsl_running = False # Flag to check if LSL is running
18
18
npg_running = False # Flag to check if NPG is running
19
- npg_process = None # Process for NPG
19
+ npg_process = None # Process Variable for NPG
20
20
app_processes = {} # Dictionary to hold other app processes
21
21
current_message = None # Message to display in the UI
22
22
discovered_devices = [] # List for all discovered devices
@@ -29,7 +29,7 @@ def is_process_running(name):
29
29
return True # Returns True if process found
30
30
return False # Returns False if process not found
31
31
32
- @app .route ("/" )
32
+ @app .route ("/" ) # Route for the Home page
33
33
def home ():
34
34
"""Render the home page with the current status of LSL Stream , NPG stream, running applications, messages."""
35
35
return render_template ("index.html" , lsl_started = lsl_running , npg_started = npg_running , running_apps = [k for k ,v in app_processes .items () if v .poll () is None ], message = current_message , devices = session .get ('devices' , []), selected_device = session .get ('selected_device' ))
@@ -255,7 +255,7 @@ def start_lsl():
255
255
lsl_process = subprocess .Popen (command , stdout = subprocess .PIPE , stderr = subprocess .STDOUT , creationflags = creation_flags , text = True , bufsize = 1 )
256
256
257
257
output = lsl_process .stdout .readline ().strip ()
258
- if "No " in output : # Check for failure messages in output
258
+ if "Serial Connection not established properly.Try Again " in output : # Check for failure messages in output
259
259
current_message = "Failed to start LSL stream"
260
260
lsl_running = False
261
261
else :
@@ -348,7 +348,7 @@ def event_stream():
348
348
last_state = None # Initialize last_state to None
349
349
350
350
while True :
351
- current_state = {"lsl_running" : lsl_running , "npg_running" : npg_running , "running_apps" : [k for k ,v in app_processes .items () if v .poll () is None ], "message" : current_message , "stream_interrupted" : (("Data Interrupted (Bluetooth Disconnected)" or "Error while closing serial connection" in current_message ) if current_message else False )}
351
+ current_state = {"lsl_running" : lsl_running , "npg_running" : npg_running , "running_apps" : [k for k ,v in app_processes .items () if v .poll () is None ], "message" : current_message , "stream_interrupted" : (current_message and ("Data Interrupted (Bluetooth Disconnected)" in current_message or "Error while closing serial connection" in current_message ))}
352
352
if current_state != last_state :
353
353
yield f"data: { json .dumps (current_state )} \n \n "
354
354
last_state = current_state .copy ()
@@ -369,7 +369,7 @@ def cleanup_processes():
369
369
""" Remove finished processes from the app_processes dictionary."""
370
370
global app_processes
371
371
app_processes = {
372
- k : v for k , v in app_processes .items ()
372
+ k : v for k , v in app_processes .items () # need to update
373
373
if v .poll () is None # Only keep running processes
374
374
}
375
375
0 commit comments