mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
Merge pull request #13 from bleackstorm/feat/g29-vibration-buttons-and-filter
Feat/g29 vibration buttons and filter
This commit is contained in:
1 file changed
+75
-17
+75
-17
@@ -66,8 +66,8 @@ const uint16_t GAZ_AVANT_MAX_PAR_VITESSE[3] = {
|
||||
#define FORCE_RESSORT_DEFAUT 140 // Force du retour au centre : 0 a 255
|
||||
#define PENTE_RESSORT_G29 7 // Raideur autour du centre : 1 a 7
|
||||
#define ETAPES_INIT_FFB_TOTAL 2 // Nombre d'etapes d'init FFB (0=Range, 1=Spring)
|
||||
#define VIBRATION_DEFAUT 100 // Intensite par defaut des vibrations (0 a 100%)
|
||||
#define MAGIC_NUMBER_CONFIG 0x49 // Identifiant de validite en EEPROM (mis a jour pour 240 degres)
|
||||
#define VIBRATION_DEFAUT 50 // Intensite par defaut des vibrations (0 a 100%)
|
||||
#define MAGIC_NUMBER_CONFIG 0x4A // Identifiant de validite en EEPROM (mis a jour pour 50% vibrations)
|
||||
|
||||
Adafruit_NeoPixel rgb_led(NUM_PIXELS, PIN_LED_RGB, NEO_GRB + NEO_KHZ800);
|
||||
Adafruit_USBH_Host USBHost;
|
||||
@@ -145,8 +145,12 @@ volatile bool majRangeRequise = false;
|
||||
volatile bool dialPlusDejaEnfonce = false;
|
||||
volatile bool dialMoinsDejaEnfonce = false;
|
||||
volatile bool dialEnterDejaEnfonce = false;
|
||||
volatile bool btnPlusDejaEnfonce = false;
|
||||
volatile bool btnMoinsDejaEnfonce = false;
|
||||
volatile uint32_t momentDernierChangementDurete_ms = 0;
|
||||
volatile uint32_t momentDernierChangementVib_ms = 0;
|
||||
volatile bool logDureteRequis = false;
|
||||
volatile bool logVibrationRequis = false;
|
||||
volatile bool demandeSauvegardeEEPROM = false;
|
||||
volatile bool sauvegardeDifferee = false;
|
||||
|
||||
@@ -210,11 +214,11 @@ void afficherConfiguration() {
|
||||
Serial.printf("Frein (F) : Canal %d\n", configSysteme.frein);
|
||||
Serial.printf("Embrayage (E) : Canal %d\n", configSysteme.embrayage);
|
||||
Serial.printf("ARM (R2) : Canal %d (reserve)\n", CANAL_ARM);
|
||||
Serial.printf("Durete FFB (D) : %d / 255 (%d%%) [Molette / Boutons +/- ou D=xxx]\n",
|
||||
Serial.printf("Durete FFB (D) : %d / 255 (%d%%) [Molette rouge ou D=xxx]\n",
|
||||
configSysteme.forceRessort, (configSysteme.forceRessort * 100) / 255);
|
||||
Serial.printf("Plage Volant(P): %d degres [P=40..900]\n", configSysteme.angleSouhaiteTotal);
|
||||
Serial.printf("Expo Volant(X) : %.2f [X=0.00..0.80]\n", configSysteme.expoVolant);
|
||||
Serial.printf("Vibrations (T) : %d%% [T=0..100] (Mix 12Hz/60Hz + Telemetrie)\n", configSysteme.intensiteVibration);
|
||||
Serial.printf("Vibrations (T) : %d%% [Boutons +/- ou T=0..100] (0 = desactive)\n", configSysteme.intensiteVibration);
|
||||
Serial.println("Commandes : V=ch, A=ch, F=ch, E=ch, D=val, P=val, X=val, T=val, S(save), R(reset), B(bootsel), ?");
|
||||
}
|
||||
|
||||
@@ -245,8 +249,7 @@ void chargerConfiguration() {
|
||||
bool angleValide = (configSysteme.angleSouhaiteTotal >= 40) &&
|
||||
(configSysteme.angleSouhaiteTotal <= 900);
|
||||
|
||||
bool vibValide = (configSysteme.intensiteVibration >= 10) &&
|
||||
(configSysteme.intensiteVibration <= 100);
|
||||
bool vibValide = (configSysteme.intensiteVibration <= 100);
|
||||
|
||||
if (configSysteme.magicNumber != MAGIC_NUMBER_CONFIG || conflitArm || !canauxValides || !canauxDistincts || !expoValide || !angleValide || !vibValide) {
|
||||
if (conflitArm) Serial.println("!! Un axe etait mappe sur le canal ARM : configuration reinitialisee !!");
|
||||
@@ -643,7 +646,12 @@ void traiterTelemetrieCRSF() {
|
||||
prevRoll = roll;
|
||||
|
||||
int32_t secousses = deltaPitch + deltaRoll;
|
||||
rugositeTerrainExterne = (uint8_t)constrain(map(secousses, 15, 250, 0, 255), 0, 255);
|
||||
// Filtrage des micro-vibrations du FC : seuil mort de 60 (~0.35°) pour ignorer le bruit gyroscopique
|
||||
if (secousses > 60) {
|
||||
rugositeTerrainExterne = (uint8_t)constrain(map(secousses, 60, 450, 0, 255), 0, 255);
|
||||
} else {
|
||||
rugositeTerrainExterne = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Trame personnalisée (0x7F ou 0x2A pour accéléromètre brut / rugosité)
|
||||
@@ -719,6 +727,15 @@ void loop() {
|
||||
configSysteme.forceRessort, (configSysteme.forceRessort * 100) / 255);
|
||||
}
|
||||
|
||||
if (logVibrationRequis) {
|
||||
logVibrationRequis = false;
|
||||
if (configSysteme.intensiteVibration == 0) {
|
||||
Serial.println(">> [VIBRATIONS] Desactivees (0%)");
|
||||
} else {
|
||||
Serial.printf(">> [VIBRATIONS] Intensite reglee a %d%%\n", configSysteme.intensiteVibration);
|
||||
}
|
||||
}
|
||||
|
||||
// Sauvegarde différée suite à une commande série (D= / T=) passée pendant la conduite
|
||||
if (!estArme && sauvegardeDifferee) {
|
||||
sauvegardeDifferee = false;
|
||||
@@ -813,9 +830,20 @@ void gererInitMoteurG29() {
|
||||
|
||||
uint8_t calculerMasqueLedG29() {
|
||||
uint8_t masqueCible = 0x00;
|
||||
// Si la dureté a été modifiée il y a moins de 1.5s, afficher la jauge de dureté sur les LEDs
|
||||
uint32_t momentDernierChg = momentDernierChangementDurete_ms;
|
||||
if (momentDernierChg > 0 && (millis() - momentDernierChg < 1500)) {
|
||||
uint32_t now = millis();
|
||||
|
||||
// 1. Priorité aux jauges de réglage temporaires (1.5s)
|
||||
uint32_t momentVib = momentDernierChangementVib_ms;
|
||||
if (momentVib > 0 && (now - momentVib < 1500)) {
|
||||
uint8_t v = configSysteme.intensiteVibration;
|
||||
if (v >= 90) masqueCible = 0x1F; // 5 LEDs (90-100%)
|
||||
else if (v >= 70) masqueCible = 0x0F; // 4 LEDs (70-80%)
|
||||
else if (v >= 50) masqueCible = 0x07; // 3 LEDs (50-60%)
|
||||
else if (v >= 30) masqueCible = 0x03; // 2 LEDs (30-40%)
|
||||
else if (v >= 10) masqueCible = 0x01; // 1 LED (10-20%)
|
||||
else masqueCible = 0x00; // 0 LED (0% / coupé)
|
||||
}
|
||||
else if (momentDernierChangementDurete_ms > 0 && (now - momentDernierChangementDurete_ms < 1500)) {
|
||||
uint8_t f = configSysteme.forceRessort;
|
||||
if (f >= 240) masqueCible = 0x1F; // 5 LEDs (Rouge)
|
||||
else if (f >= 180) masqueCible = 0x0F; // 4 LEDs (Jaune haut)
|
||||
@@ -984,14 +1012,14 @@ void gererVibrationHaptique() {
|
||||
// 12 Hz : Grondement moteur au ralenti / régime + secousses terrain
|
||||
float freq12 = 12.0f + (dernierAccelPct * 0.15f);
|
||||
float ampMoteur12 = (14.0f + dernierAccelPct * 0.40f) * gainGlobal;
|
||||
float ampTerrain12 = ((float)rugositeTerrainExterne * 0.45f) * gainGlobal;
|
||||
float ampTerrain12 = ((float)rugositeTerrainExterne * 0.25f) * gainGlobal;
|
||||
float v12 = (ampMoteur12 + ampTerrain12) * avancerPhaseSinus(phase12, freq12, dt_s);
|
||||
|
||||
// 60 Hz : Grain de roulement lié à la vitesse (rapport engagé) et aux gaz
|
||||
// Baseline de 8.0f sur les rapports avant pour un retour haptique franc dès le rapport engagé
|
||||
float baseVitesse = (rapportEngage > 0) ? 8.0f : 0.0f;
|
||||
float ampVitesse60 = (baseVitesse + dernierAccelPct * 0.30f) * (1.0f + (float)rapportEngage * 0.25f) * gainGlobal;
|
||||
float ampTerrain60 = ((float)rugositeTerrainExterne * 0.20f) * gainGlobal;
|
||||
float ampTerrain60 = ((float)rugositeTerrainExterne * 0.12f) * gainGlobal;
|
||||
float v60 = (ampVitesse60 + ampTerrain60) * avancerPhaseSinus(phase60, 60.0f, dt_s);
|
||||
|
||||
forceCalc = 128.0f + v12 + v60;
|
||||
@@ -1223,23 +1251,28 @@ void __not_in_flash_func(tuh_hid_report_received_cb)(uint8_t dev_addr, uint8_t i
|
||||
paletteMoinsDejaEnfoncee = false;
|
||||
}
|
||||
|
||||
// Réglage de la dureté du volant à la volée via la molette ou boutons [+] / [-]
|
||||
// Réglage FFB à la volée :
|
||||
// - Molette rouge (CW/CCW) : Dureté du ressort de centrage (0 à 255)
|
||||
// - Boutons [+] / [-] : Intensité des vibrations haptiques (0 à 100%, 0 = désactivé)
|
||||
// Sur G29 en mode PS4 (PID 0xC260), la molette et les boutons +/- sont situés dans report[54].
|
||||
// On conserve également report[7] comme solution de secours universelle.
|
||||
uint8_t b54 = (len > 54) ? report[54] : 0;
|
||||
uint8_t b7 = (len > 7) ? report[7] : 0;
|
||||
|
||||
bool dialPlusActuel = (b54 & DIAL_CW_MASK_B54) || (b54 & BOUTON_PLUS_MASK_B54) ||
|
||||
(b7 & DIAL_CW_MASK_B7) || (b7 & BOUTON_PLUS_MASK_B7);
|
||||
bool dialMoinsActuel = (b54 & DIAL_CCW_MASK_B54) || (b54 & BOUTON_MOINS_MASK_B54) ||
|
||||
(b7 & DIAL_CCW_MASK_B7) || (b7 & BOUTON_MOINS_MASK_B7);
|
||||
bool dialPlusActuel = (b54 & DIAL_CW_MASK_B54) || (b7 & DIAL_CW_MASK_B7);
|
||||
bool dialMoinsActuel = (b54 & DIAL_CCW_MASK_B54) || (b7 & DIAL_CCW_MASK_B7);
|
||||
bool dialEnterActuel = (b54 & DIAL_ENTER_MASK_B54) || (b7 & DIAL_ENTER_MASK_B7);
|
||||
|
||||
bool btnPlusActuel = (b54 & BOUTON_PLUS_MASK_B54) || (b7 & BOUTON_PLUS_MASK_B7);
|
||||
bool btnMoinsActuel = (b54 & BOUTON_MOINS_MASK_B54) || (b7 & BOUTON_MOINS_MASK_B7);
|
||||
|
||||
// Molette : Dureté du ressort de rappel (FFB)
|
||||
if (dialPlusActuel && !dialPlusDejaEnfonce) {
|
||||
if (configSysteme.forceRessort <= 245) configSysteme.forceRessort += 10;
|
||||
else configSysteme.forceRessort = 255;
|
||||
majRessortRequise = true;
|
||||
logDureteRequis = true;
|
||||
majLedRequise = true;
|
||||
momentDernierChangementDurete_ms = millis();
|
||||
dialPlusDejaEnfonce = true;
|
||||
} else if (!dialPlusActuel && dialPlusDejaEnfonce) {
|
||||
@@ -1251,12 +1284,37 @@ void __not_in_flash_func(tuh_hid_report_received_cb)(uint8_t dev_addr, uint8_t i
|
||||
else configSysteme.forceRessort = 0;
|
||||
majRessortRequise = true;
|
||||
logDureteRequis = true;
|
||||
majLedRequise = true;
|
||||
momentDernierChangementDurete_ms = millis();
|
||||
dialMoinsDejaEnfonce = true;
|
||||
} else if (!dialMoinsActuel && dialMoinsDejaEnfonce) {
|
||||
dialMoinsDejaEnfonce = false;
|
||||
}
|
||||
|
||||
// Bouton [+] : Augmenter les vibrations (+10%)
|
||||
if (btnPlusActuel && !btnPlusDejaEnfonce) {
|
||||
if (configSysteme.intensiteVibration <= 90) configSysteme.intensiteVibration += 10;
|
||||
else configSysteme.intensiteVibration = 100;
|
||||
logVibrationRequis = true;
|
||||
majLedRequise = true;
|
||||
momentDernierChangementVib_ms = millis();
|
||||
btnPlusDejaEnfonce = true;
|
||||
} else if (!btnPlusActuel && btnPlusDejaEnfonce) {
|
||||
btnPlusDejaEnfonce = false;
|
||||
}
|
||||
|
||||
// Bouton [-] : Diminuer les vibrations (-10%, jusqu'à 0% = coupé)
|
||||
if (btnMoinsActuel && !btnMoinsDejaEnfonce) {
|
||||
if (configSysteme.intensiteVibration >= 10) configSysteme.intensiteVibration -= 10;
|
||||
else configSysteme.intensiteVibration = 0;
|
||||
logVibrationRequis = true;
|
||||
majLedRequise = true;
|
||||
momentDernierChangementVib_ms = millis();
|
||||
btnMoinsDejaEnfonce = true;
|
||||
} else if (!btnMoinsActuel && btnMoinsDejaEnfonce) {
|
||||
btnMoinsDejaEnfonce = false;
|
||||
}
|
||||
|
||||
// Sauvegarde en Flash protégée : nécessite un appui continu de 2 secondes sur Enter
|
||||
// véhicule à l'arrêt et désarmé, pour interdire tout gel Flash intempestif en manipulant la molette.
|
||||
static uint32_t debutAppuiEnter_ms = 0;
|
||||
|
||||
Reference in new issue
Block a user