From 70a03ed3c05bed62093989f68a2c87d2590d0e3d Mon Sep 17 00:00:00 2001 From: bleackstorm <49142331+bleackstorm@users.noreply.github.com> Date: Wed, 11 Nov 2026 22:14:12 +0100 Subject: [PATCH] fix(g29): corriger le verrouillage de plage angulaire et le recentrage FFB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Suppression de la commande 0x14 (default autocenter) qui écrasait la butée 180° - Déclaration volatile pour les variables d'état partagées inter-cœurs - Ajout de find_g29() dynamique dans isolate_led.py et test_matrix.py - Ajout du script de diagnostic FFB et butée test_spring.py --- g29_crsf.ino | 11 +++--- isolate_led.py | 16 ++++++++- test_matrix.py | 16 ++++++++- test_spring.py | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 129 insertions(+), 9 deletions(-) create mode 100755 test_spring.py diff --git a/g29_crsf.ino b/g29_crsf.ino index 461db3c..b13e496 100644 --- a/g29_crsf.ino +++ b/g29_crsf.ino @@ -106,9 +106,9 @@ volatile bool logRejetRequis = false; volatile uint16_t rejet_vid = 0; volatile uint16_t rejet_pid = 0; -uint8_t dernierMasqueLedG29 = 0xFF; -uint8_t etapeEnvoiLed = 0; -uint8_t etapeInitMoteur = 0; +volatile uint8_t dernierMasqueLedG29 = 0xFF; +volatile uint8_t etapeEnvoiLed = 0; +volatile uint8_t etapeInitMoteur = 0; char serialBuffer[32]; uint8_t serialBufferIdx = 0; @@ -394,13 +394,10 @@ void gererInitMoteurG29() { uint16_t angle = (uint16_t)ANGLE_SOUHAITE_TOTAL; const uint8_t cmdRange[7] = {0xF8, 0x81, (uint8_t)(angle & 0xFF), (uint8_t)(angle >> 8), 0x00, 0x00, 0x00}; const uint8_t cmdSpring[7] = {0xFE, 0x0D, (uint8_t)(PENTE_RESSORT_G29 & 0x07), (uint8_t)(PENTE_RESSORT_G29 & 0x07), (uint8_t)FORCE_RESSORT_G29, 0x00, 0x00}; - const uint8_t cmdEnable[7] = {0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; switch (etapeInitMoteur) { case 0: if (envoyerTrameG29_0x30(cmdRange)) etapeInitMoteur++; break; - case 1: if (envoyerTrameG29_0x30(cmdSpring)) etapeInitMoteur++; break; - case 2: if (envoyerTrameG29_0x30(cmdEnable)) etapeInitMoteur++; break; - case 3: etapeInitMoteur = 6; break; + case 1: if (envoyerTrameG29_0x30(cmdSpring)) etapeInitMoteur = 6; break; } } diff --git a/isolate_led.py b/isolate_led.py index de3a500..9cf6337 100644 --- a/isolate_led.py +++ b/isolate_led.py @@ -5,11 +5,24 @@ Isolate the exact LED command on G29 import os import sys +import glob import time import fcntl HIDIOCSFEATURE = lambda length: 0xC0004806 | (length << 16) -dev = '/dev/hidraw2' + +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 make_cmd(mask): return bytes([0xF8, 0x12, mask, 0x00, 0x00, 0x00, 0x00]) @@ -58,6 +71,7 @@ if __name__ == '__main__': name, func = candidates[cid] print(f"Test de {name} -> Action: {action}") + dev = find_g29() fd = os.open(dev, os.O_RDWR) if action == 'off': diff --git a/test_matrix.py b/test_matrix.py index f292cce..a0b6a9c 100644 --- a/test_matrix.py +++ b/test_matrix.py @@ -6,13 +6,27 @@ 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 = '/dev/hidraw2' + dev = find_g29() print(f"=== TEST DIAGNOSTIC G29 PS4 SUR {dev} ===") fd = os.open(dev, os.O_RDWR) diff --git a/test_spring.py b/test_spring.py new file mode 100755 index 0000000..71c1230 --- /dev/null +++ b/test_spring.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python3 +""" +Test interactif de Force Feedback / Recentrage (Spring) et Butée (Range) pour Logitech G29 +""" + +import os +import sys +import glob +import time + +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' + +CMD_RANGE_180 = bytes([0xF8, 0x81, 0xB4, 0x00, 0x00, 0x00, 0x00]) # 180 deg +CMD_RANGE_900 = bytes([0xF8, 0x81, 0x84, 0x03, 0x00, 0x00, 0x00]) # 900 deg +CMD_SPRING_140 = bytes([0xFE, 0x0D, 0x07, 0x07, 140, 0x00, 0x00]) # Force 140 +CMD_SPRING_MAX = bytes([0xFE, 0x0D, 0x07, 0x07, 0xFF, 0x00, 0x00]) # Force 255 +CMD_SPRING_OFF = bytes([0xFE, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00]) # Force 0 +CMD_ENABLE_14 = bytes([0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]) # 0x14 (Autocenter default) +CMD_DISABLE_F5 = bytes([0xf5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]) # 0xF5 (Deactivate default autocenter) + +def send_r30(fd, cmd7): + payload = bytes([0x30]) + cmd7 + bytes([0x00] * 56) + return os.write(fd, payload) + +def main(): + dev = find_g29() + print(f"=== TEST RECENTRAGE + BUTÉE 180° G29 SUR {dev} ===") + + try: + fd = os.open(dev, os.O_RDWR) + except Exception as e: + print(f"Erreur d'ouverture {dev} : {e}") + sys.exit(1) + + tests = { + "A": ("Range 180° + Spring 140 SANS commande 0x14 (Recommandé)", [ + ("Range 180°", CMD_RANGE_180), + ("Spring 140", CMD_SPRING_140), + ]), + "B": ("Ordre inverse : 0x14 d'abord, PUIS Range 180°, PUIS Spring 140", [ + ("Enable 0x14", CMD_ENABLE_14), + ("Range 180°", CMD_RANGE_180), + ("Spring 140", CMD_SPRING_140), + ]), + "C": ("0xF5 (Désactiver défaut) + Range 180° + Spring 140", [ + ("Disable default 0xF5", CMD_DISABLE_F5), + ("Range 180°", CMD_RANGE_180), + ("Spring 140", CMD_SPRING_140), + ]), + "D": ("Range 180° seul (sans ressort)", [ + ("Range 180°", CMD_RANGE_180), + ("Spring OFF", CMD_SPRING_OFF), + ]), + "0": ("Désactiver force et remettre en 900°", [ + ("Spring OFF", CMD_SPRING_OFF), + ("Range 900°", CMD_RANGE_900), + ]), + } + + if len(sys.argv) > 1: + choice = sys.argv[1].upper() + else: + print("\nOptions à tester :") + for k, (desc, _) in tests.items(): + print(f" [{k}] {desc}") + choice = input("\nTon choix : ").strip().upper() + + if choice in tests: + desc, steps = tests[choice] + print(f"\n▶ Exécution : {desc}") + for name, cmd in steps: + send_r30(fd, cmd) + print(f" -> Envoyé : {name} ({cmd.hex()})") + time.sleep(0.05) + print("\n👉 TOURNE LE VOLANT :") + print(" 1. Est-il dur et revient-il au centre ?") + print(" 2. Bloque-t-il bien en butée à ±90° (180° au total) ?") + else: + print("Choix invalide.") + + os.close(fd) + +if __name__ == '__main__': + main()