-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunRun.m
More file actions
115 lines (89 loc) · 2.96 KB
/
runRun.m
File metadata and controls
115 lines (89 loc) · 2.96 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
function [stoppedEarly] = runRun(subjectIdx,runId)
%% Clear the screen
sca;
close all;
%% Set file name for saving
if ~exist(sprintf('.%sOutputs',filesep),'dir')
mkdir Outputs;
end
dateTimeStr = sprintf('%04d%02d%02dT%02d%02d%02d', ...
round(clock)); %#ok<CLOCK>
saveFn = sprintf('.%sOutputs%s%02d_R%i_%s.mat',...
filesep, filesep, subjectIdx, runId, dateTimeStr);
%% Create the globals structure
globals = setGlobals(subjectIdx,runId);
%% Set up IO port
globals = setIOPort(globals);
if globals.stoppedEarly
stoppedEarly = true;
return
end
%% Set-up PsychToolbox
globals = setUp(globals);
%% Create TaskIO
TaskIO = makeTaskIO(globals);
%% Wait for Scanner
[tScan0,globals] = waitForScanner(globals);
%% Trial loop
for iTIO = 1:size(TaskIO,1)
switch TaskIO.trialType{iTIO}
case 'Null'
% Set tShow
TaskIO.tShow(iTIO) = globals.t;
% Draw a blank to the screen for 2.5 seconds
globals = showBlank(2.5, globals);
case 'CountDown'
% Set tShow
TaskIO.tShow(iTIO) = globals.t;
% Extract the count-down specs
countSpec = TaskIO.stimulus{iTIO};
% Show the starting number for 1 second
globals = showNum(countSpec.countStart, 1, globals);
% Show the arrow for a variable number of seconds
globals = showArrow(countSpec.countDur, globals);
% Request a response, 2 second response window
[response, tResponse, globals] = getCountResponse(...
countSpec.scrollStart, ...
11 - (1+countSpec.countDur), ... 11 seconds per CountDown
globals);
% Record the response and it's time
TaskIO.response(iTIO) = response;
TaskIO.tResponse(iTIO) = tResponse;
case {'Typical','Oddball'}
% Show a black for 0.5 seconds
globals = showBlank(0.5, globals);
% Set tShow
TaskIO.tShow(iTIO) = globals.t;
% Draw the image and wait 2 seconds while accepting responses
[response, keyTime, globals] = ...
showImg(TaskIO.textureIdx(iTIO), 2, globals);
% Record the response and it's time
TaskIO.response(iTIO) = response;
TaskIO.tResponse(iTIO) = keyTime;
otherwise
error('Unrecognised trial type in TaskIO at iTrial=%i',iTIO);
end
% Set stoppedEarly
[~, ~, keyCode] = KbCheck(-3);
if keyCode(globals.escapeKey)
globals.stoppedEarly = true;
end
% Save the data
try
save(saveFn, 'globals', 'TaskIO', 'tScan0');
catch
warning('Data not saved successfully on trial %i', iTIO);
end
% Escape
if globals.stoppedEarly
stoppedEarly = true;
sca;
warning('Terminated by user.');
Screen('CloseAll');
return
end
end
Screen('CloseAll');
% Extract stoppedEarly
stoppedEarly = globals.stoppedEarly;
return