I’ve been playing with http://www.signal11.us/oss/hidapi/ (to communicate with my Wacom pen)
It’s really awesome. You can transfer bytes to/from HID devices. It’s just as single .h and a per-platform .c, so Dead easy to integrate with a JUCE project.
However I’m not sure how to design the main loop. This is what I’ve got so far:
const int /*enable_nonblocking = 1,*/ disable_nonblocking = 0;
jassert( hid_set_nonblocking(handle, disable_nonblocking) != FAIL); // block!
while(true) {
int bytes_got = hid_read(handle, packet, 10);
:
}
This is obviously awful. But what’s a good solution?
I think blocking is bad period.
So my options seem to be either a timer or Thread::sleep.
I think the best design would be to spawn a new thread, and use nonblocking + Thread::sleep.
Can anyone see anything wrong with that?
π