Browse Source

Making the stop buttons actually work, cleaning code a little. -MT

master
Michael Tan 6 years ago
parent
commit
760da61da5
  1. 1
      002 After Image GUI Project/.gitignore
  2. 39
      002 After Image GUI Project/AfIm_Exp_Rivalry.m
  3. 167
      002 After Image GUI Project/Disp_Color_Rivalry.m~
  4. 158
      002 After Image GUI Project/HFP_session.m
  5. BIN
      002 After Image GUI Project/TVP_GENERATOR.mlapp

1
002 After Image GUI Project/.gitignore vendored

@ -1 +1,2 @@ @@ -1 +1,2 @@
/Program\ Compiled/
*~

39
002 After Image GUI Project/AfIm_Exp_Rivalry.m

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
function AfIm_Exp_Rivalry(subName,meanLum,Bckg_Chro,axis_chck,AdaptTime,nRep,Simu_chck)
function AfIm_Exp_Rivalry(subName,meanLum,Bckg_Chro,axis_chck,AdaptTime,nRep,Simu_chck,shouldCancel)
try
assignin('base','Stop_Press',0)% this works for the STOP experiment button
@ -209,7 +209,9 @@ try @@ -209,7 +209,9 @@ try
for iChro = 1:size(Bckg_Chro,1)
if shouldCancel
return;
end
wLMS(1,1) = Bckg_Chro(iChro,1)*meanLum;
wLMS(1,2) = (1-Bckg_Chro(iChro,1))*meanLum;
@ -224,6 +226,10 @@ try @@ -224,6 +226,10 @@ try
Speak(' Press any key when you are ready');
KbStrokeWait;
if shouldCancel
return;
end
Screen('FillRect', window, wRGB);
Screen('Flip',window)
@ -231,9 +237,14 @@ try @@ -231,9 +237,14 @@ try
WaitSecs(AdaptTime)
for iRep = 1:nRep
if shouldCancel
return;
end
cont = randperm(nCont); %randomize contrast conditions
for iCont = 1:nCont
if shouldCancel
return;
end
FlushEvents('mouseDown','keyDown');
%create colors with depending on contrast
@ -351,6 +362,9 @@ try @@ -351,6 +362,9 @@ try
%ListenChar(2)
secs0 = Screen('Flip', window);
for iFrames = 1:nFrames
if shouldCancel
return;
end
Screen('FillArc', window, rampLeft(iFrames,:), tstCircleLeft, 0, 180);
Screen('FillArc', window, rampRight(iFrames,:), tstCircleRight, 180, 180);
Screen('DrawDots', window, clockPosMat,clockPix, blackLut, [lftXCircleCenter,center(2)], 2);
@ -405,8 +419,13 @@ try @@ -405,8 +419,13 @@ try
if Simu_chck
userRes = 'simu';
if shouldCancel
return;
end
else
if shouldCancel
return;
end
keyIsDown=0;
kbName=[];
Digit = 0;
@ -415,7 +434,9 @@ try @@ -415,7 +434,9 @@ try
Screen('TextSize', window, 30);
commandwindow;
while keyIsDown==0 || (strcmp('ENTER',kbName)==0)% & strcmp('2',kbName)==0)
if shouldCancel
return;
end
%keyIsDown=0;
[keyIsDown, ~, keyCode] = KbCheck;
@ -484,6 +505,10 @@ try @@ -484,6 +505,10 @@ try
WaitSecs(.2)
if shouldCancel
return;
end
theDate = datestr(now(),'mm/dd/yyyy HH:MM:SS');
fprintf(fp, '%s\t%s\t%1.3f\t%1.3f\t%1.3f\t%1.3f\t%i\t%i\t%i\t%i\t%s\tExperiment\n',...
subName, theDate, hfpRG, hfpBG, Bckg_Chro(iChro,1), Bckg_Chro(iChro,2), cont(iCont), curr_axis(iCond), Card_Dir, randStrt+5, userRes);
@ -515,6 +540,9 @@ try @@ -515,6 +540,9 @@ try
return
end
if shouldCancel
return;
end
end %ICond
end %iCont
@ -529,6 +557,7 @@ try @@ -529,6 +557,7 @@ try
% % % % piVSsecs(:,2) = [0:numSecs/(nFrames-1):numSecs];
catch ME
warndlg('The program failed to run. Try again.')
sca
rethrow(ME);
end

