Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ before_install:
- travis_retry sudo apt-get -y -qq update
- travis_retry sudo apt-get -y install octave
- travis_retry sudo apt-get -y install liboctave-dev
- cd .. && git clone https://github.com/florianschanda/miss_hit.git && export PATH=$PATH:`pwd`/miss_hit && cd CPP_PTB

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

script:
- octave $OCTFLAGS --eval "results = runtests; assert(all(~[results.Failed]))"
jobs:
include:
- stage: "Tests and linter"
name: "Unit Tests" # names the first job
script: octave $OCTFLAGS --eval "results = runTests; assert(all(~[results.Failed]))"
- script: cd .. && mh_style.py `pwd`
name: "miss_hit linter" # names the second job
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ The exact version required for this to work but it is known to work with:
## Code guidestyle

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

We keep the McCabe complexity as reported by the [check_my_code function](https://github.com/Remi-Gau/matlab_checkcode) below 15.
We keep the McCabe complexity as reported by the [check_my_code function](https://github.com/Remi-Gau/check_my_code) below 15.

We use the [MISS_HIT linter](https://florianschanda.github.io/miss_hit/style_checker.html) to automatically fix some linting issues.

## How to install

Expand Down
60 changes: 30 additions & 30 deletions checkAbort.m
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
function checkAbort(cfg, deviceNumber)
% Check for experiment abortion from operator
% When no deviceNumber is set then it will check the default device
% When an abort key s detected this will set a global variable and throw a
% specific error that can then be catched.
%
% Maint script
% try
% % Your awesome experiment
% catch ME % when something goes wrong
% switch ME.identifier
% case 'checkAbort:abortRequested'
% % stuff to do when an abort is requested (save data...)
% otherwise
% % stuff to do otherwise
% rethrow(ME) % display the error
% end
% end
% Check for experiment abortion from operator
% When no deviceNumber is set then it will check the default device
% When an abort key s detected this will set a global variable and throw a
% specific error that can then be catched.
%
% Maint script
% try
% % Your awesome experiment
% catch ME % when something goes wrong
% switch ME.identifier
% case 'checkAbort:abortRequested'
% % stuff to do when an abort is requested (save data...)
% otherwise
% % stuff to do otherwise
% rethrow(ME) % display the error
% end
% end

if nargin < 1 || isempty(cfg)
error('I need at least one input.')
end
if nargin < 1 || isempty(cfg)
error('I need at least one input.');
end

if nargin < 2 || isempty(deviceNumber)
deviceNumber = -1;
end
if nargin < 2 || isempty(deviceNumber)
deviceNumber = -1;
end

[keyIsDown, ~, keyCode] = KbCheck(deviceNumber);
[keyIsDown, ~, keyCode] = KbCheck(deviceNumber);

if keyIsDown && keyCode(KbName(cfg.keyboard.escapeKey))

errorAbort();

end
if keyIsDown && keyCode(KbName(cfg.keyboard.escapeKey))

end
errorAbort();

end

end
75 changes: 37 additions & 38 deletions checkDependencies.m
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
function checkDependencies()
% Checks that the right dependencies are installed.

printCredits()

PTB.major = 3;
PTB.minor = 0;
PTB.point = 14;

fprintf('Checking dependencies\n')

% check ptb version
try

[~, versionStruc] = PsychtoolboxVersion;

fprintf(' Using PTB %i.%i.%i\n', ...
versionStruc.major, ...
versionStruc.minor, ...
versionStruc.point)

if any( [...
versionStruc.major < PTB.major, ...
versionStruc.minor < PTB.minor, ...
versionStruc.point < PTB.point, ...
])

str = sprintf('%s %i.%i.%i %s.\n%s', ...
'The current version PTB version is not', ...
PTB.major, ...
PTB.minor, ...
PTB.point, ...
'In case of problems (e.g json file related) consider updating.');
warning(str); %#ok<*SPWRN>
end
catch
error('Failed to check the PTB version: Are you sure that PTB is in the matlab path?')
end
% Checks that the right dependencies are installed.

printCredits();

PTB.major = 3;
PTB.minor = 0;
PTB.point = 14;

fprintf('Checking dependencies\n');

% check ptb version
try

[~, versionStruc] = PsychtoolboxVersion;

fprintf(' Using PTB %i.%i.%i\n', ...
versionStruc.major, ...
versionStruc.minor, ...
versionStruc.point);

if any([ ...
versionStruc.major < PTB.major, ...
versionStruc.minor < PTB.minor, ...
versionStruc.point < PTB.point, ...
])

str = sprintf('%s %i.%i.%i %s.\n%s', ...
'The current version PTB version is not', ...
PTB.major, ...
PTB.minor, ...
PTB.point, ...
'In case of problems (e.g json file related) consider updating.');
warning(str); %#ok<*SPWRN>
end
catch
error('Failed to check the PTB version: Are you sure that PTB is in the matlab path?');
end

fprintf(' We got all we need. Let us get to work.\n')
fprintf(' We got all we need. Let us get to work.\n');

end
37 changes: 18 additions & 19 deletions cleanUp.m
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
function cleanUp
% A wrapper function to close all windows, ports, show mouse cursor, close keyboard queues
% and give access back to the keyboards.
% A wrapper function to close all windows, ports, show mouse cursor, close keyboard queues
% and give access back to the keyboards.

WaitSecs(0.5);
WaitSecs(0.5);

Priority(0);
Priority(0);

ListenChar(0);
KbQueueRelease();
ListenChar(0);
KbQueueRelease();

ShowCursor
ShowCursor;

% Screen Close All
sca;
% Screen Close All
sca;

% Close Psychportaudio if open
if PsychPortAudio('GetOpenDeviceCount') ~= 0
PsychPortAudio('Close');
end

if ~ismac
% remove PsychDebugWindowConfiguration
clear Screen
end
% Close Psychportaudio if open
if PsychPortAudio('GetOpenDeviceCount') ~= 0
PsychPortAudio('Close');
end

close all
if ~ismac
% remove PsychDebugWindowConfiguration
clear Screen;
end

close all;

end
11 changes: 0 additions & 11 deletions deg2Pix.m

This file was deleted.

11 changes: 11 additions & 0 deletions degToPix.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function structure = degToPix(fieldName, structure, cfg)
% For a given field value in degrees of visual angle in the structure,
% this computes its value in pixel using the pixel per degree value of the cfg structure
% and returns a structure with an additional field with Pix suffix holding that new value.

deg = getfield(structure, fieldName); %#ok<GFLD>

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

end
17 changes: 8 additions & 9 deletions demos/CPP_checkAbortDemo.m
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
% add parent directory to the path (to make sure we can access the CPP_PTB
% functions)
addpath(fullfile(pwd, '..'))
addpath(fullfile(pwd, '..'));

% set up
cfg.keyboard.escapeKey = 'ESCAPE';

% beginning of demo
KbName('UnifyKeyNames');


try

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

checkAbort(cfg)
checkAbort(cfg);

end

catch ME

switch ME.identifier
case 'checkAbort:abortRequested'
warning('You pressed the escape key: will try to fail gracefully.')
fprintf('\nWe did catch your abort signal.\n')
warning('You pressed the escape key: will try to fail gracefully.');
fprintf('\nWe did catch your abort signal.\n');
otherwise
rethrow(ME) % display other errors
rethrow(ME); % display other errors
end
end

end
Loading