Skip to content

Commit 8e046e1

Browse files
committed
update functions to new cfg
1 parent 4d4642c commit 8e046e1

File tree

6 files changed

+37
-64
lines changed

6 files changed

+37
-64
lines changed

computeFOV.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function FOV = computeFOV(cfg)
2+
% FOV = computeFOV(cfg)
3+
% computes the number of degrees of visual angle in the whole field of view
4+
%
5+
6+
FOV = 2 * (180 * (atan(cfg.monitorWidth / (2 * cfg.screenDistance)) / pi));
7+
8+
end

degToPix.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
deg = getfield(structure, fieldName); %#ok<GFLD>
77

88
structure = setfield(structure, [fieldName 'Pix'], ...
9-
floor(cfg.ppd * deg)) ; %#ok<SFLD>
9+
floor(cfg.screen.ppd * deg)) ; %#ok<SFLD>
1010

1111
end

drawFixationCross.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ function drawFixationCross(cfg, color)
22
% Define the parameters of the fixation cross in `cfg` and `expParameters`
33

44
Screen('DrawLines', ...
5-
cfg.win, ...
5+
cfg.screen.win, ...
66
cfg.allCoords, ...
77
cfg.lineWidthPix, ...
88
color, ...
9-
[cfg.center(1) cfg.center(2)], 1);
9+
[cfg.screen.center(1) cfg.screen.center(2)], 1);
1010

1111
end

eyeTracker.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function [el, edfFile] = eyeTracker(input, cfg, varargin)
22

3-
if ~cfg.eyeTracker
3+
if ~cfg.eyeTracker.do
44

55
el = [];
66

initPTB.m

