mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
Merge pull request #3 from bleackstorm/feat/g29-rpm-leds
feat(g29): corriger le protocole des leds rpm avec le report id 0x30
This commit is contained in:
6 files changed
+569
-44
No files matched your search
@@ -0,0 +1,2 @@
|
||||
__pycache__/
|
||||
*.pyc
|
||||
Executable
+177
@@ -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()
|
||||
+14
-44
@@ -379,12 +379,12 @@ void loop() {
|
||||
// =========================================================================
|
||||
// CŒUR 1 : PILE PIO-USB, AUTO-CENTER ET LEDS G29
|
||||
// =========================================================================
|
||||
bool envoyerTrameG29_F3_Simple(const uint8_t cmd7[7]) {
|
||||
bool envoyerTrameG29_0x30(const uint8_t cmd7[7]) {
|
||||
if (!tuh_hid_send_ready(g29_dev_addr, g29_instance)) return false;
|
||||
static uint8_t payload63[63];
|
||||
memset(payload63, 0, sizeof(payload63));
|
||||
memcpy(payload63, cmd7, 7);
|
||||
return tuh_hid_send_report(g29_dev_addr, g29_instance, 0xF3, payload63, 63);
|
||||
return tuh_hid_send_report(g29_dev_addr, g29_instance, 0x30, payload63, sizeof(payload63));
|
||||
}
|
||||
|
||||
void gererInitMoteurG29() {
|
||||
@@ -393,13 +393,13 @@ 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, PENTE_RESSORT_G29 & 0x07, PENTE_RESSORT_G29 & 0x07, FORCE_RESSORT_G29, 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_F3_Simple(cmdRange)) etapeInitMoteur++; break;
|
||||
case 1: if (envoyerTrameG29_F3_Simple(cmdSpring)) etapeInitMoteur++; break;
|
||||
case 2: if (envoyerTrameG29_F3_Simple(cmdEnable)) etapeInitMoteur++; break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -413,52 +413,22 @@ void envoyerLedsG29(uint8_t masque5bits) {
|
||||
etapeEnvoiLed = 1;
|
||||
}
|
||||
if (etapeEnvoiLed == 0 || !tuh_hid_send_ready(g29_dev_addr, g29_instance)) return;
|
||||
|
||||
uint8_t m = dernierMasqueLedG29 & 0x1F;
|
||||
|
||||
// Format validé sur G29 PS4 physique :
|
||||
// Report ID = 0x30, payload 63 octets débutant par F8 12 <masque> suivi de zéros
|
||||
static uint8_t payload63[63];
|
||||
for (int i = 0; i < 63; i += 7) {
|
||||
payload63[i + 0] = 0xF8;
|
||||
payload63[i + 1] = 0x12;
|
||||
payload63[i + 2] = m;
|
||||
payload63[i + 3] = 0x00;
|
||||
payload63[i + 4] = 0x00;
|
||||
payload63[i + 5] = 0x00;
|
||||
payload63[i + 6] = 0x00;
|
||||
}
|
||||
memset(payload63, 0, sizeof(payload63));
|
||||
payload63[0] = 0xF8;
|
||||
payload63[1] = 0x12;
|
||||
payload63[2] = m;
|
||||
|
||||
if (etapeEnvoiLed == 1) {
|
||||
if (tuh_hid_send_report(g29_dev_addr, g29_instance, 0xF3, payload63, 63)) {
|
||||
if (tuh_hid_send_report(g29_dev_addr, g29_instance, 0x30, payload63, sizeof(payload63))) {
|
||||
statutEnvoiLed = 1;
|
||||
etapeEnvoiLed = 2;
|
||||
}
|
||||
}
|
||||
else if (etapeEnvoiLed == 2) {
|
||||
if (tuh_hid_send_report(g29_dev_addr, g29_instance, 0x30, payload63, 63)) {
|
||||
statutEnvoiLed = 2;
|
||||
etapeEnvoiLed = 3;
|
||||
}
|
||||
}
|
||||
else if (etapeEnvoiLed == 3) {
|
||||
if (tuh_hid_send_report(g29_dev_addr, g29_instance, 0x05, payload63, 31)) {
|
||||
statutEnvoiLed = 3;
|
||||
etapeEnvoiLed = 4;
|
||||
}
|
||||
}
|
||||
else if (etapeEnvoiLed == 4) {
|
||||
static uint8_t payloadDecale[63];
|
||||
memset(payloadDecale, 0, sizeof(payloadDecale));
|
||||
payloadDecale[0] = 0x00;
|
||||
for (int i = 1; i + 7 <= 63; i += 7) {
|
||||
payloadDecale[i + 0] = 0xF8;
|
||||
payloadDecale[i + 1] = 0x12;
|
||||
payloadDecale[i + 2] = m;
|
||||
}
|
||||
if (tuh_hid_send_report(g29_dev_addr, g29_instance, 0xF3, payloadDecale, 63)) {
|
||||
statutEnvoiLed = 4;
|
||||
etapeEnvoiLed = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup1() {
|
||||
sleep_ms(100);
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Isolate the exact LED command on G29
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import fcntl
|
||||
|
||||
HIDIOCSFEATURE = lambda length: 0xC0004806 | (length << 16)
|
||||
dev = '/dev/hidraw2'
|
||||
|
||||
def make_cmd(mask):
|
||||
return bytes([0xF8, 0x12, mask, 0x00, 0x00, 0x00, 0x00])
|
||||
|
||||
candidates = {
|
||||
# Key: (name, function(fd, mask))
|
||||
"P1": ("P1: Raw 7 bytes on EP OUT (hidraw strip 0x00)",
|
||||
lambda fd, m: os.write(fd, bytes([0x00]) + make_cmd(m))),
|
||||
|
||||
"P2": ("P2: 8 bytes avec 1-byte offset 0x00 (GIMX format)",
|
||||
lambda fd, m: os.write(fd, bytes([0x00, 0x00]) + make_cmd(m))),
|
||||
|
||||
"P3": ("P3: Output Report 0x05 standard (32 octets)",
|
||||
lambda fd, m: os.write(fd, bytes([0x05]) + make_cmd(m) + bytes([0x00]*24))),
|
||||
|
||||
"P4": ("P4: Output Report 0x05 avec offset 0x00 (32 octets)",
|
||||
lambda fd, m: os.write(fd, bytes([0x05, 0x00]) + make_cmd(m) + bytes([0x00]*23))),
|
||||
|
||||
"P5": ("P5: Output Report 0x05 paddé à 64 octets",
|
||||
lambda fd, m: os.write(fd, bytes([0x05]) + make_cmd(m) + bytes([0x00]*56))),
|
||||
|
||||
"P6": ("P6: Feature Report 0xF3 (7 octets payload)",
|
||||
lambda fd, m: fcntl.ioctl(fd, HIDIOCSFEATURE(8), bytearray([0xF3]) + bytearray(make_cmd(m)))),
|
||||
|
||||
"P7": ("P7: Feature Report 0xF3 (offset 0x00)",
|
||||
lambda fd, m: fcntl.ioctl(fd, HIDIOCSFEATURE(9), bytearray([0xF3, 0x00]) + bytearray(make_cmd(m)))),
|
||||
|
||||
"P8": ("P8: Feature Report 0xF0 (63 octets payload)",
|
||||
lambda fd, m: fcntl.ioctl(fd, HIDIOCSFEATURE(64), bytearray([0xF0]) + bytearray(make_cmd(m)) + bytearray([0x00]*56))),
|
||||
|
||||
"P10": ("P10: Report 0x30 (64 octets)",
|
||||
lambda fd, m: os.write(fd, bytes([0x30]) + make_cmd(m) + bytes([0x00]*56))),
|
||||
}
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 3:
|
||||
print("Usage: python3 isolate_led.py <candidate P1..P10> <on|off|blink|chase>")
|
||||
sys.exit(1)
|
||||
|
||||
cid = sys.argv[1].upper()
|
||||
action = sys.argv[2].lower()
|
||||
|
||||
if cid not in candidates:
|
||||
print(f"Candidat inconnu: {cid}. Choisis parmi {list(candidates.keys())}")
|
||||
sys.exit(1)
|
||||
|
||||
name, func = candidates[cid]
|
||||
print(f"Test de {name} -> Action: {action}")
|
||||
fd = os.open(dev, os.O_RDWR)
|
||||
|
||||
if action == 'off':
|
||||
func(fd, 0x00)
|
||||
print("Envoyé: ÉTEINT (0x00)")
|
||||
elif action == 'on':
|
||||
func(fd, 0x1F)
|
||||
print("Envoyé: TOUT ALLUMÉ (0x1F)")
|
||||
elif action == 'blink':
|
||||
print("Clignotement 3 fois...")
|
||||
for _ in range(3):
|
||||
func(fd, 0x1F)
|
||||
time.sleep(0.3)
|
||||
func(fd, 0x00)
|
||||
time.sleep(0.3)
|
||||
elif action == 'chase':
|
||||
print("Chenillard (1 par 1)...")
|
||||
# 0x01 (2 vertes), 0x03 (4 vertes), 0x07 (2 jaunes), 0x0F (4 jaunes), 0x1F (rouge)
|
||||
for m in [0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x0F, 0x07, 0x03, 0x01, 0x00]:
|
||||
func(fd, m)
|
||||
time.sleep(0.15)
|
||||
|
||||
os.close(fd)
|
||||
+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()
|
||||
@@ -0,0 +1,94 @@
|
||||
#!/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 time
|
||||
import fcntl
|
||||
|
||||
HIDIOCSFEATURE = lambda length: 0xC0004806 | (length << 16)
|
||||
|
||||
def main():
|
||||
dev = '/dev/hidraw2'
|
||||
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()
|
||||
Reference in new issue
Block a user