Skip to content

Commit f66836b

Browse files
committed
improve comments
1 parent f8c2cda commit f66836b

File tree

1 file changed

+76
-48
lines changed

1 file changed

+76
-48
lines changed

src/eyeTracker.m

Lines changed: 76 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@
4848
%
4949
% oldlevel = Eyelink(‘Verbosity’ [,level]);
5050
%
51+
% - Sanity check that ET is set a specific eye that we want, we might forget to check :)
52+
%
53+
% eye_used = Eyelink('EyeAvailable');
54+
% switch eye_used
55+
% case el.BINOCULAR
56+
% error('tracker indicates binocular')
57+
% case el.LEFT_EYE
58+
% error('tracker indicates left eye')
59+
% case el.RIGHT_EYE
60+
% disp('tracker indicates right eye')
61+
% case -1
62+
% error('eyeavailable returned -1')
63+
% otherwise
64+
% eye_used
65+
% error('unexpected result from eyeavailable')
66+
% end
67+
%
5168
% - Tag the ET data outout
5269
%
5370
% Eyelink('command', 'add_file_preamble_text', 'Recorded by EyelinkToolbox demo-experiment');
@@ -57,20 +74,28 @@
5774
% Eyelink('command', 'saccade_velocity_threshold = 35');
5875
% Eyelink('command', 'saccade_acceleration_threshold = 9500');
5976
%
60-
% - Drift correction
77+
% - Drift correction, do a final check of calibration using driftcorrection. You have to hit
78+
% esc before return.
6179
%
6280
% EyelinkDoDriftCorrection(el);
63-
%
6481
% success = EyelinkDoDriftCorrection(el);
6582
% if success~=1
6683
% Eyelink('shutdown');
6784
% cleanUp()
6885
% return;
6986
% end
7087
%
88+
% or use [status = ] Eyelink(‘DriftCorrStart’, x, y [,dtype=0][, dodraw=1][, allow_setup=0]),
89+
% e.g.:
90+
%
91+
% Perform drift correction: The special flags 1,1,1 request
92+
% interactive correction with video display:
93+
%
94+
% result = Eyelink('DriftCorrStart',30,30,1,1,1);
95+
%
7196
% - Tag the recording, in the past caused delays during the presentation so I avoided to use it
7297
%
73-
% Eyelink('message', 'Trial 1');
98+
% Eyelink('message', 'Trial_1');
7499

75100

76101

@@ -84,11 +109,13 @@
84109

85110
case 'Calibration'
86111

87-
%% STEP 2
88-
% Provide Eyelink with details about the graphics environment
89-
% and perform some initializations. The information is returned
90-
% in a structure that also contains useful defaults
91-
% and control codes (e.g. tracker state bit and Eyelink key values).
112+
%% Initialization
113+
% Provide Eyelink with details about the graphics environment and perform some
114+
% initializations. The information is returned in a structure that also contains
115+
% useful defaults and control codes (e.g. tracker state bit and Eyelink key
116+
% values).
117+
118+
% Provide Screen id where present the calibration
92119
el = EyelinkInitDefaults(cfg.screen.win);
93120

94121
% Calibration has silver background with black targets, sound and smaller
@@ -101,52 +128,53 @@
101128
el.displayCalResults = 1;
102129

103130
% Call this function for changes to the calibration structure to take
104-
% affect
131+
% affect.
105132
EyelinkUpdateDefaults(el);
106133

107-
%% STEP 3
108-
% Initialization of the connection with the Eyelink Gazetracker.
109-
% exit program if this fails.
110-
111-
% Initialize EL and make sure it worked: returns: 0 if OK, -1 if error
112-
ELinit = Eyelink('Initialize');
134+
% Initialize EL and make sure it worked: returns 0 if OK, -1 if error.
135+
% Exit program if this fails.
136+
elInit = Eyelink('Initialize');
113137
if ELinit ~= 0
114138
fprintf('Eyelink is not initialized, aborted.\n');
115139
Eyelink('Shutdown');
116140
CleanUp()
141+
return
117142
end
118143

119144
% Make sure EL is still connected: returns 1 if connected, -1 if dummy-connected,
120-
% 2 if broadcast-connected and 0 if not connected
121-
ELconnection = Eyelink('IsConnected');
145+
% 2 if broadcast-connected and 0 if not connected. Exit program if this fails.
146+
elConnection = Eyelink('IsConnected');
122147
if ELconnection ~= 1
123148
fprintf('Eyelink is not connected, aborted.\n');
124149
Eyelink('Shutdown');
125150
CleanUp()
151+
return
126152
end
127153

128-
% Last check that the EL is up to work
154+
% Last check that the EL is up to work and exit program if this fails.
129155
if ~EyelinkInit(0, 1)
130156
fprintf('Eyelink Init aborted.\n');
131157
CleanUp()
158+
return
132159
end
133160

134-
% Open the edf file to write the data
161+
% Open the edf file to write the data.
135162
edfFile = 'demo.edf';
136163
Eyelink('Openfile', edfFile);
137164

165+
% Get EyeLink setup information.
138166
[el.v, el.vs] = Eyelink('GetTrackerVersion');
139167
fprintf('Running experiment on a ''%s'' tracker.\n', el.vs);
140168

