mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
fix(crsf): supprimer le burst au demarrage et securiser la synchronisation inter-coeurs
- Initialisation de dernier_envoi_us avec micros() et resynchronisation en cas de retard >12ms pour eviter l'envoi de trames en rafale au boot ou apres ecriture Flash - Qualification volatile de configSysteme pour garantir la coherence memoire inter-coeurs (Core 0 / Core 1) - Utilisation de copies locales temporaires pour EEPROM.put() et EEPROM.get() afin de respecter le qualificateur volatile - Verification memcmp avant EEPROM.commit() pour eviter des gels inutiles de idleOtherCore() et preserver l'endurance Flash - Lecture coherente de momentDernierChangementDurete_ms dans loop()
This commit is contained in:
1 parent
db2571ec6c
commit
bcc8c08ec5
1 file changed
+29
-7
+29
-7
@@ -79,7 +79,7 @@ struct ConfigG29 {
|
||||
uint8_t magicNumber; // Identifiant de validité en EEPROM (0x47)
|
||||
};
|
||||
|
||||
ConfigG29 configSysteme;
|
||||
volatile ConfigG29 configSysteme;
|
||||
volatile int32_t maxDeltaVolant = 0;
|
||||
|
||||
void recalculerParametresVolant() {
|
||||
@@ -155,8 +155,18 @@ void reinitialiserConfigurationDefaut() {
|
||||
}
|
||||
|
||||
void sauvegarderConfiguration() {
|
||||
ConfigG29 cfgActuelle;
|
||||
memcpy(&cfgActuelle, (const void*)&configSysteme, sizeof(ConfigG29));
|
||||
|
||||
ConfigG29 cfgStockee;
|
||||
EEPROM.get(0, cfgStockee);
|
||||
|
||||
if (memcmp(&cfgActuelle, &cfgStockee, sizeof(ConfigG29)) == 0) {
|
||||
return; // Déjà synchronisé : évite un gel du Cœur 1 et préserve les cycles Flash
|
||||
}
|
||||
|
||||
rp2040.idleOtherCore();
|
||||
EEPROM.put(0, configSysteme);
|
||||
EEPROM.put(0, cfgActuelle);
|
||||
EEPROM.commit();
|
||||
rp2040.resumeOtherCore();
|
||||
Serial.println(">> Configuration sauvegardée en mémoire Flash !");
|
||||
@@ -177,7 +187,10 @@ void afficherConfiguration() {
|
||||
}
|
||||
|
||||
void chargerConfiguration() {
|
||||
EEPROM.get(0, configSysteme);
|
||||
ConfigG29 cfgStockee;
|
||||
EEPROM.get(0, cfgStockee);
|
||||
memcpy((void*)&configSysteme, &cfgStockee, sizeof(ConfigG29));
|
||||
|
||||
bool conflitArm = configSysteme.volant == CANAL_ARM || configSysteme.accel == CANAL_ARM ||
|
||||
configSysteme.frein == CANAL_ARM || configSysteme.embrayage == CANAL_ARM;
|
||||
if (configSysteme.magicNumber != 0x47 || conflitArm ||
|
||||
@@ -454,7 +467,8 @@ void loop() {
|
||||
}
|
||||
|
||||
// Sauvegarde automatique 2s après la fin du réglage à la molette
|
||||
if (momentDernierChangementDurete_ms > 0 && (millis() - momentDernierChangementDurete_ms >= 2000)) {
|
||||
uint32_t momentChgt = momentDernierChangementDurete_ms;
|
||||
if (momentChgt > 0 && (millis() - momentChgt >= 2000)) {
|
||||
momentDernierChangementDurete_ms = 0;
|
||||
sauvegarderConfiguration();
|
||||
}
|
||||
@@ -480,10 +494,18 @@ void loop() {
|
||||
(unsigned long)rapportsParSec, (unsigned long)compteurRapportsRejetes, failsafeActif);
|
||||
}
|
||||
|
||||
// Transmission CRSF précise à 166.67 Hz (toutes les 6000 µs sans dérive)
|
||||
// Transmission CRSF précise à 166.67 Hz (toutes les 6000 µs sans dérive ni burst)
|
||||
static uint32_t dernier_envoi_us = 0;
|
||||
if (micros() - dernier_envoi_us >= 6000) {
|
||||
dernier_envoi_us += 6000;
|
||||
if (dernier_envoi_us == 0) {
|
||||
dernier_envoi_us = micros();
|
||||
}
|
||||
uint32_t now_us = micros();
|
||||
if (now_us - dernier_envoi_us >= 6000) {
|
||||
if (now_us - dernier_envoi_us >= 12000) {
|
||||
dernier_envoi_us = now_us;
|
||||
} else {
|
||||
dernier_envoi_us += 6000;
|
||||
}
|
||||
envoyer_paquet_crsf(evaluerFailsafe());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user