File size: 7,132 Bytes
227148b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
function trial = runChoice(disp_struct, task_struct, trial, TRAINTEST, ioObject, LTP1address)

% Fixation
JIT=Shuffle(.3:.001:.5);
fixation_text = '+';
DrawFormattedText(disp_struct.wPtr,fixation_text,'center','center');
Screen(disp_struct.wPtr, 'Flip');
WaitSecs(JIT(1));

% get the center for the screen
center_x = round(disp_struct.wPtr_rect(3)/2);
center_y = round(disp_struct.wPtr_rect(4)/2);

% define the text font
Screen('TextSize', disp_struct.wPtr, 40);
Screen('TextFont', disp_struct.wPtr, 'Times');
Screen('TextStyle', disp_struct.wPtr, 0);
Screen('TextColor', disp_struct.wPtr, [255 255 255]);
Screen('FillRect', disp_struct.wPtr,[0 0 0]);

% stimuli bounds
sWidth = 300;
sHeight = 300;
sTop = center_y - sHeight/2;
sL_left = center_x - 80 - sWidth;
sR_left = center_x + 80;
sL_rect = [sL_left, sTop, sL_left + sWidth, sTop + sHeight];
sR_rect = [sR_left, sTop, sR_left + sWidth, sTop + sHeight];

% define the left and right stimuli
if trial(task_struct.cIsS1Left)
    respL = trial(task_struct.cS1);
    respR = trial(task_struct.cS2);
    s1Rect = sL_rect;
    s2Rect = sR_rect;
else
    respL = trial(task_struct.cS2);
    respR = trial(task_struct.cS1);
    s1Rect = sR_rect;
    s2Rect = sL_rect;
end

% show the stimuli
Screen('DrawTexture', disp_struct.wPtr, disp_struct.cards(trial(task_struct.cS1)), [], s1Rect);
Screen('DrawTexture', disp_struct.wPtr, disp_struct.cards(trial(task_struct.cS2)), [], s2Rect);
io64(ioObject,LTP1address,3); WaitSecs(.05); io64(ioObject,LTP1address,0);

% see if we need to frame the nc stim
if trial(task_struct.cTrialCond) == task_struct.NC
    if trial(task_struct.cRespAct) == trial(task_struct.cS1)
        ncFrameRect = s1Rect;
    else
        ncFrameRect = s2Rect;
    end
    Screen('FrameRect', disp_struct.wPtr, [0 0 255], ncFrameRect, 5);
end % frame the fc selected stim

% limit input
RestrictKeysForKbCheck([disp_struct.RESP_L, disp_struct.RESP_R]);
KbReleaseWait();

% flip to show the stims
[VBLTimestamp StimulusOnsetTime FlipTimestamp Missed Beampos] = Screen(disp_struct.wPtr, 'Flip', 0, 1);
% %     % wait for response
% %     [secs, keyCode, deltaSecs] = KbWait([], 2, GetSecs()+task_struct.maxRT);
wait_stamp=GetSecs;
while 1
    [a ab] = JoyMEX(0);
    if find(ab) ~= 0
        if ab(1,disp_struct.RESP_L) == 1
            stim_resp = disp_struct.RESP_L;
            io64(ioObject,LTP1address,4); WaitSecs(.05); io64(ioObject,LTP1address,0);
            break;
        elseif ab(1,disp_struct.RESP_R) == 1
            stim_resp = disp_struct.RESP_R;
            io64(ioObject,LTP1address,5); WaitSecs(.05); io64(ioObject,LTP1address,0);
            break;
        end
    elseif(GetSecs-wait_stamp) > task_struct.maxRT,
        stim_resp=999;
        break;
    end
end
% compute the RT
RT = GetSecs - StimulusOnsetTime;

if stim_resp == disp_struct.RESP_L
    % left-most action
    choice = respL;
    % hide the non-selected stim
    Screen('FillRect', disp_struct.wPtr, [0 0 0], sR_rect);
    % hide selection
    Screen(disp_struct.wPtr, 'Flip');
    WaitSecs(0.75);
    
elseif stim_resp == disp_struct.RESP_R
    % right-most action
    choice = respR;
    % hide the non-selected stim
    Screen('FillRect', disp_struct.wPtr, [0 0 0], sL_rect);
    % hide selection
    Screen(disp_struct.wPtr, 'Flip');
    WaitSecs(0.75);
else
    % they didn't respond in time
    choice = disp_struct.RESP_SLOW;
