-
Notifications
You must be signed in to change notification settings - Fork 3
/
eyeTrackerTestBasedOnPicture.py
598 lines (494 loc) · 23.4 KB
/
eyeTrackerTestBasedOnPicture.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
#
# Copyright (c) 1996-2021, SR Research Ltd., All Rights Reserved
# For use by SR Research licencees only. Redistribution and use in source
# and binary forms, with or without modification, are NOT permitted.
# DESCRIPTION:
# This is a basic example, which shows how connect to and disconnect from
# the tracker, how to open and close data file, how to start/stop recording,
# and the standard messages for integration with the Data Viewer software.
# Four pictures will be shown one-by-one and each trial terminates upon a
# keypress response (the spacebar) or until 3 secs have elapsed.
# Last updated by SR: 3/29/2021
from __future__ import division
from __future__ import print_function
import pylink
import os
import platform
import random
import time
import sys
try:
from eyetrackingCode import EyeLinkCoreGraphicsPsychoPy as EyeLink #imports from subfolder
#import EyeLinkCoreGraphicsPsychoPy as EyeLink #imports from subfolder
except Exception as e:
print(f"An exception occurred: {str(e)}")
print('Could not import EyeLinkCoreGraphicsPsychoPy.py (you need that file to be in the eyetrackingCode subdirectory, which needs an __init__.py file in it too)')
from psychopy import visual, core, event, monitors, gui
from PIL import Image # for preparing the Host backdrop image
from string import ascii_letters, digits
# Switch to the script folder
script_path = os.path.dirname(sys.argv[0])
if len(script_path) != 0:
os.chdir(script_path)
# Show only critical log message in the PsychoPy console
from psychopy import logging
logging.console.setLevel(logging.CRITICAL)
# Set this variable to True if you use the built-in retina screen as your
# primary display device on macOS. If have an external monitor, set this
# variable True if you choose to "Optimize for Built-in Retina Display"
# in the Displays preference settings.
use_retina = True
# Set this variable to True to run the script in "Dummy Mode"
dummy_mode = True
# Set this variable to True to run the task in full screen mode
# It is easier to debug the script in non-fullscreen mode
full_screen = False
# Store the parameters of all trials in a list, [condition, image]
trials = [
['cond_1', 'img_1.jpg'],
['cond_2', 'img_2.jpg'],
]
# Set up EDF data file name and local data folder
#
# The EDF data filename should not exceed 8 alphanumeric characters
# use ONLY number 0-9, letters, & _ (underscore) in the filename
timeAndDateStr = time.strftime("%H%M%d%b", time.localtime())
#edf_fname= 'results' +'_'+subject+'_'+timeAndDateStr+'.EDF' #Too long, on eyetracker PC, filename is limited to 8 chars!!
edf_fname = timeAndDateStr[0:8] #on eyetracker PC, filename is limited to 8 chars!!
print('Eyetracking file on eyetracker PC will be called',edf_fname, ' which is hour_minute_day_, and will be called that .EDF here')
# check if the filename is valid (length <= 8 & no special char)
allowed_char = ascii_letters + digits + '_'
if not all([c in allowed_char for c in edf_fname]):
print('ERROR: Invalid EDF filename')
elif len(edf_fname) > 8:
print('ERROR: EDF filename should not exceed 8 characters')
# Set up a folder to store the EDF data files and the associated resources
# e.g., files defining the interest areas used in each trial
results_folder = 'eyetrackingtest_results'
if not os.path.exists(results_folder):
os.makedirs(results_folder)
print('Created a subfolder called ', results_folder)
# We download EDF data file from the EyeLink Host PC to the local hard
# drive at the end of each testing session, here we rename the EDF to
# include session start date/time
time_str = time.strftime("_%Y_%m_%d_%H_%M", time.localtime())
session_identifier = edf_fname + time_str
# create a folder for the current testing session in the results_folder
session_folder = os.path.join(results_folder, session_identifier)
if not os.path.exists(session_folder):
os.makedirs(session_folder)
# Step 1: Connect to the EyeLink Host PC
#
# The Host IP address, by default, is "100.1.1.1".
# the "el_tracker" objected created here can be accessed through the Pylink
# Set the Host PC address to "None" (without quotes) to run the script
# in "Dummy Mode"
if dummy_mode:
el_tracker = pylink.EyeLink(None)
else:
try:
el_tracker = pylink.EyeLink("100.1.1.1")
except RuntimeError as error:
print('ERROR:', error)
core.quit()
sys.exit()
# Step 2: Open an EDF data file on the Host PC
edf_file = edf_fname + ".EDF"
try:
el_tracker.openDataFile(edf_file)
except RuntimeError as err:
print('ERROR:', err)
# close the link if we have one open
if el_tracker.isConnected():
el_tracker.close()
core.quit()
sys.exit()
# Add a header text to the EDF file to identify the current experiment name
# This is OPTIONAL. If your text starts with "RECORDED BY " it will be
# available in DataViewer's Inspector window by clicking
# the EDF session node in the top panel and looking for the "Recorded By:"
# field in the bottom panel of the Inspector.
preamble_text = 'RECORDED BY %s' % os.path.basename(__file__)
el_tracker.sendCommand("add_file_preamble_text '%s'" % preamble_text)
# Step 3: Configure the tracker
#
# Put the tracker in offline mode before we change tracking parameters
el_tracker.setOfflineMode()
# Get the software version: 1-EyeLink I, 2-EyeLink II, 3/4-EyeLink 1000,
# 5-EyeLink 1000 Plus, 6-Portable DUO
eyelink_ver = 0 # set version to 0, in case running in Dummy mode
if not dummy_mode:
vstr = el_tracker.getTrackerVersionString()
eyelink_ver = int(vstr.split()[-1].split('.')[0])
# print out some version info in the shell
print('Running experiment on %s, version %d' % (vstr, eyelink_ver))
# File and Link data control
# what eye events to save in the EDF file, include everything by default
file_event_flags = 'LEFT,RIGHT,FIXATION,SACCADE,BLINK,MESSAGE,BUTTON,INPUT'
# what eye events to make available over the link, include everything by default
link_event_flags = 'LEFT,RIGHT,FIXATION,SACCADE,BLINK,BUTTON,FIXUPDATE,INPUT'
# what sample data to save in the EDF data file and to make available
# over the link, don't include the 'HTARGET' flag to save head target sticker
# data for supported eye trackers
if eyelink_ver > 3:
file_sample_flags = 'LEFT,RIGHT,GAZE,HREF,RAW,AREA,GAZERES,BUTTON,STATUS,INPUT'
link_sample_flags = 'LEFT,RIGHT,GAZE,GAZERES,AREA,STATUS,INPUT'
else:
file_sample_flags = 'LEFT,RIGHT,GAZE,HREF,RAW,AREA,GAZERES,BUTTON,STATUS,INPUT'
link_sample_flags = 'LEFT,RIGHT,GAZE,GAZERES,AREA,STATUS,INPUT'
el_tracker.sendCommand("file_event_filter = %s" % file_event_flags)
el_tracker.sendCommand("file_sample_data = %s" % file_sample_flags)
el_tracker.sendCommand("link_event_filter = %s" % link_event_flags)
el_tracker.sendCommand("link_sample_data = %s" % link_sample_flags)
# Optional tracking parameters
# Sample rate, 250, 500, 1000, or 2000, check your tracker specification
# if eyelink_ver > 2:
# el_tracker.sendCommand("sample_rate 1000")
# Choose a calibration type, H3, HV3, HV5, HV13 (HV = horizontal/vertical),
el_tracker.sendCommand("calibration_type = HV9")
# Set a gamepad button to accept calibration/drift check target
# You need a supported gamepad/button box that is connected to the Host PC
el_tracker.sendCommand("button_function 5 'accept_target_fixation'")
# Step 4: set up a graphics environment for calibration
#
# Open a window, be sure to specify monitor parameters
mon = monitors.Monitor('myMonitor', width=53.0, distance=70.0)
win = visual.Window(fullscr=full_screen,
monitor=mon,
winType='pyglet',
units='pix')
# get the native screen resolution used by PsychoPy
scn_width, scn_height = win.size
print('pixels scn_width= %d, scn_height= %d' % (scn_width, scn_width))
# resolution fix for Mac retina displays
if 'Darwin' in platform.system():
if use_retina:
scn_width = int(scn_width/2.0)
scn_height = int(scn_height/2.0)
print('Because OSX and retina display (use_retina), changing to scn_width= %d, scn_height= %d' %
(scn_width, scn_width))
# Pass the display pixel coordinates (left, top, right, bottom) to the tracker
# see the EyeLink Installation Guide, "Customizing Screen Settings"
el_coords = "screen_pixel_coords = 0 0 %d %d" % (scn_width - 1, scn_height - 1)
el_tracker.sendCommand(el_coords)
# Write a DISPLAY_COORDS message to the EDF file
# Data Viewer needs this piece of info for proper visualization, see Data
# Viewer User Manual, "Protocol for EyeLink Data to Viewer Integration"
dv_coords = "DISPLAY_COORDS 0 0 %d %d" % (scn_width - 1, scn_height - 1)
el_tracker.sendMessage(dv_coords)
# Configure a graphics environment (genv) for tracker calibration
genv = EyeLink.EyeLinkCoreGraphicsPsychoPy(el_tracker, win)
print(genv) # print out the version number of the CoreGraphics library
# Set background and foreground colors for the calibration target
# in PsychoPy, (-1, -1, -1)=black, (1, 1, 1)=white, (0, 0, 0)=mid-gray
foreground_color = (-1, -1, -1)
background_color = win.color
genv.setCalibrationColors(foreground_color, background_color)
# Set up the calibration target
#
# The target could be a "circle" (default), a "picture", a "movie" clip,
# or a rotating "spiral". To configure the type of calibration target, set
# genv.setTargetType to "circle", "picture", "movie", or "spiral", e.g.,
# genv.setTargetType('picture')
#
# Use gen.setPictureTarget() to set a "picture" target
# genv.setPictureTarget(os.path.join('images', 'fixTarget.bmp'))
#
# Use genv.setMovieTarget() to set a "movie" target
# genv.setMovieTarget(os.path.join('videos', 'calibVid.mov'))
# Use a picture as the calibration target
genv.setTargetType('picture')
genv.setPictureTarget(os.path.join('eyetrackingCode','images', 'fixTarget.bmp'))
# Configure the size of the calibration target (in pixels)
# this option applies only to "circle" and "spiral" targets
# genv.setTargetSize(24)
# Beeps to play during calibration, validation and drift correction
# parameters: target, good, error
# target -- sound to play when target moves
# good -- sound to play on successful operation
# error -- sound to play on failure or interruption
# Each parameter could be ''--default sound, 'off'--no sound, or a wav file
genv.setCalibrationSounds('', '', '')
#genv.setCalibrationSounds('sounds/type.wav', 'sounds/error.wav', 'sounds/qbeep.wav') #this doesn't work, and I'm not sure where EyeLinkCoreGraphicsPsychoPy.py looks for files (no directory is specified)
#Defaults are found in EyeLinkCoreGraphicsPsychoPy.py self._target_beep = Sound('type.wav', stereo=True)
# self._error_beep = Sound('error.wav', stereo=True)
# self._done_beep = Sound('qbeep.wav', stereo=True)
# resolution fix for macOS retina display issues
if use_retina:
genv.fixMacRetinaDisplay()
# Request Pylink to use the PsychoPy window we opened above for calibration
pylink.openGraphicsEx(genv)
# define a few helper functions for trial handling
def clear_screen(win):
""" clear the PsychoPy window"""
win.fillColor = genv.getBackgroundColor()
win.flip()
def show_msg(win, text, wait_for_keypress=True):
""" Show task instructions on screen"""
msg = visual.TextStim(win, text,
color=genv.getForegroundColor(),
wrapWidth=scn_width/2)
clear_screen(win)
msg.draw()
win.flip()
# wait indefinitely, terminates upon any key press
if wait_for_keypress:
event.waitKeys()
clear_screen(win)
def terminate_task():
""" Terminate the task gracefully and retrieve the EDF data file
file_to_retrieve: The EDF on the Host that we would like to download
win: the current window used by the experimental script
"""
el_tracker = pylink.getEYELINK()
if el_tracker.isConnected():
# Terminate the current trial first if the task terminated prematurely
error = el_tracker.isRecording()
if error == pylink.TRIAL_OK:
abort_trial()
# Put tracker in Offline mode
el_tracker.setOfflineMode()
# Clear the Host PC screen and wait for 500 ms
el_tracker.sendCommand('clear_screen 0')
pylink.msecDelay(500)
# Close the edf data file on the Host
el_tracker.closeDataFile()
# Show a file transfer message on the screen
msg = 'Trying to transfer EDF data from EyeLink Host PC...'
show_msg(win, msg, wait_for_keypress=False)
print(msg)
# Download the EDF data file from the Host PC to a local data folder
# parameters: source_file_on_the_host, destination_file_on_local_drive
local_edf = os.path.join(session_folder, session_identifier + '.EDF')
try:
el_tracker.receiveDataFile(edf_file, local_edf)
except RuntimeError as error:
print('when trying to get EDF file from eyetracker computer, ERROR:', error)
# Close the link to the tracker.
el_tracker.close()
# close the PsychoPy window
win.close()
# quit PsychoPy
core.quit()
sys.exit()
def abort_trial():
"""Ends recording """
el_tracker = pylink.getEYELINK()
# Stop recording
if el_tracker.isRecording():
# add 100 ms to catch final trial events
pylink.pumpDelay(100)
el_tracker.stopRecording()
# clear the screen
clear_screen(win)
# Send a message to clear the Data Viewer screen
bgcolor_RGB = (116, 116, 116)
el_tracker.sendMessage('!V CLEAR %d %d %d' % bgcolor_RGB)
# send a message to mark trial end
el_tracker.sendMessage('TRIAL_RESULT %d' % pylink.TRIAL_ERROR)
return pylink.TRIAL_ERROR
def run_trial(trial_pars, trial_index):
""" Helper function specifying the events that will occur in a single trial
trial_pars - a list containing trial parameters, e.g.,
['cond_1', 'img_1.jpg']
trial_index - record the order of trial presentation in the task
"""
# unpacking the trial parameters
cond, pic = trial_pars
# load the image to display, here we stretch the image to fill full screen
img = visual.ImageStim(win,
image=os.path.join('eyetrackingCode','images', pic),
size=(scn_width, scn_height))
# get a reference to the currently active EyeLink connection
el_tracker = pylink.getEYELINK()
# put the tracker in the offline mode first
el_tracker.setOfflineMode()
# clear the host screen before we draw the backdrop
el_tracker.sendCommand('clear_screen 0')
# show a backdrop image on the Host screen, imageBackdrop() the recommended
# function, if you do not need to scale the image on the Host
# parameters: image_file, crop_x, crop_y, crop_width, crop_height,
# x, y on the Host, drawing options
## el_tracker.imageBackdrop(os.path.join('images', pic),
## 0, 0, scn_width, scn_height, 0, 0,
## pylink.BX_MAXCONTRAST)
# If you need to scale the backdrop image on the Host, use the old Pylink
# bitmapBackdrop(), which requires an additional step of converting the
# image pixels into a recognizable format by the Host PC.
# pixels = [line1, ...lineH], line = [pix1,...pixW], pix=(R,G,B)
#
# the bitmapBackdrop() command takes time to return, not recommended
# for tasks where the ITI matters, e.g., in an event-related fMRI task
# parameters: width, height, pixel, crop_x, crop_y,
# crop_width, crop_height, x, y on the Host, drawing options
#
# Use the code commented below to convert the image and send the backdrop
im = Image.open('eyetrackingCode'+os.sep+'images' +os.sep + pic) # read image with PIL
im = im.resize((scn_width, scn_height))
img_pixels = im.load() # access the pixel data of the image
pixels = [[img_pixels[i, j] for i in range(scn_width)]
for j in range(scn_height)]
el_tracker.bitmapBackdrop(scn_width, scn_height, pixels,
0, 0, scn_width, scn_height,
0, 0, pylink.BX_MAXCONTRAST)
# OPTIONAL: draw landmarks and texts on the Host screen
# In addition to backdrop image, You may draw simples on the Host PC to use
# as landmarks. For illustration purpose, here we draw some texts and a box
# For a list of supported draw commands, see the "COMMANDS.INI" file on the
# Host PC (under /elcl/exe)
left = int(scn_width/2.0) - 60
top = int(scn_height/2.0) - 60
right = int(scn_width/2.0) + 60
bottom = int(scn_height/2.0) + 60
draw_cmd = 'draw_filled_box %d %d %d %d 1' % (left, top, right, bottom)
el_tracker.sendCommand(draw_cmd)
# send a "TRIALID" message to mark the start of a trial, see Data
# Viewer User Manual, "Protocol for EyeLink Data to Viewer Integration"
el_tracker.sendMessage('TRIALID %d' % trial_index)
# record_status_message : show some info on the Host PC
# here we show how many trial has been tested
status_msg = 'TRIAL number %d' % trial_index
el_tracker.sendCommand("record_status_message '%s'" % status_msg)
# drift check
# we recommend drift-check at the beginning of each trial
# the doDriftCorrect() function requires target position in integers
# the last two arguments:
# draw_target (1-default, 0-draw the target then call doDriftCorrect)
# allow_setup (1-press ESCAPE to recalibrate, 0-not allowed)
#
# Skip drift-check if running the script in Dummy Mode
while not dummy_mode:
# terminate the task if no longer connected to the tracker or
# user pressed Ctrl-C to terminate the task
if (not el_tracker.isConnected()) or el_tracker.breakPressed():
terminate_task()
return pylink.ABORT_EXPT
# drift-check and re-do camera setup if ESCAPE is pressed
try:
error = el_tracker.doDriftCorrect(int(scn_width/2.0),
int(scn_height/2.0), 1, 1)
# break following a success drift-check
if error is not pylink.ESC_KEY:
break
except:
pass
# put tracker in idle/offline mode before recording
el_tracker.setOfflineMode()
# Start recording
# arguments: sample_to_file, events_to_file, sample_over_link,
# event_over_link (1-yes, 0-no)
try:
el_tracker.startRecording(1, 1, 1, 1)
except RuntimeError as error:
print("ERROR:", error)
abort_trial()
return pylink.TRIAL_ERROR
# Allocate some time for the tracker to cache some samples
pylink.pumpDelay(100)
# show the image, and log a message to mark the onset of the image
clear_screen(win)
img.draw()
win.flip()
el_tracker.sendMessage('image_onset')
img_onset_time = core.getTime() # record the image onset time
# Send a message to clear the Data Viewer screen, get it ready for
# drawing the pictures during visualization
bgcolor_RGB = (116, 116, 116)
el_tracker.sendMessage('!V CLEAR %d %d %d' % bgcolor_RGB)
# send over a message to specify where the image is stored relative
# to the EDF data file, see Data Viewer User Manual, "Protocol for
# EyeLink Data to Viewer Integration"
bg_image = '../../images/' + pic
imgload_msg = '!V IMGLOAD CENTER %s %d %d %d %d' % (bg_image,
int(scn_width/2.0),
int(scn_height/2.0),
int(scn_width),
int(scn_height))
el_tracker.sendMessage(imgload_msg)
# send interest area messages to record in the EDF data file
# here we draw a rectangular IA, for illustration purposes
# format: !V IAREA RECTANGLE <id> <left> <top> <right> <bottom> [label]
# for all supported interest area commands, see the Data Viewer Manual,
# "Protocol for EyeLink Data to Viewer Integration"
ia_pars = (1, left, top, right, bottom, 'screen_center')
el_tracker.sendMessage('!V IAREA RECTANGLE %d %d %d %d %d %s' % ia_pars)
# show the image for 5-secs or until the SPACEBAR is pressed
event.clearEvents() # clear cached PsychoPy events
RT = -1 # keep track of the response time
get_keypress = False
while not get_keypress:
# present the picture for a maximum of 5 seconds
if core.getTime() - img_onset_time >= 5.0:
el_tracker.sendMessage('time_out')
break
# abort the current trial if the tracker is no longer recording
error = el_tracker.isRecording()
if error is not pylink.TRIAL_OK:
el_tracker.sendMessage('tracker_disconnected')
abort_trial()
return error
# check keyboard events
for keycode, modifier in event.getKeys(modifiers=True):
# Stop stimulus presentation when the spacebar is pressed
if keycode == 'space':
# send over a message to log the key press
el_tracker.sendMessage('key_pressed')
# get response time in ms, PsychoPy report time in sec
RT = int((core.getTime() - img_onset_time)*1000)
get_keypress = True
# Abort a trial if "ESCAPE" is pressed
if keycode == 'escape':
el_tracker.sendMessage('trial_skipped_by_user')
# clear the screen
clear_screen(win)
# abort trial
abort_trial()
return pylink.SKIP_TRIAL
# Terminate the task if Ctrl-c
if keycode == 'c' and (modifier['ctrl'] is True):
el_tracker.sendMessage('terminated_by_user')
terminate_task()
return pylink.ABORT_EXPT
# clear the screen
clear_screen(win)
el_tracker.sendMessage('blank_screen')
# send a message to clear the Data Viewer screen as well
el_tracker.sendMessage('!V CLEAR 128 128 128')
# stop recording; add 100 msec to catch final events before stopping
pylink.pumpDelay(100)
el_tracker.stopRecording()
# record trial variables to the EDF data file, for details, see Data
# Viewer User Manual, "Protocol for EyeLink Data to Viewer Integration"
el_tracker.sendMessage('!V TRIAL_VAR condition %s' % cond)
el_tracker.sendMessage('!V TRIAL_VAR image %s' % pic)
el_tracker.sendMessage('!V TRIAL_VAR RT %d' % RT)
# send a 'TRIAL_RESULT' message to mark the end of trial, see Data
# Viewer User Manual, "Protocol for EyeLink Data to Viewer Integration"
el_tracker.sendMessage('TRIAL_RESULT %d' % pylink.TRIAL_OK)
# Step 5: Set up the camera and calibrate the tracker
# Show the task instructions
task_msg = 'In the task, you may press the SPACEBAR to end a trial\n' + \
'\nPress Ctrl-C to if you need to quit the task early\n'
if dummy_mode:
task_msg = task_msg + '\nNow, press ENTER to start the task'
else:
task_msg = task_msg + '\nNow, press ENTER twice to calibrate tracker'
show_msg(win, task_msg)
# skip this step if running the script in Dummy Mode
if not dummy_mode:
try:
el_tracker.doTrackerSetup()
except RuntimeError as err:
print('ERROR:', err)
el_tracker.exitCalibration()
# Step 6: Run the experimental trials, index all the trials
# construct a list of 4 trials
test_list = trials[:]*2
# randomize the trial list
random.shuffle(test_list)
trial_index = 1
for trial_pars in test_list:
run_trial(trial_pars, trial_index)
trial_index += 1
# Step 7: disconnect, download the EDF file, then terminate the task
terminate_task()