【问题标题】:How to control the LED on an xbox 360 gamepad using pyusb如何使用 pyusb 控制 Xbox 360 游戏手柄上的 LED
【发布时间】:2016-07-20 01:32:53
【问题描述】:

我希望使用 pyusb 与有线 xbox 360 游戏手柄进行交互。到目前为止,我可以很好地阅读,但我也想写,这样我就可以让 LED 停止闪烁。

看着here,我应该可以做到,但无论我尝试发送什么消息,我都无法控制 LED。以下是我到目前为止的代码,有什么建议吗?

import usb
dev = usb.core.find(idVendor=1118, idProduct=654)
dev.set_configuration()
readEP = dev[0][(0,0)][0] #endpoint to read from
writeEP = dev[0][(0,0)][1] #endpoint to write to

print readEP #should be: <ENDPOINT 0x81: Interrupt IN>
print writeEP #should be: <ENDPOINT 0x1: Interrupt OUT>

##read the startup messages
for i in range(4): #usually only 4 messages
  data = dev.read(readEP.bEndpointAddress,readEP.wMaxPacketSize,100)
  print len(data) #should be 3

##get initial button/axes state
data = dev.read(readEP.bEndpointAddress,readEP.wMaxPacketSize,100)
print len(data) #should be 20

##Try to set the LED to illuminate just one element (message 0x06).
##Each of the following commented-out attempts fails to leave only the first
##element illuminated and subsequent attempts at reading or writing yields
##"usb.core.USBError: [Errno 5] Input/Output Error"
dev.write(writeEP,'010306',100) 
# dev.write(writeEP,'0\x010306',100) 
# dev.write(writeEP,'66310',100) #decimal value of 0x010306

##attempt to read again
while True:
  data = dev.read(readEP.bEndpointAddress,readEP.wMaxPacketSize,100)

【问题讨论】:

    标签: python usb pyusb gamepad


    【解决方案1】:

    解决了;只需要尝试正在编写的字符串的更多变体。以下是最终奏效的方法:

    dev.write(writeEP,"\x01\x03\x06",0)
    

    【讨论】:

      猜你喜欢
      • 2020-06-16
      • 1970-01-01
      • 2018-05-10
      • 2018-08-07
      • 1970-01-01
      • 1970-01-01
      • 2019-01-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多