mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
feat(g29): corriger le protocole des leds rpm avec le report id 0x30
This commit is contained in:
1 parent
0e4667b8eb
commit
abd5214863
6 files changed
+571
-46
No files matched your search
+199
@@ -0,0 +1,199 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Interactive LED frame test for Logitech G29 on Linux (/dev/hidraw2)
|
||||
Tests multiple framing methods for RPM LEDs:
|
||||
- Output report 0x05 (32 bytes)
|
||||
- Feature report 0xF3 (7-8 bytes)
|
||||
- Feature report 0xF0 (64 bytes)
|
||||
- Raw unnumbered output report (0x00 + 7-8 bytes)
|
||||
- Raw direct output report (0xF8 + 7 bytes)
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import fcntl
|
||||
import time
|
||||
|
||||
HIDIOCSFEATURE = lambda length: 0xC0004806 | (length << 16)
|
||||
|
||||
def find_g29():
|
||||
import glob
|
||||
for h in sorted(glob.glob('/dev/hidraw*')):
|
||||
uevent = f'/sys/class/hidraw/{os.path.basename(h)}/device/uevent'
|
||||
if os.path.exists(uevent):
|
||||
with open(uevent) as f:
|
||||
c = f.read().upper()
|
||||
if '046D:0000C260' in c or '046D:0000C24F' in c or 'LOGITECH' in c:
|
||||
return h
|
||||
return '/dev/hidraw2'
|
||||
|
||||
def test_method(fd, name, func):
|
||||
print(f"\n==========================================")
|
||||
print(f"▶ TEST: {name}")
|
||||
print(f"==========================================")
|
||||
# Send all LEDs ON (0x1F = 5 pairs = all 5 LEDs)
|
||||
func(0x1F)
|
||||
time.sleep(1.5)
|
||||
# Send all LEDs OFF (0x00)
|
||||
func(0x00)
|
||||
time.sleep(0.5)
|
||||
|
||||
def main():
|
||||
dev = find_g29()
|
||||
print(f"Ouverture de {dev}...")
|
||||
fd = os.open(dev, os.O_RDWR)
|
||||
|
||||
# Method 1: Output Report 0x05 (32 bytes total: 0x05, 0xF8, 0x12, mask, 0x00...)
|
||||
def m1(mask):
|
||||
pkt = bytes([0x05, 0xF8, 0x12, mask] + [0x00] * 28)
|
||||
try:
|
||||
res = os.write(fd, pkt)
|
||||
print(f" [M1 - Output 0x05] write({len(pkt)} bytes) -> {res}")
|
||||
except Exception as e:
|
||||
print(f" [M1 - Output 0x05] Erreur: {e}")
|
||||
|
||||
# Method 2: Output Report 0x00 prefix (Unnumbered report 7-8 bytes: 0x00, 0xF8, 0x12, mask, 0, 0, 0, 0)
|
||||
def m2(mask):
|
||||
pkt = bytes([0x00, 0xF8, 0x12, mask, 0x00, 0x00, 0x00, 0x00])
|
||||
try:
|
||||
res = os.write(fd, pkt)
|
||||
print(f" [M2 - Unnumbered Output] write({len(pkt)} bytes) -> {res}")
|
||||
except Exception as e:
|
||||
print(f" [M2 - Unnumbered Output] Erreur: {e}")
|
||||
|
||||
# Method 3: Output Report 0xF8 prefix (Report ID 0xF8: 0xF8, 0x12, mask, 0, 0, 0, 0)
|
||||
def m3(mask):
|
||||
pkt = bytes([0xF8, 0x12, mask, 0x00, 0x00, 0x00, 0x00])
|
||||
try:
|
||||
res = os.write(fd, pkt)
|
||||
print(f" [M3 - Output 0xF8] write({len(pkt)} bytes) -> {res}")
|
||||
except Exception as e:
|
||||
print(f" [M3 - Output 0xF8] Erreur: {e}")
|
||||
|
||||
# Method 4: Feature Report 0xF3 (8 bytes: 0xF3, 0xF8, 0x12, mask, 0, 0, 0, 0)
|
||||
def m4(mask):
|
||||
pkt = bytearray([0xF3, 0xF8, 0x12, mask, 0x00, 0x00, 0x00, 0x00])
|
||||
try:
|
||||
res = fcntl.ioctl(fd, HIDIOCSFEATURE(len(pkt)), pkt)
|
||||
print(f" [M4 - Feature 0xF3 (F8 12)] ioctl(8 bytes) -> {res}")
|
||||
except Exception as e:
|
||||
print(f" [M4 - Feature 0xF3 (F8 12)] Erreur: {e}")
|
||||
|
||||
# Method 5: Feature Report 0xF3 (8 bytes: 0xF3, 0x12, mask, 0, 0, 0, 0, 0)
|
||||
def m5(mask):
|
||||
pkt = bytearray([0xF3, 0x12, mask, 0x00, 0x00, 0x00, 0x00, 0x00])
|
||||
try:
|
||||
res = fcntl.ioctl(fd, HIDIOCSFEATURE(len(pkt)), pkt)
|
||||
print(f" [M5 - Feature 0xF3 (12 mask)] ioctl(8 bytes) -> {res}")
|
||||
except Exception as e:
|
||||
print(f" [M5 - Feature 0xF3 (12 mask)] Erreur: {e}")
|
||||
|
||||
# Method 6: Feature Report 0xF0 (64 bytes: 0xF0, 0xF8, 0x12, mask, 0x00...)
|
||||
def m6(mask):
|
||||
pkt = bytearray([0xF0, 0xF8, 0x12, mask] + [0x00] * 60)
|
||||
try:
|
||||
res = fcntl.ioctl(fd, HIDIOCSFEATURE(len(pkt)), pkt)
|
||||
print(f" [M6 - Feature 0xF0] ioctl(64 bytes) -> {res}")
|
||||
except Exception as e:
|
||||
print(f" [M6 - Feature 0xF0] Erreur: {e}")
|
||||
|
||||
# Method 7: Init sequence first (CMD 4, CMD 3 range 900), then Output 0x05
|
||||
def m7(mask):
|
||||
# f8 04 01 ...
|
||||
cmd_init = bytes([0x05, 0xF8, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00] + [0x00]*24)
|
||||
# f8 03 00 ... (900 deg)
|
||||
cmd_range = bytes([0x05, 0xF8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00] + [0x00]*24)
|
||||
# f8 12 mask ...
|
||||
cmd_led = bytes([0x05, 0xF8, 0x12, mask, 0x00, 0x00, 0x00, 0x00] + [0x00]*24)
|
||||
try:
|
||||
os.write(fd, cmd_init)
|
||||
os.write(fd, cmd_range)
|
||||
res = os.write(fd, cmd_led)
|
||||
print(f" [M7 - Init + Output 0x05] write -> {res}")
|
||||
except Exception as e:
|
||||
print(f" [M7 - Init + Output 0x05] Erreur: {e}")
|
||||
|
||||
# Method 8: Repeating 7-byte pattern in Output 0x05 (like in g29_crsf.ino)
|
||||
def m8(mask):
|
||||
pattern = bytes([0xF8, 0x12, mask, 0x00, 0x00, 0x00, 0x00])
|
||||
# 31 bytes payload = 4 x 7 bytes + 3 bytes
|
||||
payload = pattern * 4 + bytes([0xF8, 0x12, mask])
|
||||
pkt = bytes([0x05]) + payload
|
||||
try:
|
||||
res = os.write(fd, pkt)
|
||||
print(f" [M8 - Repeating in 0x05] write -> {res}")
|
||||
except Exception as e:
|
||||
print(f" [M8 - Repeating in 0x05] Erreur: {e}")
|
||||
|
||||
tests = [
|
||||
("1", "Output Report 0x05 standard (0x05, 0xF8, 0x12, mask, 0...)", m1),
|
||||
("2", "Output Sans ID (0x00, 0xF8, 0x12, mask, 0...)", m2),
|
||||
("3", "Output Report 0xF8 direct (0xF8, 0x12, mask...)", m3),
|
||||
("4", "Feature Report 0xF3 (0xF3, 0xF8, 0x12, mask...)", m4),
|
||||
("5", "Feature Report 0xF3 court (0xF3, 0x12, mask...)", m5),
|
||||
("6", "Feature Report 0xF0 (0xF0, 0xF8, 0x12, mask...)", m6),
|
||||
("7", "Init PS4 (CMD 4 + Range) puis Output 0x05", m7),
|
||||
("8", "Répétition 7-octets dans Output 0x05", m8),
|
||||
]
|
||||
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--method', '-m', type=str, default='all', help='Méthode à tester (1 à 8, ou all)')
|
||||
parser.add_argument('--on', action='store_true', help='Allumer en continu (ne pas éteindre)')
|
||||
parser.add_argument('--interactive', '-i', action='store_true', help='Mode interactif (touches 1 à 8 pour allumer, 0 pour éteindre)')
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.interactive:
|
||||
print("\n=== MODE INTERACTIF TEST LEDS G29 ===")
|
||||
print("Touches :")
|
||||
for num, name, _ in tests:
|
||||
print(f" [{num}] : {name}")
|
||||
print(" [0] : Éteindre toutes les méthodes")
|
||||
print(" [q] : Quitter\n")
|
||||
try:
|
||||
import tty, termios
|
||||
old_settings = termios.tcgetattr(sys.stdin)
|
||||
tty.setcbreak(sys.stdin.fileno())
|
||||
while True:
|
||||
ch = sys.stdin.read(1)
|
||||
if ch == 'q':
|
||||
break
|
||||
if ch == '0':
|
||||
print("\r-> Éteindre tout...")
|
||||
for _, _, f in tests:
|
||||
f(0x00)
|
||||
else:
|
||||
for num, name, func in tests:
|
||||
if ch == num:
|
||||
print(f"\r-> Test {num} ({name}) : ALLUMÉ (0x1F)")
|
||||
func(0x1F)
|
||||
break
|
||||
finally:
|
||||
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
|
||||
print("\nFin.")
|
||||
os.close(fd)
|
||||
return
|
||||
|
||||
if args.method != 'all':
|
||||
chosen = [t for t in tests if t[0] == args.method]
|
||||
if not chosen:
|
||||
print(f"Méthode {args.method} inconnue. Choisis entre 1 et 8.")
|
||||
sys.exit(1)
|
||||
num, name, func = chosen[0]
|
||||
print(f"\n▶ Test Méthode {num} : {name}")
|
||||
func(0x1F)
|
||||
if not args.on:
|
||||
time.sleep(2.0)
|
||||
func(0x00)
|
||||
print("Éteint.")
|
||||
else:
|
||||
print("Démarrage du test séquentiel des méthodes d'allumage des LEDs...")
|
||||
print("Observe bien le volant : nous testons chaque méthode pendant 1.5s.\n")
|
||||
for num, name, func in tests:
|
||||
test_method(fd, f"Méthode {num} : {name}", func)
|
||||
print("\nFin des tests !")
|
||||
|
||||
os.close(fd)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in new issue
Block a user