#!/usr/bin/env python3 """ Deep diagnostic for Logitech G29 (046d:c260) on /dev/hidraw2 Tests both FFB (force/spring) and LEDs to find which channel the G29 responds to. """ import os import sys import glob import time import fcntl HIDIOCSFEATURE = lambda length: 0xC0004806 | (length << 16) def find_g29(): for h in sorted(glob.glob('/dev/hidraw*')): uevent = f'/sys/class/hidraw/{os.path.basename(h)}/device/uevent' if os.path.exists(uevent): try: 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 except Exception: pass return '/dev/hidraw2' def main(): dev = find_g29() print(f"=== TEST DIAGNOSTIC G29 PS4 SUR {dev} ===") fd = os.open(dev, os.O_RDWR) # Spring command (centering force 0xFE 0x0D ... or high res spring 0x21 0x0B ...) # If accepted, the steering wheel immediately resists when turned! spring_cmd = bytes([0xFE, 0x0D, 0x07, 0x07, 0xFF, 0x00, 0x00]) # 7 bytes led_cmd = bytes([0xF8, 0x12, 0x1F, 0x00, 0x00, 0x00, 0x00]) # 7 bytes patterns = [ ("P1: Raw 7 bytes on EP OUT (hidraw strip 0x00)", bytes([0x00]) + led_cmd, 'write'), ("P2: 8 bytes with 1-byte offset 0x00 (hidraw strip 0x00)", bytes([0x00, 0x00]) + led_cmd, 'write'), ("P3: Output Report 0x05 + 7 bytes command", bytes([0x05]) + led_cmd + bytes([0x00]*24), 'write'), ("P4: Output Report 0x05 + 1-byte offset 0x00 + 7 bytes command", bytes([0x05, 0x00]) + led_cmd + bytes([0x00]*23), 'write'), ("P5: Output Report 0x05 padded to 64 bytes", bytes([0x05]) + led_cmd + bytes([0x00]*56), 'write'), ("P6: Feature Report 0xF3 (7 bytes payload)", bytearray([0xF3]) + bytearray(led_cmd), 'feature'), ("P7: Feature Report 0xF3 (8 bytes: 0xF3 0x00 F8 12 1F...)", bytearray([0xF3, 0x00]) + bytearray(led_cmd), 'feature'), ("P8: Feature Report 0xF0 (63 bytes)", bytearray([0xF0]) + bytearray(led_cmd) + bytearray([0x00]*56), 'feature'), ("P9: Feature Report 0x03 (47 bytes)", bytearray([0x03]) + bytearray(led_cmd) + bytearray([0x00]*40), 'feature'), ("P10: Report 0x30 padded to 64 bytes", bytes([0x30]) + led_cmd + bytes([0x00]*56), 'write'), ] print("\n--- Test des LEDs (1 seconde par motif) ---") for i, (name, pkt, ptype) in enumerate(patterns, 1): print(f"[{i:2d}/10] Test: {name}") try: if ptype == 'write': os.write(fd, pkt) else: fcntl.ioctl(fd, HIDIOCSFEATURE(len(pkt)), pkt) except Exception as e: print(f" Erreur: {e}") time.sleep(1.0) # Let's test Spring Force (Resistance) print("\n--- Test du Retour au Centre (Force / Spring) ---") print("Essaie de tourner le volant pour voir s'il devient dur / résistant...") spring_tests = [ ("S1: Spring via Output 0x05 (32 bytes)", bytes([0x05]) + spring_cmd + bytes([0x00]*24), 'write'), ("S2: Spring via Output 0x05 avec offset 0x00", bytes([0x05, 0x00]) + spring_cmd + bytes([0x00]*23), 'write'), ("S3: Spring via Feature 0xF3", bytearray([0xF3]) + bytearray(spring_cmd), 'feature'), ("S4: Spring via Raw EP OUT", bytes([0x00]) + spring_cmd, 'write'), ("S5: Spring High-Res PS4 (0x21 0x0B...)", bytes([0x05, 0x21, 0x0B, 0x7F, 0x7F, 0x77, 0xEE, 0xFF] + [0x00]*24), 'write'), ] for name, pkt, ptype in spring_tests: print(f"Test force: {name}") try: if ptype == 'write': os.write(fd, pkt) else: fcntl.ioctl(fd, HIDIOCSFEATURE(len(pkt)), pkt) except Exception as e: print(f" Erreur: {e}") time.sleep(1.5) os.close(fd) print("\nFin des tests diagnostic !") if __name__ == '__main__': main()