Events?
Now that I've got node-usb running, I've plugged in an xbox controller and am exploring what it offers.
One thing that I'm not really sure about is how to listen for events from a given device. Is it necessary to poll a usb device continuously, such as a game controller, to get its modified input values? Or rather, is there an event interface on node-usb that I can subscribe to?
On further research, I see that one must poll interruptTransfer based on the bInterval value provided by the device.
There's no examples of using interruptTransfer in the examples, though there is a controlInterrupt. However the interfaces seem different.
Exactly, you must poll the endpoint. Interrupt transfer has the same arguments as Endpoint.bulkTransfer.
I was able to get this all working after digging through source code.
One thing I want to get your opinion on is the argument order. The interrupt is looks like (I forget what 'first' is at the moment):
interrupt(first, callbackFunction, timeout);
As I wrote code for this:
interrupt(first, function(){ //do stuff }, 0);
It feels funny to have something other than the callback function as the last argument. Shouldn't it be in the order of first, timeout, callback?