Lines changed: 18 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,13 @@
1414
% - sound
1515
%
1616
% OUTPUT:
17-
% cfg.keyboard = [];
18-
% cfg.responseBox = [];
1917
%
20-
% cfg.debug = true;
21-
% cfg.testingTranspScreen = true;
22-
% cfg.testingSmallScreen = true;
2318
%
24-
% cfg.screen : screen numbers where drawing the stimulation (external screen if available)
25-
% cfg.win : window opened by PTB
26-
% cfg.winRect : window rectangule positiona and dimensions in pixel coordinates
27-
% cfg.winWidth : window width in pixels
28-
% cfg.winHeight : window height in pixels
29-
% cfg.center : coordinate of the window center
30-
% cfg.ppd : pixels per degree assuming the window fills the whole screen
31-
% cfg.ifi : estimate of the monitor flip interval
32-
% cfg.monRefresh : monitor refresh rate
33-
% cfg.vbl : (I don't think this output is useful)
34-
% cfg.textFont = 'Courier New';
35-
% cfg.textSize = 18;
36-
% cfg.textStyle = 1;
37-
% cfg.backgroundColor = [0 0 0];
38-
% cfg.monitorWidth = 42;
39-
% cfg.screenDistance = 134;
40-
41-
% TO DO
42-
% - We might want to add a couple of IF in case the experiment does not use audio for example.
4319

4420
checkPtbVersion();
21+
22+
pth = fileparts(mfilename('fullpath'));
23+
addpath(fullfile(pth, 'subfun'));
4524

4625
% For octave: to avoid displaying messenging one screen at a time
4726
more off;
@@ -63,36 +42,32 @@
6342
%% Visual
6443

6544
% Get the screen numbers and draw to the external screen if avaliable
66-
cfg.screen = max(Screen('Screens'));
45+
cfg.screen.idx = max(Screen('Screens'));
6746

6847
cfg = openWindow(cfg);
6948

7049
% window size info
71-
[cfg.winWidth, cfg.winHeight] = WindowSize(cfg.win);
72-
73-
% if strcmpi(cfg.stimPosition, 'mri')
74-
% cfg.winRect(1, 4) = cfg.winRect(1, 4) * 2 / 3;
75-
% end
50+
[cfg.screen.winWidth, cfg.screen.winHeight] = WindowSize(cfg.screen.win);
7651

7752
% Get the Center of the Screen
78-
cfg.center = [cfg.winRect(3), cfg.winRect(4)] / 2;
53+
cfg.screen.center = [cfg.screen.winRect(3), cfg.screen.winRect(4)] / 2;
7954

8055
% Computes the number of pixels per degree given the distance to screen and
8156
% monitor width
8257
% This assumes that the window fills the whole screen
83-
cfg.FOV = computeFOV(cfg);
84-
cfg.ppd = cfg.winRect(3) / cfg.FOV;
58+
cfg.screen.FOV = computeFOV(cfg);
59+
cfg.screen.ppd = cfg.winRect(3) / cfg.FOV;
8560

8661
%% Select specific text font, style and size
8762
initText(cfg);
8863

8964
%% Timing
9065
% Query frame duration
91-
cfg.ifi = Screen('GetFlipInterval', cfg.win);
92-
cfg.monRefresh = 1 / cfg.ifi;
66+
cfg.screen.ifi = Screen('GetFlipInterval', cfg.win);
67+
cfg.screen.monRefresh = 1 / cfg.ifi;
9368

9469
% Set priority for script execution to realtime priority:
95-
Priority(MaxPriority(cfg.win));
70+
Priority(MaxPriority(cfg.screen.win));
9671

9772
%% Warm up some functions
9873
% Do dummy calls to GetSecs, WaitSecs, KbCheck to make sure
@@ -102,17 +77,14 @@
10277
WaitSecs(0.1);
10378
GetSecs;
10479

105-
%% Initial flip to get a first time stamp
106-
% Initially sync us to VBL at start of animation loop.
107-
cfg.vbl = Screen('Flip', cfg.win);
10880

10981
end
11082

11183
function initDebug(cfg)
11284

11385
% init PTB with different options in concordance to the debug Parameters
11486
Screen('Preference', 'SkipSyncTests', 0);
115-
if cfg.debug
87+
if cfg.debug.do
11688

11789
Screen('Preference', 'SkipSyncTests', 2);
11890
Screen('Preference', 'Verbosity', 0);
@@ -128,7 +100,7 @@ function initDebug(cfg)
128100

129101
end
130102

131-
if cfg.testingTranspScreen
103+
if cfg.debug.transpWin
132104
PsychDebugWindowConfiguration;
133105
end
134106

@@ -147,7 +119,7 @@ function initDebug(cfg)
147119

148120
function cfg = initAudio(cfg)
149121

150-
if cfg.initAudio
122+
if cfg.audio.do
151123

152124
InitializePsychSound(1);
153125

@@ -194,23 +166,16 @@ function initDebug(cfg)
194166

195167
function cfg = openWindow(cfg)
196168

197-
if cfg.testingSmallScreen
198-
[cfg.win, cfg.winRect] = Screen('OpenWindow', cfg.screen, cfg.backgroundColor, ...
169+
if cfg.debug.smallWin
170+
[cfg.screen.win, cfg.screen.winRect] = Screen('OpenWindow', cfg.screen.idx, cfg.color.background, ...
199171
[0, 0, 480, 270]);
200172
else
201-
[cfg.win, cfg.winRect] = Screen('OpenWindow', cfg.screen, cfg.backgroundColor);
173+
[cfg.screen.win, cfg.screen.winRect] = Screen('OpenWindow', cfg.screen.idx, cfg.color.background);
202174
end
203175

204176
% Enable alpha-blending, set it to a blend equation useable for linear
205177
% superposition with alpha-weighted source.
206-
Screen('BlendFunction', cfg.win, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
207-
208-
end
209-
210-
function FOV = computeFOV(cfg)
211-
212-
% computes the number of degrees of visual angle in the whole field of view
213-
FOV = 2 * (180 * (atan(cfg.monitorWidth / (2 * cfg.screenDistance)) / pi));
178+
Screen('BlendFunction', cfg.screen.win, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
214179

215180
end
216181

waitForTrigger.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function waitForTrigger(cfg, deviceNumber)
2828
msg = 'Waiting for trigger';
2929
talkToMe(cfg, msg);
3030

31-
while triggerCounter < cfg.numTriggers
31+
while triggerCounter < cfg.triggerNb
3232

3333
keyCode = []; %#ok<NASGU>
3434

@@ -42,7 +42,7 @@ function waitForTrigger(cfg, deviceNumber)
4242
talkToMe(cfg, msg);
4343

4444
% we only wait if this is not the last trigger
45-
if triggerCounter < cfg.numTriggers
45+
if triggerCounter < cfg.triggerNb
4646
pauseBetweenTriggers(cfg);
4747
end
4848

@@ -55,12 +55,12 @@ function talkToMe(cfg, msg)
5555

5656
fprintf([msg, ' \n']);
5757

58-
if isfield(cfg, 'win')
58+
if isfield(cfg, 'screen') && isfield(cfg.screen, 'win')
5959

60-
DrawFormattedText(cfg.win, msg, ...
60+
DrawFormattedText(cfg.screen.win, msg, ...
6161
'center', 'center', cfg.text.color);
6262

63-
Screen('Flip', cfg.win);
63+
Screen('Flip', cfg.screen.win);
6464

6565
end
6666

@@ -71,8 +71,8 @@ function pauseBetweenTriggers(cfg)
7171
% catch several triggers in one go.
7272

7373
waitTime = 0.5;
74-
if ~isempty(cfg.bids.MRI.repetitionTime)
75-
waitTime = cfg.bids.MRI.repetitionTime / 2;
74+
if ~isempty(cfg.mri.repetitionTime)
75+
waitTime = cfg.mri.repetitionTime / 2;
7676
end
7777

7878
WaitSecs(waitTime);

0 commit comments

Comments
 (0)