Merge pull request #15 from bleackstorm/fix/disable-vibrations-when-disarmed

fix(haptic): couper toutes les vibrations lorsque le programme est de…
This commit is contained in:
bleackstorm authored and GitHub committed 2026-11-14 23:34:54 +01:00
commit 338235f13e
1 file changed
+38 -11
+38 -11
View File
@@ -643,8 +643,11 @@ void traiterTelemetrieCRSF() {
dernierPaquetTelemetrie_ms = millis(); dernierPaquetTelemetrie_ms = millis();
uint8_t frameType = crsfRxBuffer[2]; uint8_t frameType = crsfRxBuffer[2];
// Trame d'attitude (0x1E) : Pitch (int16), Roll (int16), Yaw (int16) if (!estArme) {
if (frameType == 0x1E && paquetLongueurAttendue >= 8) { rugositeTerrainExterne = 0;
attitudeInitialisee = false;
} else if (frameType == 0x1E && paquetLongueurAttendue >= 8) {
// Trame d'attitude (0x1E) : Pitch (int16), Roll (int16), Yaw (int16)
int16_t pitch = (int16_t)((crsfRxBuffer[3] << 8) | crsfRxBuffer[4]); int16_t pitch = (int16_t)((crsfRxBuffer[3] << 8) | crsfRxBuffer[4]);
int16_t roll = (int16_t)((crsfRxBuffer[5] << 8) | crsfRxBuffer[6]); int16_t roll = (int16_t)((crsfRxBuffer[5] << 8) | crsfRxBuffer[6]);
if (!attitudeInitialisee) { if (!attitudeInitialisee) {
@@ -684,6 +687,12 @@ void traiterTelemetrieCRSF() {
} }
} }
if (!estArme) {
rugositeTerrainExterne = 0;
attitudeInitialisee = false;
return;
}
if (dernierPaquetTelemetrie_ms > 0 && (millis() - dernierPaquetTelemetrie_ms > 500)) { if (dernierPaquetTelemetrie_ms > 0 && (millis() - dernierPaquetTelemetrie_ms > 500)) {
attitudeInitialisee = false; attitudeInitialisee = false;
} }
@@ -838,6 +847,11 @@ bool envoyerForceG29(uint8_t forceByte) {
return envoyerTrameG29_0x30(cmdForce); return envoyerTrameG29_0x30(cmdForce);
} }
bool arreterForceG29() {
const uint8_t cmdStop[7] = {0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
return envoyerTrameG29_0x30(cmdStop);
}
void gererInitMoteurG29() { void gererInitMoteurG29() {
if (!volant_est_pret || etapeInitMoteur >= ETAPES_INIT_FFB_TOTAL) return; if (!volant_est_pret || etapeInitMoteur >= ETAPES_INIT_FFB_TOTAL) return;
// Attendre 6s après la connexion USB pour que le G29 ait terminé son calibrage matériel // Attendre 6s après la connexion USB pour que le G29 ait terminé son calibrage matériel
@@ -979,7 +993,8 @@ float avancerPhaseSinus(float& phase, float freqHz, float dt_s) {
void gererVibrationHaptique() { void gererVibrationHaptique() {
if (!volant_est_pret || etapeInitMoteur < ETAPES_INIT_FFB_TOTAL) return; if (!volant_est_pret || etapeInitMoteur < ETAPES_INIT_FFB_TOTAL) return;
if (etapeEnvoiLed != 0 || majRangeRequise || majRessortRequise) return; if (majRangeRequise || majRessortRequise) return;
if (etapeEnvoiLed != 0 && (estArme || forceEstAuNeutre)) return;
if (!tuh_hid_send_ready(g29_dev_addr, g29_instance)) return; if (!tuh_hid_send_ready(g29_dev_addr, g29_instance)) return;
static uint32_t dernierCalculPhase_us = 0; static uint32_t dernierCalculPhase_us = 0;
@@ -999,10 +1014,11 @@ void gererVibrationHaptique() {
// 2. Gestion des vibrations haptiques et retours mécaniques // 2. Gestion des vibrations haptiques et retours mécaniques
uint8_t intensite = configSysteme.intensiteVibration; uint8_t intensite = configSysteme.intensiteVibration;
if (intensite == 0) { if (!estArme || intensite == 0) {
dernierCalculPhase_us = 0; dernierCalculPhase_us = 0;
directionDernierChocRapport = 0;
if (!forceEstAuNeutre) { if (!forceEstAuNeutre) {
if (envoyerForceG29(128)) { if (arreterForceG29()) {
forceEstAuNeutre = true; forceEstAuNeutre = true;
} }
} }
@@ -1030,11 +1046,11 @@ void gererVibrationHaptique() {
directionDernierChocRapport = 0; directionDernierChocRapport = 0;
} }
// Silence complet si désarmé (!estArme), au point mort (0) ou en marche arrière (-1) // Silence complet au point mort (0) ou en marche arrière (-1)
if (!estArme || rapportEngage <= 0) { if (rapportEngage <= 0) {
dernierCalculPhase_us = 0; dernierCalculPhase_us = 0;
if (!forceEstAuNeutre) { if (!forceEstAuNeutre) {
if (envoyerForceG29(128)) { if (arreterForceG29()) {
forceEstAuNeutre = true; forceEstAuNeutre = true;
} }
} }
@@ -1132,6 +1148,14 @@ void loop1() {
} }
} }
// Arrêt prioritaire du moteur de vibration dès le désarmement (avant l'animation LED)
if (!estArme && !forceEstAuNeutre) {
if (arreterForceG29()) {
forceEstAuNeutre = true;
return;
}
}
if (etapeEnvoiLed != 0) { if (etapeEnvoiLed != 0) {
if (envoyerLedsPendingG29()) { if (envoyerLedsPendingG29()) {
return; // Laisse 20 ms au G29 pour digérer la commande LED avant le prochain envoi FFB return; // Laisse 20 ms au G29 pour digérer la commande LED avant le prochain envoi FFB
@@ -1153,7 +1177,8 @@ void reinitialiserEtatVolant() {
statutEnvoiLed = 0; statutEnvoiLed = 0;
rapportEngage = 0; rapportEngage = 0;
estArme = false; estArme = false;
forceEstAuNeutre = false; forceEstAuNeutre = true;
directionDernierChocRapport = 0;
murActifDroite = false; murActifDroite = false;
murActifGauche = false; murActifGauche = false;
dernierVolantCentre = 0; dernierVolantCentre = 0;
@@ -1255,6 +1280,8 @@ void __not_in_flash_func(tuh_hid_report_received_cb)(uint8_t dev_addr, uint8_t i
if (estArme) { if (estArme) {
estArme = false; estArme = false;
logArmRequis = -1; logArmRequis = -1;
directionDernierChocRapport = 0;
rugositeTerrainExterne = 0;
momentDesarmement_ms = millis(); momentDesarmement_ms = millis();
momentArmement_ms = 0; momentArmement_ms = 0;
} else if (etapeInitMoteur < ETAPES_INIT_FFB_TOTAL) { } else if (etapeInitMoteur < ETAPES_INIT_FFB_TOTAL) {
@@ -1278,7 +1305,7 @@ void __not_in_flash_func(tuh_hid_report_received_cb)(uint8_t dev_addr, uint8_t i
int8_t ancienRapport = rapportEngage; int8_t ancienRapport = rapportEngage;
rapportEngage++; rapportEngage++;
majLedRequise = true; majLedRequise = true;
if (ancienRapport >= 0) { if (estArme && ancienRapport >= 0) {
momentDernierChocRapport_ms = millis(); momentDernierChocRapport_ms = millis();
directionDernierChocRapport = 1; // À-coup sec vers la droite directionDernierChocRapport = 1; // À-coup sec vers la droite
} }
@@ -1292,7 +1319,7 @@ void __not_in_flash_func(tuh_hid_report_received_cb)(uint8_t dev_addr, uint8_t i
if (rapportEngage > -1 && !(rapportEngage <= 0 && accelRaw > DEADZONE_PEDALE)) { if (rapportEngage > -1 && !(rapportEngage <= 0 && accelRaw > DEADZONE_PEDALE)) {
rapportEngage--; rapportEngage--;
majLedRequise = true; majLedRequise = true;
if (rapportEngage >= 0) { if (estArme && rapportEngage >= 0) {
momentDernierChocRapport_ms = millis(); momentDernierChocRapport_ms = millis();
directionDernierChocRapport = -1; // À-coup sec vers la gauche directionDernierChocRapport = -1; // À-coup sec vers la gauche
} }