-
-
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
Add usage examples for VirtualInput class #13
Comments
Hello there. Is there any more information about this? I have a lot of problems creating a functional joystick where I don't have any axis directly from any pins. Below example is redacted but its something like this:
|
There are a couple of things you'll need to modify to get that code to work as expected. First, verify that the Next, you should avoid calling
When you're finished just call I've modified the example you posted above with these suggestions, you can give it a shot and see if it works better for you. import math
import time
import board
import busio
import adafruit_vl53l0x
from joystick_xl.inputs import Axis, Button, Hat
from joystick_xl.joystick import Joystick
from adafruit_simplemath import map_range
# Axis configuration constants - remember that these are applied in the 16-bit raw input range,
# not the 8-bit scaled axis range.
AXIS_DB = 0 # Deadband to apply to axis center points.
AXIS_MIN = 0 # Minimum raw axis value.
AXIS_MAX = 65535 # Maximum raw axis value.
# Initialize joystick library
joystick = Joystick()
# Add axis inputs as VirtualInputs with no direct connection to analog pins
joystick.add_input(
Axis(deadband=AXIS_DB, min=AXIS_MIN, max=AXIS_MAX), # x-axis
Axis(deadband=AXIS_DB, min=AXIS_MIN, max=AXIS_MAX), # y-axis
)
# ...
while True:
# ...
# Update the axis VirtualInput source values
joystick.axis[Axis.X].source_value = int_value_computed_from_I2C_sensor
joystick.axis[Axis.Y].source_value = int_value_computed_elsewhere
# Process all inputs and send a USB-HID report to the host
joystick.update() |
Excellent. Glad to see you're so active! Maybe its an idea to add this use case to the examples? most seem focused on actual pins. |
The VirtualInput class decouples I/O pins from JoystickXL inputs and allows developers to do their own input processing before passing values along to JoystickXL. This functionality needs more documentation and examples.
The text was updated successfully, but these errors were encountered: