PaulStoffregen
Well-known member
Can anyone see any problems with trying to use a rotary encoder to act as a Mouse.scroll() wheel in a Teensy build of a hybrid mouse-keyboard-gamepad-mega-joystick with more than 8 axes?
This should be possible. Certainly Teensy gives you the way to implement these HID interfaces and precisely control what actually gets sent to your PC.
To specifically answer your question, here are some challenges you might face.
If using Microsoft Windows, the default joystick driver might not recognize more than 8 axes, even though it's properly implemented on the Teensy side (assuming you've edited the code to enable the bigger HID joystick report - or otherwise edited the USB code).
In designing your code on the Teensy side, you'll want to avoid delays, so you're always being responsive to all the input signals. Simple as this sounds, real-world signals often aren't as nice as you might like and require "debouncing" or other techniques. Many people have gone down a path of adding delays in their code, which tends to work for only 1 signal, but then becomes really difficult when the delays to clean up 1 signal cause everything to be unresponsive to all the others. Teensyduino has features like elapsedMillis to make this easier, so if you need to do this sort of work I recommend using those and avoid delay().
HID provides fixed bandwidth. At best you can send 1000 events per second. That's usually plenty, but it can quickly become a limitation if you do things inefficiently. The joystick functions have a way to freeze, so you can change multiple settings and have it all go out the USB cable to your PC as a single packet.
If you do approach the bandwidth limits, those functions to send will end up waiting. If using the Encoder library, you may see the result of several changes at once. Likewise for other inputs, if those functions have to wait, your code may be "blind" to changes. Teensy's USB stack does buffer several outgoing packets, which gives you some flexibility. But as a general rule, if you try to sustain close to or more than 1000 updates per second, you will run into HID bandwidth limits and ultimately your code will suffer waits in the transmit functions.