-
-
Notifications
You must be signed in to change notification settings - Fork 9
Issue #12: Converted joystick_xl to send 16-bits per axis #15
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. off-by-one in the comments?
|
||
0x75, 0x10, # : REPORT_SIZE (16) | ||
0x95, _num_axes, # : REPORT_COUNT (num_axes) | ||
0x81, 0x02, # : INPUT (Data,Var,Abs) | ||
))) | ||
|
||
_report_length = _num_axes | ||
_report_length = _num_axes * 2 | ||
|
||
if _num_hats: | ||
for i in range(_num_hats): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,10 +37,10 @@ class Axis: | |
MIN = 0 | ||
"""Lowest possible axis value for USB HID reports.""" | ||
|
||
MAX = 255 | ||
MAX = (1 << 16) - 1 | ||
"""Highest possible axis value for USB HID reports.""" | ||
|
||
IDLE = 128 | ||
IDLE = 1 << 15 | ||
"""Idle/Center axis value for USB HID reports.""" | ||
|
||
X = 0 | ||
|
@@ -236,16 +236,11 @@ def _update(self) -> int: | |
new_value = min(max(self._source.value, self._min), self._max) | ||
|
||
# account for deadband | ||
if new_value < (self._raw_midpoint - self._deadband): | ||
new_value -= self._min | ||
elif new_value > (self._raw_midpoint + self._deadband): | ||
new_value = new_value - self._min - (self._deadband * 2) | ||
else: | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Is it correct that scaling is not supported? |
||
if new_value >= self._raw_midpoint - self._deadband and \ | ||
new_value <= self._raw_midpoint + self._deadband: | ||
new_value = self._raw_midpoint | ||
|
||
self._value = new_value | ||
return self._value | ||
|
||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.
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)