-
-
Notifications
You must be signed in to change notification settings - Fork 310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(radio): properly center analog USB joystick axis #4883
base: main
Are you sure you want to change the base?
Conversation
Analog joystick axis are encoded as unsigned integers ranging [0 - 2047]. As a consequence input value 0 is reported as output 1024. This leads to asymmetric output: 1024 values smaller than 0 and 1023 values larger than 0. Fix EdgeTX#4881 by changing the range from [0 - 2027] to [0 - 2026]. As a consequence inputs -1024 and -1023 are both encoded as the same output 0.
Ignore, text was fixed above (You probably mean to change the range from [0 - 2047] to [0 - 2046] (and not 0-2027 to 0-2026)? In the PR code you have the values correct, the comment above is likely only wrong.) |
Why clip the high and low channel values? The code can also be simplified: int16_t value = limit(0, channelOutputs[i] + 1024, 2048); |
If you're cleaning up the code, the final '& 0x07' in these lines is redundant as the value range has already been limited: HID_Buffer[i*2 +4] = static_cast<uint8_t>((value >> 8) & 0x07); |
For no-clipping to occur the joystick output has to encode 12 bits instead of 11 bits. As the output already reserves space for 16 bits that's OK. I've incorporated the suggested code cleanup. There is quite a bit of potential for general code cleanup and de-duplication in the joystick area 😅 |
Not only in the joystick area. You are more than welcome to halo with that 😉. |
radio/src/mixer.cpp actually generates values [-1024 to +1024] (11 bit + 1) instead of [-1024 to +1023] (11 bit). Luckily the HID report descriptor already reserves 16 bits so the shift from 11 bit to 12 bit output is easy.
Analog USB joystick axis are encoded as unsigned integers ranging [0 - 2047]. As a consequence input value 0 is reported as output 1024. This leads to asymmetric output: 1024 values smaller than 0 and 1023 values larger than 0.
mixer.cpp generates values [-1024 to +1024] (11 bit + 1) instead of [-1024 to +1023] (11 bit). Luckily the HID report descriptor already reserves 16 bits so the shift from 11 bit to 12 bit output is easy.
Fix #4881 by changing the joystick range from [0 - 2047] to [0 - 2048].