Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion checkPtbVersion.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function checkPtbVersion()
% Checks that the right dependencies are installed.

printCredits();
printCreditsCppPtb();

PTB.major = 3;
PTB.minor = 0;
Expand Down
17 changes: 17 additions & 0 deletions collectAndSaveResponses.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function responseEvents = collectAndSaveResponses(cfg, expParameters, logFile, experimentStart)

responseEvents = getResponse('check', cfg.keyboard.responseBox, cfg);

if isfield(responseEvents(1), 'onset') && ~isempty(responseEvents(1).onset)

for iResp = 1:size(responseEvents, 1)
responseEvents(iResp).onset = ...
responseEvents(iResp).onset - experimentStart;
end

responseEvents.fileID = logFile.fileID;
responseEvents.extraColumns = logFile.extraColumns;
saveEventsFile('save', expParameters, responseEvents);

end
end
154 changes: 110 additions & 44 deletions eyeTracker.m
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
function [el, edfFile] = eyeTracker(input, cfg, expParameters, varargin)

if ~cfg.eyeTracker

el = [];

else

switch input

case 'Calibration'

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

% calibration has silver background with black targets, sound and smaller
% targets
el.backgroundcolour = [192 192 192, (cfg.win)];
Expand All @@ -25,15 +25,15 @@
el.calibrationtargetsize = 1;
el.calibrationtargetwidth = 0.5;
el.displayCalResults = 1;

% call this function for changes to the calibration structure to take
% affect
EyelinkUpdateDefaults(el);

% STEP 3
%% STEP 3
% Initialization of the connection with the Eyelink Gazetracker.
% exit program if this fails.

% make sure EL is initialized.
ELinit = Eyelink('Initialize');
if ELinit ~= 0
Expand All @@ -42,7 +42,7 @@
Screen('CloseAll');
return
end

% make sure we're still connected.
ELconnection = Eyelink('IsConnected');
if ELconnection ~= 1
Expand All @@ -51,45 +51,45 @@
Screen('CloseAll');
return
end

%
if ~EyelinkInit(0, 1)
fprintf('Eyelink Init aborted.\n');
return
end

% Open the edf file to write the data
edfFile = 'demo.edf';
Eyelink('Openfile', edfFile);

[el.v, el.vs] = Eyelink('GetTrackerVersion');
fprintf('Running experiment on a ''%s'' tracker.\n', el.vs);

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

