Skip to content

Commit 2f5be67

Browse files
committed
update from retinotopy
1 parent 69e251e commit 2f5be67

File tree

7 files changed

+256
-112
lines changed

7 files changed

+256
-112
lines changed

checkPtbVersion.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function checkPtbVersion()
22
% Checks that the right dependencies are installed.
33

4-
printCredits();
4+
printCreditsCppPtb();
55

66
PTB.major = 3;
77
PTB.minor = 0;

collectAndSaveResponses.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function responseEvents = collectAndSaveResponses(cfg, expParameters, logFile, experimentStart)
2+
3+
responseEvents = getResponse('check', cfg.keyboard.responseBox, cfg);
4+
5+
if isfield(responseEvents(1), 'onset') && ~isempty(responseEvents(1).onset)
6+
7+
for iResp = 1:size(responseEvents, 1)
8+
responseEvents(iResp).onset = ...
9+
responseEvents(iResp).onset - experimentStart;
10+
end
11+
12+
responseEvents.fileID = logFile.fileID;
13+
responseEvents.extraColumns = logFile.extraColumns;
14+
saveEventsFile('save', expParameters, responseEvents);
15+
16+
end
17+
end

eyeTracker.m

Lines changed: 110 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
function [el, edfFile] = eyeTracker(input, cfg, expParameters, varargin)
2-
2+
33
if ~cfg.eyeTracker
4-
4+
55
el = [];
6-
6+
77
else
8-
8+
99
switch input
10-
10+
1111
case 'Calibration'
12-
12+
1313
%% STEP 2
1414
% Provide Eyelink with details about the graphics environment
1515
% and perform some initializations. The information is returned
1616
% in a structure that also contains useful defaults
1717
% and control codes (e.g. tracker state bit and Eyelink key values).
1818
el = EyelinkInitDefaults(cfg.win);
19-
19+
2020
% calibration has silver background with black targets, sound and smaller
2121
% targets
2222
el.backgroundcolour = [192 192 192, (cfg.win)];
@@ -25,15 +25,15 @@
2525
el.calibrationtargetsize = 1;
2626
el.calibrationtargetwidth = 0.5;
2727
el.displayCalResults = 1;
28-
28+
2929
% call this function for changes to the calibration structure to take
3030
% affect
3131
EyelinkUpdateDefaults(el);
32-
33-
% STEP 3
32+
33+
%% STEP 3
3434
% Initialization of the connection with the Eyelink Gazetracker.
3535
% exit program if this fails.
36-
36+
3737
% make sure EL is initialized.
3838
ELinit = Eyelink('Initialize');
3939
if ELinit ~= 0
@@ -42,7 +42,7 @@
4242
Screen('CloseAll');
4343
return
4444
end
45-
45+
4646
% make sure we're still connected.
4747
ELconnection = Eyelink('IsConnected');
4848
if ELconnection ~= 1
@@ -51,45 +51,45 @@
5151
Screen('CloseAll');
5252
return
5353
end
54-
54+
5555
%
5656
if ~EyelinkInit(0, 1)
5757
fprintf('Eyelink Init aborted.\n');
5858
return
5959
end
60-
60+
6161
% Open the edf file to write the data
6262
edfFile = 'demo.edf';
6363
Eyelink('Openfile', edfFile);
64-
64+
6565
[el.v, el.vs] = Eyelink('GetTrackerVersion');
6666
fprintf('Running experiment on a ''%s'' tracker.\n', el.vs);
67-
67+
6868
% make sure that we get gaze data from the Eyelink
6969
Eyelink('Command', 'link_sample_data = LEFT,RIGHT,GAZE,AREA');
70-
70+
7171
% STEP 4
7272
% SET UP TRACKER CONFIGURATION
7373
% Setting the proper recording resolution, proper calibration type,
7474
% as well as the data file content;
75-
% Eyelink('command', 'add_file_preamble_text ''Recorded by
75+
% Eyelink('command', 'add_file_preamble_text ''Recorded by
7676
%EyelinkToolbox demo-experiment''');
77-
77+
7878
% This command is crucial to map the gaze positions from the tracker to
7979
% screen pixel positions to determine fixation
8080
Eyelink('command', 'screen_pixel_coords = %ld %ld %ld %ld', 0, 0, 0, 0);
8181
Eyelink('message', 'DISPLAY_COORDS %ld %ld %ld %ld', 0, 0, 0, 0);
82-
82+
8383
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
8484
% DEFAULT CALIBRATION
8585
% set calibration type.
8686
Eyelink('command', 'calibration_type = HV5');
87-
87+
8888
% you must send this command with value NO for custom calibration
8989
% you must also reset it to YES for subsequent experiments
9090
Eyelink('command', 'generate_default_targets = YES');
9191
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
92-
92+
9393
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
9494
% % CUSTOM CALIBRATION
9595
% % (SET MANUALLY THE DOTS COORDINATES, HERE FOR 6 DOTS)
@@ -120,17 +120,17 @@
120120
% 128,341, ... %width*0.1,height*1/3
121121
% 1152,341 ); %width-width*0.1,height*1/3
122122
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
123-
123+
124124
% % set parser (conservative saccade thresholds)
125125
% Eyelink('command', 'saccade_velocity_threshold = 35');
126126
% Eyelink('command', 'saccade_acceleration_threshold = 9500');
127-
127+
128128
% set EDF file contents (not clear what this lines are used for)
129129
el.vsn = regexp(el.vs, '\d', 'match'); % wont work on EL
130-
130+
131131
% enter Eyetracker camera setup mode, calibration and validation
132132
EyelinkDoTrackerSetup(el);
133-
133+
134134
% % % do a final check of calibration using driftcorrection
135135
% % % You have to hit esc before return.
136136
% % EyelinkDoDriftCorrection(el);
@@ -142,13 +142,13 @@
142142
% % Screen('CloseAll');
143143
% % return;
144144
% % end
145-
145+
146146
% Go back to black screen
147147
Screen('FillRect', cfg.win, [0 0 0]);
148148
Screen('Flip', cfg.win);
149-
149+
150150
case 'StartRecording'
151-
151+
152152
% STEP 5
153153
% EyeLink Start recording the block
154154
Eyelink('Command', 'set_idle_mode');
@@ -157,7 +157,7 @@
157157
% % here to tag the recording, in the past caused delays during the
158158
% % presentation so I avoided to use it
159159
% Eyelink('message',['TRIALID ',num2str(blocks),'_startTrial']);
160-
160+
161161
% check recording status, stop display if error
162162
checkrec = Eyelink('checkrecording');
163163
if checkrec ~= 0
@@ -166,17 +166,17 @@
166166
Screen('CloseAll');
167167
return
168168
end
169-
169+
170170
% record a few samples before we actually start displaying
171171
% otherwise you may lose a few msec of data
172172
WaitSecs(0.1);
173-
174-
% HERE START THE STIMALTION OF THE BLOCK
173+
174+
% HERE START THE STIMULATION OF THE BLOCK
175175
% to mark the beginning of the trial
176176
Eyelink('Message', 'SYNCTIME');
177-
177+
178178
case 'StopRecordings'
179-
179+
180180
% STEP 8
181181
% finish up: stop recording eye-movements,
182182
% EyeLink Stop recording the block
@@ -185,20 +185,20 @@
185185
WaitSecs(0.1);
186186
% close graphics window, close data file and shut down tracker
187187
Eyelink('StopRecording');
188-
188+
189189
case 'Shutdown'
190-
190+
191191
edfFileName = expParameters.fileName.eyetracker;
192192
edfFile = 'demo.edf';
193-
193+
194194
% STEP 6
195195
% At the end of the experiment, save the edf file and shut down connection
196196
% with Eyelink
197-
197+
198198
Eyelink('Command', 'set_idle_mode');
199199
WaitSecs(0.5);
200200
Eyelink('CloseFile');
201-
201+
202202
% download data file
203203
try
204204
fprintf('Receiving data file ''%s''\n', edfFileName);
@@ -215,10 +215,76 @@
215215
catch
216216
fprintf('Problem receiving data file ''%s''\n', edfFileName);
217217
end
218-
218+
219219
Eyelink('shutdown');
220-
Screen('CloseAll');
221-
220+
222221
end
223-
222+
223+
end
224+
225+
end
226+
227+
%% subfunctions for iView
228+
229+
function ivx = eyeTrackInit(expParameters)
230+
% initialize iView eye tracker
231+
232+
ivx = [];
233+
234+
if cfg.eyeTracker
235+
236+
host = expParameters.Eyetracker.Host;
237+
port = expParameters.Eyetracker.Port;
238+
window = expParameters.Eyetracker.Window;
239+
240+
% original: ivx=iviewxinitdefaults(window, 9 , host, port);
241+
ivx = iviewxinitdefaults2(window, 9, [], host, port);
242+
ivx.backgroundColour = 0;
243+
[~, ivx] = iViewX('openconnection', ivx);
244+
[success, ivx] = iViewX('checkconnection', ivx);
245+
if success ~= 1
246+
error('connection to eye tracker failed');
247+
end
248+
end
249+
end
250+
251+
function eyeTrackStart(ivx, expParameters)
252+
% start iView eye tracker
253+
if cfg.eyeTracker
254+
% to clear data buffer
255+
iViewX('clearbuffer', ivx);
256+
% start recording
257+
iViewX('startrecording', ivx);
258+
iViewX('message', ivx, ...
259+
[ ...
260+
'Start_Ret_', ...
261+
'Subj_', expParameters.Subj, '_', ...
262+
'Run', num2str(expParameters.Session(end)), '_', ...
263+
expParameters.Apperture, '_', ...
264+
expParameters.Direction]);
265+
iViewX('incrementsetnumber', ivx, 0);
266+
end
267+
end
268+
269+
function eyeTrackStop(ivx, expParameters)
270+
% stop iView eye tracker
271+
272+
if cfg.eyeTracker
273+
274+
% stop tracker
275+
iViewX('stoprecording', ivx);
276+
277+
% save data file
278+
thedatestr = datestr(now, 'yyyy-mm-dd_HH.MM');
279+
strFile = fullfile(OutputDir, ...
280+
[expParameters.Subj, ...
281+
'_run', num2str(expParameters.Session(end)), '_', ...
282+
expParameters.Apperture, '_', ...
283+
expParameters.Direction, '_', ...
284+
thedatestr, '.idf"']);
285+
iViewX('datafile', ivx, strFile);
286+
287+
% close iView connection
288+
iViewX('closeconnection', ivx);
224289
end
290+
end

0 commit comments

Comments
 (0)