-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomButtonsClass.m
More file actions
96 lines (71 loc) · 2.81 KB
/
customButtonsClass.m
File metadata and controls
96 lines (71 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
classdef customButtonsClass < dotsReadableHIDKeyboard
% @class dotsReadableHIDButtons
%
% Simple subclass for a button box that maps button presses to keyboard
% presses
%
properties
end
methods
% Contstructor -- just a keyboard, really.
function self = customButtonsClass()
mexHID('initialize');
infoStruct = mexHID('summarizeDevices');
if any([infoStruct.VendorID] == 1240)
% Try for Black Box Toolbox first
devicePreference.vendorID = 1240;
devicePreference.ProductID = 1;
devicePreference.PrimaryUsage = 6;
elseif any([infoStruct.ProductID] == 13896)
% Next try the custom button box
devicePreference.vendorID = 1204;
devicePreference.ProductID = 13896;
devicePreference.PrimaryUsage = 6;
else
% Whatevs
devicePreference.PrimaryUsage = 6;
end
% Get the device
self = self@dotsReadableHIDKeyboard(devicePreference);
% Check that we got it
if strcmp(self.deviceInfo.Product, 'BBTK Response Box')
% Found Black Box, use it to map component names
buttons = {'KeyboardD' 'KeyboardK' 'KeyboardReturnOrEnter' 'KeyboardSpacebar'};
else % NEED CHECK HERE strcmp(self.deviceInfo.Product, 'BBTK Response Box')
% Found Custom Button Box, use it to map component names
buttons = {'KeyboardShiftLeft' 'KeyboardShiftRight'};
end
% Get the list of component names
names = {self.components.name};
% Loop through the buttons
for bb = 1:length(buttons)
% Find the component
Lcomponent = strcmp(buttons{bb}, names);
if sum(Lcomponent) == 1
% Update the name
self.components(Lcomponent).name = ['Button' int2str(bb)];
end
end
end
function nullfunc(self)
% this function does nothing on purpose
end
end
methods (Static)
% For testing
function [didHappen, waitTime] = waitForButton(buttonNumber, maxWait)
% Make a button object
btn = dotsReadableHIDButtons();
% Parse args
if nargin < 1 || isempty(buttonNumber)
buttonNumber = 1;
end
if nargin < 2 || isempty(maxWait)
maxWait = 10;
end
% Wait for press
[didHappen, waitTime] = dotsReadableHIDKeyboard.waitForKeyPress(btn, ...
['Button' int2str(buttonNumber)], maxWait);
end
end
end