Skip to content

Commit 1dca05d

Browse files
author
Wouter Kroot
committed
Added Button events in eyelink test
1 parent bf5b980 commit 1dca05d

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

mne/io/eyelink/tests/test_eyelink.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,19 @@ def _simulate_eye_tracking_data(in_file, out_file):
201201
"SAMPLES\tPUPIL\tLEFT\tVEL\tRES\tHTARGET\tRATE\t1000.00"
202202
"\tTRACKING\tCR\tFILTER\t2\tINPUT"
203203
)
204+
205+
# Define your known BUTTON events
206+
button_events = [
207+
(5488529, 1, 0),
208+
(5488532, 1, 1),
209+
(5488540, 1, 0),
210+
(5488543, 1, 1),
211+
(5488550, 1, 0),
212+
(5488553, 1, 1),
213+
(5488571, 1, 0),
214+
]
215+
button_idx = 0
216+
204217
with out_file.open("w") as fp:
205218
in_recording_block = False
206219
events = []
@@ -214,7 +227,7 @@ def _simulate_eye_tracking_data(in_file, out_file):
214227
if event_type.isnumeric(): # samples
215228
tokens[4:4] = ["100", "20", "45", "45", "127.0"] # vel, res, DIN
216229
tokens.extend(["1497.0", "5189.0", "512.5", "............."])
217-
elif event_type in ("EFIX", "ESACC"):
230+
elif event_type in ("EFIX", "ESACC", "BUTTON"):
218231
if event_type == "ESACC":
219232
tokens[5:7] = [".", "."] # pretend start pos is unknown
220233
tokens.extend(["45", "45"]) # resolution
@@ -224,6 +237,15 @@ def _simulate_eye_tracking_data(in_file, out_file):
224237
tokens.append("INPUT")
225238
elif event_type == "EBLINK":
226239
continue # simulate no blink events
240+
elif event_type == "BUTTON":
241+
# simulate a button event
242+
tokens[1] = "BUTTON" # simulate button press
243+
tokens[2] = "1" # simulate button 1
244+
tokens[3] = "1" # simulate button pressed
245+
tokens[4:4] = ["100", "20", "45", "45", "127.0"]
246+
tokens.extend(["1497.0", "5189.0", "512.5", "............."])
247+
248+
continue
227249
elif event_type == "END":
228250
pass
229251
else:
@@ -245,6 +267,18 @@ def _simulate_eye_tracking_data(in_file, out_file):
245267
f"{timestamp}\t-2434.0\t-1760.0\t840.0\t100\t20\t45\t45\t127.0\t"
246268
"...\t1497\t5189\t512.5\t.............\n"
247269
)
270+
271+
for timestamp in np.arange(5488500, 5488600): # 100 samples
272+
# Write sample line
273+
fp.write(
274+
f"{timestamp}\t-2434.0\t-1760.0\t840.0\t100\t20\t45\t45\t127.0\t"
275+
"...\t1497\t5189\t512.5\t.............\n"
276+
)
277+
# Check and insert button events at this timestamp
278+
while button_idx < len(button_events) and button_events[button_idx][0] == timestamp:
279+
t, btn_id, state = button_events[button_idx]
280+
fp.write(f"BUTTON\t{t}\t{btn_id}\t{state}\n")
281+
button_idx += 1
248282

249283
fp.write("END\t7453390\tRIGHT\tSAMPLES\tEVENTS\n")
250284

0 commit comments

Comments
 (0)