Skip to content

Commit c9a457b

Browse files
committed
Handle LSL stream disconnection by closing app after 2s of no data.
1 parent 6796cd9 commit c9a457b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

eog.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def __init__(self):
1414
self.setWindowTitle("Real-Time EOG Monitor - Eye Blink Detection")
1515
self.setGeometry(100, 100, 800, 400)
1616

17+
self.stream_active = True # Flag to check if the stream is active
18+
self.last_data_time = None # Variable to store the last data time
19+
1720
# Create layout
1821
layout = QVBoxLayout()
1922
central_widget = QWidget()
@@ -99,6 +102,7 @@ def __init__(self):
99102
def update_plot(self):
100103
samples, _ = self.inlet.pull_chunk(timeout=0.0, max_samples=30)
101104
if samples:
105+
self.last_data_time = time.time() # Store the last data time
102106
for sample in samples:
103107
# Overwrite the oldest data point in the buffer
104108
self.eog_data[self.current_index] = sample[0]
@@ -132,6 +136,12 @@ def update_plot(self):
132136

133137
# Update the blink plot with the current blink data
134138
self.blink_curve.setData(self.time_data, self.blink_data)
139+
else:
140+
if self.last_data_time and (time.time() - self.last_data_time) > 2:
141+
self.stream_active = False
142+
print("LSL stream disconnected!")
143+
self.timer.stop()
144+
self.close()
135145

136146
def detect_blinks(self, filtered_eog):
137147
mean_signal = np.mean(filtered_eog)

0 commit comments

Comments
 (0)