Skip to content

Commit cb9f5cb

Browse files
committed
apply some linting
1 parent 36d6ca5 commit cb9f5cb

File tree

11 files changed

+403
-287
lines changed

11 files changed

+403
-287
lines changed

CPP_getResponseDemo.m

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
%% Demo showing how to use the getResponse function
2+
3+
% This small script shows how to use the getReponse function
4+
% (a wrapper around the KbQueue function from PTB)
5+
6+
% start with a clean slate
7+
clear; clc;
8+
if IsOctave
9+
more off % for a better display experience
10+
end
11+
12+
%% set parameters
13+
14+
% cfg.responseBox would be the device number of the device used by the participant to give his/her
15+
% response: like the button box in the scanner or a separate keyboard for a behavioral experiment
16+
%
17+
% cfg.keyboard would be the device number of the keyboard on which the experimenter will type or
18+
% press the keys necessary to start or abort the experiment.
19+
20+
% cfg.responseBox and cfg.keyboard can be different or the same.
21+
22+
% If you want to know the device number of all the keyboards and responses
23+
% boxes connected to the computer you can use the following code.
24+
% [cfg.keyboardNumbers, cfg.keyboardNames] = GetKeyboardIndices
25+
26+
% Using empty vectors should work for linux when to select the "main"
27+
% keyboard. You might have to try some other values for Windows. To
28+
% assigne a specific keyboard input the kb assigned value (see README)
29+
cfg.keyboard = [];
30+
cfg.responseBox = [];
31+
32+
% We set which keys are "valid", any keys other than those will be ignored
33+
expParameters.responseKey = {};
34+
35+
36+
%% init
37+
38+
% Keyboard
39+
% Make sure keyboard mapping is the same on all supported operating systems
40+
% Apple MacOS/X, MS-Windows and GNU/Linux:
41+
KbName('UnifyKeyNames');
42+
43+
44+
% we ask PTB to tell us which keyboard devices are connected to the computer
45+
[cfg.keyboardNumbers, cfg.keyboardNames] = GetKeyboardIndices;
46+
47+
cfg.keyboardNumbers
48+
cfg.keyboardNames
49+
50+
51+
% Test that the keyboards are correctly configured
52+
testKeyboards(cfg);
53+
54+
% Give the time to the test key to be released and not listened
55+
WaitSecs(1);
56+
57+
58+
fprintf('\nDuring the next 5 seconds we will collect responses on the following keys: \n\n');
59+
if isempty(expParameters.responseKey)
60+
fprintf('\nALL KEYS\n\n');
61+
else
62+
for iKey=1:numel(expParameters.responseKey)
63+
fprintf('\n%s', expParameters.responseKey{iKey});
64+
end
65+
fprintf('\n\n');
66+
end
67+
68+
69+
70+
%% Run demo
71+
72+
% Create the keyboard queue to collect responses.
73+
getResponse('init', cfg, expParameters, 1);
74+
75+
% Start collecting responses for 5 seconds
76+
% Each new key press is added to the queue of events recorded by KbQueue
77+
startSecs = GetSecs();
78+
getResponse('start', cfg, expParameters, 1);
79+
80+
81+
82+
% Here we wait for 5 seconds but are still collecting responses.
83+
% So you could still be doing something else (presenting audio and visual stim) and
84+
% still collect responses.
85+
WaitSecs(5);
86+
87+
88+
89+
% Check what keys were pressed (all of them)
90+
responseEvents = getResponse('check', cfg, expParameters, 0);
91+
92+
% The following line would only return key presses and not releases
93+
% responseEvents = getResponse('check', cfg, expParameters, 1);
94+
95+
% This can be used to flush the queue: empty all events that are still present in the queue
96+
getResponse('flush', cfg, expParameters, 1);
97+
98+
% If you wan to stop listening to key presses.
99+
getResponse('stop', cfg, expParameters, 1);
100+
101+
102+
103+
104+
%% Now we look what keys were pressed and when
105+
for iEvent = 1:size(responseEvents, 1)
106+
107+
if responseEvents(iEvent).pressed
108+
eventType = 'pressed';
109+
else
110+
eventType = 'released';
111+
end
112+
113+
fprintf('%s was %s at time %.3f seconds\n', ...
114+
responseEvents(iEvent).key_name, ...
115+
eventType, ...
116+
responseEvents(iEvent).onset - startSecs);
117+
118+
end

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

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_wait4TriggerDemo.m

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
% set up
2-
cfg.testingDevice = 'scanner';
3-
cfg.numTriggers = 4;
4-
cfg.triggerKey = 't';
1+
cd ..
2+
3+
cfg.device = 'Scanner';
54

6-
% this field is not required but can be mentioned
7-
cfg.MRI.repetitionTime = 3;
5+
cfg.numTriggers = 4;
86

9-
% add parent directory to the path (to make sure we can access the CPP_PTB
10-
% functions)
11-
addpath(fullfile(pwd, '..'))
7+
cfg.triggerKey = 'space';
128

13-
% beginning of demo
149
KbName('UnifyKeyNames');
1510

16-
% press the key "t" to simulate triggers
1711
wait4Trigger(cfg)

demos/CPP_waitForTriggerDemo.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cd ..;
2+
3+
cfg.device = 'Scanner';
4+
5+
cfg.numTriggers = 4;
6+
7+
cfg.triggerKey = 'space';
8+
9+
KbName('UnifyKeyNames');
10+
11+
waitForTrigger(cfg);

drawFixationCross.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
function drawFixationCross(cfg, expParameters, color)
2-
% Define the parameters of the fixation cross in `cfg` and `expParameters` and this does the rest.
2+
% Define the parameters of the fixation cross in `cfg` and `expParameters` and this does the rest.
33

4-
Screen('DrawLines', ...
5-
cfg.win, ...
6-
cfg.allCoords, ...
7-
expParameters.lineWidthPix, ...
8-
color , ...
9-
[cfg.center(1) cfg.center(2)], 1);
4+
Screen('DrawLines', ...
5+
cfg.win, ...
6+
cfg.allCoords, ...
7+
expParameters.lineWidthPix, ...
8+
color, ...
9+
[cfg.center(1) cfg.center(2)], 1);
1010

1111
end

0 commit comments

Comments
 (0)