|
7 | 7 | from flask import Response
|
8 | 8 | import queue
|
9 | 9 | import threading
|
| 10 | +import time |
10 | 11 |
|
11 | 12 | console_queue = queue.Queue()
|
12 | 13 | app = Flask(__name__)
|
|
16 | 17 | connection_manager = None
|
17 | 18 | connection_thread = None
|
18 | 19 | ble_devices = []
|
| 20 | +stream_active = False |
19 | 21 |
|
20 | 22 | def run_async(coro):
|
21 | 23 | def wrapper(*args, **kwargs):
|
@@ -46,16 +48,22 @@ async def scan_ble_devices():
|
46 | 48 |
|
47 | 49 | @app.route('/check_stream')
|
48 | 50 | def check_stream():
|
49 |
| - if connection_manager and connection_manager.lsl_connection: |
| 51 | + if connection_manager and connection_manager.stream_active: |
50 | 52 | return jsonify({'connected': True})
|
51 | 53 | return jsonify({'connected': False})
|
52 | 54 |
|
| 55 | +@app.route('/check_connection') |
| 56 | +def check_connection(): |
| 57 | + if connection_manager and connection_manager.stream_active: |
| 58 | + return jsonify({'status': 'connected'}) |
| 59 | + return jsonify({'status': 'connecting'}) |
| 60 | + |
53 | 61 | def post_console_message(message):
|
54 |
| - if connection_manager: |
55 |
| - if "LSL stream started" in message: |
56 |
| - connection_manager.stream_active = True |
57 |
| - elif "Connection error" in message or "disconnected" in message: |
58 |
| - connection_manager.stream_active = False |
| 62 | + global stream_active |
| 63 | + if "LSL stream started" in message: |
| 64 | + stream_active = True |
| 65 | + elif "disconnected" in message: |
| 66 | + stream_active = False |
59 | 67 | console_queue.put(message)
|
60 | 68 |
|
61 | 69 | @app.route('/console_updates')
|
@@ -120,10 +128,10 @@ def run_connection():
|
120 | 128 |
|
121 | 129 | @app.route('/disconnect', methods=['POST'])
|
122 | 130 | def disconnect_device():
|
123 |
| - global connection_manager |
| 131 | + global connection_manager, stream_active |
124 | 132 | if connection_manager:
|
125 | 133 | connection_manager.cleanup()
|
126 |
| - connection_manager.stream_active = False |
| 134 | + stream_active = False |
127 | 135 | post_console_message("disconnected")
|
128 | 136 | return jsonify({'status': 'disconnected'})
|
129 | 137 | return jsonify({'status': 'no active connection'})
|
|
0 commit comments