mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
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:
1 file changed
+37
-10
+37
-10
@@ -643,8 +643,11 @@ void traiterTelemetrieCRSF() {
|
||||
dernierPaquetTelemetrie_ms = millis();
|
||||
uint8_t frameType = crsfRxBuffer[2];
|
||||
|
||||
if (!estArme) {
|
||||
rugositeTerrainExterne = 0;
|
||||
attitudeInitialisee = false;
|
||||
} else if (frameType == 0x1E && paquetLongueurAttendue >= 8) {
|
||||
// Trame d'attitude (0x1E) : Pitch (int16), Roll (int16), Yaw (int16)
|
||||
if (frameType == 0x1E && paquetLongueurAttendue >= 8) {
|
||||
int16_t pitch = (int16_t)((crsfRxBuffer[3] << 8) | crsfRxBuffer[4]);
|
||||
int16_t roll = (int16_t)((crsfRxBuffer[5] << 8) | crsfRxBuffer[6]);
|
||||
if (!attitudeInitialisee) {
|
||||
@@ -684,6 +687,12 @@ void traiterTelemetrieCRSF() {
|
||||
}
|
||||
}
|
||||
|
||||
if (!estArme) {
|
||||
rugositeTerrainExterne = 0;
|
||||
attitudeInitialisee = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (dernierPaquetTelemetrie_ms > 0 && (millis() - dernierPaquetTelemetrie_ms > 500)) {
|
||||
attitudeInitialisee = false;
|
||||
}
|
||||
@@ -838,6 +847,11 @@ bool envoyerForceG29(uint8_t forceByte) {
|
||||
return envoyerTrameG29_0x30(cmdForce);
|
||||
}
|
||||
|
||||
bool arreterForceG29() {
|
||||
const uint8_t cmdStop[7] = {0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
return envoyerTrameG29_0x30(cmdStop);
|
||||
}
|
||||
|
||||
void gererInitMoteurG29() {
|
||||
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
|
||||
@@ -979,7 +993,8 @@ float avancerPhaseSinus(float& phase, float freqHz, float dt_s) {
|
||||
|
||||
void gererVibrationHaptique() {
|
||||
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;
|
||||
|
||||
static uint32_t dernierCalculPhase_us = 0;
|
||||
@@ -999,10 +1014,11 @@ void gererVibrationHaptique() {
|
||||
|
||||
// 2. Gestion des vibrations haptiques et retours mécaniques
|
||||
uint8_t intensite = configSysteme.intensiteVibration;
|
||||
if (intensite == 0) {
|
||||
if (!estArme || intensite == 0) {
|
||||
dernierCalculPhase_us = 0;
|
||||
directionDernierChocRapport = 0;
|
||||
if (!forceEstAuNeutre) {
|
||||
if (envoyerForceG29(128)) {
|
||||
if (arreterForceG29()) {
|
||||
forceEstAuNeutre = true;
|
||||
}
|
||||
}
|
||||
@@ -1030,11 +1046,11 @@ void gererVibrationHaptique() {
|
||||
directionDernierChocRapport = 0;
|
||||
}
|
||||
|
||||
// Silence complet si désarmé (!estArme), au point mort (0) ou en marche arrière (-1)
|
||||
if (!estArme || rapportEngage <= 0) {
|
||||
// Silence complet au point mort (0) ou en marche arrière (-1)
|
||||
if (rapportEngage <= 0) {
|
||||
dernierCalculPhase_us = 0;
|
||||
if (!forceEstAuNeutre) {
|
||||
if (envoyerForceG29(128)) {
|
||||
if (arreterForceG29()) {
|
||||
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 (envoyerLedsPendingG29()) {
|
||||
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;
|
||||
rapportEngage = 0;
|
||||
estArme = false;
|
||||
forceEstAuNeutre = false;
|
||||
forceEstAuNeutre = true;
|
||||
directionDernierChocRapport = 0;
|
||||
murActifDroite = false;
|
||||
murActifGauche = false;
|
||||
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) {
|
||||
estArme = false;
|
||||
logArmRequis = -1;
|
||||
directionDernierChocRapport = 0;
|
||||
rugositeTerrainExterne = 0;
|
||||
momentDesarmement_ms = millis();
|
||||
momentArmement_ms = 0;
|
||||
} 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;
|
||||
rapportEngage++;
|
||||
majLedRequise = true;
|
||||
if (ancienRapport >= 0) {
|
||||
if (estArme && ancienRapport >= 0) {
|
||||
momentDernierChocRapport_ms = millis();
|
||||
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)) {
|
||||
rapportEngage--;
|
||||
majLedRequise = true;
|
||||
if (rapportEngage >= 0) {
|
||||
if (estArme && rapportEngage >= 0) {
|
||||
momentDernierChocRapport_ms = millis();
|
||||
directionDernierChocRapport = -1; // À-coup sec vers la gauche
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user