Skip to content

Commit f19e45e

Browse files
committed
mh autofix
1 parent cb9f5cb commit f19e45e

20 files changed

+876
-935
lines changed

CPP_getResponseDemo.m

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
% (a wrapper around the KbQueue function from PTB)
55

66
% start with a clean slate
7-
clear; clc;
7+
clear;
8+
clc;
89
if IsOctave
9-
more off % for a better display experience
10+
more off; % for a better display experience
1011
end
1112

1213
%% set parameters
@@ -32,41 +33,35 @@
3233
% We set which keys are "valid", any keys other than those will be ignored
3334
expParameters.responseKey = {};
3435

35-
3636
%% init
3737

3838
% Keyboard
3939
% Make sure keyboard mapping is the same on all supported operating systems
4040
% Apple MacOS/X, MS-Windows and GNU/Linux:
4141
KbName('UnifyKeyNames');
4242

43-
4443
% we ask PTB to tell us which keyboard devices are connected to the computer
4544
[cfg.keyboardNumbers, cfg.keyboardNames] = GetKeyboardIndices;
4645

47-
cfg.keyboardNumbers
48-
cfg.keyboardNames
49-
46+
cfg.keyboardNumbers;
47+
cfg.keyboardNames;
5048

5149
% Test that the keyboards are correctly configured
5250
testKeyboards(cfg);
5351

5452
% Give the time to the test key to be released and not listened
5553
WaitSecs(1);
5654

57-
5855
fprintf('\nDuring the next 5 seconds we will collect responses on the following keys: \n\n');
5956
if isempty(expParameters.responseKey)
6057
fprintf('\nALL KEYS\n\n');
6158
else
62-
for iKey=1:numel(expParameters.responseKey)
59+
for iKey = 1:numel(expParameters.responseKey)
6360
fprintf('\n%s', expParameters.responseKey{iKey});
6461
end
6562
fprintf('\n\n');
6663
end
6764

68-
69-
7065
%% Run demo
7166

7267
% Create the keyboard queue to collect responses.
@@ -77,15 +72,11 @@
7772
startSecs = GetSecs();
7873
getResponse('start', cfg, expParameters, 1);
7974

80-
81-
8275
% Here we wait for 5 seconds but are still collecting responses.
8376
% So you could still be doing something else (presenting audio and visual stim) and
8477
% still collect responses.
8578
WaitSecs(5);
8679

87-
88-
8980
% Check what keys were pressed (all of them)
9081
responseEvents = getResponse('check', cfg, expParameters, 0);
9182

@@ -98,9 +89,6 @@
9889
% If you wan to stop listening to key presses.
9990
getResponse('stop', cfg, expParameters, 1);
10091

101-
102-
103-
10492
%% Now we look what keys were pressed and when
10593
for iEvent = 1:size(responseEvents, 1)
10694

checkAbort.m

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
function checkAbort(cfg, deviceNumber)
2-
% Check for experiment abortion from operator
3-
% When no deviceNumber is set then it will check the default device
4-
% When an abort key s detected this will set a global variable and throw a
5-
% specific error that can then be catched.
6-
%
7-
% Maint script
8-
% try
9-
% % Your awesome experiment
10-
% catch ME % when something goes wrong
11-
% switch ME.identifier
12-
% case 'checkAbort:abortRequested'
13-
% % stuff to do when an abort is requested (save data...)
14-
% otherwise
15-
% % stuff to do otherwise
16-
% rethrow(ME) % display the error
17-
% end
18-
% end
2+
% Check for experiment abortion from operator
3+
% When no deviceNumber is set then it will check the default device
4+
% When an abort key s detected this will set a global variable and throw a
5+
% specific error that can then be catched.
6+
%
7+
% Maint script
8+
% try
9+
% % Your awesome experiment
10+
% catch ME % when something goes wrong
11+
% switch ME.identifier
12+
% case 'checkAbort:abortRequested'
13+
% % stuff to do when an abort is requested (save data...)
14+
% otherwise
15+
% % stuff to do otherwise
16+
% rethrow(ME) % display the error
17+
% end
18+
% end
1919

20-
if nargin < 1 || isempty(cfg)
21-
error('I need at least one input.')
22-
end
20+
if nargin < 1 || isempty(cfg)
21+
error('I need at least one input.');
22+
end
2323

24-
if nargin < 2 || isempty(deviceNumber)
25-
deviceNumber = -1;
26-
end
24+
if nargin < 2 || isempty(deviceNumber)
25+
deviceNumber = -1;
26+
end
2727

28-
[keyIsDown, ~, keyCode] = KbCheck(deviceNumber);
28+
[keyIsDown, ~, keyCode] = KbCheck(deviceNumber);
2929

30-
if keyIsDown && keyCode(KbName(cfg.keyboard.escapeKey))
31-
32-
errorAbort();
33-
34-
end
30+
if keyIsDown && keyCode(KbName(cfg.keyboard.escapeKey))
3531

36-
end
32+
errorAbort();
33+
34+
end
35+
36+
end

