FRC4564 / Xbox

Python class to support xbox 360 controller under Linux on RaspberryPi
129 stars 35 forks source link

False positives if pressing a button during init #8

Closed daz closed 5 years ago

daz commented 5 years ago

From the command line, running the below script:

sudo python3 test.py

And immediately tapping and releasing "down" on the dpad, results in an infinite stream of "dpad down" printed to stdout, until you tap another button. Anyone know a workaround?

#!/usr/bin/env python3

# test.py

from __future__ import print_function
import xbox

joy = xbox.Joystick()

while True:
    if (joy.dpadDown()):
      print("dpad down")

joy.close()
FRC4564 commented 5 years ago

I tried out your test code and don't see that there is necessarily a problem. As this code is written, the while loop is running at an unconstrained speed, so a quick tap of the dpad registers dozens, if not hundreds of lines of output, filling the screen instantly.

By default, the Joystick class refreshes, at most, 30 times per second, or about every 33ms. As a result, a quick press of the dpad will appear to last 33ms, at a minimum. During that time, the unconstrained while loop has plenty of time to spill out many lines on screen.

I'd suggest you give 'sample.py', included in the repository, a try to get a good visual response on how things are working. If you are still seeing a stuck button issue, then I suggest you run xboxdrv interactively to see the exact output that is being interpreted by the xbox.py code. Just issue the following command from your linux console.

sudo xboxdrv --detach-kernel-driver