167
002 After Image GUI Project/Disp_Color_Rivalry.m~

@ -1,167 +0,0 @@ @@ -1,167 +0,0 @@
function Disp_Color_Rivalry(l_value,s_value,hfpRG,hfpBG)
commandwindow; % open this, and the cursor will appear in the command window
% %% Choose program
% EEW_StdObsANDSubj = 0;
% EEW_Subj = 1;
%%
% Check that Psychtoolbox is properly installed, and switch color range to normalized 0 - 1 range:
PsychDefaultSetup(2);
%% Start Experiment
%a = cd;
theDate = fix(clock);
% subName = 'DC'%input(sprintf('\nEnter Subject Initials: '))
duration= 5; % sec
% %% Color information, load hfp data and color calibration
%
% aa = cd('/Users/clemente/Dropbox/Luminotecnia/2017/Chicago Lab files/2 Experiments/Color AfterImage_Exp_Room_150/2nd/1 Programs/A Outputs');
% hfpFile = sprintf('%sHFP', subName);
% load(hfpFile, '-mat')
% hfpRG = rg_avg;
% hfpBG = bg_avg;
% hfpRG = .89;
% hfpBG = .97 ;
%%
%cd(a); % return to folder where the program is
Calib_Dire = cd('/Users/mike/Documents/AfterimageOutputs');
load colorCalFile1.mat
fprintf('\nLast calibrationS was %s\n', describe.date);
pix = pix/1001;
maxLum = 20; %cd/m^2
l_s_pair = [l_value s_value];
blackLut = [0 0 0];
redLut = [.8 0 0];
%% set up psych toolbox
%set up 10 bit color
PsychImaging('PrepareConfiguration');
%PsychImaging('AddTask', 'General', 'EnableNative10BitFrameBuffer',1); %the 0 is turn off dithering?
expScreen = 1;
%create white LUT
wLMS(1,1) = .665*maxLum;%l_s_pair(1,1)*maxLum;
wLMS(1,2) = (1-.665)*maxLum;%(1-l_s_pair(1,1))*maxLum;
wLMS(1,3) = 1*maxLum;%l_s_pair(1,2)*maxLum;
wXYZ(1,:) = LMS_to_XYZ(wLMS(1,:));
wRGB(1,:) = XYZ_to_RGB(wXYZ(1,:), maxPhosXYZ);
wRGB(1,1) = pix(dsearchn(redProp(:), wRGB(1,1)))%*hfpRG;
wRGB(1,2) = pix(dsearchn(grnProp(:), wRGB(1,2)));
wRGB(1,3) = pix(dsearchn(blueProp(:), wRGB(1,3)))%*hfpBG;
[window, windowRect] = PsychImaging('OpenWindow', expScreen, [0 0 0]); %EEW for standard observer
[xWinSize,~] = Screen('WindowSize',window);
[xcent,ycent] = RectCenter(windowRect);
center = [xcent ycent];
%% Stimulus Size Parameters
circleDeg = 3.6;
clockPt = 0.1;
% code assumes 1 pixel = 1 arc min
pixPerDeg = 36; %at a distance of 57 cm
circlePix = circleDeg*pixPerDeg
clockPix = clockPt*pixPerDeg;
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%% CIRCLE HALf LOCATIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%tstcircle = [xcent - circlePix/2 ycent - circlePix/2 xcent + circlePix/2 ycent + circlePix/2];
rhtXCircleCenter = xWinSize/4;
lftXCircleCenter = xWinSize-xWinSize/4;
tstCircleLeft = [lftXCircleCenter - circlePix/2 ycent - circlePix/2 lftXCircleCenter + circlePix/2 ycent + circlePix/2];
tstCircleRight = [rhtXCircleCenter - circlePix/2 ycent - circlePix/2 rhtXCircleCenter + circlePix/2 ycent + circlePix/2];
%create circular grid for clock face and the numbers
% % % circleDegGrid = 2 ;
% % % rad = circleDegGrid/2*pixPerDeg; %circlePix/2-pixPerDeg/2;
rad = circleDeg/2*pixPerDeg; %circlePix/2-pixPerDeg/2;
radNum = (circleDeg/2) * pixPerDeg;
degreeNumbers = linspace(0,360,25);
clockDegs = degreeNumbers(1:end-1); %[1:15:360];
clockDegsLft = [90:15:269];
clockDegsRht = [270:15:359,0:15:89];
for iC = 1:length(clockDegs)
[xcFace(iC), ycFace(iC)] = pol2cart(clockDegs(iC)*pi/180, rad);
[xcNumber(iC), ycNumber(iC)] = pol2cart(clockDegs(iC)*pi/180, 1*radNum);
end
for iC = 1:length(clockDegsLft)
[xcRhtFace(iC), ycRhtFace(iC)] = pol2cart(clockDegsLft(iC)*pi/180, rad);
[xcRhtNumber(iC), ycRhtNumber(iC)] = pol2cart(clockDegsLft(iC)*pi/180, 1*radNum);
end
for iC = 1:length(clockDegsRht)
[xcLftFace(iC), ycLftFace(iC)] = pol2cart(clockDegsRht(iC)*pi/180, rad);
[xcLftNumber(iC), ycLftNumber(iC)] = pol2cart(clockDegsRht(iC)*pi/180, 1*radNum);
end
%create matrix of dot locations
clockPosMat = [reshape(xcFace,1, length(clockDegs)); reshape(ycFace,1, length(clockDegs))];
%clockNumMat = [reshape(xcNumber,1, length(clockDegs)); reshape(ycNumber,1, length(clockDegs))];
%clockRhtPosMat = [reshape(xcRhtFace,1, length(clockDegsRht)); reshape(ycRhtFace,1, length(clockDegsRht))];
clockRhtNumMat = [reshape(xcRhtNumber,1, length(clockDegsRht)); reshape(ycRhtNumber,1, length(clockDegsRht))];
%clockLftPosMat = [reshape(xcLftFace,1, length(clockDegsLft)); reshape(ycLftFace,1, length(clockDegsLft))];
clockLftNumMat = [reshape(xcLftNumber,1, length(clockDegsLft)); reshape(ycLftNumber,1, length(clockDegsLft))];
%%
Screen('FillRect', window, [0 0 0], windowRect);% dark screen
Screen('Flip', window);
WaitSecs(1)
Screen('FillRect', window, wRGB.*2);
Screen('Flip',window)
% % if EEW_StdObsANDSubj
% Screen('FillOval', window, wRGB, centeredRect, maxDiameter); % Draw the rect to the screen
% Screen('Flip', window);
% WaitSecs(duration)
%
% % end
% if EEW_Subj
wRGB(1,1) = wRGB(1,1)*hfpRG;
wRGB(1,2) = wRGB(1,2);
wRGB(1,3) = wRGB(1,3)*hfpBG;
%
%Screen('FillOval', window, wRGB, centeredRect, maxDiameter); % Draw the rect to the screen
% Screen('FillOval', window, wRGB, centeredRect1, maxDiameter); % Draw the rect to the screen
% Screen('FillOval', window, wRGB, centeredRect2, maxDiameter); % Draw the rect to the screen
Screen('FillArc', window, wRGB, tstCircleLeft, 0, 180);
Screen('FillArc', window, wRGB.*1.5 , tstCircleRight, 180, 180);
Screen('DrawDots', window, clockPosMat,clockPix, blackLut, [lftXCircleCenter,center(2)], 2);
Screen('DrawDots', window, clockPosMat,clockPix, blackLut, [rhtXCircleCenter,center(2)], 2);
Screen('DrawDots', window, [0 0],clockPix, 0, [lftXCircleCenter,center(2)], 2); % black dot for fixation
Screen('DrawDots', window, [0 0],clockPix, 0, [rhtXCircleCenter,center(2)], 2); % black dot for fixation
textOne = [12:24,1:11];
scl = 1.35;
for itxt = 1:12
textNum = num2str(textOne(itxt));
Screen('DrawText', window, textNum, scl*clockRhtNumMat(1,itxt)+rhtXCircleCenter-7, scl*clockRhtNumMat(2,itxt)+center(1,2)-14, blackLut, wRGB);
textNum = num2str(textOne(itxt+12));
Screen('DrawText', window, textNum, .9*scl*clockLftNumMat(1,itxt)+lftXCircleCenter-7, .9*scl*clockLftNumMat(2,itxt)+center(1,2)-14, blackLut, wRGB);
end
Screen('Flip', window);
% WaitSecs(duration)
KbWait();
%
% end
% KbStrokeWait;
Screen('CloseAll')
end

