FRC4564 / Xbox

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

Python 3 support #7

Closed Oracking closed 6 years ago

Oracking commented 6 years ago

Added in bytes to string conversion of pipe output for python3. Also added an extra condition to detect if controller has been detected when run with python3.

FRC4564 commented 6 years ago

@Oracking Thanks for the contribution. It's funny, this weekend I was working on a Python 3 adaptation for this module. I had it working fairly well, but had a problem with it not always reading the most recent update of the controller. I'll test out the revisions you've made to see how they work. It may be a few days before I get it, since I'm going on a short vacation.

I do have a question for you. Did you find it necessary to add in the test for 'usb path'? Perhaps something has changed with xboxdrv that necessitates this, but it isn't something that I've noticed.

FRC4564 commented 6 years ago

@Oracking I had a chance to download and run your Branch and found that it had the same flaw a ran into this past weekend. After a bit of research, I found that the issue was related to the subprocess call. Under Python 2 bud size defaults to 0, by under Python 3 it defaults to -1. Simple enough. I’ve updated the sample.py code to be compatible with Python 3. It need many changes. Will upload these updates shortly.

FRC4564 commented 6 years ago

Autocorrect typo in that last post. Should say bufsize, not bud size.

FRC4564 commented 6 years ago

Python 3 patches are in place, as mentioned in previous comments.

Oracking commented 6 years ago

Sorry for the late response, was having some ISP issues and couldn't get github to load.

It's awesome you were able to patch up the code for python3.

Also, interesting thing there about the bufsize, did not know that myself. After making my changes to the xbox module, I did have to set a read interval in my code to prevent the program from hanging up. I forgot to mention that. With that setup, I was able to get it to run on my PC. Your solution is certainly preferable.

I will definitely test the changes when I get my hands on another controller.

My only concern is that in the code, 'response' from 'self.pipe.readline()' is assumed to be in bytes. Per my knowledge, this is not the case with python2, which defaults to a string. This may cause some backwards compatibility issues. However, if the aim was to make it work solely with python3, then that's fine.

If not, then I'd suggest encoding string 'response' for python2 support.

FRC4564 commented 6 years ago

I do expect it to work with both Python 2 and 3. The testing I did with the latest update worked well for both versions, so I think it is good to go. Let me know if you run into any issues.

Oracking commented 6 years ago

Alright then. Will keep you updated