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
Zero division when trying detect joysticks #986
Comments
It doesn't look like you're doing anything wrong, but the controller is reporting invalid values. >>> js = pyglet.input.get_joysticks()[0]
>>> js.x_control.min
0
>>> js.z_control.max
255 pyglet uses evdev directly, not the ...clip...
Event type 3 (EV_ABS)
Event code 0 (ABS_X)
Value 129
Min 0
Max 255
Event code 1 (ABS_Y)
Value 125
Min 0
Max 255
...clip... pyglet's Controller and Joystick interfaces will always normalize input values between -1, 1. The lower level Devices interface will not, and you can also use that to check the raw values that the inputs return. For example: >>> for device in pyglet.input.get_devices():
... print(device)
...
EvdevDevice(name=Wireless Controller)
XInputDevice(name=Virtual core pointer)
XInputDevice(name=Virtual core keyboard)
XInputDevice(name=Virtual core XTEST pointer)
XInputDevice(name=Virtual core XTEST keyboard)
XInputDevice(name=xwayland-pointer:15)
XInputDevice(name=xwayland-relative-pointer:15)
XInputDevice(name=xwayland-pointer-gestures:15)
XInputDevice(name=xwayland-keyboard:15)
>>>
>>> device = pyglet.input.get_devices()[0]
>>> device.controls
[AbsoluteAxis(name=x, raw_name=ABS_X), AbsoluteAxis(name=y, raw_name=ABS_Y), AbsoluteAxis(name=z, raw_name=ABS_Z), AbsoluteAxis(name=rx, raw_name=ABS_RX), AbsoluteAxis(name=ry, raw_name=ABS_RY), AbsoluteAxis(name=rz, raw_name=ABS_RZ), AbsoluteAxis(name=hat_x, raw_name=ABS_HAT0X), AbsoluteAxis(name=hat_y, raw_name=ABS_HAT0Y), Button(raw_name=BTN_A), Button(raw_name=BTN_B), Button(raw_name=BTN_X), Button(raw_name=BTN_Y), Button(raw_name=BTN_TL), Button(raw_name=BTN_TR), Button(raw_name=BTN_TL2), Button(raw_name=BTN_TR2), Button(raw_name=BTN_SELECT), Button(raw_name=BTN_START), Button(raw_name=BTN_MODE), Button(raw_name=BTN_THUMBL), Button(raw_name=BTN_THUMBR)]
>>> device.controls[0].min
0
>>> device.controls[0].max
255 |
Many thanks, benmoran56, you gave me to figure out what was going on. I was getting the error even with no joystick connected and using evtest I noticed everything was correct with the PS3 game pad. The problem was in the "dummy" device which in the end was created by Input Remapper (https://github.com/sezanzeb/input-remapper/tree/main), a tool that I had forgotten I installed like one or two years ago to solve an issue with a logitech mouse. It seems that even with no remapping defined, the tool keeps alive a dummy device not properly defined (min-max axis values are equal). After removing the tool, I can normally read pad inputs with pyglet. Many thanks again for your help all pyglet team! |
I'm glad you found the root cause. I've added a small check in the control enumeration code, so that any axis with min/max both set to 0 will be skipped. At least this way it won't crash end user code. If you have a chance to test that utility again, it would be useful feedback, but no obligation. I'll close this ticket for now. |
Hi
I'm using pyglet 2.0.9 under Linux Mint and I'm having an issue when trying to initialise and read joystick inputs. I have physically only one PS3 DualShock pad connected through Bluetooth but somehow the OS recognises it as /dev/input/js0 and /dev/input/js1; only the latter is showing any activity when I calibrate it.
I'm using the code below which is pretty much straight from the documentation with the exception that I'm sub-classing pyglet.Window:
When I run it I'm getting the following error:
Any idea on what's the problem or what I'm doing wrong?
The text was updated successfully, but these errors were encountered: