Skip to content

Commit

Permalink
separate Trigger class, fixation on top of all
Browse files Browse the repository at this point in the history
* 5 grating degrees instead of 3
* GenScreenSetup at beginning of script again
  • Loading branch information
mschrimpf committed Jul 31, 2016
1 parent c0fbbc0 commit 3398a27
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 146 deletions.
13 changes: 6 additions & 7 deletions experiment/AwaitGoodFixation.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
function [exp_params, hadToRecalibrate] = AwaitGoodFixation(exp_params, ...
window, windowRect, ...
fixationScreen, fixationSourceRect, fixationDestRect,...
drawFixation, fixationDestRect,...
getKeyInput)
%AWAITGOODFIXATION wait for good fixation and recalibrate if necessary
goodFixation = false;
hadToRecalibrate = false;
while(~goodFixation)
goodFixation = fixationPoint(window, fixationScreen, ...
fixationSourceRect, fixationDestRect, ...
goodFixation = fixationPoint(drawFixation, ...
fixationDestRect, ...
exp_params.fixation_threshold, exp_params.fixation_time, ...
exp_params.fixation_timeout);

Expand Down Expand Up @@ -50,11 +50,10 @@
end
end

function resultcode = fixationPoint(window, fixationScreen, ...
fixationSourceRect, fixationDestRect, ...
function resultcode = fixationPoint(drawFixation, ...
fixationDestRect, ...
fixAccuracy, fixTime, timeout)
Screen('DrawTexture',window,fixationScreen, fixationSourceRect, fixationDestRect);
Screen('flip',window);
drawFixation();
fixOnTime = GetSecs;
fixX = (fixationDestRect(1) + fixationDestRect(3)) / 2;
fixY = (fixationDestRect(2) + fixationDestRect(4)) / 2;
Expand Down
15 changes: 15 additions & 0 deletions experiment/DummyTrigger.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
classdef DummyTrigger
methods
function deviceIndex = initializeTrigger(~)
fprintf('Initializing DummyTrigger\n');
deviceIndex = -1;
end

function sendTriggers(~, deviceIndex, numTriggers, ...
trigger_duration, trigger_interval)
fprintf('Sending %d triggers on device %d with duration %d and interval %d\n', ...
numTriggers, deviceIndex, trigger_duration, trigger_interval);
end
end
end

3 changes: 2 additions & 1 deletion experiment/GenScreenSetup.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@
ScrVars.Fixation = CenterRectOnPoint (ScrVars.FixRect, ScrVars.x_center, ScrVars.y_center);
ScrVars.FixationBig = CenterRectOnPoint (ScrVars.FixRectBig, ScrVars.x_center, ScrVars.y_center);

%[ScrVars.ScreenGeo] = SkyraScreenGeometry;
Screen('CloseAll');
WaitSecs(1);
31 changes: 31 additions & 0 deletions experiment/Trigger.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
classdef Trigger
methods
function deviceIndex = initializeTrigger(~)
% initialize PMD1208FS
device=initPMD1208FS;
if isnumeric(device) && device<0
error('Trigger device not found');
else
device=device.index;
err=DaqDConfigPort(device,0,0); % port = 0 direction = 0
FastDaqDout=inline('PsychHID(''SetReport'', device, 2, hex2dec(''04''), uint8([0 port data]))','device', 'port', 'data');
end
deviceIndex = DaqDeviceIndex;
DaqDConfigPort(deviceIndex,0,0);
DaqDOut(deviceIndex,0,0);
end

function sendTriggers(~, deviceIndex, numTriggers, ...
trigger_duration, trigger_interval)
for i=1:numTriggers
DaqDOut(deviceIndex,0,1);
WaitSecs(trigger_duration);
DaqDOut(deviceIndex,0,0);
if i<numTriggers
WaitSecs(trigger_interval-trigger_duration);
end
end
end
end
end

60 changes: 60 additions & 0 deletions experiment/centerFixation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
function centerFixation(w, pattern, sz, color, lineWidth)

% Usage: centerFixation (windowPtr, patternOrStr, fixationOrTextSize, color, lineWidth)
%
% Draws a fixation point or text in the center of the screen.
%
% Inputs: Pattern - If pattern is a string, it will be displayed.
% Otherwise:
% 1 - circle
% 2 - square
% 3 - + (default)
% 4 - x
% fixationOrTextSize - figure it out
% color - index of CLUT, scalar or triplet.
% lineWidth - use only if pattern is 3 or 4
%
% Created by XRL, 09/01/2005

if (nargin<1)
windowPtrs=Screen('Windows');
if isempty(windowPtrs) | (Screen('WindowKind',windowPtrs(1)) ~=1); % is not onscreen
w =Screen('OpenWindow',1,0);
else, error('On screen window not found');
end
end
if (nargin<2); pattern=3; end
if (nargin<3); sz=12; end
if (nargin<4); color=Screen('TextColor',w); end
if (nargin<5); lineWidth=1; end
rect =Screen('Rect',w);
if ischar(pattern)
if (nargin<3), sz=Screen('TextSize',w); end
oldSize=Screen('TextSize',w,sz);
xx = round(rect(3)/2-RectWidth(Screen('TextBounds',w,pattern))/2);
yy = round(rect(4)/2-sz*0.71);
Screen('DrawText',w,pattern,xx,yy, color);
Screen('TextSize',w,oldSize);
return;
end

xc = rect(3)/2; yc = rect(4)/2;
rect=CenterRect([xc-sz/2 yc-sz/2 xc+sz/2 yc+sz/2], rect);
switch pattern
case 1 %circle
Screen('FillOval', w,color, rect);
case 2 % square
Screen('FillRect',w, color, rect);
case 3 % +
sz=floor((sz+mod(lineWidth+sz,2))/2);% for symmetry when using small fixation
% s01=mod(lineWidth,2); ss01=mod(lineWidth+1,2);
Screen('DrawLine',w, color, xc-sz, yc, xc+sz, yc, lineWidth);
Screen('DrawLine',w, color, xc, yc-sz, xc, yc+sz, lineWidth);
% Screen('DrawLine',w, color, xc-sz-ss01, yc, xc+sz+s01, yc, lineWidth);
% Screen('DrawLine',w, color, xc, yc-sz-ss01, xc, yc+sz+s01, lineWidth);
case 4 % x
% sz=sz/2;
sz=floor((sz+mod(lineWidth+sz,2))/2/1.4);% for symmetry when using small fixation
Screen('DrawLine',w, color, xc-sz, yc-sz, xc+sz, yc+sz, lineWidth*1.4);
Screen('DrawLine',w, color, xc-sz, yc+sz, xc+sz, yc-sz, lineWidth*1.4);
end
4 changes: 2 additions & 2 deletions experiment/createGratingImage.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
background, foreground)
pixels = round(targetDegrees / degreesPerPixel);
gratingImage = background * ones(pixels, pixels);
numBars = 5;
gratingWidth = (targetDegrees / numBars) / degreesPerPixel;
numBars = 4;
gratingWidth = round((targetDegrees / numBars) / degreesPerPixel);
for x = 1:gratingWidth * 2:pixels
gratingImage(:, x:x + gratingWidth) = foreground;
end
Expand Down
Loading

0 comments on commit 3398a27

Please sign in to comment.