Non-standard usage #11
-
Hi! Thank you in advance |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The short answer is yes, this is possible using JoystickXL. A word of warning, though - you mentioned "dozen of resistive sensors", but JoystickXL currently supports a maximum of 8 axes, so if you need more than 8 analog inputs on a single HID device then JoystickXL may not work for you. As far as implementation goes, JoystickXL natively supports ADC expanders that are already supported in CircuitPython such as the MCP3008. See the example in the JoystickXL docs here. You can also do completely custom input processing using """JoystickXL example using fully custom axis input processing."""
import random
from joystick_xl.inputs import Axis, VirtualInput
from joystick_xl.joystick import Joystick
joystick = Joystick()
joystick.add_input(
Axis(source=VirtualInput(value=32768)), # x-axis
Axis(source=VirtualInput(value=32768)), # y-axis
Axis(source=VirtualInput(value=32768)), # z-axis
Axis(source=VirtualInput(value=32768)), # rx-axis
Axis(source=VirtualInput(value=32768)), # ry-axis
Axis(source=VirtualInput(value=32768)), # rz-axis
Axis(source=VirtualInput(value=32768)), # s0-axis
Axis(source=VirtualInput(value=32768)), # s1-axis
)
def fancy_multiplexed_input_processing_for_axis(axis: int) -> int:
"""Retrieve and return your multiplexed source values here."""
new_value = (axis * 8191) + random.randint(0, 8191) # just generating random data in this example
return new_value
while True:
for a, axis in enumerate(joystick.axis):
axis.source_value = fancy_multiplexed_input_processing_for_axis(a)
joystick.update() |
Beta Was this translation helpful? Give feedback.
The short answer is yes, this is possible using JoystickXL. A word of warning, though - you mentioned "dozen of resistive sensors", but JoystickXL currently supports a maximum of 8 axes, so if you need more than 8 analog inputs on a single HID device then JoystickXL may not work for you.
As far as implementation goes, JoystickXL natively supports ADC expanders that are already supported in CircuitPython such as the MCP3008. See the example in the JoystickXL docs here.
You can also do completely custom input processing using
VirtualInput
objects as input sources. If you can collect analog sensor data and convert it to an integer range of 0-65535 (CircuitPython's standard range for analog i…