Skip to content

Commit 66600be

Browse files
committed
add tested and working version
1 parent 2944353 commit 66600be

File tree

1 file changed

+68
-108
lines changed

1 file changed

+68
-108
lines changed

eyeTracker.m

Lines changed: 68 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,25 @@
1-
function [ el, edfFile ] = eyeTracker(input, cfg, expParameters)
1+
function [ el, edfFile ] = eyeTracker(input, cfg, expParameters, varargin)
22

33
if ~cfg.eyeTracker
44

55
el = [];
66

77
else
88

9-
%% Assign parameters
10-
edfFile = expParameters.fileName.eyetracker;
11-
129
switch input
1310

1411
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);
5812

5913
%% STEP 2
6014
% Provide Eyelink with details about the graphics environment
6115
% and perform some initializations. The information is returned
6216
% in a structure that also contains useful defaults
6317
% and control codes (e.g. tracker state bit and Eyelink key values).
64-
6518
el = EyelinkInitDefaults(cfg.win);
6619

6720
% calibration has silver background with black targets, sound and smaller
6821
% targets
69-
el.backgroundcolour = [192 192 192,(cfg.win)];
22+
el.backgroundcolour = [ 192 192 192, (cfg.win)];
7023
el.msgfontcolour = BlackIndex(cfg.win);
7124
el.calibrationtargetcolour = BlackIndex(cfg.win);
7225
el.calibrationtargetsize = 1;
@@ -99,30 +52,30 @@
9952
return;
10053
end
10154

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+
10265
[el.v, el.vs] = Eyelink('GetTrackerVersion');
10366
fprintf('Running experiment on a ''%s'' tracker.\n', el.vs );
10467

10568
% make sure that we get gaze data from the Eyelink
10669
Eyelink('Command', 'link_sample_data = LEFT,RIGHT,GAZE,AREA');
10770

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-
11671
% STEP 4
11772
% SET UP TRACKER CONFIGURATION
11873
% Setting the proper recording resolution, proper calibration type,
11974
% 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''');
12176

12277
% This command is crucial to map the gaze positions from the tracker to
12378
% 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);
12679
Eyelink('command','screen_pixel_coords = %ld %ld %ld %ld', 0, 0, 0, 0);
12780
Eyelink('message', 'DISPLAY_COORDS %ld %ld %ld %ld', 0, 0, 0, 0);
12881

@@ -136,56 +89,60 @@
13689
Eyelink('command', 'generate_default_targets = YES');
13790
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
13891

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');
171124

172125
% set EDF file contents (not clear what this lines are used for)
173126
el.vsn = regexp(el.vs,'\d','match'); % wont work on EL
174127

175128
% enter Eyetracker camera setup mode, calibration and validation
176129
EyelinkDoTrackerSetup(el);
177130

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);
189146

190147
case 'StartRecording'
191148

@@ -228,6 +185,9 @@
228185

229186
case 'Shutdown'
230187

188+
edfFileName = expParameters.fileName.eyetracker;
189+
edfFile = 'demo.edf';
190+
231191
% STEP 6
232192
% At the end of the experiment, save the edf file and shut down connection
233193
% with Eyelink
@@ -238,16 +198,16 @@
238198

239199
% download data file
240200
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]);
243203
if status > 0
244204
fprintf('ReceiveFile status %d\n', status);
245205
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] );
248208
end
249209
catch
250-
fprintf('Problem receiving data file ''%s''\n', fileEdf );
210+
fprintf('Problem receiving data file ''%s''\n', edfFileName );
251211
end
252212

253213
Eyelink('shutdown');

0 commit comments

Comments
 (0)