PS3控制器驱动程序 - > uinput-> python?不知何故?

ter*_*ret 5 python ps3

我试图在Ubuntu的python中读取PS3控制器,但我没有太多运气.我开始使用Willow Garage的ps3joy驱动程序(http://www.ros.org/wiki/ps3joy),该驱动程序据称将PS3控制器的所有重要部分发布到我从未听说过的称为"uinput"的部分.显然它是一个Linux功能,允许用户空间驱动程序提供系统事件....为什么WG驱动程序需要root访问权限,因为它应该是一个用户空间驱动程序超出我的范围,但这不是我的问题.

无论如何,我试图让它工作的当前状态是我有驱动程序工作,我已经验证它响应按钮按下控制器,但我不知道如何拉动任何数据输出所以我可以使用它.

我的第一个猜测是使用pygame(希望)从/ dev/uinput读取(我很确定驱动程序发送数据的位置):

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
Run Code Online (Sandbox Code Playgroud)

但它不起作用.问题中最有说服力的部分是,如果我根本没有运行WG驱动程序,它会做同样的事情.

我确信这很容易,我只是没有阅读正确的信息,但谷歌搜索并没有帮助我找到正确的信息,我已经厌倦和绝望.

Ign*_*ams 3

你不需要司机。假设控制器将自身公开为 HID,您可以使用事件子系统直接从设备读取控制器事件。