mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
Update g29_crsf.ino
watchdog
This commit is contained in:
1 parent
59c7e0ec65
commit
b501833872
1 file changed
+180
-25
+180
-25
@@ -3,6 +3,7 @@
|
|||||||
#include <pio_usb.h>
|
#include <pio_usb.h>
|
||||||
#include <Adafruit_NeoPixel.h>
|
#include <Adafruit_NeoPixel.h>
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
|
#include <hardware/watchdog.h>
|
||||||
|
|
||||||
// Brochage natif de la Waveshare RP2350-USB-A
|
// Brochage natif de la Waveshare RP2350-USB-A
|
||||||
#define HOST_PIN_DP 12 // USB-A D+ (D- est automatiquement sur GP13)
|
#define HOST_PIN_DP 12 // USB-A D+ (D- est automatiquement sur GP13)
|
||||||
@@ -10,9 +11,20 @@
|
|||||||
#define PIN_LED_RGB 16 // LED RGB WS2812 intégrée
|
#define PIN_LED_RGB 16 // LED RGB WS2812 intégrée
|
||||||
#define EEPROM_SIZE 32
|
#define EEPROM_SIZE 32
|
||||||
|
|
||||||
|
// Sécurité : failsafe, watchdog et identification du volant
|
||||||
|
#define TIMEOUT_FAILSAFE_MS 100 // Sans rapport USB valide depuis X ms -> canaux au neutre
|
||||||
|
#define WATCHDOG_TIMEOUT_MS 500 // Reboot matériel si le cœur 0 se fige
|
||||||
|
#define G29_VID 0x046D
|
||||||
|
#define G29_PID_PS4 0xC260 // G29 en mode PS4 (le mode PS3 = 0xC24F a un autre format de rapport)
|
||||||
|
#define G29_REPORT_ID 0x01
|
||||||
|
|
||||||
// Masques des palettes dans report[6]
|
// Masques des palettes dans report[6]
|
||||||
#define PALETTE_MOINS_MASK 0x01 // L1 (Palette gauche : Rétrograder)
|
#define PALETTE_MOINS_MASK 0x01 // L1 (Palette gauche : Rétrograder)
|
||||||
#define PALETTE_PLUS_MASK 0x02 // R1 (Palette droite : Monter un rapport)
|
#define PALETTE_PLUS_MASK 0x02 // R1 (Palette droite : Monter un rapport)
|
||||||
|
#define BOUTON_ARM_MASK 0x08 // R2 (Bascule Armé / Désarmé)
|
||||||
|
|
||||||
|
// Armement ELRS : AUX1 = canal 5 (réservé, ne peut pas être mappé ailleurs)
|
||||||
|
#define CANAL_ARM 5
|
||||||
|
|
||||||
// Bornes officielles CRSF
|
// Bornes officielles CRSF
|
||||||
#define CRSF_VAL_MIN 172 // ~988 us
|
#define CRSF_VAL_MIN 172 // ~988 us
|
||||||
@@ -47,7 +59,7 @@ Adafruit_USBH_Host USBHost;
|
|||||||
|
|
||||||
volatile uint16_t crsf_channels[16] = {
|
volatile uint16_t crsf_channels[16] = {
|
||||||
CRSF_VAL_MID, CRSF_VAL_MID, CRSF_VAL_MID, CRSF_VAL_MID,
|
CRSF_VAL_MID, CRSF_VAL_MID, CRSF_VAL_MID, CRSF_VAL_MID,
|
||||||
CRSF_VAL_MID, CRSF_VAL_MID, CRSF_VAL_MID, CRSF_VAL_MID,
|
CRSF_VAL_MIN, CRSF_VAL_MID, CRSF_VAL_MID, CRSF_VAL_MID, // Canal 5 (ARM) : désarmé
|
||||||
CRSF_VAL_MID, CRSF_VAL_MID, CRSF_VAL_MID, CRSF_VAL_MID,
|
CRSF_VAL_MID, CRSF_VAL_MID, CRSF_VAL_MID, CRSF_VAL_MID,
|
||||||
CRSF_VAL_MID, CRSF_VAL_MID, CRSF_VAL_MID, CRSF_VAL_MID
|
CRSF_VAL_MID, CRSF_VAL_MID, CRSF_VAL_MID, CRSF_VAL_MID
|
||||||
};
|
};
|
||||||
@@ -68,6 +80,11 @@ volatile bool palettePlusDejaEnfoncee = false;
|
|||||||
volatile bool paletteMoinsDejaEnfoncee = false;
|
volatile bool paletteMoinsDejaEnfoncee = false;
|
||||||
volatile bool majLedRequise = true;
|
volatile bool majLedRequise = true;
|
||||||
|
|
||||||
|
// Armement (bascule par R2) : écrit uniquement par le cœur 1
|
||||||
|
volatile bool estArme = false;
|
||||||
|
volatile bool boutonArmDejaEnfonce = false;
|
||||||
|
volatile int8_t logArmRequis = 0; // 1 = armé, -1 = désarmé, 2 = armement refusé
|
||||||
|
|
||||||
// État USB Host et diagnostic inter-cœurs
|
// État USB Host et diagnostic inter-cœurs
|
||||||
volatile uint8_t g29_dev_addr = 0;
|
volatile uint8_t g29_dev_addr = 0;
|
||||||
volatile uint8_t g29_instance = 0;
|
volatile uint8_t g29_instance = 0;
|
||||||
@@ -80,6 +97,15 @@ volatile uint32_t momentConnexionUSB_ms = 0;
|
|||||||
volatile bool logMountRequis = false;
|
volatile bool logMountRequis = false;
|
||||||
volatile int8_t statutEnvoiLed = 0; // <-- Déclaration ajoutée ici
|
volatile int8_t statutEnvoiLed = 0; // <-- Déclaration ajoutée ici
|
||||||
|
|
||||||
|
// Failsafe et diagnostic
|
||||||
|
volatile bool failsafeActif = true; // Écrit uniquement par le cœur 0
|
||||||
|
volatile bool demandeRetourNeutre = false; // Cœur 0 -> Cœur 1 : forcer le point mort
|
||||||
|
volatile uint32_t compteurRapportsOK = 0; // Écrit uniquement par le cœur 1
|
||||||
|
volatile uint32_t compteurRapportsRejetes = 0;
|
||||||
|
volatile bool logRejetRequis = false;
|
||||||
|
volatile uint16_t rejet_vid = 0;
|
||||||
|
volatile uint16_t rejet_pid = 0;
|
||||||
|
|
||||||
uint8_t dernierMasqueLedG29 = 0xFF;
|
uint8_t dernierMasqueLedG29 = 0xFF;
|
||||||
uint8_t etapeEnvoiLed = 0;
|
uint8_t etapeEnvoiLed = 0;
|
||||||
uint8_t etapeInitMoteur = 0;
|
uint8_t etapeInitMoteur = 0;
|
||||||
@@ -91,6 +117,7 @@ void reinitialiserCanauxCRSF() {
|
|||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
crsf_channels[i] = CRSF_VAL_MID;
|
crsf_channels[i] = CRSF_VAL_MID;
|
||||||
}
|
}
|
||||||
|
crsf_channels[CANAL_ARM - 1] = CRSF_VAL_MIN; // Toujours désarmé par défaut
|
||||||
}
|
}
|
||||||
|
|
||||||
void sauvegarderConfiguration() {
|
void sauvegarderConfiguration() {
|
||||||
@@ -107,11 +134,15 @@ void afficherConfiguration() {
|
|||||||
Serial.printf("Accel (A) : Canal %d\n", configCanaux.accel);
|
Serial.printf("Accel (A) : Canal %d\n", configCanaux.accel);
|
||||||
Serial.printf("Frein (F) : Canal %d\n", configCanaux.frein);
|
Serial.printf("Frein (F) : Canal %d\n", configCanaux.frein);
|
||||||
Serial.printf("Embrayage (E) : Canal %d\n", configCanaux.embrayage);
|
Serial.printf("Embrayage (E) : Canal %d\n", configCanaux.embrayage);
|
||||||
|
Serial.printf("ARM (R2) : Canal %d (reserve)\n", CANAL_ARM);
|
||||||
}
|
}
|
||||||
|
|
||||||
void chargerConfiguration() {
|
void chargerConfiguration() {
|
||||||
EEPROM.get(0, configCanaux);
|
EEPROM.get(0, configCanaux);
|
||||||
if (configCanaux.magicNumber != 42) {
|
bool conflitArm = configCanaux.volant == CANAL_ARM || configCanaux.accel == CANAL_ARM ||
|
||||||
|
configCanaux.frein == CANAL_ARM || configCanaux.embrayage == CANAL_ARM;
|
||||||
|
if (configCanaux.magicNumber != 42 || conflitArm) {
|
||||||
|
if (conflitArm) Serial.println("!! Un axe etait mappe sur le canal ARM : configuration reinitialisee !!");
|
||||||
configCanaux.volant = 1;
|
configCanaux.volant = 1;
|
||||||
configCanaux.accel = 2;
|
configCanaux.accel = 2;
|
||||||
configCanaux.frein = 3;
|
configCanaux.frein = 3;
|
||||||
@@ -132,6 +163,10 @@ void traiterLigneSerie(char* commande) {
|
|||||||
if (strlen(commande) >= 3 && commande[1] == '=') {
|
if (strlen(commande) >= 3 && commande[1] == '=') {
|
||||||
char periph = commande[0];
|
char periph = commande[0];
|
||||||
int nouveauCanal = atoi(&commande[2]);
|
int nouveauCanal = atoi(&commande[2]);
|
||||||
|
if (nouveauCanal == CANAL_ARM) {
|
||||||
|
Serial.printf("!! Canal %d reserve a l'armement (R2) !!\n", CANAL_ARM);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (nouveauCanal >= 1 && nouveauCanal <= 16) {
|
if (nouveauCanal >= 1 && nouveauCanal <= 16) {
|
||||||
bool modifOk = true;
|
bool modifOk = true;
|
||||||
switch (periph) {
|
switch (periph) {
|
||||||
@@ -169,30 +204,38 @@ void verifierCommandesSerie() {
|
|||||||
// GESTION LED RGB SUR GP16
|
// GESTION LED RGB SUR GP16
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
void actualiserLED() {
|
void actualiserLED() {
|
||||||
|
uint8_t r = 0, g = 0, b = 0;
|
||||||
if (!volant_est_pret) {
|
if (!volant_est_pret) {
|
||||||
rgb_led.setPixelColor(0, rgb_led.Color(0, 0, 255)); // Bleu : Attente G29
|
b = 255; // Bleu : Attente G29
|
||||||
|
} else if (failsafeActif) {
|
||||||
|
r = 255; g = 255; b = 255; // Blanc : Failsafe (G29 muet)
|
||||||
} else {
|
} else {
|
||||||
switch (rapportEngage) {
|
switch (rapportEngage) {
|
||||||
case -1: rgb_led.setPixelColor(0, rgb_led.Color(255, 0, 0)); break; // Rouge : R
|
case -1: r = 255; g = 0; b = 0; break; // Rouge : R
|
||||||
case 0: rgb_led.setPixelColor(0, rgb_led.Color(255, 100, 0)); break; // Orange : N
|
case 0: r = 255; g = 100; b = 0; break; // Orange : N
|
||||||
case 1: rgb_led.setPixelColor(0, rgb_led.Color(0, 255, 255)); break; // Cyan : 1ère
|
case 1: r = 0; g = 255; b = 255; break; // Cyan : 1ère
|
||||||
case 2: rgb_led.setPixelColor(0, rgb_led.Color(0, 255, 0)); break; // Vert : 2ème
|
case 2: r = 0; g = 255; b = 0; break; // Vert : 2ème
|
||||||
case 3: rgb_led.setPixelColor(0, rgb_led.Color(180, 0, 255)); break; // Violet : 3ème
|
case 3: r = 180; g = 0; b = 255; break; // Violet : 3ème
|
||||||
|
}
|
||||||
|
if (!estArme) { // Désarmé : couleur du rapport très atténuée
|
||||||
|
r /= 10; g /= 10; b /= 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
rgb_led.setPixelColor(0, rgb_led.Color(r, g, b));
|
||||||
rgb_led.show();
|
rgb_led.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
// ENVOI CRSF DEPUIS LA SRAM DU RP2350
|
// ENVOI CRSF DEPUIS LA SRAM DU RP2350
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
void __not_in_flash_func(envoyer_paquet_crsf)() {
|
void __not_in_flash_func(envoyer_paquet_crsf)(bool neutre) {
|
||||||
uint8_t packet[26];
|
uint8_t packet[26];
|
||||||
uint16_t ch[16];
|
uint16_t ch[16];
|
||||||
|
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
ch[i] = crsf_channels[i];
|
ch[i] = neutre ? CRSF_VAL_MID : crsf_channels[i];
|
||||||
}
|
}
|
||||||
|
if (neutre) ch[CANAL_ARM - 1] = CRSF_VAL_MIN; // Failsafe : toujours désarmé
|
||||||
|
|
||||||
packet[0] = 0xC8;
|
packet[0] = 0xC8;
|
||||||
packet[1] = 24;
|
packet[1] = 24;
|
||||||
@@ -254,9 +297,37 @@ void setup() {
|
|||||||
|
|
||||||
Serial.println("\n--- WAVESHARE RP2350-USB-A PRETE ---");
|
Serial.println("\n--- WAVESHARE RP2350-USB-A PRETE ---");
|
||||||
afficherConfiguration();
|
afficherConfiguration();
|
||||||
|
|
||||||
|
// Watchdog matériel : reboot si loop() ne le nourrit plus pendant WATCHDOG_TIMEOUT_MS
|
||||||
|
if (watchdog_caused_reboot()) {
|
||||||
|
Serial.println("!! [WATCHDOG] Redemarrage suite a un blocage !!");
|
||||||
|
}
|
||||||
|
rp2040.wdt_begin(WATCHDOG_TIMEOUT_MS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Évalue le failsafe (cœur 0). Retourne true si les canaux doivent être forcés au neutre.
|
||||||
|
bool evaluerFailsafe() {
|
||||||
|
// Lire l'horodatage AVANT millis() : si le cœur 1 le met à jour entre les deux,
|
||||||
|
// la soustraction reste positive (pas de faux déclenchement par débordement).
|
||||||
|
uint32_t dernier = dernierRapportUSB_ms;
|
||||||
|
uint32_t age = millis() - dernier;
|
||||||
|
bool stale = !volant_est_pret || (age > TIMEOUT_FAILSAFE_MS);
|
||||||
|
|
||||||
|
if (stale && !failsafeActif) {
|
||||||
|
failsafeActif = true;
|
||||||
|
demandeRetourNeutre = true; // Au retour du signal, la voiture repart au point mort
|
||||||
|
majLedRequise = true;
|
||||||
|
Serial.printf("!! [FAILSAFE] ACTIF (dernier rapport USB il y a %lu ms) !!\n", (unsigned long)age);
|
||||||
|
} else if (!stale && failsafeActif) {
|
||||||
|
failsafeActif = false;
|
||||||
|
majLedRequise = true;
|
||||||
|
Serial.println("[FAILSAFE] Signal G29 retabli");
|
||||||
|
}
|
||||||
|
return stale;
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
rp2040.wdt_reset();
|
||||||
verifierCommandesSerie();
|
verifierCommandesSerie();
|
||||||
|
|
||||||
if (majLedRequise) {
|
if (majLedRequise) {
|
||||||
@@ -267,25 +338,41 @@ void loop() {
|
|||||||
|
|
||||||
if (logMountRequis) {
|
if (logMountRequis) {
|
||||||
logMountRequis = false;
|
logMountRequis = false;
|
||||||
tuh_vid_pid_get(g29_dev_addr, (uint16_t*)&g29_vid, (uint16_t*)&g29_pid);
|
|
||||||
Serial.printf("[USB HOST] G29 detecte ! VID=%04X, PID=%04X, dev=%d, inst=%d, desc_len=%d\n",
|
Serial.printf("[USB HOST] G29 detecte ! VID=%04X, PID=%04X, dev=%d, inst=%d, desc_len=%d\n",
|
||||||
g29_vid, g29_pid, g29_dev_addr, g29_instance, g29_desc_len);
|
g29_vid, g29_pid, g29_dev_addr, g29_instance, g29_desc_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t dernierHeartbeat = 0;
|
if (logRejetRequis) {
|
||||||
if (millis() - dernierHeartbeat >= 2000) {
|
logRejetRequis = false;
|
||||||
dernierHeartbeat = millis();
|
Serial.printf("[USB HOST] Peripherique ignore (VID=%04X, PID=%04X) : pas un G29 en mode PS4\n",
|
||||||
if (volant_est_pret && g29_vid == 0) {
|
rejet_vid, rejet_pid);
|
||||||
tuh_vid_pid_get(g29_dev_addr, (uint16_t*)&g29_vid, (uint16_t*)&g29_pid);
|
|
||||||
}
|
}
|
||||||
Serial.printf("[ETAT] G29_Pret=%d (PID=%04X) | InitFFB=%d/6 | Rapport=%d | Statut_LED=%d\n",
|
|
||||||
volant_est_pret, g29_pid, etapeInitMoteur, rapportEngage, statutEnvoiLed);
|
int8_t evtArm = logArmRequis;
|
||||||
|
if (evtArm != 0) {
|
||||||
|
logArmRequis = 0;
|
||||||
|
if (evtArm == 1) Serial.println(">> [ARM] ARME (R2)");
|
||||||
|
else if (evtArm == -1) Serial.println(">> [ARM] DESARME");
|
||||||
|
else Serial.println("!! [ARM] Refuse : passer au point mort (N) et relacher l'accelerateur !!");
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t dernierHeartbeat = 0;
|
||||||
|
static uint32_t dernierCompteOK = 0;
|
||||||
|
if (millis() - dernierHeartbeat >= 2000) {
|
||||||
|
uint32_t dt = millis() - dernierHeartbeat;
|
||||||
|
dernierHeartbeat = millis();
|
||||||
|
uint32_t compteOK = compteurRapportsOK;
|
||||||
|
uint32_t rapportsParSec = ((compteOK - dernierCompteOK) * 1000UL) / (dt ? dt : 1);
|
||||||
|
dernierCompteOK = compteOK;
|
||||||
|
Serial.printf("[ETAT] G29_Pret=%d (PID=%04X) | InitFFB=%d/6 | Rapport=%d | Arme=%d | Statut_LED=%d | USB=%lu rap/s | Rejetes=%lu | Failsafe=%d\n",
|
||||||
|
volant_est_pret, g29_pid, etapeInitMoteur, rapportEngage, estArme, statutEnvoiLed,
|
||||||
|
(unsigned long)rapportsParSec, (unsigned long)compteurRapportsRejetes, failsafeActif);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t dernier_envoi = 0;
|
static uint32_t dernier_envoi = 0;
|
||||||
if (millis() - dernier_envoi >= 6) {
|
if (millis() - dernier_envoi >= 6) {
|
||||||
dernier_envoi = millis();
|
dernier_envoi = millis();
|
||||||
envoyer_paquet_crsf();
|
envoyer_paquet_crsf(evaluerFailsafe());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,19 +498,36 @@ void loop1() {
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
void assignerCanalCRSF(uint8_t numeroCh, uint16_t valeur11bits) {
|
void assignerCanalCRSF(uint8_t numeroCh, uint16_t valeur11bits) {
|
||||||
if (numeroCh >= 1 && numeroCh <= 16) {
|
if (numeroCh >= 1 && numeroCh <= 16 && numeroCh != CANAL_ARM) {
|
||||||
crsf_channels[numeroCh - 1] = valeur11bits;
|
crsf_channels[numeroCh - 1] = valeur11bits;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len) {
|
void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len) {
|
||||||
(void)desc_report;
|
(void)desc_report;
|
||||||
|
|
||||||
|
// Filtrage : n'accepter que le G29 en mode PS4, et une seule interface à la fois
|
||||||
|
uint16_t vid = 0, pid = 0;
|
||||||
|
tuh_vid_pid_get(dev_addr, &vid, &pid);
|
||||||
|
if (vid != G29_VID || pid != G29_PID_PS4 || volant_est_pret) {
|
||||||
|
rejet_vid = vid;
|
||||||
|
rejet_pid = pid;
|
||||||
|
logRejetRequis = true;
|
||||||
|
return; // Pas de tuh_hid_receive_report() : on ignore ce périphérique
|
||||||
|
}
|
||||||
|
|
||||||
|
g29_vid = vid;
|
||||||
|
g29_pid = pid;
|
||||||
g29_dev_addr = dev_addr;
|
g29_dev_addr = dev_addr;
|
||||||
g29_instance = instance;
|
g29_instance = instance;
|
||||||
g29_desc_len = desc_len;
|
g29_desc_len = desc_len;
|
||||||
dernierMasqueLedG29 = 0xFF;
|
dernierMasqueLedG29 = 0xFF;
|
||||||
etapeEnvoiLed = 0;
|
etapeEnvoiLed = 0;
|
||||||
etapeInitMoteur = 0;
|
etapeInitMoteur = 0;
|
||||||
|
rapportEngage = 0;
|
||||||
|
demandeRetourNeutre = false;
|
||||||
|
estArme = false;
|
||||||
|
boutonArmDejaEnfonce = true; // Ignorer R2 s'il est déjà enfoncé au branchement
|
||||||
momentConnexionUSB_ms = millis();
|
momentConnexionUSB_ms = millis();
|
||||||
dernierRapportUSB_ms = millis();
|
dernierRapportUSB_ms = millis();
|
||||||
volant_est_pret = true;
|
volant_est_pret = true;
|
||||||
@@ -434,20 +538,47 @@ void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_re
|
|||||||
}
|
}
|
||||||
|
|
||||||
void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance) {
|
void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance) {
|
||||||
(void)dev_addr;
|
// Ignorer la déconnexion d'un autre périphérique que le G29
|
||||||
(void)instance;
|
if (!volant_est_pret || dev_addr != g29_dev_addr || instance != g29_instance) return;
|
||||||
|
|
||||||
volant_est_pret = false;
|
volant_est_pret = false;
|
||||||
g29_vid = 0;
|
g29_vid = 0;
|
||||||
g29_pid = 0;
|
g29_pid = 0;
|
||||||
etapeInitMoteur = 0;
|
etapeInitMoteur = 0;
|
||||||
rapportEngage = 0;
|
rapportEngage = 0;
|
||||||
|
estArme = false;
|
||||||
reinitialiserCanauxCRSF();
|
reinitialiserCanauxCRSF();
|
||||||
majLedRequise = true;
|
majLedRequise = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void __not_in_flash_func(tuh_hid_report_received_cb)(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len) {
|
void __not_in_flash_func(tuh_hid_report_received_cb)(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len) {
|
||||||
if (len >= 51) {
|
// Ignorer tout rapport ne venant pas du G29, ou n'ayant pas le bon format
|
||||||
dernierRapportUSB_ms = millis();
|
if (dev_addr != g29_dev_addr || instance != g29_instance) {
|
||||||
|
return; // Ne pas réarmer la réception d'un périphérique étranger
|
||||||
|
}
|
||||||
|
if (len < 51 || report[0] != G29_REPORT_ID) {
|
||||||
|
compteurRapportsRejetes++;
|
||||||
|
tuh_hid_receive_report(dev_addr, instance);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
compteurRapportsOK++;
|
||||||
|
|
||||||
|
// Retour du signal après un failsafe : repartir au point mort ET désarmé
|
||||||
|
if (demandeRetourNeutre) {
|
||||||
|
demandeRetourNeutre = false;
|
||||||
|
if (rapportEngage != 0) {
|
||||||
|
rapportEngage = 0;
|
||||||
|
majLedRequise = true;
|
||||||
|
}
|
||||||
|
if (estArme) {
|
||||||
|
estArme = false;
|
||||||
|
logArmRequis = -1;
|
||||||
|
majLedRequise = true;
|
||||||
|
}
|
||||||
|
boutonArmDejaEnfonce = true; // Exiger un relâchement de R2 avant de réarmer
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t volantRaw = (report[44] << 8) | report[43];
|
uint16_t volantRaw = (report[44] << 8) | report[43];
|
||||||
uint16_t accelRaw = 65535 - ((report[46] << 8) | report[45]);
|
uint16_t accelRaw = 65535 - ((report[46] << 8) | report[45]);
|
||||||
@@ -457,6 +588,25 @@ void __not_in_flash_func(tuh_hid_report_received_cb)(uint8_t dev_addr, uint8_t i
|
|||||||
uint8_t boutonsEpaule = report[6];
|
uint8_t boutonsEpaule = report[6];
|
||||||
bool pPlusActuel = (boutonsEpaule & PALETTE_PLUS_MASK);
|
bool pPlusActuel = (boutonsEpaule & PALETTE_PLUS_MASK);
|
||||||
bool pMoinsActuel = (boutonsEpaule & PALETTE_MOINS_MASK);
|
bool pMoinsActuel = (boutonsEpaule & PALETTE_MOINS_MASK);
|
||||||
|
bool armActuel = (boutonsEpaule & BOUTON_ARM_MASK);
|
||||||
|
|
||||||
|
// Bascule ARM / DÉSARMÉ sur front montant de R2.
|
||||||
|
// Armement autorisé uniquement au point mort et accélérateur relâché.
|
||||||
|
if (armActuel && !boutonArmDejaEnfonce) {
|
||||||
|
if (estArme) {
|
||||||
|
estArme = false;
|
||||||
|
logArmRequis = -1;
|
||||||
|
} else if (rapportEngage == 0 && accelRaw <= DEADZONE_PEDALE) {
|
||||||
|
estArme = true;
|
||||||
|
logArmRequis = 1;
|
||||||
|
} else {
|
||||||
|
logArmRequis = 2;
|
||||||
|
}
|
||||||
|
majLedRequise = true;
|
||||||
|
boutonArmDejaEnfonce = true;
|
||||||
|
} else if (!armActuel && boutonArmDejaEnfonce) {
|
||||||
|
boutonArmDejaEnfonce = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (pPlusActuel && !palettePlusDejaEnfoncee) {
|
if (pPlusActuel && !palettePlusDejaEnfoncee) {
|
||||||
if (rapportEngage < 3 && !(rapportEngage < 0 && accelRaw > DEADZONE_PEDALE)) {
|
if (rapportEngage < 3 && !(rapportEngage < 0 && accelRaw > DEADZONE_PEDALE)) {
|
||||||
@@ -486,7 +636,7 @@ void __not_in_flash_func(tuh_hid_report_received_cb)(uint8_t dev_addr, uint8_t i
|
|||||||
uint16_t vVolant = constrain((int32_t)(CRSF_VAL_MID - y * (CRSF_VAL_MAX - CRSF_VAL_MID)), CRSF_VAL_MIN, CRSF_VAL_MAX);
|
uint16_t vVolant = constrain((int32_t)(CRSF_VAL_MID - y * (CRSF_VAL_MAX - CRSF_VAL_MID)), CRSF_VAL_MIN, CRSF_VAL_MAX);
|
||||||
|
|
||||||
uint16_t vAccel = CRSF_VAL_MID;
|
uint16_t vAccel = CRSF_VAL_MID;
|
||||||
if (accelRaw > DEADZONE_PEDALE) {
|
if (estArme && accelRaw > DEADZONE_PEDALE) { // Désarmé : gaz coupés quoi qu'il arrive
|
||||||
if (rapportEngage == -1) {
|
if (rapportEngage == -1) {
|
||||||
vAccel = constrain(map(accelRaw, DEADZONE_PEDALE, 65535, GAZ_ARRIERE_MIN, GAZ_ARRIERE_MAX), CRSF_VAL_MIN, CRSF_VAL_MAX);
|
vAccel = constrain(map(accelRaw, DEADZONE_PEDALE, 65535, GAZ_ARRIERE_MIN, GAZ_ARRIERE_MAX), CRSF_VAL_MIN, CRSF_VAL_MAX);
|
||||||
} else if (rapportEngage >= 1 && rapportEngage <= 3) {
|
} else if (rapportEngage >= 1 && rapportEngage <= 3) {
|
||||||
@@ -507,6 +657,11 @@ void __not_in_flash_func(tuh_hid_report_received_cb)(uint8_t dev_addr, uint8_t i
|
|||||||
assignerCanalCRSF(configCanaux.accel, vAccel);
|
assignerCanalCRSF(configCanaux.accel, vAccel);
|
||||||
assignerCanalCRSF(configCanaux.frein, vFrein);
|
assignerCanalCRSF(configCanaux.frein, vFrein);
|
||||||
assignerCanalCRSF(configCanaux.embrayage, vEmbrayage);
|
assignerCanalCRSF(configCanaux.embrayage, vEmbrayage);
|
||||||
|
crsf_channels[CANAL_ARM - 1] = estArme ? CRSF_VAL_MAX : CRSF_VAL_MIN;
|
||||||
|
|
||||||
|
// Horodatage APRÈS l'écriture des canaux : à la sortie d'un failsafe, le cœur 0
|
||||||
|
// ne peut pas renvoyer d'anciennes valeurs (d'avant la coupure) pendant un paquet.
|
||||||
|
dernierRapportUSB_ms = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
tuh_hid_receive_report(dev_addr, instance);
|
tuh_hid_receive_report(dev_addr, instance);
|
||||||
|
|||||||
Reference in new issue
Block a user