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