PS3 controller driver & # 8594; uinput-> python? in some way?

I am trying to read from a PS3 controller in python on Ubuntu and I am not very lucky. I started with the ps3joy driver from Willow Garage (http://www.ros.org/wiki/ps3joy), which supposedly publishes all the important bits of the PS3 controller for something that I have never heard of the name "uinput". Apparently, this is a linux function that allows userpace drivers to provide system events .... Why does the WG driver require root access, given that it is supposedly a user space driver located outside of me, but that is not my question.

In any case, the current state when I try to make it work is that I have a driver, and I checked that it responds to button presses on the controller, but I don’t know how to pull any of this data, so I can use it.

My first assumption was to use pygame to (hopefully) read from / dev / uinput (which I'm sure where the driver sends the data):

from pygame import joystick
if not joystick.get_init():
  joystick.init()
js = joystick.Joystick(0)  # there is only one joystick... even if the driver isn't running(!)
js.init()
print js.get_numbuttons()  # perhaps coincidentally correctly prints 17 which is the number of buttons on a PS3 controller
for i in range(js.get_numaxes()):
  print js.get_axis(i)   # always prints 0, no matter what I'm doing with the controller

but it didn’t work. The most important part of the problem is that it does the same if I don't have a WG driver at all.

I am sure that this is something simple, that I just do not read the right information, but googling did not help me find the right information, and I get tired and desperate.

+5
source share
5 answers

. , HID, .

+3

pygame.event.pump()

. 360

+1

, - , . script python, ps3 USB MAC- -bluetooth ( ps3controller.py ). quadcopter.

https://github.com/urbanzrim/ps3controller

+1

: / Bluetooth bluetooth PS3 python GNU/Linux.

:

0

, , , :

from pygame import joystick, event, display
display.init()
joystick.init()
js=joystick.Joystick(0)
js.init()
...
for foo in bar:
    event.pump()
    ...

if foo:
    event.pump()
    ...

while bar:
    event.pump()
    ...

, display.init() , ...

,

import pygame
pygame.init()
js=pygame.joystick.Joystick(0)
js.init()
...
for foo in bar:
    pygame.event.pump()
    ...
if foo:
    pygame.event.pump()
    ...

while bar:
    pygame.event.pump()
    ....

, , : A) event.pump if/while/for B) display.init()

Sources: http://webcache.googleusercontent.com/search?q=cache:I56GyE7I4CkJ:iamtherockstar.com/archive/making-hid-devices-easier-using-pygame-joysticks/+&cd=1&hl=en&ct=clnk&gl=us as well as http://www.pygame.org/docs/ref/event.html

"The input queue is highly dependent on the pygame display module."

0
source

All Articles