|
| 1 | +function [ el, edfFile ] = eyeTracker(input, cfg, expParameters) |
| 2 | + |
| 3 | +if ~cfg.eyeTracker |
| 4 | + |
| 5 | + el = []; |
| 6 | + |
| 7 | +else |
| 8 | + |
| 9 | + %% Assign parameters |
| 10 | + edfFile = expParameters.fileName.eyetracker; |
| 11 | + |
| 12 | + switch input |
| 13 | + |
| 14 | + case 'Calibration' |
| 15 | +%% |
| 16 | +% screenNumber = max(Screen('Screens')); |
| 17 | +% gray=GrayIndex(screenNumber); |
| 18 | +% [w, wRect]=Screen('OpenWindow',screenNumber, gray); |
| 19 | +% Screen('TextSize', w, 32); |
| 20 | +% silver=[192 192 192,(w)]; |
| 21 | +% dummymode=0; |
| 22 | +% |
| 23 | +% el=EyelinkInitDefaults(w); |
| 24 | +% el.backgroundcolour = silver; |
| 25 | +% el.msgfontcolour = BlackIndex(w); |
| 26 | +% el.calibrationtargetcolour= BlackIndex(w); |
| 27 | +% el.calibrationtargetsize= 1; |
| 28 | +% el.calibrationtargetwidth=0.5; |
| 29 | +% el.displayCalResults = 1; |
| 30 | +% EyelinkUpdateDefaults(el); |
| 31 | +% |
| 32 | +% if ~EyelinkInit(dummymode, 1) |
| 33 | +% fprintf('Eyelink Init aborted.\n'); |
| 34 | +% cleanup; % cleanup function |
| 35 | +% return; |
| 36 | +% end |
| 37 | +% |
| 38 | +% [~, vs] = Eyelink('GetTrackerVersion'); |
| 39 | +% fprintf('Running experiment on a ''%s'' tracker.\n', vs ); |
| 40 | +% Eyelink('Command', 'link_sample_data = LEFT,RIGHT,GAZE,AREA'); |
| 41 | +% |
| 42 | +% edfFile='demo.edf'; |
| 43 | +% Eyelink('Openfile', edfFile); |
| 44 | +% |
| 45 | +% Eyelink('command','screen_pixel_coords = %ld %ld %ld %ld', 0, 0, 0, 0); |
| 46 | +% Eyelink('message', 'DISPLAY_COORDS %ld %ld %ld %ld', 0, 0, 0, 0); |
| 47 | +% |
| 48 | +% Eyelink('command', 'calibration_type = HV5'); |
| 49 | +% Eyelink('command', 'generate_default_targets = YES'); |
| 50 | +% |
| 51 | +% fprintf('Running experiment on a ''%s'' tracker.\n', vs ); |
| 52 | +% vsn = regexp(vs,'\d','match'); |
| 53 | +% EyelinkDoTrackerSetup(el); |
| 54 | +% |
| 55 | +% %go back to black screen |
| 56 | +% Screen('FillRect', w, [0 0 0]); |
| 57 | +% blank_onset=Screen('Flip', w); |
| 58 | + |
| 59 | + %% STEP 2 |
| 60 | + % Provide Eyelink with details about the graphics environment |
| 61 | + % and perform some initializations. The information is returned |
| 62 | + % in a structure that also contains useful defaults |
| 63 | + % and control codes (e.g. tracker state bit and Eyelink key values). |
| 64 | + |
| 65 | + el = EyelinkInitDefaults(cfg.win); |
| 66 | + |
| 67 | + % calibration has silver background with black targets, sound and smaller |
| 68 | + % targets |
| 69 | + el.backgroundcolour = [192 192 192,(cfg.win)]; |
| 70 | + el.msgfontcolour = BlackIndex(cfg.win); |
| 71 | + el.calibrationtargetcolour = BlackIndex(cfg.win); |
| 72 | + el.calibrationtargetsize = 1; |
| 73 | + el.calibrationtargetwidth = 0.5; |
| 74 | + el.displayCalResults = 1; |
| 75 | + |
| 76 | + % call this function for changes to the calibration structure to take |
| 77 | + % affect |
| 78 | + EyelinkUpdateDefaults(el); |
| 79 | + |
| 80 | + % STEP 3 |
| 81 | + % Initialization of the connection with the Eyelink Gazetracker. |
| 82 | + % exit program if this fails. |
| 83 | + |
| 84 | + % make sure EL is initialized. |
| 85 | + ELinit = Eyelink('Initialize'); |
| 86 | + if ELinit~=0 |
| 87 | + fprintf('Eyelink is not initialized, aborted.\n'); |
| 88 | + Eyelink('Shutdown'); |
| 89 | + Screen('CloseAll'); |
| 90 | + return; |
| 91 | + end |
| 92 | + |
| 93 | + % make sure we're still connected. |
| 94 | + ELconnection = Eyelink('IsConnected'); |
| 95 | + if ELconnection~=1 |
| 96 | + fprintf('Eyelink is not connected, aborted.\n'); |
| 97 | + Eyelink('Shutdown'); |
| 98 | + Screen('CloseAll'); |
| 99 | + return; |
| 100 | + end |
| 101 | + |
| 102 | + [el.v, el.vs] = Eyelink('GetTrackerVersion'); |
| 103 | + fprintf('Running experiment on a ''%s'' tracker.\n', el.vs ); |
| 104 | + |
| 105 | + % make sure that we get gaze data from the Eyelink |
| 106 | + Eyelink('Command', 'link_sample_data = LEFT,RIGHT,GAZE,AREA'); |
| 107 | + |
| 108 | +% % open file to record data to |
| 109 | +% if ~exist('eyetracker','dir') |
| 110 | +% mkdir('eyetracker') |
| 111 | +% end |
| 112 | + |
| 113 | + fileEDF = 'demo.edf'; |
| 114 | + Eyelink('Openfile', fileEDF); |
| 115 | + |
| 116 | + % STEP 4 |
| 117 | + % SET UP TRACKER CONFIGURATION |
| 118 | + % Setting the proper recording resolution, proper calibration type, |
| 119 | + % as well as the data file content; |
| 120 | +% Eyelink('command', 'add_file_preamble_text ''Recorded by EyelinkToolbox demo-experiment'''); |
| 121 | + |
| 122 | + % This command is crucial to map the gaze positions from the tracker to |
| 123 | + % screen pixel positions to determine fixation |
| 124 | +% Eyelink('command','screen_pixel_coords = %ld %ld %ld %ld', 0, 0, cfg.winWidth-1, cfg.winHeight-1); |
| 125 | +% Eyelink('message', 'DISPLAY_COORDS %ld %ld %ld %ld', 0, 0, cfg.winWidth-1, cfg.winHeight-1); |
| 126 | + Eyelink('command','screen_pixel_coords = %ld %ld %ld %ld', 0, 0, 0, 0); |
| 127 | + Eyelink('message', 'DISPLAY_COORDS %ld %ld %ld %ld', 0, 0, 0, 0); |
| 128 | + |
| 129 | + % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % |
| 130 | + % DEFAULT CALIBRATION |
| 131 | + % set calibration type. |
| 132 | + Eyelink('command', 'calibration_type = HV5'); |
| 133 | + |
| 134 | + % you must send this command with value NO for custom calibration |
| 135 | + % you must also reset it to YES for subsequent experiments |
| 136 | + Eyelink('command', 'generate_default_targets = YES'); |
| 137 | + % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % |
| 138 | + |
| 139 | +% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % |
| 140 | +% % CUSTOM CALIBRATION |
| 141 | +% % (SET MANUALLY THE DOTS COORDINATES, HERE FOR 6 DOTS) |
| 142 | +% Eyelink('command', 'calibration_type = HV5'); |
| 143 | +% % you must send this command with value NO for custom calibration |
| 144 | +% % you must also reset it to YES for subsequent experiments |
| 145 | +% Eyelink('command', 'generate_default_targets = NO'); |
| 146 | +% |
| 147 | +% % calibration and validation target locations |
| 148 | +% [width, height]=Screen('WindowSize', screenNumber); |
| 149 | +% Eyelink('command','calibration_samples = 6'); |
| 150 | +% Eyelink('command','calibration_sequence = 0,1,2,3,4,5'); |
| 151 | +% Eyelink('command','calibration_targets = %d,%d %d,%d %d,%d %d,%d %d,%d',... |
| 152 | +% 640,512, ... %width/2,height/2 |
| 153 | +% 640,102, ... %width/2,height*0.1 |
| 154 | +% 640,614, ... %width/2,height*0.6 |
| 155 | +% 128,341, ... %width*0.1,height*1/3 |
| 156 | +% 1152,341 ); %width-width*0.1,height*1/3 |
| 157 | +% |
| 158 | +% Eyelink('command','validation_samples = 5'); |
| 159 | +% Eyelink('command','validation_sequence = 0,1,2,3,4,5'); |
| 160 | +% Eyelink('command','validation_targets = %d,%d %d,%d %d,%d %d,%d %d,%d',... |
| 161 | +% 640,512, ... %width/2,height/2 |
| 162 | +% 640,102, ... %width/2,height*0.1 |
| 163 | +% 640,614, ... %width/2,height*0.6 |
| 164 | +% 128,341, ... %width*0.1,height*1/3 |
| 165 | +% 1152,341 ); %width-width*0.1,height*1/3 |
| 166 | +% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % |
| 167 | + |
| 168 | +% % set parser (conservative saccade thresholds) |
| 169 | +% Eyelink('command', 'saccade_velocity_threshold = 35'); |
| 170 | +% Eyelink('command', 'saccade_acceleration_threshold = 9500'); |
| 171 | + |
| 172 | + % set EDF file contents (not clear what this lines are used for) |
| 173 | + el.vsn = regexp(el.vs,'\d','match'); % wont work on EL |
| 174 | + |
| 175 | + % enter Eyetracker camera setup mode, calibration and validation |
| 176 | + EyelinkDoTrackerSetup(el); |
| 177 | + |
| 178 | +% % % do a final check of calibration using driftcorrection |
| 179 | +% % % You have to hit esc before return. |
| 180 | +% % EyelinkDoDriftCorrection(el); |
| 181 | +% |
| 182 | +% % % do a final check of calibration using driftcorrection |
| 183 | +% % success=EyelinkDoDriftCorrection(el); |
| 184 | +% % if success~=1 |
| 185 | +% % Eyelink('shutdown'); |
| 186 | +% % Screen('CloseAll'); |
| 187 | +% % return; |
| 188 | +% % end |
| 189 | + |
| 190 | + case 'StartRecording' |
| 191 | + |
| 192 | + % STEP 5 |
| 193 | + % EyeLink Start recording the block |
| 194 | + Eyelink('Command', 'set_idle_mode'); |
| 195 | + WaitSecs(0.05); |
| 196 | + Eyelink('StartRecording'); |
| 197 | + % % here to tag the recording, in the past caused delays during the |
| 198 | + % % presentation so I avoided to use it |
| 199 | + % Eyelink('message',['TRIALID ',num2str(blocks),'_startTrial']); |
| 200 | + |
| 201 | + % check recording status, stop display if error |
| 202 | + checkrec=Eyelink('checkrecording'); |
| 203 | + if(checkrec~=0) |
| 204 | + fprintf('\nEyelink is not recording.\n\n'); |
| 205 | + Eyelink('Shutdown'); |
| 206 | + Screen('CloseAll'); |
| 207 | + return; |
| 208 | + end |
| 209 | + |
| 210 | + % record a few samples before we actually start displaying |
| 211 | + % otherwise you may lose a few msec of data |
| 212 | + WaitSecs(0.1); |
| 213 | + |
| 214 | + % HERE START THE STIMALTION OF THE BLOCK |
| 215 | + % to mark the beginning of the trial |
| 216 | + Eyelink('Message', 'SYNCTIME'); |
| 217 | + |
| 218 | + case 'StopRecordings' |
| 219 | + |
| 220 | + % STEP 8 |
| 221 | + % finish up: stop recording eye-movements, |
| 222 | + % EyeLink Stop recording the block |
| 223 | + Eyelink('Message', 'BLANK_SCREEN'); |
| 224 | + % adds 100 msec of data to catch final events |
| 225 | + WaitSecs(0.1); |
| 226 | + % close graphics window, close data file and shut down tracker |
| 227 | + Eyelink('StopRecording'); |
| 228 | + |
| 229 | + case 'Shutdown' |
| 230 | + |
| 231 | + % STEP 6 |
| 232 | + % At the end of the experiment, save the edf file and shut down connection |
| 233 | + % with Eyelink |
| 234 | + |
| 235 | + Eyelink('Command', 'set_idle_mode'); |
| 236 | + WaitSecs(0.5); |
| 237 | + Eyelink('CloseFile'); |
| 238 | + |
| 239 | + % download data file |
| 240 | + try |
| 241 | + fprintf('Receiving data file ''%s''\n', fileEdf ); |
| 242 | + status=Eyelink('ReceiveFile','',fileEdf); |
| 243 | + if status > 0 |
| 244 | + fprintf('ReceiveFile status %d\n', status); |
| 245 | + end |
| 246 | + if 2==exist(fileEdf, 'file') |
| 247 | + fprintf('Data file ''%s'' can be found in ''%s''\n', fileEdf, pwd ); |
| 248 | + end |
| 249 | + catch |
| 250 | + fprintf('Problem receiving data file ''%s''\n', fileEdf ); |
| 251 | + end |
| 252 | + |
| 253 | + Eyelink('shutdown'); |
| 254 | + Screen('CloseAll'); |
| 255 | + |
| 256 | + |
| 257 | + end |
| 258 | + |
| 259 | +end |
0 commit comments