Hi,
A newbie to eyelink here.
I’m trying to do pupillometry simultaneously with a resting-state scan. I’m attaching my Matlab script that I’m trying to use to start eyelink to record below. But it’s unclear to me what happens after I do calibration and accept fixation on the host PC. After I’ve accepted fixations, do I press any buttons on the host PC before running by Matlab script? Do I have to press the “output record” button before running the script? Would appreciate any advice. Also, would appreciate any feedback on the script!
function edfFile = eyetracker(use_eye_tracker)
% EYETRACKER Initialize Eyelink and wait for fMRI TR trigger before recording
% edfFile = eyetracker(true) initializes and returns EDF file name
% edfFile = eyetracker(false) does nothing and returns empty string
if use_eye_tracker
% Generate a unique EDF filename using date/time
c = datetime("now");
yearChar = char(65 + year(c) - 2014);
monthChar = num2str(dec2hex(month(c)));
dayChar = sprintf('%02d', day(c));
hourChar = char(65 - 1 + hour(c));
minuteChar = sprintf('%02d', minute(c));
secondChar = char(65 + floor(second(c) / 3));
edfFile = \[yearChar monthChar dayChar hourChar minuteChar secondChar\];
edfFile = upper(edfFile);
edfFile = edfFile(1:min(end,8));
fprintf('EDF File name: %s\\n', edfFile);
% Initialize Eyelink connection
if ~EyelinkInit(0, 1)
fprintf('Eyelink initialization failed.\\n');
edfFile = '';
return;
end
% Open EDF file on host
Eyelink('OpenFile', edfFile);
% Configure data collection
Eyelink('Command', 'file_sample_data = LEFT,RIGHT,GAZE,AREA');
Eyelink('Command', 'link_sample_data = LEFT,RIGHT,GAZE,AREA');
Eyelink('Command', 'pupil_size_diameter = YES');
Eyelink('Command', 'heuristic_filter = 1 2');
Eyelink('Command', 'button_function 5 "accept_target_fixation"');
Eyelink('Message', 'DISPLAY_COORDS 0 0 1024 768');
% === Wait for first TR triggerEyelink
% ===
KbName('UnifyKeyNames');
triggerKey = KbName('5%'); % Adjust if different scanner key (prisma B is "5")
fprintf('Waiting for fMRI trigger key (%s)...\\n', KbName(triggerKey));
while true
\[keyIsDown, \~, keyCode\] = KbCheck;
if keyIsDown && keyCode(triggerKey)
fprintf('Trigger received. Starting Eyelink recording.\\n');
break;
end
end
% Start Eyelink recording after trigger
Eyelink('StartRecording');
WaitSecs(1);
Eyelink('Message', 'SYNCTIME');
else
edfFile = '';
end
end