Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jamesra
Copy link

@jamesra jamesra commented Mar 28, 2023

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.

@@ -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)
Copy link

@henrygab henrygab Sep 22, 2023

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)

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)

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...

@henrygab
Copy link

FYI ... 8-bit axis have ubiquitous support ... every OS and every embedded OS I've tries supports an 8-bit axis.
I don't think the same is true for 16-bit axis. On smaller microcontrollers, every byte of the descriptor matters ... some boards have a smaller upper limit on total descriptor size. If a project is already pushing the limit, this could also cause a break on upgrade.

Therefore, I would like to suggest a slightly different approach, to minimize risk of breaking existing projects:

Opt-In to 16-bit axis support.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants