fix(usb): cadencer le FFB a 50Hz et ajouter abort recovery sur endpoint IN

This commit is contained in:
bleackstorm committed 2026-11-12 21:40:38 +01:00
1 parent 87854b6e9b
commit 88b038acdf
1 file changed
+15 -6
+15 -6
View File
@@ -919,9 +919,13 @@ void gererVibrationHaptique() {
if (dtChoc < 70 && directionDernierChocRapport != 0) {
dernierCalculPhase_us = 0;
forceEstAuNeutre = false;
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();
}