node-usb icon indicating copy to clipboard operation
node-usb copied to clipboard

Events?

Open geuis opened this issue 13 years ago • 3 comments

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?

geuis avatar Apr 08 '12 05:04 geuis

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.

geuis avatar Apr 08 '12 07:04 geuis

Exactly, you must poll the endpoint. Interrupt transfer has the same arguments as Endpoint.bulkTransfer.

schakko avatar Apr 10 '12 11:04 schakko

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?

geuis avatar Apr 10 '12 20:04 geuis