Skip to content

Commit e885052

Browse files
committed
Merge remote-tracking branch 'cpp-lln-lab/master'
2 parents 2beab04 + 5e66e04 commit e885052

33 files changed

+1497
-1102
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
# exclude content of logfiles folders
77
*.tsv
88
*.mat
9+
check_my_code_report.txt

.travis.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Travis CI (https://travis-ci.org/)
2+
3+
language: c
4+
dist: bionic
5+
cache:
6+
apt: true # only works with Pro version
7+
8+
env:
9+
global:
10+
- OCTFLAGS="--no-gui --no-window-system --silent"
11+
12+
before_install:
13+
- travis_retry sudo apt-get -y -qq update
14+
- travis_retry sudo apt-get -y install octave
15+
- 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
17+
18+
install:
19+
- octave $OCTFLAGS --eval "addpath (pwd); savepath ();"
20+
21+
before_script:
22+
# Change current directory
23+
- cd tests
24+
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

CPP_getResponseDemo.m

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

README.md

Lines changed: 40 additions & 9 deletions
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

@@ -70,6 +73,30 @@ You can then use the [matlab package manager](https://github.com/mobeets/mpm), t
7073
end
7174
```
7275

76+
## Setting up keyboards
77+
78+
To select a specific keyboard to be used by the experimenter or the participant, you need to know
79+
the value assigned by PTB to each keyboard device.
80+
81+
To know this copy-paste this on the command window:
82+
83+
``` matlab
84+
[keyboardNumbers, keyboardNames] = GetKeyboardIndices;
85+
86+
disp(keyboardNumbers);
87+
disp(keyboardNames);
88+
```
89+
90+
You can then assign a specific device number to the main keyboard or the response box in the `cfg` structure
91+
92+
- `cfg.keyboard.responseBox` would be the device number of the device used by the participant to give his/her
93+
response: like the button box in the scanner or a separate keyboard for a behavioral experiment
94+
- `cfg.keyboard.keyboard` would be the device number of the keyboard on which the experimenter will type or
95+
press the keys necessary to start or abort the experiment.
96+
97+
`cfg.keyboard.responseBox` and `cfg.keyboard.keyboard` can be different or the same.
98+
99+
Using empty vectors (ie `[]`) or a negative value for those means that you will let PTB find and use the default device.
73100

74101
## Structure and function details
75102

@@ -106,23 +133,27 @@ It is wrapper function to use `KbQueue` which is definitely what you should used
106133

107134
You can easily collect responses while running some other code at the same time.
108135

109-
It will only take responses from the `response box` which can simply be the "main keyboard" or
110-
another keyboard connected to the computer or the response box that the participant is using.
136+
It will only take responses from one device which can simply be the "main keyboard"
137+
(the default device that PTB will find) or another keyboard connected to the computer
138+
or the response box that the participant is using.
111139

112140
You can use it in a way so that it only takes responses from certain keys and ignore others (like
113141
the triggers from an MRI scanner).
114142

115143
If you want to know more on how to use it check its help section and the `CPP_getResponseDemo.m`.
116144

117-
To select a specific keyboard to be used by the experimenter or the participant, you need to know
118-
the value assigned by PTB to each keyboard device.
145+
In brief, there are several actions you can execute with this function.
119146

120-
To know this copy-paste this on the command window:
147+
- init: initialize the buffer for key presses on a given device (you can also specify the keys of interest that should be listened to).
148+
- start: start listening to the key presses (carefully insert into your script - where do you want to start buffering the responses).
149+
- check: till that point, it will check the buffer for all key presses.
150+
- It only reports presses on the keys of interest mentioned at initialization.
151+
- It **can** also check for presses on the escape key and abort if the escape key is part of the keys of interest.
152+
- flush: Empties the buffer of key presses in case you want to discard any previous key presses.
153+
- stop: Stops buffering key presses. You can still restart by calling "start" again.
154+
- release: Closes the buffer for good.
121155

122-
[keyboardNumbers, keyboardNames] = GetKeyboardIndices;
123156

124-
keyboardNumbers
125-
keyboardNames
126157

127158
### deg2Pix
128159

checkAbort.m

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
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
19+
20+
if nargin < 1 || isempty(cfg)
21+
error('I need at least one input.');
22+
end
23+
24+
if nargin < 2 || isempty(deviceNumber)
25+
deviceNumber = -1;
26+
end
27+
28+
[keyIsDown, ~, keyCode] = KbCheck(deviceNumber);
29+
30+
if keyIsDown && keyCode(KbName(cfg.keyboard.escapeKey))
31+
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

0 commit comments

Comments
 (0)