end


% make sure they matched if this was a no-choice trial
if trial(task_struct.cTrialCond) == task_struct.NC && choice == trial(task_struct.cRespAct)
    trial(task_struct.cMatch) = true;
else
    trial(task_struct.cMatch) = false;
end

% do not update the response if they didn't match
if trial(task_struct.cTrialCond) == task_struct.FC || trial(task_struct.cMatch)
    % store response
    trial(task_struct.cRespAct) = choice;
    trial(task_struct.cRT) = RT;
end


% --------------------------------------- FB
if TRAINTEST==1
    % define the text font
    Screen('TextSize', disp_struct.wPtr, 60);
    Screen('TextFont', disp_struct.wPtr, 'Times');
    Screen('TextStyle', disp_struct.wPtr, 0);
    Screen('TextColor', disp_struct.wPtr, [255 255 255]);
    Screen('FillRect', disp_struct.wPtr,[0 0 0]);
    
    % get feedback for the selected stimulus
    if trial(task_struct.cTrialCond) == task_struct.NC && ~trial(task_struct.cMatch)
        fbText = 'You must match the framed symbol';
        respRew = NaN;
        SIMPLEFB=1;
        FBTRIGGER=6;
    elseif trial(task_struct.cRespAct) == trial(task_struct.cS1)
        % they picked stim 1
        respRew = trial(task_struct.cS1Rew);
        fbText = num2str(respRew);
        SIMPLEFB=0;
        FBTRIGGER=10+respRew;
    elseif trial(task_struct.cRespAct) == trial(task_struct.cS2)
        % they picked stim 2
        respRew = trial(task_struct.cS2Rew);
        fbText = num2str(respRew);
        SIMPLEFB=0;
        FBTRIGGER=10+respRew;
    else
        % they responded too slow
        fbText = ['Too Slow!\nYou must respond in under ' num2str(task_struct.maxRT) ' seconds'];
        respRew = NaN;
        SIMPLEFB=1;
        FBTRIGGER=7;
    end
    
    if respRew==0
        Screen('TextSize', disp_struct.wPtr, 100);
        Screen('TextColor', disp_struct.wPtr, [255 0 0]);
    elseif  respRew==1
        Screen('TextSize', disp_struct.wPtr, 100);
        Screen('TextColor', disp_struct.wPtr, [0 255 0]);
    end
    
    
    % show the feedback
    if SIMPLEFB==1
        io64(ioObject,LTP1address,FBTRIGGER); WaitSecs(.05); io64(ioObject,LTP1address,0);
        DrawFormattedText(disp_struct.wPtr, fbText, 'center', 'center');
        Screen(disp_struct.wPtr, 'Flip');
        WaitSecs(0.75);
        Screen(disp_struct.wPtr, 'Flip');
    else
        % FIRST show the selected stim
        Screen('DrawTexture', disp_struct.wPtr, disp_struct.cards(trial(task_struct.cS1)), [], s1Rect);
        Screen('DrawTexture', disp_struct.wPtr, disp_struct.cards(trial(task_struct.cS2)), [], s2Rect);
        % Blank out the alternative
        if trial(task_struct.cRespAct) == respL
            Screen('FillRect', disp_struct.wPtr, [0 0 0], sR_rect);
        elseif trial(task_struct.cRespAct) == respR
            Screen('FillRect', disp_struct.wPtr, [0 0 0], sL_rect);
        end
        % If forced, show the box
        if trial(task_struct.cTrialCond) == task_struct.NC
            if trial(task_struct.cRespAct) == trial(task_struct.cS1)
                ncFrameRect = s1Rect;
            else
                ncFrameRect = s2Rect;
            end
            Screen('FrameRect', disp_struct.wPtr, [0 0 255], ncFrameRect, 5);
        end
        % Next show the FB
        io64(ioObject,LTP1address,FBTRIGGER); WaitSecs(.05); io64(ioObject,LTP1address,0);
        DrawFormattedText(disp_struct.wPtr, fbText, 'center', 'center');
        Screen(disp_struct.wPtr, 'Flip');
        WaitSecs(1.25);
        Screen(disp_struct.wPtr, 'Flip');
    end
    clear FBTRIGGER;
    Screen('TextSize', disp_struct.wPtr, 60);
    Screen('TextColor', disp_struct.wPtr, [255 255 255]);
    
    % store the feedback
    trial(task_struct.cRespRew) = respRew;
end
end % function