% STEP 4
% SET UP TRACKER CONFIGURATION
% Setting the proper recording resolution, proper calibration type,
% as well as the data file content;
% Eyelink('command', 'add_file_preamble_text ''Recorded by
% Eyelink('command', 'add_file_preamble_text ''Recorded by
%EyelinkToolbox demo-experiment''');

% This command is crucial to map the gaze positions from the tracker to
% screen pixel positions to determine fixation
Eyelink('command', 'screen_pixel_coords = %ld %ld %ld %ld', 0, 0, 0, 0);
Eyelink('message', 'DISPLAY_COORDS %ld %ld %ld %ld', 0, 0, 0, 0);

% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% DEFAULT CALIBRATION
% set calibration type.
Eyelink('command', 'calibration_type = HV5');

% you must send this command with value NO for custom calibration
% you must also reset it to YES for subsequent experiments
Eyelink('command', 'generate_default_targets = YES');
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %

% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % CUSTOM CALIBRATION
% % (SET MANUALLY THE DOTS COORDINATES, HERE FOR 6 DOTS)
Expand Down Expand Up @@ -120,17 +120,17 @@
% 128,341, ... %width*0.1,height*1/3
% 1152,341 ); %width-width*0.1,height*1/3
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % %

% % set parser (conservative saccade thresholds)
% Eyelink('command', 'saccade_velocity_threshold = 35');
% Eyelink('command', 'saccade_acceleration_threshold = 9500');

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

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

% % % do a final check of calibration using driftcorrection
% % % You have to hit esc before return.
% % EyelinkDoDriftCorrection(el);
Expand All @@ -142,13 +142,13 @@
% % Screen('CloseAll');
% % return;
% % end

% Go back to black screen
Screen('FillRect', cfg.win, [0 0 0]);
Screen('Flip', cfg.win);

case 'StartRecording'

% STEP 5
% EyeLink Start recording the block
Eyelink('Command', 'set_idle_mode');
Expand All @@ -157,7 +157,7 @@
% % here to tag the recording, in the past caused delays during the
% % presentation so I avoided to use it
% Eyelink('message',['TRIALID ',num2str(blocks),'_startTrial']);

% check recording status, stop display if error
checkrec = Eyelink('checkrecording');
if checkrec ~= 0
Expand All @@ -166,17 +166,17 @@
Screen('CloseAll');
return
end

% record a few samples before we actually start displaying
% otherwise you may lose a few msec of data
WaitSecs(0.1);

% HERE START THE STIMALTION OF THE BLOCK
% HERE START THE STIMULATION OF THE BLOCK
% to mark the beginning of the trial
Eyelink('Message', 'SYNCTIME');

case 'StopRecordings'

% STEP 8
% finish up: stop recording eye-movements,
% EyeLink Stop recording the block
Expand All @@ -185,20 +185,20 @@
WaitSecs(0.1);
% close graphics window, close data file and shut down tracker
Eyelink('StopRecording');

case 'Shutdown'

edfFileName = expParameters.fileName.eyetracker;
edfFile = 'demo.edf';

% STEP 6
% At the end of the experiment, save the edf file and shut down connection
% with Eyelink

Eyelink('Command', 'set_idle_mode');
WaitSecs(0.5);
Eyelink('CloseFile');

% download data file
try
fprintf('Receiving data file ''%s''\n', edfFileName);
Expand All @@ -215,10 +215,76 @@
catch
fprintf('Problem receiving data file ''%s''\n', edfFileName);
end

Eyelink('shutdown');
Screen('CloseAll');


end


end

end

%% subfunctions for iView

function ivx = eyeTrackInit(expParameters)
% initialize iView eye tracker

ivx = [];

if cfg.eyeTracker

host = expParameters.Eyetracker.Host;
port = expParameters.Eyetracker.Port;
window = expParameters.Eyetracker.Window;

% original: ivx=iviewxinitdefaults(window, 9 , host, port);
ivx = iviewxinitdefaults2(window, 9, [], host, port);
ivx.backgroundColour = 0;
[~, ivx] = iViewX('openconnection', ivx);
[success, ivx] = iViewX('checkconnection', ivx);
if success ~= 1
error('connection to eye tracker failed');
end
end
end

function eyeTrackStart(ivx, expParameters)
% start iView eye tracker
if cfg.eyeTracker
% to clear data buffer
iViewX('clearbuffer', ivx);
% start recording
iViewX('startrecording', ivx);
iViewX('message', ivx, ...
[ ...
'Start_Ret_', ...
'Subj_', expParameters.Subj, '_', ...
'Run', num2str(expParameters.Session(end)), '_', ...
expParameters.Apperture, '_', ...
expParameters.Direction]);
iViewX('incrementsetnumber', ivx, 0);
end
end

function eyeTrackStop(ivx, expParameters)
% stop iView eye tracker

if cfg.eyeTracker

% stop tracker
iViewX('stoprecording', ivx);

% save data file
thedatestr = datestr(now, 'yyyy-mm-dd_HH.MM');
strFile = fullfile(OutputDir, ...
[expParameters.Subj, ...
'_run', num2str(expParameters.Session(end)), '_', ...
expParameters.Apperture, '_', ...
expParameters.Direction, '_', ...
thedatestr, '.idf"']);
iViewX('datafile', ivx, strFile);

% close iView connection
iViewX('closeconnection', ivx);
end
end
Loading