Ich habe mir nach einiger Zeit mal wieder mein altes
"Xbox360 wireless Controller with chatpad" Script
vorgenommen und auf meinen neuen Rechner installiert.
Das Script hatte auch schonmal funktioniert, obwohl ich mir nicht sicher bin, ob es die selbe Version ist
(ja ich sollte mich mal mit Subversion o.ä. beschäftigen),
oder ich zwischenzeitig nochmal etwas geändert habe, jedenfalls habe ich wieder Probleme damit.
Ähnliche Probleme wie früher,
damals hat mir das chatpad 8 Tastendrücke pro Loop ausgegeben,
Jetzt aber gibt es mir nur noch einen, etwa alle 3sek. aus.
Also, Zählerschleife deaktiviert, mit dem selben Ergebnis.
Da ich jetzt schon einiges ausprobiert habe, gebe ich jetzt mal den (fast) kompletten Programmcode raus,
Vielleicht könnt ihr mir ja helfen,
oder vielleicht hat jemand anderes Lust den Code weiter zu schreiben.
Code: Alles auswählen
#!/usr/bin/env python3
## Import utilities -------------------------------------------
import os, time, struct
import usb.core
import usb.util
import uinput
## Import mappings ------------------------------------------------------------
from initcodes import code
from keycodes import *
from buttoncodes import *
## XBox 360 wireless controller with chatpad --------------------------
## By David Vasic aka djevil(a)remotors.de ------------------------------
## Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)
#help(uinput)
## Get device
dev = usb.core.find(idVendor=0x045e, idProduct=0x0719)
time.sleep(.4)
## Write to controller at: --------------------------------------------------------
iface = 0
epoint = 0x01
## Controller commands: ---------------------------------------------------------
def rumble():
dev.write(epoint, bytes([0x00, 0x01, 0x0f, 0xc0, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00]), iface)
def statusLED():
dev.write(epoint, bytes([0x00, 0x00, 0x08, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), iface)
def keepAlive1():
dev.write(epoint, bytes([0x00, 0x00, 0x0c, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), iface)
def keepAlive2():
dev.write(epoint, bytes([0x00, 0x00, 0x0c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), iface)
def chatpadInit():
dev.write(epoint, bytes([0x00, 0x00, 0x0c, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), iface)
## Controller / Analog sticks ------------------------------------------------------
def leftStick():
if u > 16384:
device.emit(uinput.REL_X, 15, syn=False)
if u < -16384:
device.emit(uinput.REL_X, -15, syn=False)
if v > 16384:
device.emit(uinput.REL_Y, -15, syn=False)
if v < -16384:
device.emit(uinput.REL_Y, 15, syn=False)
## Chatpad / Keys -------------------------------------------------------------------
def keys():
knr=data[26]
print(knr)
if counter == 0 and knr != 128 and knr != 0:
## None / default
if data[25] == 0:
device.emit_click(keycode[knr])
print(knr)
## Counter for debouncing / debugging ------------------------------------
global counter
counter = 0
## Infinte loop for reading input ----------------------------------------------
with uinput.Device(code) as device:
while 1:
try:
statusLED()
keepAlive2()
chatpadInit()
## Keep alive3
#device.emit_click(buttoncode[64])
keepAlive1()
## read(bEndpointAddress, size_or_buffer, timeout ms )
data = dev.read(0x81, 29) #len=29
#print(data)
keepAlive2()
## Chatpad / Keys ----------------------------------------------------
keys()
## -------------------------------------------------------------------------
keepAlive1()
### read(bEndpointAddress, size_or_buffer, timeout ms )
data = dev.read(0x81, 29, 0) #len=29
##print(data)
### Controller / Analog sticks ---------------------------------------
u, v = struct.unpack_from("<hh", data, 10)
#print("U: ", u, "V: ", v)
leftStick()
### -------------------------------------------------------------------------
#counter += 1
#if counter == 8:
#counter = 0
except Exception as e:
print(e)
## https://www.python-forum.de/viewtopic.php?f=4&t=39444
## Special thanks to: Sirius3 and BlackJack
ich habe den Code dokumentiert, ist vielleicht nicht alles unbedingt selbst erklären, also gerne fragen.
Die keepAlive Packages sind nötig um das Chatpad nach der Initialisierung anzuschalten, und ihm am "Leben zu erhalten", andererseits behindern diese auch die Tastenausgabe und verzögern diese, das also ist wohl Kern des Problems.
Wenn jemand dieses Script weiterentwickeln will, kann ich ihm auch den kompletten Source senden.
Wäre dann schön den neuen Source hier wieder anzufügen, bzw mir zu senden.
MFG djevil