mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
feat(ffb): ajouter la butee active FFB a +/-120 degres (240 degres au total)
This commit is contained in:
1 parent
9294aa52de
commit
e87a999489
1 file changed
+38
-9
+38
-9
@@ -53,13 +53,13 @@ const uint16_t GAZ_AVANT_MAX_PAR_VITESSE[3] = {
|
||||
// Configuration par défaut du volant G29
|
||||
#define CENTRE_VOLANT_BRUT 32528
|
||||
#define ANGLE_MAX_VOLANT_G29 900.0f
|
||||
#define ANGLE_DEFAUT_TOTAL 180.0f
|
||||
#define EXPO_DEFAUT 0.25f // 0.0f = Linéaire, 0.25f = Doux au centre (FPU RP2350)
|
||||
#define FORCE_RESSORT_DEFAUT 140 // Force du retour au centre : 0 à 255
|
||||
#define PENTE_RESSORT_G29 7 // Raideur autour du centre : 1 à 7
|
||||
#define ETAPES_INIT_FFB_TOTAL 2 // Nombre d'étapes d'init FFB (0=Range, 1=Spring)
|
||||
#define VIBRATION_DEFAUT 100 // Intensité par défaut des vibrations (0 à 100%)
|
||||
#define MAGIC_NUMBER_CONFIG 0x48 // Identifiant de validité en EEPROM
|
||||
#define ANGLE_DEFAUT_TOTAL 240.0f // Plage totale par defaut : 240 degres (+/- 120 degres)
|
||||
#define EXPO_DEFAUT 0.25f // 0.0f = Lineaire, 0.25f = Doux au centre (FPU RP2350)
|
||||
#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)
|
||||
|
||||
Adafruit_NeoPixel rgb_led(NUM_PIXELS, PIN_LED_RGB, NEO_GRB + NEO_KHZ800);
|
||||
Adafruit_USBH_Host USBHost;
|
||||
@@ -143,6 +143,7 @@ volatile float dernierFreinPct = 0.0f; // 0.0 à 100.0%
|
||||
volatile uint32_t momentDernierChocRapport_ms = 0; // Horodatage du passage de vitesse
|
||||
volatile int8_t directionDernierChocRapport = 0; // -1 gauche, +1 droite
|
||||
volatile bool forceEstAuNeutre = false;
|
||||
volatile int32_t dernierVolantCentre = 0; // Position mesurée du volant par rapport au centre
|
||||
|
||||
char serialBuffer[32];
|
||||
uint8_t serialBufferIdx = 0;
|
||||
@@ -682,7 +683,8 @@ bool envoyerTrameG29_0x30(const uint8_t cmd7[7]) {
|
||||
|
||||
void gererInitMoteurG29() {
|
||||
if (!volant_est_pret || etapeInitMoteur >= ETAPES_INIT_FFB_TOTAL) return;
|
||||
if (millis() - momentConnexionUSB_ms < 600) return;
|
||||
// Attendre 6s après la connexion USB pour que le G29 ait terminé son calibrage matériel
|
||||
if (millis() - momentConnexionUSB_ms < 6000) return;
|
||||
|
||||
uint16_t angle = configSysteme.angleSouhaiteTotal;
|
||||
const uint8_t cmdRange[7] = {0xF8, 0x81, (uint8_t)(angle & 0xFF), (uint8_t)(angle >> 8), 0x00, 0x00, 0x00};
|
||||
@@ -725,6 +727,32 @@ void gererVibrationHaptique() {
|
||||
if (etapeEnvoiLed != 0 || majRangeRequise || majRessortRequise) return;
|
||||
if (!tuh_hid_send_ready(g29_dev_addr, g29_instance)) return;
|
||||
|
||||
// Calcul du mur de butée active (Active Soft Stop FFB à +/- 120°)
|
||||
int32_t posCentre = dernierVolantCentre;
|
||||
int32_t deltaMax = (maxDeltaVolant > 0) ? maxDeltaVolant : 8738;
|
||||
float forceButee = 0.0f;
|
||||
|
||||
if (posCentre > deltaMax) {
|
||||
// Dépassement à droite (> +120°) : contre-force puissante vers la gauche
|
||||
int32_t surplus = posCentre - deltaMax;
|
||||
forceButee = -constrain(50.0f + (float)surplus * 0.40f, 50.0f, 125.0f);
|
||||
} else if (posCentre < -deltaMax) {
|
||||
// Dépassement à gauche (< -120°) : contre-force puissante vers la droite
|
||||
int32_t surplus = -deltaMax - posCentre;
|
||||
forceButee = constrain(50.0f + (float)surplus * 0.40f, 50.0f, 125.0f);
|
||||
}
|
||||
|
||||
// 1. Si on dépasse la butée : le mur actif de blocage est prioritaire absolu
|
||||
if (forceButee != 0.0f) {
|
||||
forceEstAuNeutre = false;
|
||||
float forceTotale = 128.0f + forceButee;
|
||||
uint8_t forceByte = (uint8_t)constrain((int)forceTotale, 0, 255);
|
||||
const uint8_t cmdForce[7] = {0x11, 0x00, forceByte, 0x00, 0x00, 0x00, 0x00};
|
||||
envoyerTrameG29_0x30(cmdForce);
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Dans la plage normale (-120° à +120°) : vibrations haptiques si armé
|
||||
uint8_t intensite = configSysteme.intensiteVibration;
|
||||
if (intensite == 0 || !estArme) {
|
||||
if (!forceEstAuNeutre) {
|
||||
@@ -1031,7 +1059,8 @@ void __not_in_flash_func(tuh_hid_report_received_cb)(uint8_t dev_addr, uint8_t i
|
||||
}
|
||||
|
||||
int32_t volantCentre = (int32_t)volantRaw - CENTRE_VOLANT_BRUT;
|
||||
int32_t deltaMax = (maxDeltaVolant > 0) ? maxDeltaVolant : 6553;
|
||||
dernierVolantCentre = volantCentre;
|
||||
int32_t deltaMax = (maxDeltaVolant > 0) ? maxDeltaVolant : 8738;
|
||||
int32_t volantBorne = constrain(volantCentre, -deltaMax, deltaMax);
|
||||
|
||||
float x = (float)volantBorne / (float)deltaMax;
|
||||
|
||||
Reference in new issue
Block a user