2

我想用 Raspberry Pi 读取 Logitech Logitech Extreme 3D Pro 的值。我正在使用pygame 库

剧本:

import pygame
import sys
import time

pygame.joystick.init()

print pygame.joystick.get_count()

_joystick = pygame.joystick.Joystick(0)
_joystick.init()
print _joystick.get_init()
print _joystick.get_id()
print _joystick.get_name()
print _joystick.get_numaxes()
print _joystick.get_numballs()
print _joystick.get_numbuttons()
print _joystick.get_numhats()
print _joystick.get_axis(0)

输出:

1
1
0
Logitech Logitech Extreme 3D Pro
4
0
12
SDL_JoystickNumHats value:1:
1
SDL_JoystickGetAxis value:0:
0.0

有 4 个轴,我转动了所有轴。

我找不到问题。我已经尝试过使用其他轴。

感谢帮助。

4

3 回答 3

3

我遇到了同样的问题。您必须编写 pygame.event.get() 才能从操纵杆读取信息。否则它永远不会更新。

于 2014-09-29T23:09:44.820 回答
2

如果问题是值始终为 0,那么pygame.event.pump()在读取值之前尝试做。我有一个类似的问题,这有帮助。

于 2014-01-11T17:03:33.593 回答
0

我宁愿等待(甚至更多地在一个线程中),例如:

    axes = [ 0.0 ] * your_joystick.get_numaxes()
    buttons = [ False ] * your_joystick.get_numbuttons()

    while self.keep_alive:
        event = pygame.event.wait()
        if event.type == pygame.QUIT:
             self.keep_alive = False
        elif event.type == pygame.JOYAXISMOTION:
            e = event.dict
            axes[e['axis']] = e['value']
        elif event.type in [pygame.JOYBUTTONUP, pygame.JOYBUTTONDOWN ]:
            e = event.dict
            buttons[e['button']] ^= True
于 2015-05-21T16:17:20.923 回答