Skip to content

Commit 082eae1

Browse files
committed
Merge remote-tracking branch 'cpp-lln-lab/master'
2 parents e885052 + 9de4030 commit 082eae1

File tree

8 files changed

+281
-133
lines changed

8 files changed

+281
-133
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ jobs:
2727
- stage: "Tests and linter"
2828
name: "Unit Tests" # names the first job
2929
script: octave $OCTFLAGS --eval "results = runTests; assert(all(~[results.Failed]))"
30-
- script: cd .. && mh_style.py `pwd`
30+
- script: cd .. && mh_style `pwd`
3131
name: "miss_hit linter" # names the second job

checkDependencies.m renamed to checkPtbVersion.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
function checkDependencies()
1+
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: 123 additions & 51 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,46 @@
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 EyelinkToolbox demo-experiment''');
76-
75+
% Eyelink('command', 'add_file_preamble_text ''Recorded by
76+
%EyelinkToolbox demo-experiment''');
77+
7778
% This command is crucial to map the gaze positions from the tracker to
7879
% screen pixel positions to determine fixation
7980
Eyelink('command', 'screen_pixel_coords = %ld %ld %ld %ld', 0, 0, 0, 0);
8081
Eyelink('message', 'DISPLAY_COORDS %ld %ld %ld %ld', 0, 0, 0, 0);
81-
82+
8283
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
8384
% DEFAULT CALIBRATION
8485
% set calibration type.
8586
Eyelink('command', 'calibration_type = HV5');
86-
87+
8788
% you must send this command with value NO for custom calibration
8889
% you must also reset it to YES for subsequent experiments
8990
Eyelink('command', 'generate_default_targets = YES');
9091
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
91-
92-
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
92+
93+
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
9394
% % CUSTOM CALIBRATION
9495
% % (SET MANUALLY THE DOTS COORDINATES, HERE FOR 6 DOTS)
9596
% Eyelink('command', 'calibration_type = HV5');
@@ -101,7 +102,8 @@
101102
% [width, height]=Screen('WindowSize', screenNumber);
102103
% Eyelink('command','calibration_samples = 6');
103104
% 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+
% Eyelink('command','calibration_targets = ...
106+
% %d,%d %d,%d %d,%d %d,%d %d,%d',...
105107
% 640,512, ... %width/2,height/2
106108
% 640,102, ... %width/2,height*0.1
107109
% 640,614, ... %width/2,height*0.6
@@ -110,24 +112,25 @@
110112
%
111113
% Eyelink('command','validation_samples = 5');
112114
% 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',...
115+
% Eyelink('command','validation_targets = ...
116+
% %d,%d %d,%d %d,%d %d,%d %d,%d',...
114117
% 640,512, ... %width/2,height/2
115118
% 640,102, ... %width/2,height*0.1
116119
% 640,614, ... %width/2,height*0.6
117120
% 128,341, ... %width*0.1,height*1/3
118121
% 1152,341 ); %width-width*0.1,height*1/3
119-
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
120-
122+
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
123+
121124
% % set parser (conservative saccade thresholds)
122125
% Eyelink('command', 'saccade_velocity_threshold = 35');
123126
% Eyelink('command', 'saccade_acceleration_threshold = 9500');
124-
127+
125128
% set EDF file contents (not clear what this lines are used for)
126129
el.vsn = regexp(el.vs, '\d', 'match'); % wont work on EL
127-
130+
128131
% enter Eyetracker camera setup mode, calibration and validation
129132
EyelinkDoTrackerSetup(el);
130-
133+
131134
% % % do a final check of calibration using driftcorrection
132135
% % % You have to hit esc before return.
133136
% % EyelinkDoDriftCorrection(el);
@@ -139,13 +142,13 @@
139142
% % Screen('CloseAll');
140143
% % return;
141144
% % end
142-
145+
143146
% Go back to black screen
144147
Screen('FillRect', cfg.win, [0 0 0]);
145148
Screen('Flip', cfg.win);
146-
149+
147150
case 'StartRecording'
148-
151+
149152
% STEP 5
150153
% EyeLink Start recording the block
151154
Eyelink('Command', 'set_idle_mode');
@@ -154,7 +157,7 @@
154157
% % here to tag the recording, in the past caused delays during the
155158
% % presentation so I avoided to use it
156159
% Eyelink('message',['TRIALID ',num2str(blocks),'_startTrial']);
157-
160+
158161
% check recording status, stop display if error
159162
checkrec = Eyelink('checkrecording');
160163
if checkrec ~= 0
@@ -163,17 +166,17 @@
163166
Screen('CloseAll');
164167
return
165168
end
166-
169+
167170
% record a few samples before we actually start displaying
168171
% otherwise you may lose a few msec of data
169172
WaitSecs(0.1);
170-
171-
% HERE START THE STIMALTION OF THE BLOCK
173+
174+
% HERE START THE STIMULATION OF THE BLOCK
172175
% to mark the beginning of the trial
173176
Eyelink('Message', 'SYNCTIME');
174-
177+
175178
case 'StopRecordings'
176-
179+
177180
% STEP 8
178181
% finish up: stop recording eye-movements,
179182
% EyeLink Stop recording the block
@@ -182,37 +185,106 @@
182185
WaitSecs(0.1);
183186
% close graphics window, close data file and shut down tracker
184187
Eyelink('StopRecording');
185-
188+
186189
case 'Shutdown'
187-
190+
188191
edfFileName = expParameters.fileName.eyetracker;
189192
edfFile = 'demo.edf';
190-
193+
191194
% STEP 6
192195
% At the end of the experiment, save the edf file and shut down connection
193196
% with Eyelink
194-
197+
195198
Eyelink('Command', 'set_idle_mode');
196199
WaitSecs(0.5);
197200
Eyelink('CloseFile');
198-
201+
199202
% download data file
200203
try
201204
fprintf('Receiving data file ''%s''\n', edfFileName);
202-
status = Eyelink('ReceiveFile', '', [expParameters.outputDir, filesep, 'eyetracker', filesep, edfFileName]);
205+
status = Eyelink('ReceiveFile', '', ...
206+
[expParameters.outputDir, filesep, 'eyetracker', filesep, edfFileName]);
203207
if status > 0
204208
fprintf('ReceiveFile status %d\n', status);
205209
end
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]);
210+
if 2 == exist([expParameters.outputDir, filesep, 'eyetracker', ...
211+
filesep, edfFileName], 'file')
212+
fprintf('Data file ''%s'' can be found in ''%s''\n', edfFileName, ...
213+
[expParameters.outputDir, filesep, 'eyetracker', filesep]);
208214
end
209215
catch
210216
fprintf('Problem receiving data file ''%s''\n', edfFileName);
211217
end
212-
218+
213219
Eyelink('shutdown');
214-
Screen('CloseAll');
215-
220+
216221
end
217-
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);
218289
end
290+
end

0 commit comments

Comments
 (0)