|
1 | | -function [ el, edfFile ] = eyeTracker(input, cfg, expParameters) |
| 1 | +function [ el, edfFile ] = eyeTracker(input, cfg, expParameters, varargin) |
2 | 2 |
|
3 | 3 | if ~cfg.eyeTracker |
4 | 4 |
|
5 | 5 | el = []; |
6 | 6 |
|
7 | 7 | else |
8 | 8 |
|
9 | | - %% Assign parameters |
10 | | - edfFile = expParameters.fileName.eyetracker; |
11 | | - |
12 | 9 | switch input |
13 | 10 |
|
14 | 11 | 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 | 12 |
|
59 | 13 | %% STEP 2 |
60 | 14 | % Provide Eyelink with details about the graphics environment |
61 | 15 | % and perform some initializations. The information is returned |
62 | 16 | % in a structure that also contains useful defaults |
63 | 17 | % and control codes (e.g. tracker state bit and Eyelink key values). |
64 | | - |
65 | 18 | el = EyelinkInitDefaults(cfg.win); |
66 | 19 |
|
67 | 20 | % calibration has silver background with black targets, sound and smaller |
68 | 21 | % targets |
69 | | - el.backgroundcolour = [192 192 192,(cfg.win)]; |
| 22 | + el.backgroundcolour = [ 192 192 192, (cfg.win)]; |
70 | 23 | el.msgfontcolour = BlackIndex(cfg.win); |
71 | 24 | el.calibrationtargetcolour = BlackIndex(cfg.win); |
72 | 25 | el.calibrationtargetsize = 1; |
|
99 | 52 | return; |
100 | 53 | end |
101 | 54 |
|
| 55 | + % |
| 56 | + if ~EyelinkInit(0, 1) |
| 57 | + fprintf('Eyelink Init aborted.\n'); |
| 58 | + return; |
| 59 | + end |
| 60 | + |
| 61 | + % Open the edf file to write the data |
| 62 | + edfFile = 'demo.edf'; |
| 63 | + Eyelink('Openfile', edfFile); |
| 64 | + |
102 | 65 | [el.v, el.vs] = Eyelink('GetTrackerVersion'); |
103 | 66 | fprintf('Running experiment on a ''%s'' tracker.\n', el.vs ); |
104 | 67 |
|
105 | 68 | % make sure that we get gaze data from the Eyelink |
106 | 69 | Eyelink('Command', 'link_sample_data = LEFT,RIGHT,GAZE,AREA'); |
107 | 70 |
|
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 | 71 | % STEP 4 |
117 | 72 | % SET UP TRACKER CONFIGURATION |
118 | 73 | % Setting the proper recording resolution, proper calibration type, |
119 | 74 | % as well as the data file content; |
120 | | -% Eyelink('command', 'add_file_preamble_text ''Recorded by EyelinkToolbox demo-experiment'''); |
| 75 | + % Eyelink('command', 'add_file_preamble_text ''Recorded by EyelinkToolbox demo-experiment'''); |
121 | 76 |
|
122 | 77 | % This command is crucial to map the gaze positions from the tracker to |
123 | 78 | % 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 | 79 | Eyelink('command','screen_pixel_coords = %ld %ld %ld %ld', 0, 0, 0, 0); |
127 | 80 | Eyelink('message', 'DISPLAY_COORDS %ld %ld %ld %ld', 0, 0, 0, 0); |
128 | 81 |
|
|
136 | 89 | Eyelink('command', 'generate_default_targets = YES'); |
137 | 90 | % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % |
138 | 91 |
|
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'); |
| 92 | + % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % |
| 93 | + % % CUSTOM CALIBRATION |
| 94 | + % % (SET MANUALLY THE DOTS COORDINATES, HERE FOR 6 DOTS) |
| 95 | + % Eyelink('command', 'calibration_type = HV5'); |
| 96 | + % % you must send this command with value NO for custom calibration |
| 97 | + % % you must also reset it to YES for subsequent experiments |
| 98 | + % Eyelink('command', 'generate_default_targets = NO'); |
| 99 | + % |
| 100 | + % % calibration and validation target locations |
| 101 | + % [width, height]=Screen('WindowSize', screenNumber); |
| 102 | + % Eyelink('command','calibration_samples = 6'); |
| 103 | + % Eyelink('command','calibration_sequence = 0,1,2,3,4,5'); |
| 104 | + % Eyelink('command','calibration_targets = %d,%d %d,%d %d,%d %d,%d %d,%d',... |
| 105 | + % 640,512, ... %width/2,height/2 |
| 106 | + % 640,102, ... %width/2,height*0.1 |
| 107 | + % 640,614, ... %width/2,height*0.6 |
| 108 | + % 128,341, ... %width*0.1,height*1/3 |
| 109 | + % 1152,341 ); %width-width*0.1,height*1/3 |
| 110 | + % |
| 111 | + % Eyelink('command','validation_samples = 5'); |
| 112 | + % Eyelink('command','validation_sequence = 0,1,2,3,4,5'); |
| 113 | + % Eyelink('command','validation_targets = %d,%d %d,%d %d,%d %d,%d %d,%d',... |
| 114 | + % 640,512, ... %width/2,height/2 |
| 115 | + % 640,102, ... %width/2,height*0.1 |
| 116 | + % 640,614, ... %width/2,height*0.6 |
| 117 | + % 128,341, ... %width*0.1,height*1/3 |
| 118 | + % 1152,341 ); %width-width*0.1,height*1/3 |
| 119 | + % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % |
| 120 | + |
| 121 | + % % set parser (conservative saccade thresholds) |
| 122 | + % Eyelink('command', 'saccade_velocity_threshold = 35'); |
| 123 | + % Eyelink('command', 'saccade_acceleration_threshold = 9500'); |
171 | 124 |
|
172 | 125 | % set EDF file contents (not clear what this lines are used for) |
173 | 126 | el.vsn = regexp(el.vs,'\d','match'); % wont work on EL |
174 | 127 |
|
175 | 128 | % enter Eyetracker camera setup mode, calibration and validation |
176 | 129 | EyelinkDoTrackerSetup(el); |
177 | 130 |
|
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 |
| 131 | + % % % do a final check of calibration using driftcorrection |
| 132 | + % % % You have to hit esc before return. |
| 133 | + % % EyelinkDoDriftCorrection(el); |
| 134 | + % |
| 135 | + % % % do a final check of calibration using driftcorrection |
| 136 | + % % success=EyelinkDoDriftCorrection(el); |
| 137 | + % % if success~=1 |
| 138 | + % % Eyelink('shutdown'); |
| 139 | + % % Screen('CloseAll'); |
| 140 | + % % return; |
| 141 | + % % end |
| 142 | + |
| 143 | + % Go back to black screen |
| 144 | + Screen('FillRect', cfg.win, [0 0 0]); |
| 145 | + Screen('Flip', cfg.win); |
189 | 146 |
|
190 | 147 | case 'StartRecording' |
191 | 148 |
|
|
228 | 185 |
|
229 | 186 | case 'Shutdown' |
230 | 187 |
|
| 188 | + edfFileName = expParameters.fileName.eyetracker; |
| 189 | + edfFile = 'demo.edf'; |
| 190 | + |
231 | 191 | % STEP 6 |
232 | 192 | % At the end of the experiment, save the edf file and shut down connection |
233 | 193 | % with Eyelink |
|
238 | 198 |
|
239 | 199 | % download data file |
240 | 200 | try |
241 | | - fprintf('Receiving data file ''%s''\n', fileEdf ); |
242 | | - status=Eyelink('ReceiveFile','',fileEdf); |
| 201 | + fprintf('Receiving data file ''%s''\n', edfFileName ); |
| 202 | + status=Eyelink('ReceiveFile','',[expParameters.outputDir, filesep, 'eyetracker', filesep, edfFileName]); |
243 | 203 | if status > 0 |
244 | 204 | fprintf('ReceiveFile status %d\n', status); |
245 | 205 | end |
246 | | - if 2==exist(fileEdf, 'file') |
247 | | - fprintf('Data file ''%s'' can be found in ''%s''\n', fileEdf, pwd ); |
| 206 | + if 2==exist([expParameters.outputDir, filesep, 'eyetracker', filesep, edfFileName], 'file') |
| 207 | + fprintf('Data file ''%s'' can be found in ''%s''\n', edfFileName, [expParameters.outputDir, filesep, 'eyetracker', filesep] ); |
248 | 208 | end |
249 | 209 | catch |
250 | | - fprintf('Problem receiving data file ''%s''\n', fileEdf ); |
| 210 | + fprintf('Problem receiving data file ''%s''\n', edfFileName ); |
251 | 211 | end |
252 | 212 |
|
253 | 213 | Eyelink('shutdown'); |
|
0 commit comments