MasterScan
Lab_Matlab_control Master Branch
|
Reads data from a HID keyboard device.
dotsReadableHIDKeyboard extends the dotsReadableHID superclass to manage HID keyboard devices. Many integrated and USB keybords are HID keyboards.
By default, dotsReadableHIDKeyboard defines "pressed" events for each keyboard key. Use getNextEvent() to make sure that no key presses are missed, and that each press is observed only once.
Properties and Events | |
Property | keyMatching |
Example usage: kb = dotsReadableHIDKeyboard(); [isPressed, waitTime, data, kbout] = dotsReadableHIDKeyboard.waitForKeyPress(kb, 'KeyboardF', 5, true) More... | |
Property | VendorIDs |
matching preferences read from machine defaults ... More... | |
![]() | |
Property | deviceInfo |
struct of info about the HID device | |
Property | deviceMatching |
struct of HID parameters for identifying suitable HID devices. More... | |
Property | devicePreference |
struct of HID parameters for choosing among suitable devices. More... | |
Property | queueDepth = 1024 |
size of the mexHID() internal data queue More... | |
Property | queueIsOpen = false |
whether or not the internal data queue opened successfully | |
Property | isExclusive = false |
whether or not to get exclusive access to device data | |
Property | allowMultipleConnections = false |
whether or not to allow multiple objects to access the same device | |
![]() | |
Property | isAvailable = false |
| |
Property | components |
| |
Property | state |
| |
Property | history |
| |
Property | isAutoRead = true |
| |
Property | eventDefinitions |
| |
Property | initialEventQueueSize = 100 |
| |
Property | clockFunction |
| |
Property | filename |
| |
Property | filepath |
| |
Property | recordDuringCalibration = true |
| |
Property | useGUI = false |
Flag to use GUI for feedback, etc. | |
Property | useExistingCalibration = false |
Flag to skip calibration routine. | |
Property | calibrationUI |
Possibly use a keyboard or other UI to help with calibration. | |
Property | deactivateEventsAtStartTrial =false |
Flag to deactivate all events at the beginning of each trial. | |
Methods | |
self | dotsReadableHIDKeyboard (devicePreference) |
Get rid of annoying rollover event. More... | |
![]() | |
self | dotsReadableHID () |
Constructor takes no arguments. | |
flushData (self, varargin) | |
Clear data from this object and the mexHID() internal queue. More... | |
components | setComponentCalibration (self, namesOrIDs, rawRange, deadRange, calibratedRange, granularity) |
Adjust scaling of raw values from HID components. More... | |
event | defineEvent (self, name, varargin) |
Define a calibrated event for given component. More... | |
![]() | |
self | dotsReadable () |
| |
initialize (self) | |
| |
calibrate (self, varargin) | |
More... | |
record (self, onFlag, filename) | |
More... | |
reset (self, varargin) | |
reset device More... | |
close (self) | |
| |
delete (self) | |
| |
read (self) | |
More... | |
flushData (self, waitForNoEvents) | |
More... | |
logData (self) | |
More... | |
stateAtTime | getState (self, time) |
More... | |
value data | getValue (self, ID) |
More... | |
event | defineEvent (self, name, varargin) |
More... | |
defineEventsFromComponents (self, names, varargin) | |
defineEventsFromComponents More... | |
defineEventsFromStruct (self, eventStruct, setName, keepExisting, inactivate) | |
defineEventsFromStruct More... | |
showActiveEvents (self) | |
Mostly for debugging. | |
activateEventSet (self, name) | |
Swap in a set of events. | |
activateEvents (self) | |
Activate all events. More... | |
deactivateEvents (self) | |
Deactivate all events. More... | |
activeFlags | getActiveFlags (self) |
Get all active flags. | |
setActiveFlags (self, activeFlags) | |
Set all active flags from array. | |
setEventsActiveFlag (self, activateList, deactivateList) | |
Set/unset activeFlag. More... | |
name data | getNextEvent (self, isPeek, acceptedEvents) |
More... | |
lastName lastID names IDs | getHappeningEvent (self, time) |
More... | |
name waitTime data | waitForEvents (self, eventNames, maxWait) |
Wait for event(s) | |
nEvents | getNumberOfEvents (self) |
More... | |
IDs | getComponentIDs (self) |
More... | |
ID | getComponentID (self, nameOrID) |
| |
name | getComponentName (self, nameOrID) |
| |
indices | getComponentIndicesByID (self, IDs) |
| |
indices | getComponentIndicesByName (self, names) |
| |
time | getDeviceTime (self) |
| |
setDeviceTime (self, val) | |
| |
startTrial (self, varargin) | |
More... | |
finishTrial (self, varargin) | |
More... | |
plotData (self) | |
More... | |
startTrialDevice (self, varargin) | |
Overloaded methods. | |
Protected Methods | |
components | openComponents (self) |
Locate and enqueue all the keys of the keyboard. | |
closeComponents (self) | |
Unenqueue all the keys of the keyboard. | |
![]() | |
isOpen | openDevice (self) |
Find the best available HID device with mexHID(). | |
closeDevice (self) | |
Release mexHID() resources for this device. | |
isOpen | openHIDQueue (self, cookies) |
Open a queue to record value changes for device elements. More... | |
newData | readNewData (self) |
Pass any data from the mexHID() internal queue to this object(). More... | |
![]() | |
isOpen | openDevice (self) |
More... | |
closeDevice (self) | |
More... | |
resetDevice (self, varargin) | |
Reset the device. | |
status | calibrateDevice (self, varargin) |
More... | |
isRecording | startRecording (self) |
| |
isRecording | stopRecording (self) |
| |
components | openComponents (self) |
More... | |
closeComponents (self) | |
More... | |
newData | readNewData (self) |
More... | |
isEvent | detectEvents (self, data) |
More... | |
newSize | resizeEventQueue (self, minSize, doClear) |
More... | |
nEvents | enqueueEvents (self, eventValues) |
More... | |
eventValue nEvents | dequeueEvent (self, isPeek) |
More... | |
Static Methods | |
static kbs | openManyKeyboards () |
Open all of the available HID keyboards. More... | |
static | closeManyKeyboards (kbs) |
Close several HID keyboards. More... | |
static isPressed data kb | isKeyPressed (kbs, keyName) |
Is the given key pressed, on one or many keyboards? More... | |
static didHappen waitTime data kb name | waitForKeyPress (kbs, keyName, maxWait, flush, waitForRelease) |
Wait for given key to be pressed, on one or many keyboards. More... | |
![]() | |
static | mexHIDQueueCallback (self, newData) |
Pass data from the mexHID() internal queue to Matlab. For newData, Rows are inputs Columns are. | |
static time | currentHIDTime () |
Get the current time from the system USB/HID implementation. | |
![]() | |
static isHappening data readable | isEventHappening (readables, eventName) |
More... | |
static didHappen waitTime data readable name | waitForEvent (readables, eventName, maxWait) |
More... | |
static data | loadDataFile (filename, varargin) |
Load data from file. More... | |
Additional Inherited Members | |
![]() | |
Property | deviceID |
device identifier from mexHID('openMatchingDevice') More... | |
Property | queueCallback = @dotsReadableHID.mexHIDQueueCallback |
Callback which mexHID() uses to pass HID data to Matlab. More... | |
Property | queueCallbackData |
matrix of recent data passed in from mexHID() | |
![]() | |
Property | eventQueue |
| |
Property | queueNext |
| |
Property | queueLast =0 |
| |
Property | isRecording =false |
| |
Property | didCalibrate = true |
Keep track of whether calibration occurs. | |
Property | defaultEventPrefix = 'event' |
Default prefix for event names: <prefix>_<componentName> | |
Property | eventSets |
Strutures with different named event definitions, in case we want to quickly swap between them. | |
self dotsReadableHIDKeyboard | ( | devicePreference | ) |
Get rid of annoying rollover event.
Constructor may take device matching preferences.
devicePreference | struct of HID matching parameters |
devicePreference is an optional struct of HID parameters for choosing among suitable devices, assigned to the devicePreference property. jig added useSecondary flag to be able to get a second keyboar
|
static |
Open all of the available HID keyboards.
Scans for connected HID keyboards and constructs a dotsReadableHIDKeyboard object for each. Returns the objectss as an array of dotsReadableHIDKeyboard.
|
static |
Close several HID keyboards.
kbs | array of dotsReadableHIDKeyboard objects |
Invokes close() on each of the given dotsReadableHIDKeyboard objects. Objects should be re-initialized or discarded.
|
static |
Is the given key pressed, on one or many keyboards?
kbs | array of dotsReadableHIDKeyboard objects |
keyName | the HID usage name of a keyboard key |
Creates a "pressed" event for the given keyName, on each of the given kbs. Checks whether the pressed event is happening on any of the given kbs.
Returns true if any of given kbs has keyName currently pressed. Returns as a second output the data associated with the key press. The data has the form [ID, value, time]. Returns as a third output the keyboard object on which the key is pressed. If keyboard has the key pressed, returns only the first one.
|
static |
Wait for given key to be pressed, on one or many keyboards.
Arguments: kbs ... dotsReadableHIDKeyboard object (or cell array of them) keyName ... the HID usage name (component) of a keyboard key (or blank for any key to wait for any key) maxWait ... maximum time to wait for key press (sec) flush ... whether or not to flush queue before starting waitForRelease ... whether to wait for release after press
Creates a "pressed" event for the given keyName, on each of the given kbs. Waits for one of of the given kbs to report that the given keyName was pressed. maxWait specifies how long to wait before giving up. Uses currentTime() of the first object to keep track of time. Invokes read() and checks each object for events at least once, even if maxWait is zero or negative.
Returns true if any of given kbs reports that keyName was pressed, before maxWait. Returns as a second output the amout of time waited. Returns as a third output the data associated with the key press. The data has the form [ID, value, time]. Returns as a fourth output the object which reported the key press. If more than one keyboard can report that the key was pressed, only the first one is returned.
Property keyMatching |
Example usage: kb = dotsReadableHIDKeyboard(); [isPressed, waitTime, data, kbout] = dotsReadableHIDKeyboard.waitForKeyPress(kb, 'KeyboardF', 5, true)
struct of HID parameters to identify the key elements of the keyboard.
See mexHIDUsage() or mexHIDUsage.gui() for lists of valid HID parameters.
Property VendorIDs |
matching preferences read from machine defaults ...
including secondary values if/when second keyboard is added