-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPresentAnnulus.m
175 lines (150 loc) · 5.86 KB
/
PresentAnnulus.m
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
function [ ] = PresentAnnulus( contrastText )
%PRESENTANNULUS Summary of this function goes here
% Detailed explanation goes here
if nargin < 1
contrastText = '';
end
presentPairs = 10; % Number of pairs of presentations
% Stimulus parameters
Porig = struct();
Porig.bgLuminance = 6.2/227.6; % TODO specify in absolute Cd/m^2 units
Porig.outerRadiusDeg = 2;
Porig.innerRadiusDeg = 1;
Porig.fixColor = 255 * 0.3 * 6.2/227.6;
Porig.fixWidthDeg = 0.5;
Porig.fixLineWidthPx = 3;
Pempty = Porig;
Pempty.eyesToDraw = [0 1];
Pempty.outerRadiusDeg = 0;
Pempty.innerRadiusDeg = 0;
Pempty.stimLuminance = Pempty.bgLuminance; % just to be sure
e = []; %caught exception
HW = HardwareParameters();
[didHWInit, HW] = InitializeHardware(HW);
server = PL_InitClient(0);
LPTSetup();
LPT_Stimulus_Trigger = 4;
LPT_Stimulus_End = 1;
exitFlag = false;
try
% Calibrate pupil
CalibratePupil(HW, server);
% Five-minute countdown
countDown(5*60, 10, '5-minute dark adaptation');
[~] = input('Start Plexon data collection and press Enter...','s');
% Open data file for responses to task
dataColumns = {'pairCount', 'WhichEye', 'plexonGoTime', 'localGoTime', 'stimStartTime', 'Contrast', 'BlinkDetected'};
sessionName = [];
while length(sessionName) < 2
sessionName = input('Session name - main pupil experiment (Subjectcode+experimentInitial):', 's');
if length(sessionName) < 2
fprintf('Session name too short!\n');
end
end
datafile = DataFile(DataFile.defaultPath(sessionName), dataColumns);
while ~exitFlag
% Show blank for now...
HW = DrawAnnulus(HW, Pempty);
% Ask for the contrast (or exit)
contrast = [];
while isempty(contrast)
switch lower(contrastText)
case {'l', 'low'}
contrast = 0.3;
case {'m', 'medium'}
contrast = 0.6;
case {'h', 'high'}
contrast = 1.8;
case {'f', 'ff', 'full', 'flash'}
contrast = Inf;
case {'x', 'exit'}
exitFlag = true;
contrast = 0;
case {'2', 'two'}
countDown(2*60, 10, '2-minute dark adaptation');
contrast = [];
end
if (isempty(contrast))
contrastText = input('Which contrast (l, m, h, f)? (2 for dark adaptation timer, or "x" to exit): ', 's');
end
end
% Calculate stimulus parameters
P = Porig;
if isinf(contrast)
% Full field flash
P.stimLuminance = 1.0;
P.outerRadiusDeg = 170;
P.innerRadiusDeg = 0;
else
P.stimLuminance = P.bgLuminance * (1.0 + contrast);
end
if ~exitFlag
PL_GetTS(server); % erase existing timestamps
for presCount = 1:presentPairs
% whether we should present entire stimulus pair (again),
% ex. because of a blink, etc.
presentPair = true;
while presentPair
presentPair = false;
for eyeToPresent = [0 1]
P.eyesToDraw = eyeToPresent;
% Wait for subject to be ready...
LPTTrigger(LPT_Stimulus_Trigger);
go_ts = []; GetEventsPlexon(server);
lrStr = ['l' 'r'];
fprintf('Waiting for go (#%i-%s)...', ...
presCount, lrStr(eyeToPresent+1));
while isempty(go_ts)
[~,~,go_ts,~]=GetEventsPlexon(server);
pause(1e-2); % prevent 100% CPU usage
end
localGoTime = GetSecs();
% Present stimulus for this eye
fprintf('Going now!\n');
pause(.3);
[HW, stimStartTime] = DrawAnnulus(HW, P);
pause(.1);
[HW, ~] = DrawAnnulus(HW, Pempty);
pause(1.0);
LPTTrigger(LPT_Stimulus_End);
% Check for blinks, just up to this point
[~,~,~,stop_ts]=GetEventsPlexon(server);
blinkDetected = ~isempty(stop_ts);
% Write to data file
% (timestamp, contrast, eye, whether blink was detected)
datafile.append([presCount, eyeToPresent, go_ts, localGoTime, stimStartTime, contrast, blinkDetected]);
if blinkDetected
presentPair = true;
fprintf('Blink detected!\n');
break; % Redo entire pair
end
% Not delaying before next trial here - Plexon
% machine controls delay before it will send next
% 'go' signal
%pause(0.0);
end
end
end
end
contrastText = ''; % Reset for next contrast
end
catch e
end
if didHWInit
HW = CleanupHardware(HW); %#ok<NASGU>
end
if ~isempty(e)
rethrow(e);
end
end
function countDown(breakLength, updateLength, prefix)
for time = breakLength:-updateLength:0
fprintf('%s - time remaining (hold down Esc to skip): %is\n', prefix, time);
pause(updateLength);
[ ~, ~, keyCode ] = KbCheck;
if keyCode(KbName('Esc'));
fprintf('Detected ''Esc'' - skipping!\n');
break;
end
end
end