-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Issue #12: Converted joystick_xl to send 16-bits per axis #15
base: main
Are you sure you want to change the base?
Conversation
@@ -73,13 +73,15 @@ def create_joystick( | |||
|
|||
_descriptor.extend(bytes(( | |||
0x15, 0x00, # : LOGICAL_MINIMUM (0) | |||
0x26, 0xFF, 0x00, # : LOGICAL_MAXIMUM (255) | |||
0x75, 0x08, # : REPORT_SIZE (8) | |||
0x27, 0xFF, 0xFF, 0x00, 0x00, # : LOGICAL_MAXIMUM (1 << 16) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
off-by-one in the comments?
LOGICAL_MAXIMUM ((1 << 16) - 1)
0x75, 0x08, # : REPORT_SIZE (8) | ||
0x27, 0xFF, 0xFF, 0x00, 0x00, # : LOGICAL_MAXIMUM (1 << 16) | ||
0x35, 0x00, # : PHYSICAL_MINIMUM (0) | ||
0x47, 0xFF, 0xFF, 0x00, 0x00, # : PHYSICAL_MAXIMUM (1 << 16) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
off-by-one in the comments?
PHYSICAL_MAXIMUM ((1 << 16) - 1)
****
new_value = self._db_range // 2 | ||
|
||
# calculate scaled joystick-compatible value and clamp to 0-255 | ||
self._value = min(new_value * 256 // self._db_range, 255) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it correct that scaling is not supported?
I note that physical and logical maximums are equal, so scaling shouldn't do anything. Just making sure...
FYI ... 8-bit axis have ubiquitous support ... every OS and every embedded OS I've tries supports an 8-bit axis. Therefore, I would like to suggest a slightly different approach, to minimize risk of breaking existing projects:
For example, modify the constructor to handle a new type, such as: # in boot.py
create_joystick(axes_16bit=2, axes=4, buttons=10, hats=1)
# ... and later in main.py ....
joystick = Joystick()
joystick.add_input( ..., Axis_16bit(...), ...) In this way, the risk of breaking existing projects can be minimized. |
This is my 16-bit axis resolution change. I made some changes to the deadzone code that I hope match the original intention. In particular input.py#247
self._value = min(new_value * 256 // self._db_range, 255)
was causing the problems when I tried to port it to 16-bit and I decided to keep what I ended up with.