158
002 After Image GUI Project/HFP_session.m

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
function HFP_session(subName,curr_cond, calibDir)
function HFP_session(subName,curr_cond, calibDir, shouldCancel)
% HFP Code for Elliott Lab
% Written by SLE 3/24/17
@ -40,19 +40,19 @@ stepSize = 4; @@ -40,19 +40,19 @@ stepSize = 4;
name = sprintf('%sHFP.mat', subName);
if exist(name, 'file') == 2
load(name)
load(name)
% bg = [];
% rg = [];
% br = [];
% br_check = [];
% bg = [];
% rg = [];
% br = [];
% br_check = [];
else
Prev_bg = []; bg = [];
Prev_rg = []; rg = [];
Prev_br = []; br = [];
Prev_brcheck = []; br_check = [];
Prev_bg = []; bg = [];
Prev_rg = []; rg = [];
Prev_br = []; br = [];
Prev_brcheck = []; br_check = [];
end
@ -85,11 +85,11 @@ tstcircle = [xcent - circlePix/2 ycent - circlePix/2 xcent + circlePix/2 ycent + @@ -85,11 +85,11 @@ tstcircle = [xcent - circlePix/2 ycent - circlePix/2 xcent + circlePix/2 ycent +
%run experiment
Priority(topPriorityLevel);
% for iRepeat = 1:numRep
stim_order = [1 1 1 2 2 2 3 3 3];%randperm(3);
keypress = 0;
%Speak('Setting %i', iRepeat)
commandwindow;
for j = 1:9
stim_order = [1 1 1 2 2 2 3 3 3];%randperm(3);
keypress = 0;
%Speak('Setting %i', iRepeat)
commandwindow;
for j = 1:9
vbl = Screen('Flip', window);
switch stim_order(j)
@ -108,23 +108,27 @@ Priority(topPriorityLevel); @@ -108,23 +108,27 @@ Priority(topPriorityLevel);
end
%ListenChar(2);
% % % % BeginMatch = 0;
% Speak('press start to begin')
% % % % while ~BeginMatch %wait for initial key press
% % % % if(CharAvail) % check for keypress, record if key=4
% % % % [char] = GetChar;
% % % % if char =='8'
% % % % BeginMatch = 1;
% % % % end
% % % % FlushEvents('keyDown');
% % % % end
% % % % end
% % % % BeginMatch = 0;
% Speak('press start to begin')
% % % % while ~BeginMatch %wait for initial key press
% % % % if(CharAvail) % check for keypress, record if key=4
% % % % [char] = GetChar;
% % % % if char =='8'
% % % % BeginMatch = 1;
% % % % end
% % % % FlushEvents('keyDown');
% % % % end
% % % % end
FlushEvents('keyDown');
%Speak('Next Session')
DoneMatch = 0;
count = 0; %count the number of frames
while ~DoneMatch %look for key presses and put up stimulus
if shouldCancel
fprintf('Cancel 1\n\n');
return;
end
[ keyIsDown, timeSecs, keyCode ] = KbCheck;
if(CharAvail) % check for keypress, record if key=1 or 2 or 3
[char] = GetChar;
@ -142,7 +146,7 @@ Priority(topPriorityLevel); @@ -142,7 +146,7 @@ Priority(topPriorityLevel);
case '6'
switch stim_order(j)
case 1 %RG
current_RED = current_RED + stepSize
current_RED = current_RED + stepSize;
if current_RED > 1001
beep%Speak('setting limit');
current_RED = 1001;
@ -150,7 +154,7 @@ Priority(topPriorityLevel); @@ -150,7 +154,7 @@ Priority(topPriorityLevel);
colClut_one = [pixDec(current_RED) 0 0];
colClut_two = [0 pixDec(initial_GREEN) 0];
case 2 %BG
current_BLUE = current_BLUE + stepSize
current_BLUE = current_BLUE + stepSize;
if current_BLUE > 1001
beep%Speak('setting limit');
current_BLUE = 1001;
@ -158,7 +162,7 @@ Priority(topPriorityLevel); @@ -158,7 +162,7 @@ Priority(topPriorityLevel);
colClut_one = [0 0 pixDec(current_BLUE)];
colClut_two = [0 pixDec(initial_GREEN) 0];
case 3 %BR
current_RED = current_RED + stepSize
current_RED = current_RED + stepSize;
if current_RED > 1001
beep%Speak('setting limit');
current_RED = 1001;
@ -170,7 +174,7 @@ Priority(topPriorityLevel); @@ -170,7 +174,7 @@ Priority(topPriorityLevel);
case '9'
switch stim_order(j)
case 1 %RG
current_RED = current_RED + stepSize/4
current_RED = current_RED + stepSize/4;
if current_RED > 1001
beep%Speak('setting limit');
current_RED = 1001;
@ -178,7 +182,7 @@ Priority(topPriorityLevel); @@ -178,7 +182,7 @@ Priority(topPriorityLevel);
colClut_one = [pixDec(current_RED) 0 0];
colClut_two = [0 pixDec(initial_GREEN) 0];
case 2 %BG
current_BLUE = current_BLUE + stepSize/4
current_BLUE = current_BLUE + stepSize/4;
if current_BLUE > 1001
beep%Speak('setting limit');
current_BLUE = 1001;
@ -186,7 +190,7 @@ Priority(topPriorityLevel); @@ -186,7 +190,7 @@ Priority(topPriorityLevel);
colClut_one = [0 0 pixDec(current_BLUE)];
colClut_two = [0 pixDec(initial_GREEN) 0];
case 3 %BR
current_RED = current_RED + stepSize/4
current_RED = current_RED + stepSize/4;
if current_RED > 1001
beep%Speak('setting limit');
current_RED = 1001;
@ -197,29 +201,29 @@ Priority(topPriorityLevel); @@ -197,29 +201,29 @@ Priority(topPriorityLevel);
case '4'
switch stim_order(j)
case 1 %RG
current_RED = current_RED - stepSize
current_RED = current_RED - stepSize;
if current_RED <= 1
beep%speak('setting limit');
current_RED = 1;
% else
% else
end
colClut_one = [pixDec(current_RED) 0 0];
colClut_two = [0 pixDec(initial_GREEN) 0];
case 2 %BG
current_BLUE = current_BLUE - stepSize
current_BLUE = current_BLUE - stepSize;
if current_BLUE <= 1
beep%speak('setting limit')
current_BLUE = 1;
% else
% else
end
colClut_one = [0 0 pixDec(current_BLUE)];
colClut_two = [0 pixDec(initial_GREEN) 0];
case 3 %BR
current_RED = current_RED - stepSize
current_RED = current_RED - stepSize;
if current_RED <= 1
beep%speak('setting limit')
current_RED = 1;
% else
% else
end
colClut_one = [0 0 pixDec(initial_BLUE)];
colClut_two = [pixDec(current_RED) 0 0];
@ -227,49 +231,97 @@ Priority(topPriorityLevel); @@ -227,49 +231,97 @@ Priority(topPriorityLevel);
case '7'
switch stim_order(j)
case 1 %RG
current_RED = current_RED - stepSize/4
current_RED = current_RED - stepSize/4;
if current_RED <= 1
beep%speak('setting limit');
current_RED = 1;
% else
end
colClut_one = [pixDec(current_RED) 0 0];
colClut_two = [0 pixDec(initial_GREEN) 0];
case 2 %BG
current_BLUE = current_BLUE - stepSize/4;
if current_BLUE <= 1
beep%speak('setting limit')
current_BLUE = 1;
% else
end
colClut_one = [0 0 pixDec(current_BLUE)];
colClut_two = [0 pixDec(initial_GREEN) 0];
case 3 %BR
current_RED = current_RED - stepSize/4;
if current_RED <= 1
beep%speak('setting limit')
current_RED = 1;
% else
end
colClut_one = [0 0 pixDec(initial_BLUE)];
colClut_two = [pixDec(current_RED) 0 0];
end
case '2'
switch stim_order(j)
case 1 %RG
current_RED = initial_RED;
if current_RED <= 1
beep%speak('setting limit');
current_RED = 1;
% else
% else
end
colClut_one = [pixDec(current_RED) 0 0];
colClut_two = [0 pixDec(initial_GREEN) 0];
case 2 %BG
current_BLUE = current_BLUE - stepSize/4
current_BLUE = initial_BLUE;
if current_BLUE <= 1
beep%speak('setting limit')
current_BLUE = 1;
% else
% else
end
colClut_one = [0 0 pixDec(current_BLUE)];
colClut_two = [0 pixDec(initial_GREEN) 0];
case 3 %BR
current_RED = current_RED - stepSize/4
current_RED = initial_RED;
if current_RED <= 1
beep%speak('setting limit')
current_RED = 1;
% else
% else
end
colClut_one = [0 0 pixDec(initial_BLUE)];
colClut_two = [pixDec(current_RED) 0 0];
end
end
FlushEvents('keyDown');
if stim_order(j)==1 || stim_order(j)==3
fprintf('Red: %d\n',current_RED);
else
fprintf('Blue: %d\n', current_BLUE);
end
end
if shouldCancel==1
fprintf('Cancel 2\n\n');
return;
end
Screen('FillOval', window, colClut_one, tstcircle);
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
Screen('FillOval', window, colClut_two, tstcircle);
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
end %while done
if shouldCancel
fprintf('Cancel 3\n\n');
return;
end
Screen('FillOval', window, [0 0 0], windowRect);
Screen('Flip', window);
pause(1);
end %for j
end %for j
for irep = 1:3
if shouldCancel
fprintf('Cancel 4\n\n');
return;
end
for irep = 1:3
br_check(irep) = bg(irep)/rg(irep);
end
end
% end %i
Priority(0)
%ListenChar(0);
@ -286,13 +338,13 @@ Prev_br = [Prev_br ; br]; @@ -286,13 +338,13 @@ Prev_br = [Prev_br ; br];
Prev_brcheck = [Prev_brcheck ; br_check];
if ge(size(Prev_bg,1),3);
rg_avg = median(reshape(Prev_rg(end-2:end,2:3),6,1));
bg_avg = median(reshape(Prev_bg(end-2:end,2:3),6,1));
rb_avg = median(reshape(Prev_br(end-2:end,2:3),6,1));
rg_avg = median(reshape(Prev_rg(end-2:end,2:3),6,1));
bg_avg = median(reshape(Prev_bg(end-2:end,2:3),6,1));
rb_avg = median(reshape(Prev_br(end-2:end,2:3),6,1));
else
rg_avg = [];
bg_avg = [];
rb_avg = [];
rg_avg = [];
bg_avg = [];
rb_avg = [];
end
% Save to mat file

BIN
002 After Image GUI Project/TVP_GENERATOR.mlapp

Binary file not shown.
Loading…
Cancel
Save