141-
% Make sure that we get gaze data from the Eyelink
169+
% Make sure that we get gaze data from the Eyelink.
142170
Eyelink('Command', 'link_sample_data = LEFT,RIGHT,GAZE,AREA');
171+
Eyelink('command', 'link_event_data = GAZE,GAZERES,HREF,AREA,VELOCITY');
172+
Eyelink('command', 'link_event_filter = LEFT,RIGHT,FIXATION,BLINK,SACCADE,BUTTON');
143173

144-
%% STEP 4
145-
% Setting the proper recording resolution, proper calibration type,
146-
% as well as the data file content;
174+
%% Calibration
147175

148176
% This command is crucial to map the gaze positions from the tracker to
149-
% screen pixel positions to determine fixation
177+
% screen pixel positions to determine fixation.
150178
Eyelink('command', 'screen_pixel_coords = %ld %ld %ld %ld', 0, 0, 0, 0);
151179
Eyelink('message', 'DISPLAY_COORDS %ld %ld %ld %ld', 0, 0, 0, 0);
152180

@@ -155,16 +183,16 @@
155183

156184
if cfg.eyeTracker.defaultCalibration
157185

158-
% Set default calibration parameters
186+
% Set default calibration parameters.
159187
Eyelink('command', 'generate_default_targets = YES');
160188

161189
else
162190

163-
% Set default calibration parameters
191+
% Set custom calibration parameters.
164192
Eyelink('command', 'generate_default_targets = NO');
165193

166194
% Calibration target locations, set manually the dots
167-
% coordinates, here for 6 dots
195+
% coordinates, here for 6 dots.
168196

169197
% [width, height]=Screen('WindowSize', screenNumber);
170198

@@ -189,25 +217,26 @@
189217

190218
end
191219

192-
% Set EDF file contents (not clear what this lines are used for)
220+
% Set EDF file contents (not clear what this lines are used for).
193221
el.vsn = regexp(el.vs, '\d', 'match'); % wont work on EL
194222

195-
% Enter Eyetracker camera setup mode, calibration and validation
223+
% Enter Eyetracker camera setup mode, calibration and validation.
196224
EyelinkDoTrackerSetup(el);
197225

198-
% Go back to default screen background color
226+
% Go back to default screen background color.
199227
Screen('FillRect', cfg.screen.win, cfg.color.background);
200228
Screen('Flip', cfg.screen.win);
201229

202230
case 'StartRecording'
203231

204-
% STEP 5
205-
% EyeLink Start recording the block
232+
%% Start recording of eye-movements
233+
234+
% EyeLink Start recording the block.
206235
Eyelink('Command', 'set_idle_mode');
207236
WaitSecs(0.05);
208237
Eyelink('StartRecording');
209238

210-
% Check recording status, stop display if error
239+
% Check recording status, stop display if error.
211240
checkrec = Eyelink('checkrecording');
212241
if checkrec ~= 0
213242
fprintf('\nEyelink is not recording.\n\n');
@@ -216,34 +245,32 @@
216245
return
217246
end
218247

219-
% Record a few samples before we actually start displaying
220-
% otherwise you may lose a few msec of data
248+
% Record a few samples before we actually start displaying otherwise you may lose
249+
% a few msec of data.
221250
WaitSecs(0.1);
222251

223-
% Mark the beginning of the trial, here start the stimulation of the experiment
252+
% Mark the beginning of the trial, here start the stimulation of the experiment.
224253
Eyelink('Message', 'SYNCTIME');
225254

226255
case 'StopRecordings'
227256

228-
% STEP 8
229-
% Finish up: stop recording of eye-movements
257+
%% Stop recording of eye-movements
230258

231-
% EyeLink Stop recording the block
259+
% EyeLink Stop recording the block.
232260
Eyelink('Message', 'BLANK_SCREEN');
233261

234-
% Add 100 msec of data to catch final events
262+
% Add 100 msec of data to catch final events.
235263
WaitSecs(0.1);
236264

237-
% Stop recoding
265+
% Stop recoding.
238266
Eyelink('StopRecording');
239267

240268
case 'Shutdown'
241269

242-
% STEP 6
243-
% At the end of the experiment, save the edf file and shut down connection
244-
% with Eyelink
270+
%% End of the experiment
271+
% Save the edf file and shut down connection with Eyelink.
245272

246-
# Set the edf file path + name
273+
# Set the edf file path + name.
247274
edfFileName = fullfile( ...
248275
cfg.dir.outputSubject, ...
249276
'eyetracker', ...
@@ -253,18 +280,19 @@
253280

254281
WaitSecs(0.5);
255282

283+
# Close the file to be ready to be exported and saved.
256284
Eyelink('CloseFile');
257285

258286
% Download data file
259287
try
260288
fprintf('Receiving data file ''%s''\n', edfFileName);
261289

262290
% Download the file and check the status: returns file size if OK, 0 if file
263-
% transfer was cancelled, negative = error
291+
% transfer was cancelled, negative = error.
264292
elReceiveFile = Eyelink('ReceiveFile', '', edfFileName);
265293

266294
if elReceiveFile > 0
267-
fprintf('Downloading eye tracker file of size %d\n', elReceiveFile);
295+
fprintf('Exporting eye tracker file of size %d\n', elReceiveFile);
268296
end
269297

270298
if exist(edfFileName, 'file') == 2
@@ -281,7 +309,7 @@
281309

282310
end
283311

284-
% Close connection with EyeLink
312+
% Close connection with EyeLink.
285313
Eyelink('shutdown');
286314

287315
end

0 commit comments

Comments
 (0)