-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunRun.m
More file actions
117 lines (98 loc) · 2.93 KB
/
runRun.m
File metadata and controls
117 lines (98 loc) · 2.93 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
function [TaskIO] = runRun(SubjectId,RunId)
if ~exist(sprintf('.%sOutputs',filesep),'dir')
mkdir Outputs
end
dateTimeStr = sprintf('%04d%02d%02dT%02d%02d%02d',round(clock)); %#ok<CLOCK>
targetFn = sprintf('.%sOutputs%s%s_R%i_%s.mat',...
filesep, filesep, SubjectId, RunId, dateTimeStr);
%% Create the globals structure
clear global;
globals = struct;
globals.SubjectId = SubjectId;
%% Set IO port
globals.sendTriggers = true;
try
[globals.portObj,globals.portAddress] = setIOPort();
io64(globals.portObj,globals.portAddress,0);
choice = questdlg(...
sprintf('Successfully setup IO port.%cWould you like to continue?',10),...
'Continue?', ...
'Exit execution','Let''s go!','Exit execution');
switch choice
case 'Exit execution'
return
end
catch
choice = questdlg(...
sprintf('Failed to setup IO port.%cWhat would you like to do?',10),...
'IO port not working', ...
'Exit execution','Continue; I am testing','Exit execution');
switch choice
case 'Exit execution'
return
case 'Continue; I am testing'
globals.sendTriggers = false;
end
end
%% Clear the screen
sca;
close all;
%% Set the globals
globals = setGlobals(globals);
%% Set-up PsychToolbox
setUp(globals.window);
%% Set TaskIO
TaskIO = setTaskIO(SubjectId,RunId);
HideCursor();
%% Wait for Scanner
[tScan0,globals] = waitForScanner(globals);
%% Trial loop
for iT = 1:numel(TaskIO)
if strcmp(TaskIO(iT).TrialType,"Null")
globals = showCross(8, globals);
else
% Set the trial characteristics
trialType = TaskIO(iT).TrialType;
a = TaskIO(iT).a;
isiLength = TaskIO(iT).isiLength;
b = TaskIO(iT).b;
arrayPerm = TaskIO(iT).arrayPerm;
startPos = TaskIO(iT).startPos;
%% Display
globals = showCross(1, globals);
tShowA = globals.t;
globals = showImg(a, 3, globals);
liSendTrig(a+8,globals);
globals = showBlank(isiLength, globals);
tShowB = globals.t;
globals = showImg(b, 3, globals);
liSendTrig(b+16,globals);
globals = showSym(trialType, 1, globals);
%% Request response
[r, tArray, tRespo, globals] = ...
requestResponse(arrayPerm, startPos, 6, globals);
%% Save to TaskIO
TaskIO(iT).r = r;
TaskIO(iT).tShowA = tShowA;
TaskIO(iT).tShowB = tShowB;
TaskIO(iT).tArray = tArray;
TaskIO(iT).tRespo = tRespo;
try
save(targetFn, "TaskIO", "tScan0", "globals");
catch
warning('Data not saved successfully on trial %i', iT);
end
%% Escape
[~, ~, keyCode] = KbCheck(-3);
if keyCode(globals.escapeKey)
sca;
error('Terminated by user.');
end
end
end
%% Close the screen
sca;
close all;
%% Switch running priority of PTB back to normal
Priority(0);
return