From 88b038acdf05fc5ef9855d2fcfc94a140ffb5c3c Mon Sep 17 00:00:00 2001 From: bleackstorm <49142331+bleackstorm@users.noreply.github.com> Date: Thu, 12 Nov 2026 21:40:38 +0100 Subject: [PATCH] fix(usb): cadencer le FFB a 50Hz et ajouter abort recovery sur endpoint IN --- g29_crsf.ino | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/g29_crsf.ino b/g29_crsf.ino index b4b94e7..5bf70aa 100644 --- a/g29_crsf.ino +++ b/g29_crsf.ino @@ -919,9 +919,13 @@ void gererVibrationHaptique() { if (dtChoc < 70 && directionDernierChocRapport != 0) { dernierCalculPhase_us = 0; forceEstAuNeutre = false; - float forceCalc = 128.0f + (float)directionDernierChocRapport * 85.0f * gainGlobal; - uint8_t forceByte = (uint8_t)constrain((int)forceCalc, 0, 255); - envoyerForceG29(forceByte); + static uint32_t dernierMomentChocEnvoye = 0; + if (momentDernierChocRapport_ms != dernierMomentChocEnvoye) { + dernierMomentChocEnvoye = momentDernierChocRapport_ms; + float forceCalc = 128.0f + (float)directionDernierChocRapport * 85.0f * gainGlobal; + uint8_t forceByte = (uint8_t)constrain((int)forceCalc, 0, 255); + envoyerForceG29(forceByte); + } return; } @@ -938,8 +942,8 @@ void gererVibrationHaptique() { forceEstAuNeutre = false; uint32_t now_us = micros(); - float dt_s = (dernierCalculPhase_us == 0) ? 0.008f : (float)(now_us - dernierCalculPhase_us) * 1e-6f; - if (dt_s > 0.05f) dt_s = 0.008f; + float dt_s = (dernierCalculPhase_us == 0) ? 0.020f : (float)(now_us - dernierCalculPhase_us) * 1e-6f; + if (dt_s > 0.05f) dt_s = 0.020f; dernierCalculPhase_us = now_us; float forceCalc = 128.0f; @@ -984,10 +988,13 @@ void loop1() { if (!volant_est_pret) return; - // Watchdog USB-Host : si aucun rapport reçu depuis > 25 ms et endpoint prêt, réarmer ! + // Watchdog USB-Host : si aucun rapport reçu depuis > 25 ms, réarmer (ou avorter si bloqué > 50 ms) if (millis() - dernierRapportUSB_ms > 25) { if (tuh_hid_receive_ready(g29_dev_addr, g29_instance)) { tuh_hid_receive_report(g29_dev_addr, g29_instance); + } else if (millis() - dernierRapportUSB_ms > 50) { + tuh_hid_receive_abort(g29_dev_addr, g29_instance); + tuh_hid_receive_report(g29_dev_addr, g29_instance); } } @@ -1029,12 +1036,14 @@ void loop1() { } if (etapeEnvoiLed != 0) { - envoyerLedsPendingG29(); + if (envoyerLedsPendingG29()) { + return; // Laisse 20 ms au G29 pour digérer la commande LED avant le prochain envoi FFB + } } - // 5. Moteur de vibration haptique & butée active (cadencé à ~125 Hz, toutes les 8 ms) + // 5. Moteur de vibration haptique & butée active (cadencé à 50 Hz, toutes les 20 ms) static uint32_t dernierTickVib = 0; - if ((millis() - dernierTickVib >= 8) && tuh_hid_send_ready(g29_dev_addr, g29_instance)) { + if ((millis() - dernierTickVib >= 20) && tuh_hid_send_ready(g29_dev_addr, g29_instance)) { dernierTickVib = millis(); gererVibrationHaptique(); }