feat(g29): corriger le protocole des leds rpm avec le report id 0x30

This commit is contained in:
bleackstorm committed 2026-11-11 21:51:06 +01:00
1 parent 0e4667b8eb
commit abd5214863
6 files changed
+571 -46

No files matched your search

Executable
+177
View File
@@ -0,0 +1,177 @@
#!/usr/bin/env python3
"""
G29 HID Frame Sniffer & Decoder
Usage: python3 decode_g29.py [--raw]
"""
import os
import sys
import glob
import time
import struct
import select
def find_g29_hidraw():
for hidraw in sorted(glob.glob('/dev/hidraw*')):
name = os.path.basename(hidraw)
uevent_path = f'/sys/class/hidraw/{name}/device/uevent'
if os.path.exists(uevent_path):
with open(uevent_path, 'r') as f:
content = f.read()
if '046D:0000C260' in content.upper() or '046D:0000C294' in content.upper() or 'LOGITECH' in content.upper():
return hidraw
return None
def format_hat(hat_val):
hat_names = {
0: "↑ (Haut)",
1: "↗ (Haut-Droite)",
2: "→ (Droite)",
3: "↘ (Bas-Droite)",
4: "↓ (Bas)",
5: "↙ (Bas-Gauche)",
6: "← (Gauche)",
7: "↖ (Haut-Gauche)",
8: "Neutre"
}
return hat_names.get(hat_val, f"Inconnu({hat_val})")
def main():
hid_path = find_g29_hidraw()
if not hid_path:
print("Erreur: Logitech G29 non trouvé dans /dev/hidraw* !")
sys.exit(1)
print(f"=== Logitech G29 détecté sur {hid_path} ===")
print("En attente de mouvements ou boutons (appuie sur une pédale, tourne le volant ou clique)...")
print("Appuie sur Ctrl+C pour quitter.\n")
try:
fd = os.open(hid_path, os.O_RDWR)
except PermissionError:
print(f"Erreur de permission sur {hid_path}. Lance avec sudo ou vérifie les ACLs.")
sys.exit(1)
last_report = None
last_print_time = 0
try:
while True:
r, _, _ = select.select([fd], [], [], 0.5)
if not r:
continue
report = os.read(fd, 128)
now = time.time()
if not report:
continue
# Check if anything changed compared to last_report
if last_report is not None and report == last_report:
continue
# Detect differences
diffs = []
if last_report is not None and len(last_report) == len(report):
for i in range(len(report)):
if report[i] != last_report[i]:
diffs.append(f"B[{i}]: 0x{last_report[i]:02X} -> 0x{report[i]:02X} (déc:{report[i]})")
last_report = report
# Decode standard G29 PS4 report
# Length is typically 64 bytes (report[0] is Report ID 0x01)
report_id = report[0]
# Print decoded info
out_lines = []
out_lines.append(f"--- [Rapport ID: 0x{report_id:02X} | Longueur: {len(report)} octets] ---")
if len(report) >= 51 and report_id == 0x01:
# 16-bit axes (from g29_crsf.ino)
wheel_raw = report[43] | (report[44] << 8)
accel_raw = 65535 - (report[45] | (report[46] << 8))
brake_raw = 65535 - (report[47] | (report[48] << 8))
clutch_raw = 65535 - (report[49] | (report[50] << 8))
# Percentages
wheel_pct = (wheel_raw / 65535.0) * 100.0
accel_pct = (accel_raw / 65535.0) * 100.0
brake_pct = (brake_raw / 65535.0) * 100.0
clutch_pct = (clutch_raw / 65535.0) * 100.0
out_lines.append(f"Volant : {wheel_raw:5d} / 65535 ({wheel_pct:5.1f}%) | "
f"Gaz : {accel_raw:5d} ({accel_pct:4.1f}%) | "
f"Frein : {brake_raw:5d} ({brake_pct:4.1f}%) | "
f"Embrayage : {clutch_raw:5d} ({clutch_pct:4.1f}%)")
# Buttons byte 5 & 6 & 7
b5 = report[5]
hat = b5 & 0x0F
btn_sq = bool(b5 & 0x10)
btn_cross = bool(b5 & 0x20)
btn_circle = bool(b5 & 0x40)
btn_triangle = bool(b5 & 0x80)
b6 = report[6]
btn_l1 = bool(b6 & 0x01) # Palette -
btn_r1 = bool(b6 & 0x02) # Palette +
btn_l2 = bool(b6 & 0x04)
btn_r2 = bool(b6 & 0x08)
btn_share = bool(b6 & 0x10)
btn_option = bool(b6 & 0x20)
btn_l3 = bool(b6 & 0x40)
btn_r3 = bool(b6 & 0x80)
b7 = report[7] if len(report) > 7 else 0
btn_ps = bool(b7 & 0x01)
btn_plus = bool(b7 & 0x04)
btn_minus = bool(b7 & 0x08)
dial_cw = bool(b7 & 0x10)
dial_ccw = bool(b7 & 0x20)
dial_enter = bool(b7 & 0x40)
active_buttons = []
if btn_sq: active_buttons.append("Carré [□]")
if btn_cross: active_buttons.append("Croix [✕]")
if btn_circle: active_buttons.append("Rond [○]")
if btn_triangle: active_buttons.append("Triangle [△]")
if btn_l1: active_buttons.append("L1 (Palette -)")
if btn_r1: active_buttons.append("R1 (Palette +)")
if btn_l2: active_buttons.append("L2")
if btn_r2: active_buttons.append("R2 (Arm)")
if btn_share: active_buttons.append("Share")
if btn_option: active_buttons.append("Options")
if btn_l3: active_buttons.append("L3")
if btn_r3: active_buttons.append("R3")
if btn_ps: active_buttons.append("PS")
if btn_plus: active_buttons.append("Plus [+]")
if btn_minus: active_buttons.append("Moins [-]")
if dial_cw: active_buttons.append("Molette (Sens horaire ↷)")
if dial_ccw: active_buttons.append("Molette (Sens anti-horaire ↶)")
if dial_enter: active_buttons.append("Molette (Enter central)")
# Check additional bytes for rotary knob and +/- and Enter
# Often in report[7], report[8] or other vendor bytes
out_lines.append(f"D-Pad : {format_hat(hat)}")
out_lines.append(f"Boutons: {', '.join(active_buttons) if active_buttons else 'Aucun'}")
if diffs:
out_lines.append("Changements détectés : " + " | ".join(diffs))
# Raw hex dump (condensed)
hex_view = ' '.join(f'{b:02X}' for b in report[:32])
if len(report) > 32:
hex_view += ' ... ' + ' '.join(f'{b:02X}' for b in report[32:52])
out_lines.append(f"Hex: {hex_view}")
print("\n".join(out_lines))
print()
except KeyboardInterrupt:
print("\nArrêt.")
finally:
os.close(fd)
if __name__ == '__main__':
main()