|
48 | 48 | % |
49 | 49 | % oldlevel = Eyelink(‘Verbosity’ [,level]); |
50 | 50 | % |
| 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 | + % |
51 | 68 | % - Tag the ET data outout |
52 | 69 | % |
53 | 70 | % Eyelink('command', 'add_file_preamble_text', 'Recorded by EyelinkToolbox demo-experiment'); |
|
57 | 74 | % Eyelink('command', 'saccade_velocity_threshold = 35'); |
58 | 75 | % Eyelink('command', 'saccade_acceleration_threshold = 9500'); |
59 | 76 | % |
60 | | - % - Drift correction |
| 77 | + % - Drift correction, do a final check of calibration using driftcorrection. You have to hit |
| 78 | + % esc before return. |
61 | 79 | % |
62 | 80 | % EyelinkDoDriftCorrection(el); |
63 | | - % |
64 | 81 | % success = EyelinkDoDriftCorrection(el); |
65 | 82 | % if success~=1 |
66 | 83 | % Eyelink('shutdown'); |
67 | 84 | % cleanUp() |
68 | 85 | % return; |
69 | 86 | % end |
70 | 87 | % |
| 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 | + % |
71 | 96 | % - Tag the recording, in the past caused delays during the presentation so I avoided to use it |
72 | 97 | % |
73 | | - % Eyelink('message', 'Trial 1'); |
| 98 | + % Eyelink('message', 'Trial_1'); |
74 | 99 |
|
75 | 100 |
|
76 | 101 |
|
|
84 | 109 |
|
85 | 110 | case 'Calibration' |
86 | 111 |
|
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 |
92 | 119 | el = EyelinkInitDefaults(cfg.screen.win); |
93 | 120 |
|
94 | 121 | % Calibration has silver background with black targets, sound and smaller |
|
101 | 128 | el.displayCalResults = 1; |
102 | 129 |
|
103 | 130 | % Call this function for changes to the calibration structure to take |
104 | | - % affect |
| 131 | + % affect. |
105 | 132 | EyelinkUpdateDefaults(el); |
106 | 133 |
|
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'); |
113 | 137 | if ELinit ~= 0 |
114 | 138 | fprintf('Eyelink is not initialized, aborted.\n'); |
115 | 139 | Eyelink('Shutdown'); |
116 | 140 | CleanUp() |
| 141 | + return |
117 | 142 | end |
118 | 143 |
|
119 | 144 | % 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'); |
122 | 147 | if ELconnection ~= 1 |
123 | 148 | fprintf('Eyelink is not connected, aborted.\n'); |
124 | 149 | Eyelink('Shutdown'); |
125 | 150 | CleanUp() |
| 151 | + return |
126 | 152 | end |
127 | 153 |
|
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. |
129 | 155 | if ~EyelinkInit(0, 1) |
130 | 156 | fprintf('Eyelink Init aborted.\n'); |
131 | 157 | CleanUp() |
| 158 | + return |
132 | 159 | end |
133 | 160 |
|
134 | | - % Open the edf file to write the data |
| 161 | + % Open the edf file to write the data. |
135 | 162 | edfFile = 'demo.edf'; |
136 | 163 | Eyelink('Openfile', edfFile); |
137 | 164 |
|
| 165 | + % Get EyeLink setup information. |
138 | 166 | [el.v, el.vs] = Eyelink('GetTrackerVersion'); |
139 | 167 | fprintf('Running experiment on a ''%s'' tracker.\n', el.vs); |
140 | 168 |
|
141 | | - % Make sure that we get gaze data from the Eyelink |
| 169 | + % Make sure that we get gaze data from the Eyelink. |
142 | 170 | 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'); |
143 | 173 |
|
144 | | - %% STEP 4 |
145 | | - % Setting the proper recording resolution, proper calibration type, |
146 | | - % as well as the data file content; |
| 174 | + %% Calibration |
147 | 175 |
|
148 | 176 | % 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. |
150 | 178 | Eyelink('command', 'screen_pixel_coords = %ld %ld %ld %ld', 0, 0, 0, 0); |
151 | 179 | Eyelink('message', 'DISPLAY_COORDS %ld %ld %ld %ld', 0, 0, 0, 0); |
152 | 180 |
|
|
155 | 183 |
|
156 | 184 | if cfg.eyeTracker.defaultCalibration |
157 | 185 |
|
158 | | - % Set default calibration parameters |
| 186 | + % Set default calibration parameters. |
159 | 187 | Eyelink('command', 'generate_default_targets = YES'); |
160 | 188 |
|
161 | 189 | else |
162 | 190 |
|
163 | | - % Set default calibration parameters |
| 191 | + % Set custom calibration parameters. |
164 | 192 | Eyelink('command', 'generate_default_targets = NO'); |
165 | 193 |
|
166 | 194 | % Calibration target locations, set manually the dots |
167 | | - % coordinates, here for 6 dots |
| 195 | + % coordinates, here for 6 dots. |
168 | 196 |
|
169 | 197 | % [width, height]=Screen('WindowSize', screenNumber); |
170 | 198 |
|
|
189 | 217 |
|
190 | 218 | end |
191 | 219 |
|
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). |
193 | 221 | el.vsn = regexp(el.vs, '\d', 'match'); % wont work on EL |
194 | 222 |
|
195 | | - % Enter Eyetracker camera setup mode, calibration and validation |
| 223 | + % Enter Eyetracker camera setup mode, calibration and validation. |
196 | 224 | EyelinkDoTrackerSetup(el); |
197 | 225 |
|
198 | | - % Go back to default screen background color |
| 226 | + % Go back to default screen background color. |
199 | 227 | Screen('FillRect', cfg.screen.win, cfg.color.background); |
200 | 228 | Screen('Flip', cfg.screen.win); |
201 | 229 |
|
202 | 230 | case 'StartRecording' |
203 | 231 |
|
204 | | - % STEP 5 |
205 | | - % EyeLink Start recording the block |
| 232 | + %% Start recording of eye-movements |
| 233 | + |
| 234 | + % EyeLink Start recording the block. |
206 | 235 | Eyelink('Command', 'set_idle_mode'); |
207 | 236 | WaitSecs(0.05); |
208 | 237 | Eyelink('StartRecording'); |
209 | 238 |
|
210 | | - % Check recording status, stop display if error |
| 239 | + % Check recording status, stop display if error. |
211 | 240 | checkrec = Eyelink('checkrecording'); |
212 | 241 | if checkrec ~= 0 |
213 | 242 | fprintf('\nEyelink is not recording.\n\n'); |
|
216 | 245 | return |
217 | 246 | end |
218 | 247 |
|
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. |
221 | 250 | WaitSecs(0.1); |
222 | 251 |
|
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. |
224 | 253 | Eyelink('Message', 'SYNCTIME'); |
225 | 254 |
|
226 | 255 | case 'StopRecordings' |
227 | 256 |
|
228 | | - % STEP 8 |
229 | | - % Finish up: stop recording of eye-movements |
| 257 | + %% Stop recording of eye-movements |
230 | 258 |
|
231 | | - % EyeLink Stop recording the block |
| 259 | + % EyeLink Stop recording the block. |
232 | 260 | Eyelink('Message', 'BLANK_SCREEN'); |
233 | 261 |
|
234 | | - % Add 100 msec of data to catch final events |
| 262 | + % Add 100 msec of data to catch final events. |
235 | 263 | WaitSecs(0.1); |
236 | 264 |
|
237 | | - % Stop recoding |
| 265 | + % Stop recoding. |
238 | 266 | Eyelink('StopRecording'); |
239 | 267 |
|
240 | 268 | case 'Shutdown' |
241 | 269 |
|
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. |
245 | 272 |
|
246 | | - # Set the edf file path + name |
| 273 | + # Set the edf file path + name. |
247 | 274 | edfFileName = fullfile( ... |
248 | 275 | cfg.dir.outputSubject, ... |
249 | 276 | 'eyetracker', ... |
|
253 | 280 |
|
254 | 281 | WaitSecs(0.5); |
255 | 282 |
|
| 283 | + # Close the file to be ready to be exported and saved. |
256 | 284 | Eyelink('CloseFile'); |
257 | 285 |
|
258 | 286 | % Download data file |
259 | 287 | try |
260 | 288 | fprintf('Receiving data file ''%s''\n', edfFileName); |
261 | 289 |
|
262 | 290 | % 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. |
264 | 292 | elReceiveFile = Eyelink('ReceiveFile', '', edfFileName); |
265 | 293 |
|
266 | 294 | 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); |
268 | 296 | end |
269 | 297 |
|
270 | 298 | if exist(edfFileName, 'file') == 2 |
|
281 | 309 |
|
282 | 310 | end |
283 | 311 |
|
284 | | - % Close connection with EyeLink |
| 312 | + % Close connection with EyeLink. |
285 | 313 | Eyelink('shutdown'); |
286 | 314 |
|
287 | 315 | end |
|
0 commit comments