Skip to content

Commit ce6de21

Browse files
authored
Merge pull request #33 from Remi-Gau/remi-MISS_HIT_linter
apply miss_hit linter
2 parents d400c66 + ae0b503 commit ce6de21

33 files changed

+1184
-1231
lines changed

.travis.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ before_install:
1313
- travis_retry sudo apt-get -y -qq update
1414
- travis_retry sudo apt-get -y install octave
1515
- travis_retry sudo apt-get -y install liboctave-dev
16+
- cd .. && git clone https://github.com/florianschanda/miss_hit.git && export PATH=$PATH:`pwd`/miss_hit && cd CPP_PTB
1617

1718
install:
1819
- octave $OCTFLAGS --eval "addpath (pwd); savepath ();"
@@ -21,5 +22,10 @@ before_script:
2122
# Change current directory
2223
- cd tests
2324

24-
script:
25-
- octave $OCTFLAGS --eval "results = runtests; assert(all(~[results.Failed]))"
25+
jobs:
26+
include:
27+
- stage: "Tests and linter"
28+
name: "Unit Tests" # names the first job
29+
script: octave $OCTFLAGS --eval "results = runTests; assert(all(~[results.Failed]))"
30+
- script: cd .. && mh_style.py `pwd`
31+
name: "miss_hit linter" # names the second job

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ The exact version required for this to work but it is known to work with:
2727
## Code guidestyle
2828

2929
We use the `camelCase` to more easily differentiates our functions from the ones from PTB that use a `PascalCase`.
30+
We use the following regular expression for function names: `[a-z]+(([A-Z]|[0-9]){1}[a-z]+)*`.
3031

31-
We keep the McCabe complexity as reported by the [check_my_code function](https://github.com/Remi-Gau/matlab_checkcode) below 15.
32+
We keep the McCabe complexity as reported by the [check_my_code function](https://github.com/Remi-Gau/check_my_code) below 15.
33+
34+
We use the [MISS_HIT linter](https://florianschanda.github.io/miss_hit/style_checker.html) to automatically fix some linting issues.
3235

3336
## How to install
3437

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

deg2Pix.m

Lines changed: 0 additions & 11 deletions
This file was deleted.

degToPix.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function structure = degToPix(fieldName, structure, cfg)
2+
% For a given field value in degrees of visual angle in the structure,
3+
% this computes its value in pixel using the pixel per degree value of the cfg structure
4+
% and returns a structure with an additional field with Pix suffix holding that new value.
5+
6+
deg = getfield(structure, fieldName); %#ok<GFLD>
7+
8+
structure = setfield(structure, [fieldName 'Pix'], ...
9+
floor(cfg.ppd * deg)) ; %#ok<SFLD>
10+
11+
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)