-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmainScript.m
More file actions
137 lines (88 loc) · 3.52 KB
/
Copy pathmainScript.m
File metadata and controls
137 lines (88 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
% (C) Copyright 2018 Mohamed Rezk
% (C) Copyright 2020 CPP visual motion localizer developers
%% mainScript
% Clear all the previous stuff
clc;
if ~ismac
close all;
clear Screen;
end
% make sure we got access to all the required functions and inputs
initEnv();
% set and load all the parameters to run the experiment
cfg = setParameters;
cfg = userInputs(cfg);
cfg = createFilename(cfg);
%% Experiment
% Safety loop: close the screen if code crashes
try
%% Init the experiment
[cfg] = initPTB(cfg);
cfg = postInitializationSetup(cfg);
[el] = eyeTracker('Calibration', cfg);
% [cfg] = expDesign(cfg);
% Prepare for the output logfiles with all
logFile.extraColumns = cfg.extraColumns;
logFile = saveEventsFile('init', cfg, logFile);
logFile = saveEventsFile('open', cfg, logFile);
disp(cfg);
% Show experiment instruction
standByScreen(cfg);
% prepare the KbQueue to collect responses
getResponse('init', cfg.keyboard.responseBox, cfg);
%% Experiment Start
eyeTracker('StartRecording', cfg);
% Wait for Trigger from Scanner and add timestamp of experiment onset
cfg.experimentStart = waitForTrigger(cfg);
getResponse('start', cfg.keyboard.responseBox);
%% For Each Block
for iBlock = 1:cfg.design.nbBlocks
waitFor(cfg, cfg.timing.onsetDelay);
for iTrial = 1:cfg.design.nbTrials
fprintf('\n - Running trial %.0f \n', iTrial);
% Check for experiment abortion from operator
checkAbort(cfg, cfg.keyboard.keyboard);
[thisEvent, thisFixation, cfg] = preTrialSetup(cfg, iBlock, iTrial);
eyeTracker('Message', cfg, ...
['start_trial-', num2str(iTrial), '_', thisEvent.trial_type]);
% play the dots and collect onset and duraton of the event
[onset, duration] = doTrial(cfg, thisEvent, thisFixation);
thisEvent = preSaveSetup( ...
thisEvent, ...
iBlock, ...
iTrial, ...
duration, ...
onset, ...
cfg, ...
logFile);
saveEventsFile('save', cfg, thisEvent);
% collect the responses and appends to the event structure for
% saving in the tsv file
responseEvents = getResponse('check', cfg.keyboard.responseBox, cfg);
responseEvents(1).isStim = logFile.isStim;
responseEvents(1).fileID = logFile.fileID;
responseEvents(1).extraColumns = logFile.extraColumns;
saveEventsFile('save', cfg, responseEvents);
eyeTracker('Message', cfg, ...
['end_trial-', num2str(iTrial), '_', thisEvent.trial_type]);
waitFor(cfg, cfg.timing.ISI);
end
eyeTracker('Message', cfg, ['end_block-', num2str(iBlock)]);
waitFor(cfg, cfg.timing.IBI);
end
% End of the run for the BOLD to go down
waitFor(cfg, cfg.timing.endDelay);
cfg = getExperimentEnd(cfg);
eyeTracker('StopRecordings', cfg);
% Close the logfiles
saveEventsFile('close', cfg, logFile);
getResponse('stop', cfg.keyboard.responseBox);
getResponse('release', cfg.keyboard.responseBox);
eyeTracker('Shutdown', cfg);
createJson(cfg, cfg);
farewellScreen(cfg);
cleanUp();
catch
cleanUp();
psychrethrow(psychlasterror);
end