Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3ba28cb
refactor set keys of interest
Remi-Gau Jul 16, 2020
252f20e
refactor get all key events
Remi-Gau Jul 16, 2020
ae37cb6
clean getResponse
Remi-Gau Jul 16, 2020
d02e11e
Add function to check if user asked to abort experiment
Remi-Gau Jul 16, 2020
e6210ab
checkAbort called at every getResponse check
Remi-Gau Jul 16, 2020
ca83c2b
make checkAbort throw an error
Remi-Gau Jul 16, 2020
75c80f9
create demo folder
Remi-Gau Jul 17, 2020
1909cee
add demo checkAbort
Remi-Gau Jul 17, 2020
80c6d91
change defaults and set up unit test for defaults
Remi-Gau Jul 19, 2020
750c6ff
update wait for triggers to listen to all devices by defaults
Remi-Gau Jul 19, 2020
a00b2b0
make testKeyboard only test main device if response box is the same a…
Remi-Gau Jul 19, 2020
81412fe
make press space bar listen to all devices by defaults
Remi-Gau Jul 19, 2020
4f500ad
update trigger and wait for functions
Remi-Gau Jul 19, 2020
7f44c63
update initPTB to set font parameters
Remi-Gau Jul 19, 2020
ce9f25d
add CPP_PTB to path in demos
Remi-Gau Jul 19, 2020
99aaae4
update checkAbort
Remi-Gau Jul 19, 2020
e6354ea
refactor checkAbort
Remi-Gau Jul 19, 2020
9e3ebf9
set a default escape key
Remi-Gau Jul 19, 2020
2132ca7
update readme on how to set up keyboards
Remi-Gau Jul 19, 2020
3a6e4c0
define tests demos and errors for getResponse
Remi-Gau Jul 19, 2020
33ea857
make getResponse verbose by default
Remi-Gau Jul 19, 2020
90dcc06
update getResponse
Remi-Gau Jul 19, 2020
bcca2cf
make getResponse abort if escape key is pressed
Remi-Gau Jul 19, 2020
c186e4c
keysOfInterest = zeros(1,256);
Remi-Gau Jul 19, 2020
f91826c
update readme
Remi-Gau Jul 19, 2020
c6b988b
Merge pull request #2 from Remi-Gau/remi-change_keyboard_defaults
Remi-Gau Jul 19, 2020
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
# exclude content of logfiles folders
*.tsv
*.mat
check_my_code_report.txt
25 changes: 25 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Travis CI (https://travis-ci.org/)

language: c
dist: bionic
cache:
apt: true # only works with Pro version

env:
global:
- OCTFLAGS="--no-gui --no-window-system --silent"

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

install:
- octave $OCTFLAGS --eval "addpath (pwd); savepath ();"

before_script:
# Change current directory
- cd tests

script:
- octave $OCTFLAGS --eval "results = runtests; assert(all(~[results.Failed]))"
118 changes: 0 additions & 118 deletions CPP_getResponseDemo.m

This file was deleted.

44 changes: 36 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,30 @@ You can then use the [matlab package manager](https://github.com/mobeets/mpm), t
end
```

## Setting up keyboards

To select a specific keyboard to be used by the experimenter or the participant, you need to know
the value assigned by PTB to each keyboard device.

To know this copy-paste this on the command window:

``` matlab
[keyboardNumbers, keyboardNames] = GetKeyboardIndices;

disp(keyboardNumbers);
disp(keyboardNames);
```

You can then assign a specific device number to the main keyboard or the response box in the `cfg` structure

- `cfg.keyboard.responseBox` would be the device number of the device used by the participant to give his/her
response: like the button box in the scanner or a separate keyboard for a behavioral experiment
- `cfg.keyboard.keyboard` would be the device number of the keyboard on which the experimenter will type or
press the keys necessary to start or abort the experiment.

`cfg.keyboard.responseBox` and `cfg.keyboard.keyboard` can be different or the same.

Using empty vectors (ie `[]`) or a negative value for those means that you will let PTB find and use the default device.

## Structure and function details

Expand Down Expand Up @@ -106,23 +130,27 @@ It is wrapper function to use `KbQueue` which is definitely what you should used

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

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

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

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

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

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

[keyboardNumbers, keyboardNames] = GetKeyboardIndices;

keyboardNumbers
keyboardNames

### deg2Pix

Expand Down
36 changes: 36 additions & 0 deletions checkAbort.m
Original file line number Diff line number Diff line change
@@ -0,0 +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

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

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

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

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

errorAbort();

end

end
31 changes: 31 additions & 0 deletions demos/CPP_checkAbortDemo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
% add parent directory to the path (to make sure we can access the CPP_PTB
% functions)
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)

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')
otherwise
rethrow(ME) % display other errors
end

end
Loading