checkDependencies.m

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,42 @@
11
function checkDependencies()
2-
% Checks that the right dependencies are installed.
3-
4-
printCredits()
5-
6-
PTB.major = 3;
7-
PTB.minor = 0;
8-
PTB.point = 14;
9-
10-
fprintf('Checking dependencies\n')
11-
12-
% check ptb version
13-
try
14-
15-
[~, versionStruc] = PsychtoolboxVersion;
16-
17-
fprintf(' Using PTB %i.%i.%i\n', ...
18-
versionStruc.major, ...
19-
versionStruc.minor, ...
20-
versionStruc.point)
21-
22-
if any( [...
23-
versionStruc.major < PTB.major, ...
24-
versionStruc.minor < PTB.minor, ...
25-
versionStruc.point < PTB.point, ...
26-
])
27-
28-
str = sprintf('%s %i.%i.%i %s.\n%s', ...
29-
'The current version PTB version is not', ...
30-
PTB.major, ...
31-
PTB.minor, ...
32-
PTB.point, ...
33-
'In case of problems (e.g json file related) consider updating.');
34-
warning(str); %#ok<*SPWRN>
35-
end
36-
catch
37-
error('Failed to check the PTB version: Are you sure that PTB is in the matlab path?')
38-
end
2+
% Checks that the right dependencies are installed.
3+
4+
printCredits();
5+
6+
PTB.major = 3;
7+
PTB.minor = 0;
8+
PTB.point = 14;
9+
10+
fprintf('Checking dependencies\n');
3911

12+
% check ptb version
13+
try
14+
15+
[~, versionStruc] = PsychtoolboxVersion;
16+
17+
fprintf(' Using PTB %i.%i.%i\n', ...
18+
versionStruc.major, ...
19+
versionStruc.minor, ...
20+
versionStruc.point);
21+
22+
if any([ ...
23+
versionStruc.major < PTB.major, ...
24+
versionStruc.minor < PTB.minor, ...
25+
versionStruc.point < PTB.point, ...
26+
])
27+
28+
str = sprintf('%s %i.%i.%i %s.\n%s', ...
29+
'The current version PTB version is not', ...
30+
PTB.major, ...
31+
PTB.minor, ...
32+
PTB.point, ...
33+
'In case of problems (e.g json file related) consider updating.');
34+
warning(str); %#ok<*SPWRN>
35+
end
36+
catch
37+
error('Failed to check the PTB version: Are you sure that PTB is in the matlab path?');
38+
end
4039

41-
fprintf(' We got all we need. Let us get to work.\n')
40+
fprintf(' We got all we need. Let us get to work.\n');
4241

4342
end

cleanUp.m

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
function cleanUp
2-
% A wrapper function to close all windows, ports, show mouse cursor, close keyboard queues
3-
% and give access back to the keyboards.
2+
% A wrapper function to close all windows, ports, show mouse cursor, close keyboard queues
3+
% and give access back to the keyboards.
44

5-
WaitSecs(0.5);
5+
WaitSecs(0.5);
66

7-
Priority(0);
7+
Priority(0);
88

9-
ListenChar(0);
10-
KbQueueRelease();
9+
ListenChar(0);
10+
KbQueueRelease();
1111

12-
ShowCursor
12+
ShowCursor;
1313

14-
% Screen Close All
15-
sca;
14+
% Screen Close All
15+
sca;
1616

17-
% Close Psychportaudio if open
18-
if PsychPortAudio('GetOpenDeviceCount') ~= 0
19-
PsychPortAudio('Close');
20-
end
21-
22-
if ~ismac
23-
% remove PsychDebugWindowConfiguration
24-
clear Screen
25-
end
17+
% Close Psychportaudio if open
18+
if PsychPortAudio('GetOpenDeviceCount') ~= 0
19+
PsychPortAudio('Close');
20+
end
2621

27-
close all
22+
if ~ismac
23+
% remove PsychDebugWindowConfiguration
24+
clear Screen;
25+
end
2826

27+
close all;
2928

3029
end

demos/CPP_checkAbortDemo.m

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
% add parent directory to the path (to make sure we can access the CPP_PTB
22
% functions)
3-
addpath(fullfile(pwd, '..'))
3+
addpath(fullfile(pwd, '..'));
44

55
% set up
66
cfg.keyboard.escapeKey = 'ESCAPE';
77

88
% beginning of demo
99
KbName('UnifyKeyNames');
1010

11-
1211
try
1312

1413
% stay in the loop until the escape key is pressed
1514
while GetSecs < Inf
1615

17-
checkAbort(cfg)
16+
checkAbort(cfg);
1817

1918
end
2019

2120
catch ME
22-
21+
2322
switch ME.identifier
2423
case 'checkAbort:abortRequested'
25-
warning('You pressed the escape key: will try to fail gracefully.')
26-
fprintf('\nWe did catch your abort signal.\n')
24+
warning('You pressed the escape key: will try to fail gracefully.');
25+
fprintf('\nWe did catch your abort signal.\n');
2726
otherwise
28-
rethrow(ME) % display other errors
27+
rethrow(ME); % display other errors
2928
end
30-
31-
end
29+
30+
end

0 commit comments

Comments
 (0)