-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShowMsg.m
More file actions
339 lines (302 loc) · 13.9 KB
/
ShowMsg.m
File metadata and controls
339 lines (302 loc) · 13.9 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
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
function [wonTex lostTex] = ShowMsg(wPtr, imageDir, reward, punish, deck, ...
stimBoxParam, isRed, condition, stim, ...
stimIndex, myPort, modelCommID, ...
deckData, mORf, dPLength, rlPLength, sPLength)
slack = Screen('GetFlipInterval', wPtr)/2;
%Mark the deck that was selected w/ a green or red card (i.e., "flip"
%the card over)
deckColors = deckData(2:(size(deckData,2)));
mDeckTex = MarkSelectedDeck(wPtr, imageDir, deck, isRed, 1, myPort, modelCommID, deckColors, dPLength);
offset = 40;
offsetW = 80;
textX = stimBoxParam(1) + ((stimBoxParam(3)-stimBoxParam(1))*0.25);
textY = stimBoxParam(2) + ((stimBoxParam(4)-stimBoxParam(2))*0.5) - (offsetW*0.5);
stimRight = stimBoxParam(3);
stimBottom = stimBoxParam(4);
stimPosX = stimBoxParam(1);
stimPosY = stimBoxParam(2);
stimBoxParam = [stimPosX, stimPosY, stimRight, stimBottom];
[wonImg map wonAlpha] = imread(fullfile(imageDir, strcat('Won', num2str(reward),'.png')), 'PNG');
if( myPort == -1 )
rewLossStr = num2str(reward);
end
%Check whether we have Octave or Matlab as Octave imread parses image as MXNX2 matrix
%where one of the 3rd-dimension columns represents the image alpha
interpApp = ver('Octave');
if( isempty(interpApp) )
wonImg(:,:,4) = wonAlpha(:,:);
else
wonImg(:,:,2) = abs(255-wonImg(:,:,2));
end
wonTex = Screen('MakeTexture', wPtr, double(wonImg));
if (punish ~= 0)
[lostImg map lostAlpha] = imread(fullfile(imageDir, strcat('Lost', num2str(punish),'.png')), 'PNG');
interpApp = ver('Octave');
if (isempty(interpApp))
lostImg(:,:,4) = lostAlpha(:,:);
else
lostImg(:,:,2) = abs(255-lostImg(:,:,2));
end
lostTex = Screen('MakeTexture', wPtr, double(lostImg));
end
if (myPort == -1)6
rewLossStr = strcat(rewLossStr, '-', num2str(punish));
end
%msg_text2 = strcat('But lost: $', num2str(punish));
white = WhiteIndex(wPtr); % pixel value for white
black = BlackIndex(wPtr); % pixel value for black
gray = (white + black) / 2;
% Screen('TextFont', wPtr, char('sans-serif'));
stimBox = imread(fullfile(imageDir, 'rewBG.png'), 'PNG');
stimBox = rgb2gray(stimBox);
stimBoxTex = Screen('MakeTexture', wPtr, double(stimBox));
%%If the user selected from decks A or B, display images
if ( strcmpi(deck, 'a') || strcmpi(deck, 'A') || ...
strcmpi(deck, '1') || strcmpi(deck, '1!') || ...
strcmpi(deck, 'b') || strcmpi(deck, 'B') || ...
strcmpi(deck, '2') || strcmpi(deck, '2@') )
%stimBox = imread(stim{condition, stimIndex}, 'JPG');
%stimBoxTex = Screen('MakeTexture', wPtr, double(stimBox));
img = imread(stim{condition, stimIndex}, 'JPG');
img = rgb2gray(img);
stimTex = Screen('MakeTexture', wPtr, double(img));
Screen('DrawTextures', wPtr, stimTex, [], stimBoxParam');
if( myPort ~= -1 && myPort )
%Write to eye-tracker so we know this data should be associated
%with the Show Message Deck Function (before stim pres) 252
IOPort('Write', myPort, uint8(252));
elseif(exist('modelCommID', 'var') && ~isempty(modelCommID) && modelCommID ~= -1 && modelCommID)
stimImg = 'bowl';
%This should depend on which image is being shown (e.g., spider
%1, 2, 3; snake 1, 2, 3) & we'll update the stimBox Value
%(would be used in display message below) to reflect the
%stimulus
if( ~isempty(strfind(mORf, 'm')) )
switch( num2str(condition) )
case '1'
switch( stim{condition, stimIndex} )
case '1050.jpg'
stimImg = 'snake1';
case '1202.jpg'
stimImg = 'spider1';
case '1220.jpg'
stimImg = 'spider2';
case '1304.jpg'
stimImg = 'dog1';
case '1525.jpg'
stimImg = 'dog2';
end
case '2'
switch( stim{condition, stimIndex} )
case '1670.jpg'
stimImg = 'cow';
case '7006.jpg'
stimImg = 'bowl';
case '7010.jpg'
stimImg = 'basket';
case '7080.jpg'
stimImg = 'fork';
case '7175.jpg'
stimImg = 'lamp';
end
case '3'
switch( stim{condition, stimIndex} )
case '4180.jpg'
stimImg = 'girl1';
case '4210.jpg'
stimImg = 'girl2';
case '4232.jpg'
stimImg = 'girl3';
case '4664.jpg'
stimImg = 'girl4';
case '8501.jpg'
stimImg = 'money';
end
end
else
switch( num2str(condition) )
case '1'
switch( stim{condition, stimIndex} )
case '1050.jpg'
stimImg = 'snake1';
case '1120.jpg'
stimImg = 'snake2';
case '1201.jpg'
stimImg = 'spider1';
case '1202.jpg'
stimImg = 'spider2';
case '1525.jpg'
stimImg = 'dog1';
end
case '2'
switch( stim{condition, stimIndex} )
case '1670.jpg'
stimImg = 'cow';
case '7004.jpg'
stimImg = 'spoon';
case '7010.jpg'
stimImg = 'basket';
case '7012.jpg'
stimImg = 'rubber-bands';
case '7175.jpg'
stimImg = 'lamp';
end
case '3'
switch( stim{condition, stimIndex} )
case '4505.jpg'
stimImg = 'boy1';
case '4525.jpg'
stimImg = 'boy2';
case '4660.jpg'
stimImg = 'boy3';
case '8001.jpg'
stimImg = 'boy4';
case '8501.jpg'
stimImg = 'money';
end
end
end
if(~isempty(pnet(modelCommID, 'read', 'noblock', 'view')))
pnet(modelCommID, 'read', 'noblock');
SyncMsg(modelCommID);
end
deckParam = deckData{1};
UpdateDisplayMsg(modelCommID, deckParam, deckColors, ...
'IGT', 'false', [], {stimBoxParam, stimImg});
%StimBoxMsg(modelCommID, stimBoxParam, 'bowl', 'IGT');
WaitProcDisplay(modelCommID);
end
[flip1B sOT tE] = Screen('Flip', wPtr, [], 1);
%Used for timing testing
%flip1E = tE - flip1B;
else
%Write to eye-tracker so we know this data should be associated
%with the Show Message Deck Function (before stim pres) 252
if( myPort ~= -1 && myPort )
IOPort('Write', myPort, uint8(252));
end
%startStimTime = GetSecs();
Screen('FillRect', wPtr, [gray gray gray], stimBoxParam');
[flip1B sOT tE] = Screen('Flip', wPtr, [], 1);
%flip1E = tE - flip1B;
end
%%Wait the user specified stimulus presentation length if the
%%experiment isn't a model simulation
if(1)%(~exist('modelCommID', 'var') || modelCommID == -1) && exist('sPLength', 'var') )
%toc
%WaitSecs();
%toc
%format long
Screen('TextFont', wPtr, char('Helvetica'));
Screen('TextStyle', wPtr, 1);
Screen('TextSize', wPtr, 30);
Screen('DrawTextures', wPtr, stimBoxTex, [], stimBoxParam');
Screen('DrawTextures', wPtr, wonTex, [], [textX textY-94 textX+250, textY+94]);
if (punish ~= 0)
Screen('DrawTextures', wPtr, lostTex, [], [textX textY textX+250, textY+188]);
end
%flip2B = GetSecs();
[flip2B sOT t2E] = Screen('Flip', wPtr, tE+sPLength-slack, 1);
%Used for timing testing
%flip2E = t2E - flip2B;
%flipTE = GetSecs() - tE;
elseif(exist('modelCommID', 'var') && ~isempty(modelCommID) && modelCommID ~= -1 )
TimeMsg(modelCommID);
modelMsg = pnet(modelCommID, 'read', 'noblock');
while(isempty(strfind(modelMsg, 'set-mp-time')))
if(~isempty(modelMsg))
SyncMsg(modelCommID);
end
modelMsg = pnet(modelCommID, 'read', 'noblock');
end
SyncMsg(modelCommID);
startTime = ConvertJSONTime(modelMsg);
WaitJSON(modelCommID, modelMsg, startTime, sPLength);
if(~isempty(pnet(modelCommID, 'read', 'noblock', 'view')))
pnet(modelCommID, 'read', 'noblock')
SyncMsg(modelCommID);
end
deckParam = deckData{1};
UpdateDisplayMsg(modelCommID, deckParam, deckColors, ...
'IGT', 'false', [], {stimBoxParam, 'bowl'});
%StimBoxMsg(modelCommID, stimBoxParam, 'bowl', 'IGT');
WaitProcDisplay(modelCommID);
disp('Message Displayed');
Screen('TextFont', wPtr, char('Helvetica'));
Screen('TextStyle', wPtr, 1);
Screen('TextSize', wPtr, 30);
%Keep the stim box the same if use has not selected from decks A or B
Screen('DrawTextures', wPtr, stimBoxTex, [], stimBoxParam');
Screen('DrawTextures', wPtr, wonTex, [], [textX textY-94 textX+250, textY+94]);
if (punish ~= 0)
Screen('DrawTextures', wPtr, lostTex, [], [textX textY textX+250, textY+188]);
end
end
%Keep the stim box the same if use has not selected from decks A or B
Screen('DrawTextures', wPtr, stimBoxTex, [], stimBoxParam');
Screen('DrawTextures', wPtr, wonTex, [], [textX textY-94 textX+250, textY+94]);
if (punish ~= 0)
Screen('DrawTextures', wPtr, lostTex, [], [textX textY textX+250, textY+188]);
end
if( myPort ~= -1 && myPort )
%Write to eye-tracker so we know this data should be associated
%with the Show RewLoss Function 253
IOPort('Write', myPort, uint8(253));
elseif(exist('modelCommID', 'var') && ~isempty(modelCommID) && modelCommID ~= -1 )
rewParam = [textX textY-94 textX+250, textY+94];
if (punish ~= 0)
lossParam = [textX textY textX+250, textY+188];
else
lossParam = [];
end
if(~isempty(pnet(modelCommID, 'read', 'noblock', 'view')))
pnet(modelCommID, 'read', 'noblock')
SyncMsg(modelCommID);
end
deckParam = deckData{1};
deckColors = [deckData(2) deckData(3) deckData(4) deckData(5)];
num2str(punish)
UpdateDisplayMsg(modelCommID, deckParam, deckColors, ...
'IGT', 'false', [], {stimBoxParam, 'bowl'}, {rewParam, ...
num2str(reward), lossParam, num2str(punish)});
WaitProcDisplay(modelCommID);
disp('Reward Loss');
end
if( ~exist('modelCommID', 'var') || modelCommID == -1 )
WaitSecs(rlPLength);
elseif(exist('modelCommID', 'var') && ~isempty(modelCommID) && modelCommID ~= -1 )
TimeMsg(modelCommID);
modelMsg = pnet(modelCommID, 'read', 'noblock');
while(isempty(strfind(modelMsg, 'set-mp-time')))
if(~isempty(modelMsg))
SyncMsg(modelCommID);
end
modelMsg = pnet(modelCommID, 'read', 'noblock');
end
startTime = ConvertJSONTime(modelMsg);
WaitJSON(modelCommID, modelMsg, startTime, rlPLength);
if(~isempty(pnet(modelCommID, 'read', 'noblock', 'view')))
pnet(modelCommID, 'read', 'noblock');
SyncMsg(modelCommID);
end
deckParam = deckData{1};
deckColors = [deckData(2) deckData(3) deckData(4) deckData(5)];
UpdateDisplayMsg(modelCommID, deckParam, deckColors, ...
'IGT', 'false', [], {stimBoxParam, 'bowl'});
WaitProcDisplay(modelCommID);
disp('Bowl');
end
%%used to test timing, not needed normally
%timeTestFile = fopen('timeTest.txt', 'a');
%fprintf(timeTestFile, '%f\t%f\t%f\n', flip1E, flip2E, flipTE);
%fclose(timeTestFile);
if( exist('stimTex', 'var') )
Screen('Close', stimTex);
end
if( exist('lostTex', 'var') )
Screen('Close', lostTex);
end
Screen('Close', wonTex);
Screen('Close', stimBoxTex);
Screen('Close', mDeckTex);
end