Recovering from keyboard disconnection

Hi Yasmine & Jack,

I’ve made some changes to MWorks’ USBHID interface that should allow it to recover from device removal and reconnection (e.g. the spurious Bluetooth keyboard dropouts you’ve experienced) without requiring the experiment to be stopped or reloaded.

If the selected device is removed, MWorks will report the removal via an error message. For example:

ERROR: HID device "keyboard" was removed

This will happen irrespective of whether the experiment is currently running. If the device is subsequently reconnected, MWorks will report this, too, and indicate whether it was able to reestablish communication:

Attempting to reconnect to HID device "keyboard"...
HID device "keyboard" reconnected successfully

Again, this will happen even if the experiment isn’t running. After a successful reconnection, I/O from the device will once again be received and handled as per usual.

Note that, in order for an actual USB device to be recognized correctly upon reconnection, it must be plugged in to the same USB port as before disconnection. For a Bluetooth keyboard or mouse, this shouldn’t be an issue.

Also, I’ve observed that, after turning my Bluetooth keyboard off and back on to simulate disconnection, the device doesn’t actually reconnect until I press a key on it. I don’t know if this will be the case with spontaneous disconnects, but it’s something to keep in mind.

These changes will be in tonight’s nightly build.

Cheers,
Chris