简体   繁体   English

如何使用pyusb控制xbox 360游戏手柄上的LED

[英]How to control the LED on an xbox 360 gamepad using pyusb

I'm looking to use pyusb to interact with a wired xbox 360 gamepad. 我希望使用pyusb与有线xbox 360游戏手柄进行交互。 So far I can read just fine but I'd also like to write so I can make the LED stop blinking. 到目前为止,我可以读得很好,但我也想写,所以我可以让LED停止闪烁。

Looking here , I should be able to do it, but no matter what messages I try sending, I'm not having any luck controlling the LED. 看到这里 ,我应该可以做到,但无论我尝试发送什么消息,我都没有运气控制LED。 Below is the code I have thus far, any suggestions? 以下是我到目前为止的代码,有什么建议吗?

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)

Solved it; 解决了它; just had to try more variants of the string being written. 只需要尝试更多正在编写的字符串变体。 Here's what eventually worked: 这是最终起作用的:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM