|
5 | 5 | % adapted by M.Rezk to localize MT/MST (Huk,2002) |
6 | 6 | % re-adapted by MarcoB and RemiG 2020 |
7 | 7 |
|
8 | | -%% |
9 | | - |
10 | 8 | % Clear all the previous stuff |
11 | 9 | % clc; clear; |
12 | 10 | if ~ismac |
13 | | - close all; |
14 | | - clear Screen; |
| 11 | + close all; |
| 12 | + clear Screen; |
15 | 13 | end |
16 | 14 |
|
17 | | -% make sure we got access to all the required functions and inputs |
18 | | -addpath(genpath(fullfile(pwd, 'subfun'))) |
| 15 | +getOnlyPress = 1; |
19 | 16 |
|
20 | | -[expParameters, cfg] = setParameters; |
| 17 | +more off; |
21 | 18 |
|
22 | | -% set and load all the parameters to run the experiment |
23 | | -expParameters = userInputs(cfg, expParameters); |
| 19 | +% make sure we got access to all the required functions and inputs |
| 20 | +initEnv(); |
24 | 21 |
|
25 | | -expParameters = createFilename(cfg, expParameters); |
| 22 | +cfg = setParameters; |
| 23 | +cfg = userInputs(cfg); |
| 24 | +cfg = createFilename(cfg); |
26 | 25 |
|
27 | | -expParameters %#ok<NOPTS> |
28 | 26 |
|
29 | 27 | %% Experiment |
30 | 28 |
|
31 | 29 | % Safety loop: close the screen if code crashes |
32 | 30 | try |
33 | 31 |
|
| 32 | + % % % REFACTOR THIS FUNCTION |
| 33 | + [cfg] = loadAudioFiles(cfg); |
| 34 | + |
34 | 35 | %% Init the experiment |
35 | 36 | [cfg] = initPTB(cfg); |
36 | 37 |
|
37 | 38 | % % Convert some values from degrees to pixels |
38 | 39 | % cfg = deg2Pix('diameterAperture', cfg, cfg); |
39 | 40 | % expParameters = deg2Pix('dotSize', expParameters, cfg); |
40 | 41 |
|
41 | | - |
42 | | - [el] = eyeTracker('Calibration', cfg, expParameters); |
| 42 | + [el] = eyeTracker('Calibration', cfg); |
43 | 43 |
|
44 | 44 | % % % REFACTOR THIS FUNCTION |
45 | | - [expParameters] = expDesign(expParameters); |
46 | | - % % % |
| 45 | + [cfg] = expDesign(cfg); |
47 | 46 |
|
48 | 47 | % Prepare for the output logfiles with all |
49 | | - logFile = saveEventsFile('open', expParameters, [], ... |
| 48 | + logFile = saveEventsFile('open', cfg, [], ... |
50 | 49 | 'direction', 'speed', 'target', 'event', 'block'); |
51 | | - |
52 | | - logFile |
53 | | - |
54 | | - % % % REFACTOR THIS FUNCTION |
55 | | - [expParameters] = loadAudioFiles(cfg, expParameters); |
56 | | - phandle = PsychPortAudio('Open',[],[],1,expParameters.freq,2); |
57 | | - % % % |
58 | | - |
59 | | - % Prepare for fixation Cross |
60 | | - if expParameters.Task1 |
61 | | - |
62 | | - cfg.xCoords = [-expParameters.fixCrossDimPix expParameters.fixCrossDimPix 0 0] ... |
63 | | - + expParameters.xDisplacementFixCross; |
64 | | - |
65 | | - cfg.yCoords = [0 0 -expParameters.fixCrossDimPix expParameters.fixCrossDimPix] ... |
66 | | - + expParameters.yDisplacementFixCross; |
67 | | - |
68 | | - cfg.allCoords = [cfg.xCoords; cfg.yCoords]; |
69 | | - |
70 | | - end |
71 | | - |
72 | | - % Wait for space key to be pressed |
73 | | - pressSpace4me |
74 | | - |
| 50 | + |
| 51 | +% disp(cfg); |
| 52 | + |
| 53 | + standByScreen(cfg); |
| 54 | + |
75 | 55 | % prepare the KbQueue to collect responses |
76 | | - getResponse('init', cfg, expParameters, 1); |
77 | | - getResponse('start', cfg, expParameters, 1); |
78 | | - |
79 | | - % Show instructions |
80 | | - if expParameters.Task1 |
81 | | - DrawFormattedText(cfg.win,expParameters.TaskInstruction,... |
82 | | - 'center', 'center', cfg.textColor); |
83 | | - Screen('Flip', cfg.win); |
84 | | - end |
85 | | - |
| 56 | + getResponse('init', cfg.keyboard.responseBox, cfg); |
| 57 | + |
86 | 58 | % Wait for Trigger from Scanner |
87 | | - wait4Trigger(cfg) |
88 | | - |
89 | | - % Show the fixation cross |
90 | | - if expParameters.Task1 |
91 | | - drawFixationCross(cfg, expParameters, expParameters.fixationCrossColor) |
92 | | - Screen('Flip',cfg.win); |
93 | | - end |
94 | | - |
| 59 | + waitForTrigger(cfg); |
| 60 | + |
95 | 61 | %% Experiment Start |
96 | | - cfg.experimentStart = GetSecs; |
97 | | - |
98 | | - WaitSecs(expParameters.onsetDelay); |
| 62 | + cfg = getExperimentStart(cfg); |
| 63 | + |
| 64 | + getResponse('start', cfg.keyboard.responseBox); |
| 65 | + |
| 66 | + WaitSecs(cfg.onsetDelay); |
99 | 67 |
|
100 | 68 | %% For Each Block |
101 | 69 |
|
102 | | - stopEverything = 0; |
103 | | - |
104 | | - for iBlock = 1:expParameters.numBlocks |
105 | | - |
106 | | - if stopEverything |
107 | | - break; |
108 | | - end |
| 70 | + for iBlock = 1:cfg.numBlocks |
109 | 71 |
|
110 | 72 | fprintf('\n - Running Block %.0f \n',iBlock) |
111 | 73 |
|
112 | | - eyeTracker('StartRecording', cfg, expParameters); |
| 74 | + eyeTracker('StartRecording', cfg); |
113 | 75 |
|
114 | 76 | % For each event in the block |
115 | | - for iEvent = 1:expParameters.numEventsPerBlock |
116 | | - |
117 | | - |
| 77 | + for iEvent = 1:cfg.numEventsPerBlock |
| 78 | + |
118 | 79 | % Check for experiment abortion from operator |
119 | | - [keyIsDown, ~, keyCode] = KbCheck(cfg.keyboard); |
120 | | - if keyIsDown && keyCode(KbName(cfg.escapeKey)) |
121 | | - stopEverything = 1; |
122 | | - warning('OK let us get out of here') |
123 | | - break; |
124 | | - end |
125 | | - |
| 80 | + checkAbort(cfg, cfg.keyboard.keyboard); |
126 | 81 |
|
127 | 82 | % set direction, speed of that event and if it is a target |
128 | 83 | thisEvent.trial_type = 'dummy'; |
129 | | - thisEvent.direction = expParameters.designDirections(iBlock,iEvent); |
130 | | - thisEvent.speed = expParameters.designSpeeds(iBlock,iEvent); |
131 | | - thisEvent.target = expParameters.designFixationTargets(iBlock,iEvent); |
| 84 | + thisEvent.direction = cfg.designDirections(iBlock,iEvent); |
| 85 | + thisEvent.speed = cfg.designSpeeds(iBlock,iEvent); |
| 86 | + thisEvent.target = cfg.designFixationTargets(iBlock,iEvent); |
132 | 87 |
|
133 | 88 | % play the sounds and collect onset and duration of the event |
134 | | - [onset, duration] = doAudMot(cfg, expParameters, thisEvent, phandle); |
| 89 | + [onset, duration] = doAudMot(cfg, thisEvent, cfg.audio.pahandle); |
135 | 90 |
|
136 | 91 | thisEvent.event = iEvent; |
137 | 92 | thisEvent.block = iBlock; |
|
142 | 97 | % we save event by event so we clear this variable every loop |
143 | 98 | thisEvent.fileID = logFile.fileID; |
144 | 99 |
|
145 | | - saveEventsFile('save', expParameters, thisEvent, ... |
| 100 | + saveEventsFile('save', cfg, thisEvent, ... |
146 | 101 | 'direction', 'speed', 'target', 'event', 'block'); |
147 | 102 |
|
148 | 103 | clear thisEvent |
149 | 104 |
|
150 | 105 |
|
151 | 106 | % collect the responses and appends to the event structure for |
152 | 107 | % saving in the tsv file |
153 | | - responseEvents = getResponse('check', cfg, expParameters); |
| 108 | + responseEvents = getResponse('check', cfg.keyboard.responseBox, cfg, ... |
| 109 | + getOnlyPress); |
154 | 110 |
|
155 | | - if ~isempty(responseEvents(1).onset) |
156 | | - |
157 | | - responseEvents.fileID = logFile.fileID; |
158 | | - |
159 | | - for iResp = 1:size(responseEvents, 1) |
160 | | - responseEvents(iResp).onset = ... |
161 | | - responseEvents(iResp).onset - cfg.experimentStart; |
162 | | - responseEvents(iResp).target = expParameters.designFixationTargets(iBlock,iEvent); |
163 | | - responseEvents(iResp).event = iEvent; |
164 | | - responseEvents(iResp).block = iBlock; |
165 | | - end |
166 | | - |
167 | | - saveEventsFile('save', expParameters, responseEvents, ... |
168 | | - 'direction', 'speed', 'target', 'event', 'block'); |
169 | | - end |
| 111 | + triggerString = ['trigger']; |
| 112 | + saveResponsesAndTriggers(responseEvents, cfg, logFile, triggerString); |
170 | 113 |
|
171 | 114 | % wait for the inter-stimulus interval |
172 | | - WaitSecs(expParameters.ISI); |
173 | | - |
174 | | - getResponse('flush', cfg, expParameters); |
| 115 | + WaitSecs(cfg.ISI); |
175 | 116 |
|
176 | 117 | end |
177 | 118 |
|
178 | | - eyeTracker('StopRecordings', cfg, expParameters); |
| 119 | + eyeTracker('StopRecordings', cfg); |
179 | 120 |
|
180 | | - WaitSecs(expParameters.IBI); |
| 121 | + WaitSecs(cfg.IBI); |
181 | 122 |
|
182 | 123 | end |
183 | 124 |
|
184 | 125 | % End of the run for the BOLD to go down |
185 | | - WaitSecs(expParameters.endDelay); |
| 126 | + WaitSecs(cfg.endDelay); |
186 | 127 |
|
187 | 128 | % Close the logfiles |
188 | | - saveEventsFile('close', expParameters, logFile); |
| 129 | + saveEventsFile('close', cfg, logFile); |
189 | 130 |
|
190 | | - getResponse('stop', cfg, expParameters, 1); |
| 131 | + getResponse('stop', cfg.keyboard.responseBox); |
| 132 | + getResponse('release', cfg.keyboard.responseBox); |
191 | 133 |
|
192 | 134 | totalExperimentTime = GetSecs-cfg.experimentStart; |
193 | 135 |
|
194 | | - eyeTracker('Shutdown', cfg, expParameters); |
| 136 | + eyeTracker('Shutdown', cfg); |
195 | 137 |
|
196 | 138 | % save the whole workspace |
197 | | - matFile = fullfile(expParameters.outputDir, strrep(expParameters.fileName.events,'tsv', 'mat')); |
| 139 | + matFile = fullfile(cfg.dir.output, strrep(cfg.fileName.events,'tsv', 'mat')); |
198 | 140 | if IsOctave |
199 | 141 | save(matFile, '-mat7-binary'); |
200 | 142 | else |
|
0 commit comments