mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
Merge pull request #8 from bleackstorm/feat/steam-controller-support
Feat/steam controller support
This commit is contained in:
12 files changed
+3122
-94
No files matched your search
@@ -21,6 +21,7 @@ Application graphique et VR native **Linux / SteamOS (ARM64 & x86_64)** en **Rus
|
|||||||
- **`crsf`** : Trames `RC_CHANNELS_PACKED (0x16)` (11 bits `172..1811`).
|
- **`crsf`** : Trames `RC_CHANNELS_PACKED (0x16)` (11 bits `172..1811`).
|
||||||
- **`mavlink`** : `MAVLink v1 RC_CHANNELS_OVERRIDE` + `HEARTBEAT` (ex. `elrs_txbp.local:14555`).
|
- **`mavlink`** : `MAVLink v1 RC_CHANNELS_OVERRIDE` + `HEARTBEAT` (ex. `elrs_txbp.local:14555`).
|
||||||
- **Commandes volant G29 (`$G29` / `$G29_EVT`)** : Tare Head-Tracking (`Cross`/`PS`/`R3`), DVR (`Share`/`Circle`), OSD (`Triangle`), Projection VR (`Square`), Trim Pan/Tilt (`D-Pad`) et affichage rapport engagé / armement / pédales dans le HUD.
|
- **Commandes volant G29 (`$G29` / `$G29_EVT`)** : Tare Head-Tracking (`Cross`/`PS`/`R3`), DVR (`Share`/`Circle`), OSD (`Triangle`), Projection VR (`Square`), Trim Pan/Tilt (`D-Pad`) et affichage rapport engagé / armement / pédales dans le HUD.
|
||||||
|
- **Support Steam Controller (`src/controller.rs`, bascule à chaud G29 ⇄ Steam Controller)** : Lecture Linux `evdev` native (dongle sans fil `Steam Controller Puck`, USB ou gamepad standard) avec boîte séquentielle `R/N/1/2/3`, sécurité d'armement, mêmes raccourcis cockpit et injection `$SRC,EXT` / `$RC,...` à `100 Hz` vers la RP2350 via le pont UDP `14552`.
|
||||||
- **Télémétrie & OSD Vectoriel (`src/telemetry_osd.rs`)** :
|
- **Télémétrie & OSD Vectoriel (`src/telemetry_osd.rs`)** :
|
||||||
- Décodage unifié depuis le port UDP `14552` (`$CRSF,<HEX>` remonté par `g29_crsf` via la Radxa) **et/ou** le port UDP `14551` (MAVLink v1/v2 & CRSF) avec validation **CRC-16 / CRC-8 DVB-S2**.
|
- Décodage unifié depuis le port UDP `14552` (`$CRSF,<HEX>` remonté par `g29_crsf` via la Radxa) **et/ou** le port UDP `14551` (MAVLink v1/v2 & CRSF) avec validation **CRC-16 / CRC-8 DVB-S2**.
|
||||||
- Incrustation OSD zéro-allocation (`StackStr`) : horizon artificiel, ruban de cap, radar gimbal Pan/Tilt, tension/courant batterie, LQ/RSSI, vitesse, altitude/VSI, mode de projection et indicateur `REC`.
|
- Incrustation OSD zéro-allocation (`StackStr`) : horizon artificiel, ruban de cap, radar gimbal Pan/Tilt, tension/courant batterie, LQ/RSSI, vitesse, altitude/VSI, mode de projection et indicateur `REC`.
|
||||||
@@ -108,6 +109,10 @@ Le script [launch.sh](launch.sh) prépare `libxkbcommon-x11.so` si besoin, compi
|
|||||||
| `--ht-protocol` | `g29` | Protocole Head-Tracking : `g29` (pont unifié `$HT`), `msp`, `crsf`, `mavlink` |
|
| `--ht-protocol` | `g29` | Protocole Head-Tracking : `g29` (pont unifié `$HT`), `msp`, `crsf`, `mavlink` |
|
||||||
| `--nomad-ip` / `--nomad-port` | `192.168.1.1` / `14552` | Cible UDP du pont unifié Radxa/G29 (`10.0.0.1:14550` pour Backpack AP) |
|
| `--nomad-ip` / `--nomad-port` | `192.168.1.1` / `14552` | Cible UDP du pont unifié Radxa/G29 (`10.0.0.1:14550` pour Backpack AP) |
|
||||||
| `--g29-enabled` / `--g29-udp-port` | `true` / `14552` | Active la passerelle unifiée G29 + boutons + télémétrie `$CRSF` |
|
| `--g29-enabled` / `--g29-udp-port` | `true` / `14552` | Active la passerelle unifiée G29 + boutons + télémétrie `$CRSF` |
|
||||||
|
| `--control-source` | `g29` | Source de conduite active : `g29` (Volant Logitech G29) ou `steam` (Steam Controller) |
|
||||||
|
| `--controller-device` | *(auto)* | Chemin `evdev` explicite du Steam Controller (ex. `/dev/input/event28`, auto-détecté par défaut) |
|
||||||
|
| `--controller-expo` / `--controller-deadzone` | `0.25` / `0.08` | Expo cubique et zone morte du stick gauche du Steam Controller |
|
||||||
|
| `--controller-invert-steering` | `false` | Inverse le sens de direction du Steam Controller |
|
||||||
| `--telemetry-enabled` / `--telemetry-udp-port` | `false` / `14551` | Active l'OSD et écoute MAVLink / CRSF |
|
| `--telemetry-enabled` / `--telemetry-udp-port` | `false` / `14551` | Active l'OSD et écoute MAVLink / CRSF |
|
||||||
| `--dvr-dir` / `--dvr-format` / `--dvr-mode` | `recordings` / `mkv` / `copy` | Dossier, conteneur (`mkv`, `mp4`) et mode (`copy`, `composited`) |
|
| `--dvr-dir` / `--dvr-format` / `--dvr-mode` | `recordings` / `mkv` / `copy` | Dossier, conteneur (`mkv`, `mp4`) et mode (`copy`, `composited`) |
|
||||||
| `--log-file` | `steamframe_fpv.log` | Fichier de journalisation persistant |
|
| `--log-file` | `steamframe_fpv.log` | Fichier de journalisation persistant |
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ Firmware dual-core pour **Waveshare RP2350-USB-A** transformant un volant **Logi
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Ce qui est centralisé sur la RP2350 :
|
### Ce qui est centralisé sur la RP2350 :
|
||||||
1. **Pilotage G29 (`CH1..CH5`)** : Volant (`CH1`), Accélérateur avec boîte séquentielle R/N/1/2/3 (`CH2`), Frein (`CH3`), Embrayage (`CH4`), Armement R2 (`CH5`).
|
1. **Pilotage G29 (`CH1..CH5`) ou Steam Controller externe (`$SRC,EXT` + `$RC,...`)** : Volant/Stick (`CH1`), Accélérateur avec boîte séquentielle R/N/1/2/3 (`CH2`), Frein (`CH3`), Embrayage (`CH4`), Armement (`CH5`). En mode `EXT`, la RP2350 applique un **watchdog failsafe de `400 ms`** sur `$RC` et fonctionne même si le G29 est débranché.
|
||||||
2. **Mixage Head-Tracking (`CH6..CH8`)** : Réception des trames `$HT,<pan>,<tilt>,<roll>` (valeurs CRSF `172..1811`, neutre `992`) depuis le casque via la Radxa Zero 3W (`Serial2` à `460 800 bauds` ou `Serial` USB-C), avec **watchdog de recentrage automatique à `500 ms`**.
|
2. **Mixage Head-Tracking (`CH6..CH8`)** : Réception des trames `$HT,<pan>,<tilt>,<roll>` (valeurs CRSF `172..1811`, neutre `992`) depuis le casque via la Radxa Zero 3W (`Serial2` à `460 800 bauds` ou `Serial` USB-C), avec **watchdog de recentrage automatique à `500 ms`**.
|
||||||
3. **Relais Télémétrie & État Cockpit** :
|
3. **Relais Télémétrie & État Cockpit** :
|
||||||
- État G29 à 20 Hz (`$G29,ARM=...,GEAR=...,THROT=...,BRAKE=...,FFB=...,VIB=...,FAIL=...`).
|
- État actif à 20 Hz (`$G29,ARM=...,GEAR=...,THROT=...,BRAKE=...,FFB=...,VIB=...,FAIL=...,SRC=G29|EXT`).
|
||||||
- Événements boutons immédiats (`$G29_EVT,BTN=...`) pour piloter l'OSD, le DVR, le mode de projection VR et la Tare Head-Tracking depuis le volant.
|
- Événements boutons immédiats (`$G29_EVT,BTN=...`) pour piloter l'OSD, le DVR, le mode de projection VR et la Tare Head-Tracking depuis le volant.
|
||||||
- Relais complet des trames CRSF valides reçues sur `GP1` (`$CRSF,<HEX>`) vers l'OSD de `steamframe-fpv`, tout en conservant le calcul local de rugosité (`0x1E`) pour le retour de force haptique du volant.
|
- Relais complet des trames CRSF valides reçues sur `GP1` (`$CRSF,<HEX>`) vers l'OSD de `steamframe-fpv`, tout en conservant le calcul local de rugosité (`0x1E`) pour le retour de force haptique du volant.
|
||||||
|
|
||||||
@@ -76,6 +76,8 @@ Firmware dual-core pour **Waveshare RP2350-USB-A** transformant un volant **Logi
|
|||||||
|
|
||||||
| Commande | Description |
|
| Commande | Description |
|
||||||
| :--- | :--- |
|
| :--- | :--- |
|
||||||
|
| `$SRC,G29` / `$SRC,EXT` | Bascule la source de conduite active (Volant G29 ou Steam Controller externe, désarmé uniquement) |
|
||||||
|
| `$RC,<dir>,<gaz>,<frn>,<emb>,<arm>,<gear>` | Injecte la conduite externe (`CH1..CH5`, valeurs CRSF `172..1811`, watchdog `400 ms`) en mode `EXT` |
|
||||||
| `$HT,<pan>,<tilt>,<roll>` | Injecte le Head-Tracking sur `CH6, CH7, CH8` (`172..1811`) |
|
| `$HT,<pan>,<tilt>,<roll>` | Injecte le Head-Tracking sur `CH6, CH7, CH8` (`172..1811`) |
|
||||||
| `D=<0..255>` | Règle la dureté du ressort FFB (sauvegarde différée si armé) |
|
| `D=<0..255>` | Règle la dureté du ressort FFB (sauvegarde différée si armé) |
|
||||||
| `T=<0..100>` | Règle l'intensité des vibrations haptiques (`0` = désactivé) |
|
| `T=<0..100>` | Règle l'intensité des vibrations haptiques (`0` = désactivé) |
|
||||||
|
|||||||
+293
-52
@@ -56,6 +56,13 @@
|
|||||||
#define UART_BRIDGE_BAUD 460800
|
#define UART_BRIDGE_BAUD 460800
|
||||||
#define INTERVALLE_COCKPIT_MS 50 // 20 Hz
|
#define INTERVALLE_COCKPIT_MS 50 // 20 Hz
|
||||||
#define TIMEOUT_HT_MS 500 // Retour au centre si le casque ne répond plus
|
#define TIMEOUT_HT_MS 500 // Retour au centre si le casque ne répond plus
|
||||||
|
#define TIMEOUT_RC_EXT_MS 400 // Watchdog failsafe si la manette externe (Steam Controller) ne répond plus
|
||||||
|
|
||||||
|
// Source active de pilotage (bascule via $SRC,G29 ou $SRC,EXT)
|
||||||
|
enum SourceControle : uint8_t {
|
||||||
|
SRC_G29 = 0,
|
||||||
|
SRC_EXT = 1,
|
||||||
|
};
|
||||||
|
|
||||||
// Bits d'événements boutons (Cœur 1 -> Cœur 0)
|
// Bits d'événements boutons (Cœur 1 -> Cœur 0)
|
||||||
enum CockpitBoutonBit : uint16_t {
|
enum CockpitBoutonBit : uint16_t {
|
||||||
@@ -96,7 +103,7 @@ const uint16_t GAZ_AVANT_MAX_PAR_VITESSE[3] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define GAZ_ARRIERE_MIN 905
|
#define GAZ_ARRIERE_MIN 905
|
||||||
#define GAZ_ARRIERE_MAX 850
|
#define GAZ_ARRIERE_MAX 800
|
||||||
#define DEADZONE_PEDALE 800
|
#define DEADZONE_PEDALE 800
|
||||||
|
|
||||||
// Configuration par défaut du volant G29
|
// Configuration par défaut du volant G29
|
||||||
@@ -107,7 +114,7 @@ const uint16_t GAZ_AVANT_MAX_PAR_VITESSE[3] = {
|
|||||||
#define EXPO_DEFAUT 0.25f // 0.0f = Lineaire, 0.25f = Doux au centre (FPU RP2350)
|
#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 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 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 ETAPES_INIT_FFB_TOTAL 2 // Nombre d'etapes d'init FFB initiales (0=Range, 1=Spring)
|
||||||
#define VIBRATION_DEFAUT 50 // Intensite par defaut des vibrations (0 a 100%)
|
#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)
|
#define MAGIC_NUMBER_CONFIG 0x4A // Identifiant de validite en EEPROM (mis a jour pour 50% vibrations)
|
||||||
|
|
||||||
@@ -180,6 +187,7 @@ volatile uint16_t rejet_pid = 0;
|
|||||||
volatile uint8_t dernierMasqueLedG29 = 0xFF;
|
volatile uint8_t dernierMasqueLedG29 = 0xFF;
|
||||||
volatile uint8_t etapeEnvoiLed = 0;
|
volatile uint8_t etapeEnvoiLed = 0;
|
||||||
volatile uint8_t etapeInitMoteur = 0;
|
volatile uint8_t etapeInitMoteur = 0;
|
||||||
|
volatile bool reinitPlageTardiveFaite = false;
|
||||||
|
|
||||||
// Variables pour le réglage FFB à la volée (Molette / Boutons +/- et Série)
|
// Variables pour le réglage FFB à la volée (Molette / Boutons +/- et Série)
|
||||||
volatile bool majRessortRequise = false;
|
volatile bool majRessortRequise = false;
|
||||||
@@ -202,6 +210,7 @@ volatile uint32_t momentDesarmement_ms = 0;
|
|||||||
volatile uint8_t rugositeTerrainExterne = 0; // 0 à 255 (pilotable via CRSF télémétrie / FC)
|
volatile uint8_t rugositeTerrainExterne = 0; // 0 à 255 (pilotable via CRSF télémétrie / FC)
|
||||||
volatile float dernierAccelPct = 0.0f; // 0.0 à 100.0%
|
volatile float dernierAccelPct = 0.0f; // 0.0 à 100.0%
|
||||||
volatile float dernierFreinPct = 0.0f; // 0.0 à 100.0%
|
volatile float dernierFreinPct = 0.0f; // 0.0 à 100.0%
|
||||||
|
volatile float dernierEmbrayagePct = 0.0f; // 0.0 à 100.0%
|
||||||
volatile uint32_t momentDernierChocRapport_ms = 0; // Horodatage du passage de vitesse
|
volatile uint32_t momentDernierChocRapport_ms = 0; // Horodatage du passage de vitesse
|
||||||
volatile int8_t directionDernierChocRapport = 0; // -1 gauche, +1 droite
|
volatile int8_t directionDernierChocRapport = 0; // -1 gauche, +1 droite
|
||||||
volatile bool forceEstAuNeutre = false;
|
volatile bool forceEstAuNeutre = false;
|
||||||
@@ -218,6 +227,31 @@ bool cockpitEchoUSB = true; // Actif par défaut pour lia
|
|||||||
uint32_t dernierPaquetHT_ms = 0;
|
uint32_t dernierPaquetHT_ms = 0;
|
||||||
bool htActif = false;
|
bool htActif = false;
|
||||||
|
|
||||||
|
// Pilotage externe (Steam Controller via SteamFrame FPV -> Radxa -> RP2350)
|
||||||
|
volatile uint8_t sourceActive = SRC_G29;
|
||||||
|
volatile bool extRcActif = false;
|
||||||
|
volatile bool extArme = false;
|
||||||
|
volatile int8_t extRapport = 0;
|
||||||
|
volatile uint8_t extAccelPct = 0;
|
||||||
|
volatile uint8_t extFreinPct = 0;
|
||||||
|
volatile uint8_t extEmbrayagePct = 0;
|
||||||
|
volatile int8_t extVolantPct = 0;
|
||||||
|
volatile uint32_t dernierPaquetRC_ms = 0;
|
||||||
|
|
||||||
|
static inline bool estActuellementArme() {
|
||||||
|
return (sourceActive == SRC_EXT) ? extArme : estArme;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int8_t rapportActuel() {
|
||||||
|
return (sourceActive == SRC_EXT) ? extRapport : rapportEngage;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void assignerCanalCRSF(uint8_t numeroCh, uint16_t valeur11bits) {
|
||||||
|
if (numeroCh >= 1 && numeroCh <= 16 && numeroCh != CANAL_ARM) {
|
||||||
|
crsf_channels[numeroCh - 1] = valeur11bits;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
char serialBuffer[64];
|
char serialBuffer[64];
|
||||||
uint8_t serialBufferIdx = 0;
|
uint8_t serialBufferIdx = 0;
|
||||||
char serial2Buffer[64];
|
char serial2Buffer[64];
|
||||||
@@ -236,8 +270,8 @@ void reinitialiserCanauxCRSF() {
|
|||||||
void reinitialiserConfigurationDefaut() {
|
void reinitialiserConfigurationDefaut() {
|
||||||
memset((void*)&configSysteme, 0, sizeof(ConfigG29));
|
memset((void*)&configSysteme, 0, sizeof(ConfigG29));
|
||||||
configSysteme.volant = 1;
|
configSysteme.volant = 1;
|
||||||
configSysteme.accel = 2;
|
configSysteme.accel = 3; // AETR : CH3 = Gaz / ESC
|
||||||
configSysteme.frein = 3;
|
configSysteme.frein = 2; // AETR : CH2 = Frein
|
||||||
configSysteme.embrayage = 4;
|
configSysteme.embrayage = 4;
|
||||||
configSysteme.forceRessort = FORCE_RESSORT_DEFAUT;
|
configSysteme.forceRessort = FORCE_RESSORT_DEFAUT;
|
||||||
configSysteme.angleSouhaiteTotal = ANGLE_DEFAUT_TOTAL;
|
configSysteme.angleSouhaiteTotal = ANGLE_DEFAUT_TOTAL;
|
||||||
@@ -276,8 +310,10 @@ void afficherConfiguration() {
|
|||||||
configSysteme.forceRessort, (configSysteme.forceRessort * 100) / 255);
|
configSysteme.forceRessort, (configSysteme.forceRessort * 100) / 255);
|
||||||
Serial.printf("Plage Volant(P): %d degres [P=40..900]\n", configSysteme.angleSouhaiteTotal);
|
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("Expo Volant(X) : %.2f [X=0.00..0.80]\n", configSysteme.expoVolant);
|
||||||
|
Serial.printf("Source active : %s [$SRC,G29 | $SRC,EXT]\n",
|
||||||
|
(sourceActive == SRC_EXT) ? "EXT (Steam Controller)" : "G29 (Volant)");
|
||||||
Serial.printf("Vibrations (T) : %d%% [Boutons +/- ou T=0..100] (0 = desactive)\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), ?");
|
Serial.println("Commandes : V=ch, A=ch, F=ch, E=ch, D=val, P=val, X=val, T=val, $SRC,G29|EXT, $RC,..., $HT,..., S(save), R(reset), B(bootsel), ?");
|
||||||
}
|
}
|
||||||
|
|
||||||
void chargerConfiguration() {
|
void chargerConfiguration() {
|
||||||
@@ -325,7 +361,7 @@ void chargerConfiguration() {
|
|||||||
// GESTION SÉRIE NON BLOQUANTE
|
// GESTION SÉRIE NON BLOQUANTE
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
void demanderOuExecuterSauvegarde() {
|
void demanderOuExecuterSauvegarde() {
|
||||||
if (estArme) {
|
if (estActuellementArme()) {
|
||||||
sauvegardeDifferee = true;
|
sauvegardeDifferee = true;
|
||||||
Serial.println(">> Modification appliquee (sauvegarde Flash differee au desarmement).");
|
Serial.println(">> Modification appliquee (sauvegarde Flash differee au desarmement).");
|
||||||
} else {
|
} else {
|
||||||
@@ -341,7 +377,7 @@ void traiterLigneSerie(char* commande) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (commande[0] == 'B' || commande[0] == 'b') {
|
if (commande[0] == 'B' || commande[0] == 'b') {
|
||||||
if (estArme) {
|
if (estActuellementArme()) {
|
||||||
Serial.println("!! Redemarrage BOOTSEL refuse pendant la conduite (desarmer d'abord) !!");
|
Serial.println("!! Redemarrage BOOTSEL refuse pendant la conduite (desarmer d'abord) !!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -351,7 +387,7 @@ void traiterLigneSerie(char* commande) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (commande[0] == 'S' || commande[0] == 's') {
|
if (commande[0] == 'S' || commande[0] == 's') {
|
||||||
if (estArme) {
|
if (estActuellementArme()) {
|
||||||
Serial.println("!! Sauvegarde Flash refusee pendant la conduite (desarmer d'abord) !!");
|
Serial.println("!! Sauvegarde Flash refusee pendant la conduite (desarmer d'abord) !!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -361,7 +397,7 @@ void traiterLigneSerie(char* commande) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (commande[0] == 'R' || commande[0] == 'r') {
|
if (commande[0] == 'R' || commande[0] == 'r') {
|
||||||
if (estArme) {
|
if (estActuellementArme()) {
|
||||||
Serial.println("!! Reinitialisation refusee pendant la conduite (desarmer d'abord) !!");
|
Serial.println("!! Reinitialisation refusee pendant la conduite (desarmer d'abord) !!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -370,7 +406,16 @@ void traiterLigneSerie(char* commande) {
|
|||||||
reinitialiserCanauxCRSF();
|
reinitialiserCanauxCRSF();
|
||||||
rapportEngage = 0;
|
rapportEngage = 0;
|
||||||
estArme = false;
|
estArme = false;
|
||||||
|
extArme = false;
|
||||||
|
extRapport = 0;
|
||||||
|
extAccelPct = 0;
|
||||||
|
extFreinPct = 0;
|
||||||
|
extEmbrayagePct = 0;
|
||||||
|
extVolantPct = 0;
|
||||||
|
extRcActif = false;
|
||||||
|
sourceActive = SRC_G29;
|
||||||
majLedRequise = true;
|
majLedRequise = true;
|
||||||
|
cockpitEtatModifie = true;
|
||||||
momentDernierChangementDurete_ms = 0;
|
momentDernierChangementDurete_ms = 0;
|
||||||
sauvegardeDifferee = false;
|
sauvegardeDifferee = false;
|
||||||
rp2040.resumeOtherCore();
|
rp2040.resumeOtherCore();
|
||||||
@@ -384,7 +429,7 @@ void traiterLigneSerie(char* commande) {
|
|||||||
char periph = commande[0];
|
char periph = commande[0];
|
||||||
if (periph == 'V' || periph == 'v' || periph == 'A' || periph == 'a' ||
|
if (periph == 'V' || periph == 'v' || periph == 'A' || periph == 'a' ||
|
||||||
periph == 'F' || periph == 'f' || periph == 'E' || periph == 'e') {
|
periph == 'F' || periph == 'f' || periph == 'E' || periph == 'e') {
|
||||||
if (estArme) {
|
if (estActuellementArme()) {
|
||||||
Serial.println("!! Remappage des canaux refuse pendant la conduite (desarmer d'abord) !!");
|
Serial.println("!! Remappage des canaux refuse pendant la conduite (desarmer d'abord) !!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -436,7 +481,7 @@ void traiterLigneSerie(char* commande) {
|
|||||||
Serial.println("!! Durete (D) doit etre entre 0 et 255 !!");
|
Serial.println("!! Durete (D) doit etre entre 0 et 255 !!");
|
||||||
}
|
}
|
||||||
} else if (periph == 'P' || periph == 'p') {
|
} else if (periph == 'P' || periph == 'p') {
|
||||||
if (estArme) {
|
if (estActuellementArme()) {
|
||||||
Serial.println("!! Reglage de plage (P) refuse pendant la conduite (desarmer d'abord) !!");
|
Serial.println("!! Reglage de plage (P) refuse pendant la conduite (desarmer d'abord) !!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -453,7 +498,7 @@ void traiterLigneSerie(char* commande) {
|
|||||||
Serial.println("!! Plage d'angle (P) doit etre entre 40 et 900 degres !!");
|
Serial.println("!! Plage d'angle (P) doit etre entre 40 et 900 degres !!");
|
||||||
}
|
}
|
||||||
} else if (periph == 'X' || periph == 'x') {
|
} else if (periph == 'X' || periph == 'x') {
|
||||||
if (estArme) {
|
if (estActuellementArme()) {
|
||||||
Serial.println("!! Reglage d'expo (X) refuse pendant la conduite (desarmer d'abord) !!");
|
Serial.println("!! Reglage d'expo (X) refuse pendant la conduite (desarmer d'abord) !!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -494,6 +539,133 @@ void traiterLigneSerie(char* commande) {
|
|||||||
dernierPaquetHT_ms = millis();
|
dernierPaquetHT_ms = millis();
|
||||||
htActif = true;
|
htActif = true;
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sélection de la source de pilotage : $SRC,G29 ou $SRC,EXT (Steam Controller)
|
||||||
|
if (strncmp(commande, "$SRC,", 5) == 0) {
|
||||||
|
const char* mode = commande + 5;
|
||||||
|
uint8_t cible = sourceActive;
|
||||||
|
if (strcmp(mode, "G29") == 0 || strcmp(mode, "g29") == 0) {
|
||||||
|
cible = SRC_G29;
|
||||||
|
} else if (strcmp(mode, "EXT") == 0 || strcmp(mode, "ext") == 0 || strcmp(mode, "STEAM") == 0) {
|
||||||
|
cible = SRC_EXT;
|
||||||
|
} else {
|
||||||
|
Serial.printf("!! [SRC] Source inconnue : %s (attendu G29 ou EXT) !!\n", mode);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (cible == sourceActive) {
|
||||||
|
cockpitEtatModifie = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (estActuellementArme()) {
|
||||||
|
Serial.println("!! [SRC] Changement de controleur refuse : desarmer d'abord !!");
|
||||||
|
cockpitEtatModifie = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
rp2040.idleOtherCore();
|
||||||
|
sourceActive = cible;
|
||||||
|
extRcActif = false;
|
||||||
|
extArme = false;
|
||||||
|
extRapport = 0;
|
||||||
|
extAccelPct = 0;
|
||||||
|
extFreinPct = 0;
|
||||||
|
estArme = false;
|
||||||
|
rapportEngage = 0;
|
||||||
|
boutonArmDejaEnfonce = true;
|
||||||
|
palettePlusDejaEnfoncee = true;
|
||||||
|
paletteMoinsDejaEnfoncee = true;
|
||||||
|
etatBoutonsCockpitPrec = 0xFFFF;
|
||||||
|
reinitialiserCanauxCRSF();
|
||||||
|
rp2040.resumeOtherCore();
|
||||||
|
majLedRequise = true;
|
||||||
|
cockpitEtatModifie = true;
|
||||||
|
Serial.printf(">> [SRC] Source active basculee sur : %s\n",
|
||||||
|
(sourceActive == SRC_EXT) ? "EXT (Steam Controller)" : "G29 (Volant)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Injection conduite externe (Steam Controller via SteamFrame FPV) :
|
||||||
|
// $RC,<steer>,<accel>,<brake>,<clutch>,<arm>,<gear>
|
||||||
|
if (strncmp(commande, "$RC,", 4) == 0) {
|
||||||
|
if (sourceActive != SRC_EXT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int steer = CRSF_VAL_MID, accel = CRSF_VAL_MID, brake = CRSF_VAL_MID, clutch = CRSF_VAL_MID;
|
||||||
|
int arm = 0, gear = 0;
|
||||||
|
if (sscanf(commande + 4, "%d,%d,%d,%d,%d,%d", &steer, &accel, &brake, &clutch, &arm, &gear) == 6) {
|
||||||
|
uint16_t vSteer = (uint16_t)constrain(steer, CRSF_VAL_MIN, CRSF_VAL_MAX);
|
||||||
|
uint16_t vAccel = (uint16_t)constrain(accel, CRSF_VAL_MIN, CRSF_VAL_MAX);
|
||||||
|
uint16_t vBrake = (uint16_t)constrain(brake, CRSF_VAL_MIN, CRSF_VAL_MAX);
|
||||||
|
uint16_t vClutch = (uint16_t)constrain(clutch, CRSF_VAL_MIN, CRSF_VAL_MAX);
|
||||||
|
int8_t vGear = (int8_t)constrain(gear, -1, 3);
|
||||||
|
bool demandeArm = (arm != 0);
|
||||||
|
|
||||||
|
// Sécurité : refuser un armement (0 -> 1) si rapport != N ou gaz non neutres
|
||||||
|
if (demandeArm && !extArme) {
|
||||||
|
if (vGear == 0 && vAccel == CRSF_VAL_MID) {
|
||||||
|
extArme = true;
|
||||||
|
momentArmement_ms = millis();
|
||||||
|
momentDesarmement_ms = 0;
|
||||||
|
majLedRequise = true;
|
||||||
|
cockpitEtatModifie = true;
|
||||||
|
Serial.println(">> [ARM EXT] ARME (Steam Controller)");
|
||||||
|
}
|
||||||
|
} else if (!demandeArm && extArme) {
|
||||||
|
extArme = false;
|
||||||
|
momentDesarmement_ms = millis();
|
||||||
|
momentArmement_ms = 0;
|
||||||
|
majLedRequise = true;
|
||||||
|
cockpitEtatModifie = true;
|
||||||
|
Serial.println(">> [ARM EXT] DESARME (Steam Controller)");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vGear != extRapport) {
|
||||||
|
extRapport = vGear;
|
||||||
|
majLedRequise = true;
|
||||||
|
cockpitEtatModifie = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!extArme || extRapport == 0) {
|
||||||
|
vAccel = CRSF_VAL_MID;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t accelPct = 0;
|
||||||
|
if (extArme && extRapport >= 1 && extRapport <= 3 && vAccel >= GAZ_AVANT_MIN) {
|
||||||
|
uint16_t maxV = GAZ_AVANT_MAX_PAR_VITESSE[extRapport - 1];
|
||||||
|
accelPct = (uint8_t)constrain(map(vAccel, GAZ_AVANT_MIN, maxV, 0, 100), 0, 100);
|
||||||
|
} else if (extArme && extRapport == -1 && vAccel <= GAZ_ARRIERE_MIN) {
|
||||||
|
accelPct = (uint8_t)constrain(map(vAccel, GAZ_ARRIERE_MIN, GAZ_ARRIERE_MAX, 0, 100), 0, 100);
|
||||||
|
}
|
||||||
|
uint8_t brakePct = (vBrake > CRSF_VAL_MID)
|
||||||
|
? (uint8_t)constrain(map(vBrake, CRSF_VAL_MID, CRSF_VAL_MAX, 0, 100), 0, 100)
|
||||||
|
: 0;
|
||||||
|
uint8_t clutchPct = (vClutch > CRSF_VAL_MID)
|
||||||
|
? (uint8_t)constrain(map(vClutch, CRSF_VAL_MID, CRSF_VAL_MAX, 0, 100), 0, 100)
|
||||||
|
: 0;
|
||||||
|
int8_t steerPct = (int8_t)constrain(
|
||||||
|
(int)(((float)((int)CRSF_VAL_MID - (int)vSteer) / (float)(CRSF_VAL_MID - CRSF_VAL_MIN)) * 100.0f),
|
||||||
|
-100, 100
|
||||||
|
);
|
||||||
|
extAccelPct = accelPct;
|
||||||
|
extFreinPct = brakePct;
|
||||||
|
extEmbrayagePct = clutchPct;
|
||||||
|
extVolantPct = steerPct;
|
||||||
|
|
||||||
|
assignerCanalCRSF(configSysteme.volant, vSteer);
|
||||||
|
assignerCanalCRSF(configSysteme.accel, vAccel);
|
||||||
|
assignerCanalCRSF(configSysteme.frein, vBrake);
|
||||||
|
assignerCanalCRSF(configSysteme.embrayage, vClutch);
|
||||||
|
crsf_channels[CANAL_ARM - 1] = extArme ? CRSF_VAL_MAX : CRSF_VAL_MIN;
|
||||||
|
|
||||||
|
dernierPaquetRC_ms = millis();
|
||||||
|
if (!extRcActif) {
|
||||||
|
extRcActif = true;
|
||||||
|
majLedRequise = true;
|
||||||
|
cockpitEtatModifie = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -538,19 +710,19 @@ void actualiserLED() {
|
|||||||
} else if (momentDesarmement_ms > 0 && dtDesarm < 250) {
|
} else if (momentDesarmement_ms > 0 && dtDesarm < 250) {
|
||||||
// Animation NeoPixel au desarmement : flash rouge d'arret
|
// Animation NeoPixel au desarmement : flash rouge d'arret
|
||||||
r = 255; g = 20; b = 0;
|
r = 255; g = 20; b = 0;
|
||||||
} else if (!volant_est_pret) {
|
} else if ((sourceActive == SRC_G29 && !volant_est_pret) || (sourceActive == SRC_EXT && !extRcActif)) {
|
||||||
b = 255; // Bleu : Attente G29
|
b = 255; // Bleu : Attente contrôleur actif (G29 ou Steam Controller)
|
||||||
} else if (failsafeActif) {
|
} else if (failsafeActif) {
|
||||||
r = 255; g = 255; b = 255; // Blanc : Failsafe (G29 muet)
|
r = 255; g = 255; b = 255; // Blanc : Failsafe
|
||||||
} else {
|
} else {
|
||||||
switch (rapportEngage) {
|
switch (rapportActuel()) {
|
||||||
case -1: r = 255; g = 0; b = 0; break; // Rouge : R
|
case -1: r = 255; g = 0; b = 0; break; // Rouge : R
|
||||||
case 0: r = 255; g = 100; b = 0; break; // Orange : N
|
case 0: r = 255; g = 100; b = 0; break; // Orange : N
|
||||||
case 1: r = 0; g = 255; b = 255; break; // Cyan : 1ère
|
case 1: r = 0; g = 255; b = 255; break; // Cyan : 1ère
|
||||||
case 2: r = 0; g = 255; b = 0; break; // Vert : 2ème
|
case 2: r = 0; g = 255; b = 0; break; // Vert : 2ème
|
||||||
case 3: r = 180; g = 0; b = 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
|
if (!estActuellementArme()) { // Désarmé : couleur du rapport très atténuée
|
||||||
r /= 10; g /= 10; b /= 10;
|
r /= 10; g /= 10; b /= 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -659,14 +831,26 @@ bool evaluerFailsafe() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Déconnexion matérielle du volant G29 (câble USB arraché ou hors tension)
|
// 2. Surveillance de la source active (Steam Controller externe ou Volant G29)
|
||||||
if (!volant_est_pret) {
|
if (sourceActive == SRC_EXT) {
|
||||||
if (!failsafeActif) {
|
if (!extRcActif || (now - dernierPaquetRC_ms > TIMEOUT_RC_EXT_MS)) {
|
||||||
failsafeActif = true;
|
if (!failsafeActif) {
|
||||||
majLedRequise = true;
|
failsafeActif = true;
|
||||||
Serial.println(F("!! [FAILSAFE] Volant G29 non detecte ou debranche !!"));
|
majLedRequise = true;
|
||||||
|
Serial.println(F("!! [FAILSAFE] Steam Controller inactif ou deconnecte !!"));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Déconnexion matérielle du volant G29 (câble USB arraché ou hors tension)
|
||||||
|
if (!volant_est_pret) {
|
||||||
|
if (!failsafeActif) {
|
||||||
|
failsafeActif = true;
|
||||||
|
majLedRequise = true;
|
||||||
|
Serial.println(F("!! [FAILSAFE] Volant G29 non detecte ou debranche !!"));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Volant branché et Cœur 1 fonctionnel : liaison valide (pas de faux failsafe quand le volant est immobile)
|
// Volant branché et Cœur 1 fonctionnel : liaison valide (pas de faux failsafe quand le volant est immobile)
|
||||||
@@ -727,7 +911,7 @@ void traiterTelemetrieCRSF() {
|
|||||||
dernierPaquetTelemetrie_ms = millis();
|
dernierPaquetTelemetrie_ms = millis();
|
||||||
uint8_t frameType = crsfRxBuffer[2];
|
uint8_t frameType = crsfRxBuffer[2];
|
||||||
|
|
||||||
if (!estArme) {
|
if (!estArme || sourceActive != SRC_G29) {
|
||||||
rugositeTerrainExterne = 0;
|
rugositeTerrainExterne = 0;
|
||||||
attitudeInitialisee = false;
|
attitudeInitialisee = false;
|
||||||
} else if (frameType == 0x1E && paquetLongueurAttendue >= 8) {
|
} else if (frameType == 0x1E && paquetLongueurAttendue >= 8) {
|
||||||
@@ -789,7 +973,7 @@ void traiterTelemetrieCRSF() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!estArme) {
|
if (!estArme || sourceActive != SRC_G29) {
|
||||||
rugositeTerrainExterne = 0;
|
rugositeTerrainExterne = 0;
|
||||||
attitudeInitialisee = false;
|
attitudeInitialisee = false;
|
||||||
return;
|
return;
|
||||||
@@ -853,18 +1037,43 @@ void gererSortieCockpit() {
|
|||||||
bool modif = __atomic_exchange_n(&cockpitEtatModifie, false, __ATOMIC_ACQ_REL);
|
bool modif = __atomic_exchange_n(&cockpitEtatModifie, false, __ATOMIC_ACQ_REL);
|
||||||
if (modif || (now - dernierEnvoiCockpit_ms >= INTERVALLE_COCKPIT_MS)) {
|
if (modif || (now - dernierEnvoiCockpit_ms >= INTERVALLE_COCKPIT_MS)) {
|
||||||
dernierEnvoiCockpit_ms = now;
|
dernierEnvoiCockpit_ms = now;
|
||||||
int throt = (int)constrain(dernierAccelPct + 0.5f, 0.0f, 100.0f);
|
bool armeOut = estActuellementArme();
|
||||||
int brake = (int)constrain(dernierFreinPct + 0.5f, 0.0f, 100.0f);
|
int8_t rapportOut = rapportActuel();
|
||||||
char bufEtat[96];
|
int throt = (sourceActive == SRC_EXT)
|
||||||
|
? (int)extAccelPct
|
||||||
|
: (int)constrain(dernierAccelPct + 0.5f, 0.0f, 100.0f);
|
||||||
|
int brake = (sourceActive == SRC_EXT)
|
||||||
|
? (int)extFreinPct
|
||||||
|
: (int)constrain(dernierFreinPct + 0.5f, 0.0f, 100.0f);
|
||||||
|
int clutch = (sourceActive == SRC_EXT)
|
||||||
|
? (int)extEmbrayagePct
|
||||||
|
: (int)constrain(dernierEmbrayagePct + 0.5f, 0.0f, 100.0f);
|
||||||
|
int32_t dMax = (maxDeltaVolant > 0) ? maxDeltaVolant : DELTA_MAX_VOLANT_BRUT;
|
||||||
|
int steer = (sourceActive == SRC_EXT)
|
||||||
|
? (int)extVolantPct
|
||||||
|
: (int)constrain(((float)dernierVolantCentre / (float)dMax) * 100.0f, -100.0f, 100.0f);
|
||||||
|
uint16_t ch1 = failsafeActif ? CRSF_VAL_MID : crsf_channels[configSysteme.volant - 1];
|
||||||
|
uint16_t ch2 = failsafeActif ? CRSF_VAL_MID : crsf_channels[configSysteme.accel - 1];
|
||||||
|
uint16_t ch3 = failsafeActif ? CRSF_VAL_MID : crsf_channels[configSysteme.frein - 1];
|
||||||
|
uint16_t ch4 = failsafeActif ? CRSF_VAL_MID : crsf_channels[configSysteme.embrayage - 1];
|
||||||
|
const char* srcStr = (sourceActive == SRC_EXT) ? "EXT" : "G29";
|
||||||
|
char bufEtat[176];
|
||||||
snprintf(bufEtat, sizeof(bufEtat),
|
snprintf(bufEtat, sizeof(bufEtat),
|
||||||
"$G29,ARM=%d,GEAR=%d,THROT=%d,BRAKE=%d,FFB=%d,VIB=%d,FAIL=%d",
|
"$G29,ARM=%d,GEAR=%d,THROT=%d,BRAKE=%d,CLUTCH=%d,STEER=%d,CH1=%u,CH2=%u,CH3=%u,CH4=%u,FFB=%d,VIB=%d,FAIL=%d,SRC=%s",
|
||||||
estArme ? 1 : 0,
|
armeOut ? 1 : 0,
|
||||||
(int)rapportEngage,
|
(int)rapportOut,
|
||||||
throt,
|
throt,
|
||||||
brake,
|
brake,
|
||||||
|
clutch,
|
||||||
|
steer,
|
||||||
|
(unsigned int)ch1,
|
||||||
|
(unsigned int)ch2,
|
||||||
|
(unsigned int)ch3,
|
||||||
|
(unsigned int)ch4,
|
||||||
(int)configSysteme.forceRessort,
|
(int)configSysteme.forceRessort,
|
||||||
(int)configSysteme.intensiteVibration,
|
(int)configSysteme.intensiteVibration,
|
||||||
failsafeActif ? 1 : 0);
|
failsafeActif ? 1 : 0,
|
||||||
|
srcStr);
|
||||||
emettreLigneCockpit(bufEtat);
|
emettreLigneCockpit(bufEtat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -878,6 +1087,21 @@ void gererTimeoutHeadTracking() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gererTimeoutRcExterne() {
|
||||||
|
if (sourceActive == SRC_EXT && extRcActif && (millis() - dernierPaquetRC_ms > TIMEOUT_RC_EXT_MS)) {
|
||||||
|
extRcActif = false;
|
||||||
|
extArme = false;
|
||||||
|
extAccelPct = 0;
|
||||||
|
extFreinPct = 0;
|
||||||
|
extEmbrayagePct = 0;
|
||||||
|
extVolantPct = 0;
|
||||||
|
reinitialiserCanauxCRSF();
|
||||||
|
majLedRequise = true;
|
||||||
|
cockpitEtatModifie = true;
|
||||||
|
Serial.println(F("!! [FAILSAFE] Perte de liaison Steam Controller ($RC timeout) !!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// Watchdog dual-core : ne réarmer le watchdog matériel que si le Cœur 1 est également vivant
|
// Watchdog dual-core : ne réarmer le watchdog matériel que si le Cœur 1 est également vivant
|
||||||
if (heartbeatCore1_ms == 0 || (millis() - heartbeatCore1_ms <= TIMEOUT_FAILSAFE_MS)) {
|
if (heartbeatCore1_ms == 0 || (millis() - heartbeatCore1_ms <= TIMEOUT_FAILSAFE_MS)) {
|
||||||
@@ -885,6 +1109,7 @@ void loop() {
|
|||||||
}
|
}
|
||||||
verifierCommandesSerie();
|
verifierCommandesSerie();
|
||||||
gererTimeoutHeadTracking();
|
gererTimeoutHeadTracking();
|
||||||
|
gererTimeoutRcExterne();
|
||||||
traiterTelemetrieCRSF();
|
traiterTelemetrieCRSF();
|
||||||
gererSortieCockpit();
|
gererSortieCockpit();
|
||||||
|
|
||||||
@@ -897,9 +1122,10 @@ void loop() {
|
|||||||
majLedRequise = false;
|
majLedRequise = false;
|
||||||
dernierTickAnimNeo_ms = millis();
|
dernierTickAnimNeo_ms = millis();
|
||||||
actualiserLED();
|
actualiserLED();
|
||||||
if (rapportEngage != dernierRapportLog) {
|
int8_t rap = rapportActuel();
|
||||||
dernierRapportLog = rapportEngage;
|
if (rap != dernierRapportLog) {
|
||||||
Serial.printf("[BOITE] Rapport engage : %d\n", rapportEngage);
|
dernierRapportLog = rap;
|
||||||
|
Serial.printf("[BOITE] Rapport engage : %d (%s)\n", rap, (sourceActive == SRC_EXT) ? "EXT" : "G29");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -940,7 +1166,7 @@ void loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sauvegarde différée suite à une commande série (D= / T=) passée pendant la conduite
|
// Sauvegarde différée suite à une commande série (D= / T=) passée pendant la conduite
|
||||||
if (!estArme && sauvegardeDifferee) {
|
if (!estActuellementArme() && sauvegardeDifferee) {
|
||||||
sauvegardeDifferee = false;
|
sauvegardeDifferee = false;
|
||||||
sauvegarderConfiguration();
|
sauvegarderConfiguration();
|
||||||
}
|
}
|
||||||
@@ -949,7 +1175,7 @@ void loop() {
|
|||||||
// (interdite en conduite armée pour éviter un gel Flash)
|
// (interdite en conduite armée pour éviter un gel Flash)
|
||||||
if (demandeSauvegardeEEPROM) {
|
if (demandeSauvegardeEEPROM) {
|
||||||
demandeSauvegardeEEPROM = false;
|
demandeSauvegardeEEPROM = false;
|
||||||
if (estArme) {
|
if (estActuellementArme()) {
|
||||||
Serial.println(F("!! Sauvegarde Flash refusee pendant la conduite (desarmer d'abord) !!"));
|
Serial.println(F("!! Sauvegarde Flash refusee pendant la conduite (desarmer d'abord) !!"));
|
||||||
} else {
|
} else {
|
||||||
momentDernierChangementDurete_ms = 0;
|
momentDernierChangementDurete_ms = 0;
|
||||||
@@ -966,10 +1192,11 @@ void loop() {
|
|||||||
uint32_t compteOK = compteurRapportsOK;
|
uint32_t compteOK = compteurRapportsOK;
|
||||||
uint32_t rapportsParSec = ((compteOK - dernierCompteOK) * 1000UL) / (dt ? dt : 1);
|
uint32_t rapportsParSec = ((compteOK - dernierCompteOK) * 1000UL) / (dt ? dt : 1);
|
||||||
dernierCompteOK = compteOK;
|
dernierCompteOK = compteOK;
|
||||||
Serial.printf("[ETAT] G29_Pret=%d (PID=%04X) | InitFFB=%d/%d | Durete=%d/255 | Vib=%d%% | Rugosite=%d | Plage=%d deg | Rapport=%d | Arme=%d | Statut_LED=%d | USB=%lu rap/s | Rejetes=%lu (L=%d,ID=%02X) | Failsafe=%d\n",
|
Serial.printf("[ETAT] SRC=%s | G29_Pret=%d (PID=%04X) | ExtRC=%d | InitFFB=%d/%d | Durete=%d/255 | Vib=%d%% | Rugosite=%d | Plage=%d deg | Rapport=%d | Arme=%d | Statut_LED=%d | USB=%lu rap/s | Rejetes=%lu (L=%d,ID=%02X) | Failsafe=%d\n",
|
||||||
volant_est_pret, g29_pid, etapeInitMoteur, ETAPES_INIT_FFB_TOTAL, configSysteme.forceRessort,
|
(sourceActive == SRC_EXT) ? "EXT" : "G29",
|
||||||
|
volant_est_pret, g29_pid, extRcActif, etapeInitMoteur, ETAPES_INIT_FFB_TOTAL, configSysteme.forceRessort,
|
||||||
configSysteme.intensiteVibration, rugositeTerrainExterne, configSysteme.angleSouhaiteTotal,
|
configSysteme.intensiteVibration, rugositeTerrainExterne, configSysteme.angleSouhaiteTotal,
|
||||||
rapportEngage, estArme, statutEnvoiLed,
|
rapportActuel(), estActuellementArme(), statutEnvoiLed,
|
||||||
(unsigned long)rapportsParSec, (unsigned long)compteurRapportsRejetes,
|
(unsigned long)rapportsParSec, (unsigned long)compteurRapportsRejetes,
|
||||||
dernierRejetLen, dernierRejetId, failsafeActif);
|
dernierRejetLen, dernierRejetId, failsafeActif);
|
||||||
}
|
}
|
||||||
@@ -1187,7 +1414,7 @@ void gererVibrationHaptique() {
|
|||||||
|
|
||||||
// 2. Gestion des vibrations haptiques et retours mécaniques
|
// 2. Gestion des vibrations haptiques et retours mécaniques
|
||||||
uint8_t intensite = configSysteme.intensiteVibration;
|
uint8_t intensite = configSysteme.intensiteVibration;
|
||||||
if (!estArme || intensite == 0) {
|
if (sourceActive != SRC_G29 || !estArme || intensite == 0) {
|
||||||
dernierCalculPhase_us = 0;
|
dernierCalculPhase_us = 0;
|
||||||
directionDernierChocRapport = 0;
|
directionDernierChocRapport = 0;
|
||||||
if (!forceEstAuNeutre) {
|
if (!forceEstAuNeutre) {
|
||||||
@@ -1294,6 +1521,13 @@ void loop1() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 1b. Confirmation tardive à 10 s (si le calibrage mécanique du G29 a dépassé 6 s)
|
||||||
|
if (!reinitPlageTardiveFaite && !estArme && (millis() - momentConnexionUSB_ms >= 10000)) {
|
||||||
|
reinitPlageTardiveFaite = true;
|
||||||
|
majRangeRequise = true;
|
||||||
|
majRessortRequise = true;
|
||||||
|
}
|
||||||
|
|
||||||
// 2. Mise à jour continue de l'état de la butée active (avant LEDs et FFB)
|
// 2. Mise à jour continue de l'état de la butée active (avant LEDs et FFB)
|
||||||
actualiserEtatButee();
|
actualiserEtatButee();
|
||||||
|
|
||||||
@@ -1321,8 +1555,8 @@ void loop1() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Arrêt prioritaire du moteur de vibration dès le désarmement (avant l'animation LED)
|
// Arrêt prioritaire du moteur de vibration dès le désarmement (ou si source externe active)
|
||||||
if (!estArme && !forceEstAuNeutre) {
|
if ((sourceActive != SRC_G29 || !estArme) && !forceEstAuNeutre) {
|
||||||
if (arreterForceG29()) {
|
if (arreterForceG29()) {
|
||||||
forceEstAuNeutre = true;
|
forceEstAuNeutre = true;
|
||||||
return;
|
return;
|
||||||
@@ -1347,6 +1581,7 @@ void reinitialiserEtatVolant() {
|
|||||||
dernierMasqueLedG29 = 0xFF;
|
dernierMasqueLedG29 = 0xFF;
|
||||||
etapeEnvoiLed = 0;
|
etapeEnvoiLed = 0;
|
||||||
etapeInitMoteur = 0;
|
etapeInitMoteur = 0;
|
||||||
|
reinitPlageTardiveFaite = false;
|
||||||
statutEnvoiLed = 0;
|
statutEnvoiLed = 0;
|
||||||
rapportEngage = 0;
|
rapportEngage = 0;
|
||||||
estArme = false;
|
estArme = false;
|
||||||
@@ -1357,15 +1592,10 @@ void reinitialiserEtatVolant() {
|
|||||||
dernierVolantCentre = 0;
|
dernierVolantCentre = 0;
|
||||||
dernierAccelPct = 0.0f;
|
dernierAccelPct = 0.0f;
|
||||||
dernierFreinPct = 0.0f;
|
dernierFreinPct = 0.0f;
|
||||||
|
dernierEmbrayagePct = 0.0f;
|
||||||
rugositeTerrainExterne = 0;
|
rugositeTerrainExterne = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void assignerCanalCRSF(uint8_t numeroCh, uint16_t valeur11bits) {
|
|
||||||
if (numeroCh >= 1 && numeroCh <= 16 && numeroCh != CANAL_ARM) {
|
|
||||||
crsf_channels[numeroCh - 1] = valeur11bits;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
// CALLBACKS HID USB HOST (Exécutés sur Core 1)
|
// CALLBACKS HID USB HOST (Exécutés sur Core 1)
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
@@ -1417,7 +1647,9 @@ void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance) {
|
|||||||
g29_vid = 0;
|
g29_vid = 0;
|
||||||
g29_pid = 0;
|
g29_pid = 0;
|
||||||
reinitialiserEtatVolant();
|
reinitialiserEtatVolant();
|
||||||
reinitialiserCanauxCRSF();
|
if (sourceActive == SRC_G29) {
|
||||||
|
reinitialiserCanauxCRSF();
|
||||||
|
}
|
||||||
majLedRequise = true;
|
majLedRequise = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1437,14 +1669,23 @@ void __not_in_flash_func(tuh_hid_report_received_cb)(uint8_t dev_addr, uint8_t i
|
|||||||
{
|
{
|
||||||
compteurRapportsOK++;
|
compteurRapportsOK++;
|
||||||
|
|
||||||
|
// Si la source active est la manette externe (Steam Controller), on maintient la liaison USB
|
||||||
|
// mais on ignore les axes/boutons G29 pour éviter toute interférence.
|
||||||
|
if (sourceActive != SRC_G29) {
|
||||||
|
dernierRapportUSB_ms = millis();
|
||||||
|
tuh_hid_receive_report(dev_addr, instance);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
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]);
|
||||||
uint16_t freinRaw = 65535 - ((report[48] << 8) | report[47]);
|
uint16_t freinRaw = 65535 - ((report[48] << 8) | report[47]);
|
||||||
uint16_t embrayageRaw = 65535 - ((report[50] << 8) | report[49]);
|
uint16_t embrayageRaw = 65535 - ((report[50] << 8) | report[49]);
|
||||||
|
|
||||||
// Pourcentages des pédales pour la synthèse haptique (0.0 à 100.0%)
|
// Pourcentages des pédales pour la synthèse haptique et le moniteur cockpit (0.0 à 100.0%)
|
||||||
dernierAccelPct = (accelRaw > DEADZONE_PEDALE) ? (((float)(accelRaw - DEADZONE_PEDALE) / (float)(65535 - DEADZONE_PEDALE)) * 100.0f) : 0.0f;
|
dernierAccelPct = (accelRaw > DEADZONE_PEDALE) ? (((float)(accelRaw - DEADZONE_PEDALE) / (float)(65535 - DEADZONE_PEDALE)) * 100.0f) : 0.0f;
|
||||||
dernierFreinPct = (freinRaw > DEADZONE_PEDALE) ? (((float)(freinRaw - DEADZONE_PEDALE) / (float)(65535 - DEADZONE_PEDALE)) * 100.0f) : 0.0f;
|
dernierFreinPct = (freinRaw > DEADZONE_PEDALE) ? (((float)(freinRaw - DEADZONE_PEDALE) / (float)(65535 - DEADZONE_PEDALE)) * 100.0f) : 0.0f;
|
||||||
|
dernierEmbrayagePct = (embrayageRaw > DEADZONE_PEDALE) ? (((float)(embrayageRaw - DEADZONE_PEDALE) / (float)(65535 - DEADZONE_PEDALE)) * 100.0f) : 0.0f;
|
||||||
|
|
||||||
uint8_t boutonsEpaule = report[6];
|
uint8_t boutonsEpaule = report[6];
|
||||||
bool pPlusActuel = (boutonsEpaule & PALETTE_PLUS_MASK);
|
bool pPlusActuel = (boutonsEpaule & PALETTE_PLUS_MASK);
|
||||||
|
|||||||
Regular → Executable
+29
-6
@@ -26,13 +26,36 @@ if ! ip link show "${USB_IFACE}" >/dev/null 2>&1; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "[3/4] Attribution de l'adresse IP ${HOST_USB_IP} sur ${USB_IFACE}..."
|
echo "[3/4] Attribution persistante de l'adresse IP ${HOST_USB_IP} sur ${USB_IFACE}..."
|
||||||
sudo ip link set dev "${USB_IFACE}" up
|
if command -v nmcli >/dev/null 2>&1 && nmcli -t -f RUNNING general 2>/dev/null | grep -qi "running"; then
|
||||||
sudo ip addr flush dev "${USB_IFACE}"
|
# Profil NetworkManager statique (évite que le timeout DHCP 45s ne coupe la Radxa)
|
||||||
sudo ip addr add "${HOST_USB_IP}" dev "${USB_IFACE}"
|
# match.driver couvre les MAC aléatoires générées par la Radxa à chaque redémarrage.
|
||||||
|
nmcli connection delete "Radxa-VRX" >/dev/null 2>&1 || true
|
||||||
|
nmcli connection add type ethernet con-name "Radxa-VRX" \
|
||||||
|
match.driver "cdc_ether,rndis_host" \
|
||||||
|
ipv4.method manual \
|
||||||
|
ipv4.addresses "${HOST_USB_IP}" \
|
||||||
|
ipv4.never-default yes \
|
||||||
|
ipv6.method disabled \
|
||||||
|
connection.autoconnect yes \
|
||||||
|
connection.autoconnect-priority 100 >/dev/null
|
||||||
|
nmcli connection up "Radxa-VRX" ifname "${USB_IFACE}" >/dev/null 2>&1 \
|
||||||
|
|| nmcli device connect "${USB_IFACE}" >/dev/null
|
||||||
|
echo " -> Profil NetworkManager 'Radxa-VRX' activé sur ${USB_IFACE} (${HOST_USB_IP}, sans DHCP)."
|
||||||
|
else
|
||||||
|
sudo ip link set dev "${USB_IFACE}" up
|
||||||
|
sudo ip addr flush dev "${USB_IFACE}"
|
||||||
|
sudo ip addr add "${HOST_USB_IP}" dev "${USB_IFACE}"
|
||||||
|
fi
|
||||||
|
|
||||||
sudo sysctl -w net.core.rmem_max=8388608 >/dev/null
|
# Augmentation des tampons UDP si sudo non-interactif ou root disponible
|
||||||
sudo sysctl -w net.core.rmem_default=4194304 >/dev/null
|
if [ "$(id -u)" -eq 0 ]; then
|
||||||
|
sysctl -w net.core.rmem_max=8388608 >/dev/null 2>&1 || true
|
||||||
|
sysctl -w net.core.rmem_default=4194304 >/dev/null 2>&1 || true
|
||||||
|
elif sudo -n true 2>/dev/null; then
|
||||||
|
sudo -n sysctl -w net.core.rmem_max=8388608 >/dev/null 2>&1 || true
|
||||||
|
sudo -n sysctl -w net.core.rmem_default=4194304 >/dev/null 2>&1 || true
|
||||||
|
fi
|
||||||
|
|
||||||
echo "[4/4] Test de communication avec la Radxa Zero 3W (192.168.1.1)..."
|
echo "[4/4] Test de communication avec la Radxa Zero 3W (192.168.1.1)..."
|
||||||
if ping -c 1 -W 1 192.168.1.1 >/dev/null 2>&1; then
|
if ping -c 1 -W 1 192.168.1.1 >/dev/null 2>&1; then
|
||||||
|
|||||||
@@ -48,6 +48,26 @@ pub struct AppConfig {
|
|||||||
#[arg(long, default_value_t = 14552)]
|
#[arg(long, default_value_t = 14552)]
|
||||||
pub g29_udp_port: u16,
|
pub g29_udp_port: u16,
|
||||||
|
|
||||||
|
/// Source active de pilotage : "g29" (Volant Logitech G29) ou "steam" (Steam Controller via PC/Steam Frame)
|
||||||
|
#[arg(long, default_value = "g29")]
|
||||||
|
pub control_source: String,
|
||||||
|
|
||||||
|
/// Périphérique evdev explicite pour le Steam Controller (vide = détection automatique)
|
||||||
|
#[arg(long, default_value = "")]
|
||||||
|
pub controller_device: String,
|
||||||
|
|
||||||
|
/// Expo de direction du Steam Controller (0.0 = linéaire, 0.25 = doux au centre, max 0.8)
|
||||||
|
#[arg(long, default_value_t = 0.25)]
|
||||||
|
pub controller_expo: f32,
|
||||||
|
|
||||||
|
/// Zone morte du stick gauche du Steam Controller (0.0..0.45)
|
||||||
|
#[arg(long, default_value_t = 0.08)]
|
||||||
|
pub controller_deadzone: f32,
|
||||||
|
|
||||||
|
/// Inverser le sens de direction du Steam Controller
|
||||||
|
#[arg(long, default_value_t = false)]
|
||||||
|
pub controller_invert_steering: bool,
|
||||||
|
|
||||||
/// Codec vidéo reçu depuis le VRX OpenIPC / Ruby ("h264" ou "h265")
|
/// Codec vidéo reçu depuis le VRX OpenIPC / Ruby ("h264" ou "h265")
|
||||||
#[arg(long, default_value = "h264")]
|
#[arg(long, default_value = "h264")]
|
||||||
pub codec: String,
|
pub codec: String,
|
||||||
|
|||||||
+1528
File diff suppressed because it is too large.
Load diff
+160
-3
@@ -1,4 +1,7 @@
|
|||||||
use crate::config::AppConfig;
|
use crate::config::AppConfig;
|
||||||
|
use crate::controller::{
|
||||||
|
ControlSource, SteamControllerConfig, SteamControllerState, SteamControllerWorker,
|
||||||
|
};
|
||||||
use crate::dome_projection::{DomeWarpLut, ProjectionMode};
|
use crate::dome_projection::{DomeWarpLut, ProjectionMode};
|
||||||
use crate::dvr::{DvrContainer, DvrMode, DvrRecorder};
|
use crate::dvr::{DvrContainer, DvrMode, DvrRecorder};
|
||||||
use crate::g29_bridge::{G29BridgeReceiver, G29State};
|
use crate::g29_bridge::{G29BridgeReceiver, G29State};
|
||||||
@@ -10,7 +13,7 @@ use anyhow::{Context, Result};
|
|||||||
use glam::{EulerRot, Quat};
|
use glam::{EulerRot, Quat};
|
||||||
use openxr as xr;
|
use openxr as xr;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, AtomicU8, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::thread::{self, JoinHandle};
|
use std::thread::{self, JoinHandle};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
@@ -48,6 +51,8 @@ pub struct RuntimeMonitor {
|
|||||||
pub nomad_wifi_status: SubsystemStatus,
|
pub nomad_wifi_status: SubsystemStatus,
|
||||||
pub telemetry_status: SubsystemStatus,
|
pub telemetry_status: SubsystemStatus,
|
||||||
pub g29_status: SubsystemStatus,
|
pub g29_status: SubsystemStatus,
|
||||||
|
pub controller_status: SubsystemStatus,
|
||||||
|
pub active_control_source: ControlSource,
|
||||||
pub dvr_status: SubsystemStatus,
|
pub dvr_status: SubsystemStatus,
|
||||||
pub dvr_recording: bool,
|
pub dvr_recording: bool,
|
||||||
pub dvr_elapsed_secs: u64,
|
pub dvr_elapsed_secs: u64,
|
||||||
@@ -60,6 +65,7 @@ pub struct RuntimeMonitor {
|
|||||||
pub latest_head_pose: HeadPoseSample,
|
pub latest_head_pose: HeadPoseSample,
|
||||||
pub latest_telemetry: TelemetryState,
|
pub latest_telemetry: TelemetryState,
|
||||||
pub latest_g29: G29State,
|
pub latest_g29: G29State,
|
||||||
|
pub latest_controller: SteamControllerState,
|
||||||
pub preview_rgba: Vec<u8>,
|
pub preview_rgba: Vec<u8>,
|
||||||
pub preview_width: u32,
|
pub preview_width: u32,
|
||||||
pub preview_height: u32,
|
pub preview_height: u32,
|
||||||
@@ -77,6 +83,8 @@ impl Default for RuntimeMonitor {
|
|||||||
nomad_wifi_status: SubsystemStatus::Stopped,
|
nomad_wifi_status: SubsystemStatus::Stopped,
|
||||||
telemetry_status: SubsystemStatus::Disabled,
|
telemetry_status: SubsystemStatus::Disabled,
|
||||||
g29_status: SubsystemStatus::Disabled,
|
g29_status: SubsystemStatus::Disabled,
|
||||||
|
controller_status: SubsystemStatus::Disabled,
|
||||||
|
active_control_source: ControlSource::G29,
|
||||||
dvr_status: SubsystemStatus::Stopped,
|
dvr_status: SubsystemStatus::Stopped,
|
||||||
dvr_recording: false,
|
dvr_recording: false,
|
||||||
dvr_elapsed_secs: 0,
|
dvr_elapsed_secs: 0,
|
||||||
@@ -89,6 +97,7 @@ impl Default for RuntimeMonitor {
|
|||||||
latest_head_pose: HeadPoseSample::default(),
|
latest_head_pose: HeadPoseSample::default(),
|
||||||
latest_telemetry: TelemetryState::default(),
|
latest_telemetry: TelemetryState::default(),
|
||||||
latest_g29: G29State::default(),
|
latest_g29: G29State::default(),
|
||||||
|
latest_controller: SteamControllerState::default(),
|
||||||
preview_rgba: Vec::new(),
|
preview_rgba: Vec::new(),
|
||||||
preview_width: 0,
|
preview_width: 0,
|
||||||
preview_height: 0,
|
preview_height: 0,
|
||||||
@@ -108,6 +117,8 @@ pub struct EngineControlHandle {
|
|||||||
recenter_flag: Arc<AtomicBool>,
|
recenter_flag: Arc<AtomicBool>,
|
||||||
telemetry_enabled_flag: Arc<AtomicBool>,
|
telemetry_enabled_flag: Arc<AtomicBool>,
|
||||||
head_tracking_enabled_flag: Arc<AtomicBool>,
|
head_tracking_enabled_flag: Arc<AtomicBool>,
|
||||||
|
control_source_flag: Arc<AtomicU8>,
|
||||||
|
monitor_ref: Arc<Mutex<RuntimeMonitor>>,
|
||||||
optical_params: Arc<Mutex<LiveOpticalParams>>,
|
optical_params: Arc<Mutex<LiveOpticalParams>>,
|
||||||
dvr_toggle_cmd: Arc<Mutex<Option<bool>>>,
|
dvr_toggle_cmd: Arc<Mutex<Option<bool>>>,
|
||||||
dvr_config: Arc<Mutex<DvrConfig>>,
|
dvr_config: Arc<Mutex<DvrConfig>>,
|
||||||
@@ -191,6 +202,42 @@ impl EngineControlHandle {
|
|||||||
*self.dvr_toggle_cmd.lock() = Some(next);
|
*self.dvr_toggle_cmd.lock() = Some(next);
|
||||||
next
|
next
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn active_control_source(&self) -> ControlSource {
|
||||||
|
ControlSource::from_u8(self.control_source_flag.load(Ordering::Acquire))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Bascule la source de conduite (Volant G29 <-> Steam Controller).
|
||||||
|
/// Refusé par sécurité tant que le véhicule est armé.
|
||||||
|
pub fn set_control_source(&self, target: ControlSource) -> Result<(), String> {
|
||||||
|
let current = self.active_control_source();
|
||||||
|
if current == target {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let mon = self.monitor_ref.lock();
|
||||||
|
let armed_now = match current {
|
||||||
|
ControlSource::G29 => mon.latest_g29.is_live() && mon.latest_g29.armed,
|
||||||
|
ControlSource::SteamController => mon.latest_controller.armed,
|
||||||
|
};
|
||||||
|
if armed_now {
|
||||||
|
let msg = format!(
|
||||||
|
"Bascule vers {} refusée : désarmez d'abord le véhicule !",
|
||||||
|
target.label()
|
||||||
|
);
|
||||||
|
log::warn!("[Contrôleur] {}", msg);
|
||||||
|
return Err(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.control_source_flag
|
||||||
|
.store(target.as_u8(), Ordering::Release);
|
||||||
|
self.monitor_ref.lock().active_control_source = target;
|
||||||
|
log::info!(
|
||||||
|
"[Action Utilisateur] Source de conduite basculée sur : {}",
|
||||||
|
target.label()
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FpvEngineController {
|
pub struct FpvEngineController {
|
||||||
@@ -204,6 +251,7 @@ pub struct FpvEngineController {
|
|||||||
recenter_flag: Arc<AtomicBool>,
|
recenter_flag: Arc<AtomicBool>,
|
||||||
telemetry_enabled_flag: Arc<AtomicBool>,
|
telemetry_enabled_flag: Arc<AtomicBool>,
|
||||||
head_tracking_enabled_flag: Arc<AtomicBool>,
|
head_tracking_enabled_flag: Arc<AtomicBool>,
|
||||||
|
control_source_flag: Arc<AtomicU8>,
|
||||||
worker_handle: Option<JoinHandle<()>>,
|
worker_handle: Option<JoinHandle<()>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,6 +282,7 @@ impl FpvEngineController {
|
|||||||
recenter_flag: Arc::new(AtomicBool::new(false)),
|
recenter_flag: Arc::new(AtomicBool::new(false)),
|
||||||
telemetry_enabled_flag: Arc::new(AtomicBool::new(initial_telemetry_enabled)),
|
telemetry_enabled_flag: Arc::new(AtomicBool::new(initial_telemetry_enabled)),
|
||||||
head_tracking_enabled_flag: Arc::new(AtomicBool::new(initial_head_tracking_enabled)),
|
head_tracking_enabled_flag: Arc::new(AtomicBool::new(initial_head_tracking_enabled)),
|
||||||
|
control_source_flag: Arc::new(AtomicU8::new(ControlSource::G29.as_u8())),
|
||||||
worker_handle: None,
|
worker_handle: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -243,6 +292,8 @@ impl FpvEngineController {
|
|||||||
recenter_flag: Arc::clone(&self.recenter_flag),
|
recenter_flag: Arc::clone(&self.recenter_flag),
|
||||||
telemetry_enabled_flag: Arc::clone(&self.telemetry_enabled_flag),
|
telemetry_enabled_flag: Arc::clone(&self.telemetry_enabled_flag),
|
||||||
head_tracking_enabled_flag: Arc::clone(&self.head_tracking_enabled_flag),
|
head_tracking_enabled_flag: Arc::clone(&self.head_tracking_enabled_flag),
|
||||||
|
control_source_flag: Arc::clone(&self.control_source_flag),
|
||||||
|
monitor_ref: Arc::clone(&self.monitor),
|
||||||
optical_params: Arc::clone(&self.optical_params),
|
optical_params: Arc::clone(&self.optical_params),
|
||||||
dvr_toggle_cmd: Arc::clone(&self.dvr_toggle_cmd),
|
dvr_toggle_cmd: Arc::clone(&self.dvr_toggle_cmd),
|
||||||
dvr_config: Arc::clone(&self.dvr_config),
|
dvr_config: Arc::clone(&self.dvr_config),
|
||||||
@@ -300,6 +351,9 @@ impl FpvEngineController {
|
|||||||
.store(cfg.telemetry_enabled, Ordering::Relaxed);
|
.store(cfg.telemetry_enabled, Ordering::Relaxed);
|
||||||
self.head_tracking_enabled_flag
|
self.head_tracking_enabled_flag
|
||||||
.store(cfg.head_tracking_enabled, Ordering::Relaxed);
|
.store(cfg.head_tracking_enabled, Ordering::Relaxed);
|
||||||
|
let initial_src = ControlSource::from_str(&cfg.control_source);
|
||||||
|
self.control_source_flag
|
||||||
|
.store(initial_src.as_u8(), Ordering::Relaxed);
|
||||||
|
|
||||||
*self.optical_params.lock() = LiveOpticalParams {
|
*self.optical_params.lock() = LiveOpticalParams {
|
||||||
camera_fov_deg: cfg.camera_fov_deg,
|
camera_fov_deg: cfg.camera_fov_deg,
|
||||||
@@ -338,9 +392,12 @@ impl FpvEngineController {
|
|||||||
} else {
|
} else {
|
||||||
SubsystemStatus::Disabled
|
SubsystemStatus::Disabled
|
||||||
};
|
};
|
||||||
|
mon.active_control_source = initial_src;
|
||||||
|
mon.controller_status = SubsystemStatus::Starting;
|
||||||
}
|
}
|
||||||
|
|
||||||
let control_for_g29 = self.control_handle();
|
let control_for_g29 = self.control_handle();
|
||||||
|
let control_for_ctrl = self.control_handle();
|
||||||
let monitor_clone = Arc::clone(&self.monitor);
|
let monitor_clone = Arc::clone(&self.monitor);
|
||||||
let optical_clone = Arc::clone(&self.optical_params);
|
let optical_clone = Arc::clone(&self.optical_params);
|
||||||
let dvr_cmd_clone = Arc::clone(&self.dvr_toggle_cmd);
|
let dvr_cmd_clone = Arc::clone(&self.dvr_toggle_cmd);
|
||||||
@@ -351,6 +408,7 @@ impl FpvEngineController {
|
|||||||
let recenter_clone = Arc::clone(&self.recenter_flag);
|
let recenter_clone = Arc::clone(&self.recenter_flag);
|
||||||
let telem_flag_clone = Arc::clone(&self.telemetry_enabled_flag);
|
let telem_flag_clone = Arc::clone(&self.telemetry_enabled_flag);
|
||||||
let ht_flag_clone = Arc::clone(&self.head_tracking_enabled_flag);
|
let ht_flag_clone = Arc::clone(&self.head_tracking_enabled_flag);
|
||||||
|
let control_source_clone = Arc::clone(&self.control_source_flag);
|
||||||
|
|
||||||
let handle = thread::Builder::new()
|
let handle = thread::Builder::new()
|
||||||
.name("fpv-engine-worker".into())
|
.name("fpv-engine-worker".into())
|
||||||
@@ -364,10 +422,12 @@ impl FpvEngineController {
|
|||||||
dvr_rec_flag_clone,
|
dvr_rec_flag_clone,
|
||||||
head_trim_clone,
|
head_trim_clone,
|
||||||
control_for_g29,
|
control_for_g29,
|
||||||
|
control_for_ctrl,
|
||||||
stop_clone,
|
stop_clone,
|
||||||
recenter_clone,
|
recenter_clone,
|
||||||
telem_flag_clone,
|
telem_flag_clone,
|
||||||
ht_flag_clone,
|
ht_flag_clone,
|
||||||
|
control_source_clone,
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.expect("Impossible de créer le thread fpv-engine-worker");
|
.expect("Impossible de créer le thread fpv-engine-worker");
|
||||||
@@ -628,6 +688,53 @@ fn sync_g29_status(
|
|||||||
st
|
st
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn sync_controller_status(
|
||||||
|
control_source_flag: &Arc<AtomicU8>,
|
||||||
|
ctrl_worker_opt: Option<&SteamControllerWorker>,
|
||||||
|
g29_snapshot: &G29State,
|
||||||
|
monitor: &Arc<Mutex<RuntimeMonitor>>,
|
||||||
|
) -> G29State {
|
||||||
|
let active_src = ControlSource::from_u8(control_source_flag.load(Ordering::Acquire));
|
||||||
|
let ctrl_state = ctrl_worker_opt
|
||||||
|
.map(|w| w.state().lock().clone())
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
let status = match active_src {
|
||||||
|
ControlSource::SteamController => {
|
||||||
|
if ctrl_state.connected {
|
||||||
|
SubsystemStatus::Running(format!(
|
||||||
|
"{} ([{}], {})",
|
||||||
|
ctrl_state.device_name,
|
||||||
|
ctrl_state.gear_label(),
|
||||||
|
if ctrl_state.armed { "ARMED" } else { "SAFE" }
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
SubsystemStatus::Warning("Steam Controller non détecté".to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ControlSource::G29 => {
|
||||||
|
if ctrl_state.connected {
|
||||||
|
SubsystemStatus::Stopped
|
||||||
|
} else {
|
||||||
|
SubsystemStatus::Disabled
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut mon = monitor.lock();
|
||||||
|
mon.active_control_source = active_src;
|
||||||
|
mon.controller_status = status;
|
||||||
|
mon.latest_controller = ctrl_state.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
if active_src == ControlSource::SteamController {
|
||||||
|
ctrl_state.to_hud_g29_state(g29_snapshot.is_live() && g29_snapshot.failsafe)
|
||||||
|
} else {
|
||||||
|
g29_snapshot.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn run_engine_worker(
|
fn run_engine_worker(
|
||||||
cfg: AppConfig,
|
cfg: AppConfig,
|
||||||
@@ -638,10 +745,12 @@ fn run_engine_worker(
|
|||||||
dvr_rec_flag: Arc<AtomicBool>,
|
dvr_rec_flag: Arc<AtomicBool>,
|
||||||
head_trim_deg: Arc<Mutex<(f32, f32)>>,
|
head_trim_deg: Arc<Mutex<(f32, f32)>>,
|
||||||
control_for_g29: EngineControlHandle,
|
control_for_g29: EngineControlHandle,
|
||||||
|
control_for_ctrl: EngineControlHandle,
|
||||||
stop_flag: Arc<AtomicBool>,
|
stop_flag: Arc<AtomicBool>,
|
||||||
recenter_flag: Arc<AtomicBool>,
|
recenter_flag: Arc<AtomicBool>,
|
||||||
telem_enabled_flag: Arc<AtomicBool>,
|
telem_enabled_flag: Arc<AtomicBool>,
|
||||||
ht_enabled_flag: Arc<AtomicBool>,
|
ht_enabled_flag: Arc<AtomicBool>,
|
||||||
|
control_source_flag: Arc<AtomicU8>,
|
||||||
) {
|
) {
|
||||||
let mut active_dvr: Option<Arc<DvrRecorder>> = None;
|
let mut active_dvr: Option<Arc<DvrRecorder>> = None;
|
||||||
log::info!(
|
log::info!(
|
||||||
@@ -715,6 +824,34 @@ fn run_engine_worker(
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 3c. Démarrage du gestionnaire Steam Controller (evdev -> $SRC / $RC sur le même pont UDP)
|
||||||
|
let ctrl_cfg = SteamControllerConfig {
|
||||||
|
device_override: if cfg.controller_device.trim().is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(cfg.controller_device.clone())
|
||||||
|
},
|
||||||
|
steering_deadzone: cfg.controller_deadzone,
|
||||||
|
steering_expo: cfg.controller_expo,
|
||||||
|
trigger_deadzone: 0.05,
|
||||||
|
invert_steering: cfg.controller_invert_steering,
|
||||||
|
};
|
||||||
|
let ctrl_worker_opt = match SteamControllerWorker::start(
|
||||||
|
&cfg.nomad_ip,
|
||||||
|
cfg.nomad_port,
|
||||||
|
ctrl_cfg,
|
||||||
|
Arc::clone(&control_source_flag),
|
||||||
|
control_for_ctrl,
|
||||||
|
g29_rx_opt.as_ref().map(|rx| rx.state()),
|
||||||
|
) {
|
||||||
|
Ok(worker) => Some(worker),
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("[Steam Controller] Erreur démarrage worker : {}", e);
|
||||||
|
monitor.lock().controller_status = SubsystemStatus::Error(format!("{}", e));
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// 4. Tentative d'initialisation OpenXR sur le Steam Frame (sauf si mode VR désactivé / headless)
|
// 4. Tentative d'initialisation OpenXR sur le Steam Frame (sauf si mode VR désactivé / headless)
|
||||||
let fallback_needed = if cfg.headless {
|
let fallback_needed = if cfg.headless {
|
||||||
log::info!("[OpenXR] Mode VR désactivé (Mode Bureau léger actif).");
|
log::info!("[OpenXR] Mode VR désactivé (Mode Bureau léger actif).");
|
||||||
@@ -734,11 +871,13 @@ fn run_engine_worker(
|
|||||||
&recenter_flag,
|
&recenter_flag,
|
||||||
&telem_enabled_flag,
|
&telem_enabled_flag,
|
||||||
&ht_enabled_flag,
|
&ht_enabled_flag,
|
||||||
|
&control_source_flag,
|
||||||
video_rx_opt.as_ref(),
|
video_rx_opt.as_ref(),
|
||||||
&mut telem_rx_opt,
|
&mut telem_rx_opt,
|
||||||
&shared_telem_state,
|
&shared_telem_state,
|
||||||
&mut head_tracker_opt,
|
&mut head_tracker_opt,
|
||||||
g29_rx_opt.as_ref(),
|
g29_rx_opt.as_ref(),
|
||||||
|
ctrl_worker_opt.as_ref(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if !stop_flag.load(Ordering::Acquire) {
|
if !stop_flag.load(Ordering::Acquire) {
|
||||||
@@ -779,11 +918,13 @@ fn run_engine_worker(
|
|||||||
&recenter_flag,
|
&recenter_flag,
|
||||||
&telem_enabled_flag,
|
&telem_enabled_flag,
|
||||||
&ht_enabled_flag,
|
&ht_enabled_flag,
|
||||||
|
&control_source_flag,
|
||||||
video_rx_opt.as_ref(),
|
video_rx_opt.as_ref(),
|
||||||
&mut telem_rx_opt,
|
&mut telem_rx_opt,
|
||||||
&shared_telem_state,
|
&shared_telem_state,
|
||||||
&mut head_tracker_opt,
|
&mut head_tracker_opt,
|
||||||
g29_rx_opt.as_ref(),
|
g29_rx_opt.as_ref(),
|
||||||
|
ctrl_worker_opt.as_ref(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -811,11 +952,13 @@ fn try_run_openxr_session(
|
|||||||
recenter_flag: &Arc<AtomicBool>,
|
recenter_flag: &Arc<AtomicBool>,
|
||||||
telem_enabled_flag: &Arc<AtomicBool>,
|
telem_enabled_flag: &Arc<AtomicBool>,
|
||||||
ht_enabled_flag: &Arc<AtomicBool>,
|
ht_enabled_flag: &Arc<AtomicBool>,
|
||||||
|
control_source_flag: &Arc<AtomicU8>,
|
||||||
video_rx_opt: Option<&UsbVideoReceiver>,
|
video_rx_opt: Option<&UsbVideoReceiver>,
|
||||||
telem_rx_opt: &mut RetrySlot<TelemetryReceiver>,
|
telem_rx_opt: &mut RetrySlot<TelemetryReceiver>,
|
||||||
shared_telem_state: &Arc<Mutex<TelemetryState>>,
|
shared_telem_state: &Arc<Mutex<TelemetryState>>,
|
||||||
head_tracker_opt: &mut RetrySlot<NomadHeadTracker>,
|
head_tracker_opt: &mut RetrySlot<NomadHeadTracker>,
|
||||||
g29_rx_opt: Option<&G29BridgeReceiver>,
|
g29_rx_opt: Option<&G29BridgeReceiver>,
|
||||||
|
ctrl_worker_opt: Option<&SteamControllerWorker>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let entry = unsafe {
|
let entry = unsafe {
|
||||||
xr::Entry::load().context("libopenxr_loader.so introuvable sur ce système (normal sur PC sans SteamVR)")?
|
xr::Entry::load().context("libopenxr_loader.so introuvable sur ce système (normal sur PC sans SteamVR)")?
|
||||||
@@ -1148,6 +1291,12 @@ fn try_run_openxr_session(
|
|||||||
|
|
||||||
dvr_rec_flag.store(active_dvr.is_some(), Ordering::Release);
|
dvr_rec_flag.store(active_dvr.is_some(), Ordering::Release);
|
||||||
let g29_snapshot = sync_g29_status(cfg, g29_rx_opt, monitor);
|
let g29_snapshot = sync_g29_status(cfg, g29_rx_opt, monitor);
|
||||||
|
let hud_ctrl_snapshot = sync_controller_status(
|
||||||
|
control_source_flag,
|
||||||
|
ctrl_worker_opt,
|
||||||
|
&g29_snapshot,
|
||||||
|
monitor,
|
||||||
|
);
|
||||||
|
|
||||||
let mut telem_snapshot = telem_rx_opt
|
let mut telem_snapshot = telem_rx_opt
|
||||||
.inner
|
.inner
|
||||||
@@ -1172,7 +1321,7 @@ fn try_run_openxr_session(
|
|||||||
cfg.video_width,
|
cfg.video_width,
|
||||||
cfg.video_height,
|
cfg.video_height,
|
||||||
&telem_snapshot,
|
&telem_snapshot,
|
||||||
&g29_snapshot,
|
&hud_ctrl_snapshot,
|
||||||
current_pose.pan_deg,
|
current_pose.pan_deg,
|
||||||
current_pose.tilt_deg,
|
current_pose.tilt_deg,
|
||||||
current_pose.roll_deg,
|
current_pose.roll_deg,
|
||||||
@@ -1341,11 +1490,13 @@ fn run_desktop_fallback_loop(
|
|||||||
recenter_flag: &Arc<AtomicBool>,
|
recenter_flag: &Arc<AtomicBool>,
|
||||||
telem_enabled_flag: &Arc<AtomicBool>,
|
telem_enabled_flag: &Arc<AtomicBool>,
|
||||||
ht_enabled_flag: &Arc<AtomicBool>,
|
ht_enabled_flag: &Arc<AtomicBool>,
|
||||||
|
control_source_flag: &Arc<AtomicU8>,
|
||||||
video_rx_opt: Option<&UsbVideoReceiver>,
|
video_rx_opt: Option<&UsbVideoReceiver>,
|
||||||
telem_rx_opt: &mut RetrySlot<TelemetryReceiver>,
|
telem_rx_opt: &mut RetrySlot<TelemetryReceiver>,
|
||||||
shared_telem_state: &Arc<Mutex<TelemetryState>>,
|
shared_telem_state: &Arc<Mutex<TelemetryState>>,
|
||||||
head_tracker_opt: &mut RetrySlot<NomadHeadTracker>,
|
head_tracker_opt: &mut RetrySlot<NomadHeadTracker>,
|
||||||
g29_rx_opt: Option<&G29BridgeReceiver>,
|
g29_rx_opt: Option<&G29BridgeReceiver>,
|
||||||
|
ctrl_worker_opt: Option<&SteamControllerWorker>,
|
||||||
) {
|
) {
|
||||||
let mut dome_lut = DomeWarpLut::new(
|
let mut dome_lut = DomeWarpLut::new(
|
||||||
cfg.video_width,
|
cfg.video_width,
|
||||||
@@ -1469,6 +1620,12 @@ fn run_desktop_fallback_loop(
|
|||||||
|
|
||||||
dvr_rec_flag.store(active_dvr.is_some(), Ordering::Release);
|
dvr_rec_flag.store(active_dvr.is_some(), Ordering::Release);
|
||||||
let g29_snapshot = sync_g29_status(cfg, g29_rx_opt, monitor);
|
let g29_snapshot = sync_g29_status(cfg, g29_rx_opt, monitor);
|
||||||
|
let hud_ctrl_snapshot = sync_controller_status(
|
||||||
|
control_source_flag,
|
||||||
|
ctrl_worker_opt,
|
||||||
|
&g29_snapshot,
|
||||||
|
monitor,
|
||||||
|
);
|
||||||
|
|
||||||
let mut telem_snapshot = telem_rx_opt
|
let mut telem_snapshot = telem_rx_opt
|
||||||
.inner
|
.inner
|
||||||
@@ -1493,7 +1650,7 @@ fn run_desktop_fallback_loop(
|
|||||||
cfg.video_width,
|
cfg.video_width,
|
||||||
cfg.video_height,
|
cfg.video_height,
|
||||||
&telem_snapshot,
|
&telem_snapshot,
|
||||||
&g29_snapshot,
|
&hud_ctrl_snapshot,
|
||||||
current_pose.pan_deg,
|
current_pose.pan_deg,
|
||||||
current_pose.tilt_deg,
|
current_pose.tilt_deg,
|
||||||
current_pose.roll_deg,
|
current_pose.roll_deg,
|
||||||
|
|||||||
+68
-3
@@ -1,4 +1,6 @@
|
|||||||
|
use crate::controller::ControlSource;
|
||||||
use crate::engine::EngineControlHandle;
|
use crate::engine::EngineControlHandle;
|
||||||
|
use crate::nomad_elrs::{CRSF_CHANNEL_MAX, CRSF_CHANNEL_MID, CRSF_CHANNEL_MIN};
|
||||||
use crate::telemetry_osd::{TelemetryReceiver, TelemetryState};
|
use crate::telemetry_osd::{TelemetryReceiver, TelemetryState};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
@@ -18,13 +20,22 @@ pub struct G29State {
|
|||||||
pub failsafe: bool,
|
pub failsafe: bool,
|
||||||
pub armed: bool,
|
pub armed: bool,
|
||||||
pub gear: i8,
|
pub gear: i8,
|
||||||
|
pub steering_pct: i8,
|
||||||
pub throttle_pct: u8,
|
pub throttle_pct: u8,
|
||||||
pub brake_pct: u8,
|
pub brake_pct: u8,
|
||||||
|
pub clutch_pct: u8,
|
||||||
|
pub steer_crsf: u16,
|
||||||
|
pub throttle_crsf: u16,
|
||||||
|
pub brake_crsf: u16,
|
||||||
|
pub clutch_crsf: u16,
|
||||||
pub ffb_raw: u8,
|
pub ffb_raw: u8,
|
||||||
pub ffb_pct: u8,
|
pub ffb_pct: u8,
|
||||||
pub vib_pct: u8,
|
pub vib_pct: u8,
|
||||||
|
pub remote_source: ControlSource,
|
||||||
pub packets_received: u64,
|
pub packets_received: u64,
|
||||||
pub last_packet: Option<Instant>,
|
pub last_packet: Option<Instant>,
|
||||||
|
pub last_button: String,
|
||||||
|
pub last_button_at: Option<Instant>,
|
||||||
pub toast_text: String,
|
pub toast_text: String,
|
||||||
pub toast_until: Option<Instant>,
|
pub toast_until: Option<Instant>,
|
||||||
}
|
}
|
||||||
@@ -36,13 +47,22 @@ impl Default for G29State {
|
|||||||
failsafe: false,
|
failsafe: false,
|
||||||
armed: false,
|
armed: false,
|
||||||
gear: 0,
|
gear: 0,
|
||||||
|
steering_pct: 0,
|
||||||
throttle_pct: 0,
|
throttle_pct: 0,
|
||||||
brake_pct: 0,
|
brake_pct: 0,
|
||||||
|
clutch_pct: 0,
|
||||||
|
steer_crsf: CRSF_CHANNEL_MID,
|
||||||
|
throttle_crsf: CRSF_CHANNEL_MID,
|
||||||
|
brake_crsf: CRSF_CHANNEL_MID,
|
||||||
|
clutch_crsf: CRSF_CHANNEL_MID,
|
||||||
ffb_raw: 140,
|
ffb_raw: 140,
|
||||||
ffb_pct: 55,
|
ffb_pct: 55,
|
||||||
vib_pct: 50,
|
vib_pct: 50,
|
||||||
|
remote_source: ControlSource::G29,
|
||||||
packets_received: 0,
|
packets_received: 0,
|
||||||
last_packet: None,
|
last_packet: None,
|
||||||
|
last_button: String::new(),
|
||||||
|
last_button_at: None,
|
||||||
toast_text: String::new(),
|
toast_text: String::new(),
|
||||||
toast_until: None,
|
toast_until: None,
|
||||||
}
|
}
|
||||||
@@ -276,6 +296,36 @@ impl G29BridgeReceiver {
|
|||||||
st.brake_pct = val.min(100);
|
st.brake_pct = val.min(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"CLUTCH" => {
|
||||||
|
if let Ok(val) = v.trim().parse::<u8>() {
|
||||||
|
st.clutch_pct = val.min(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"STEER" => {
|
||||||
|
if let Ok(val) = v.trim().parse::<i8>() {
|
||||||
|
st.steering_pct = val.clamp(-100, 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"CH1" => {
|
||||||
|
if let Ok(val) = v.trim().parse::<u16>() {
|
||||||
|
st.steer_crsf = val.clamp(CRSF_CHANNEL_MIN, CRSF_CHANNEL_MAX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"CH2" => {
|
||||||
|
if let Ok(val) = v.trim().parse::<u16>() {
|
||||||
|
st.throttle_crsf = val.clamp(CRSF_CHANNEL_MIN, CRSF_CHANNEL_MAX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"CH3" => {
|
||||||
|
if let Ok(val) = v.trim().parse::<u16>() {
|
||||||
|
st.brake_crsf = val.clamp(CRSF_CHANNEL_MIN, CRSF_CHANNEL_MAX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"CH4" => {
|
||||||
|
if let Ok(val) = v.trim().parse::<u16>() {
|
||||||
|
st.clutch_crsf = val.clamp(CRSF_CHANNEL_MIN, CRSF_CHANNEL_MAX);
|
||||||
|
}
|
||||||
|
}
|
||||||
"FFB" => {
|
"FFB" => {
|
||||||
if let Ok(val) = v.trim().parse::<u8>() {
|
if let Ok(val) = v.trim().parse::<u8>() {
|
||||||
st.ffb_raw = val;
|
st.ffb_raw = val;
|
||||||
@@ -292,6 +342,9 @@ impl G29BridgeReceiver {
|
|||||||
st.failsafe = val != 0;
|
st.failsafe = val != 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"SRC" => {
|
||||||
|
st.remote_source = ControlSource::from_str(v);
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -392,11 +445,15 @@ impl G29BridgeReceiver {
|
|||||||
G29ButtonEvent::Options | G29ButtonEvent::L3 => None,
|
G29ButtonEvent::Options | G29ButtonEvent::L3 => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(msg) = toast {
|
{
|
||||||
let mut st = state.lock();
|
let mut st = state.lock();
|
||||||
st.connected = true;
|
st.connected = true;
|
||||||
st.last_packet = Some(Instant::now());
|
st.last_packet = Some(Instant::now());
|
||||||
st.set_toast(msg);
|
st.last_button = btn_name.trim().to_string();
|
||||||
|
st.last_button_at = Some(Instant::now());
|
||||||
|
if let Some(msg) = toast {
|
||||||
|
st.set_toast(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -437,7 +494,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
G29BridgeReceiver::process_line(
|
G29BridgeReceiver::process_line(
|
||||||
"$G29,ARM=1,GEAR=-1,THROT=0,BRAKE=80,FFB=200,VIB=50,FAIL=0",
|
"$G29,ARM=1,GEAR=-1,THROT=0,BRAKE=80,CLUTCH=45,STEER=-35,CH1=1280,CH2=890,CH3=1640,CH4=1360,FFB=200,VIB=50,FAIL=0,SRC=EXT",
|
||||||
&state,
|
&state,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
@@ -446,6 +503,13 @@ mod tests {
|
|||||||
let st = state.lock();
|
let st = state.lock();
|
||||||
assert_eq!(st.gear_label(), "R");
|
assert_eq!(st.gear_label(), "R");
|
||||||
assert_eq!(st.brake_pct, 80);
|
assert_eq!(st.brake_pct, 80);
|
||||||
|
assert_eq!(st.clutch_pct, 45);
|
||||||
|
assert_eq!(st.steering_pct, -35);
|
||||||
|
assert_eq!(st.steer_crsf, 1280);
|
||||||
|
assert_eq!(st.throttle_crsf, 890);
|
||||||
|
assert_eq!(st.brake_crsf, 1640);
|
||||||
|
assert_eq!(st.clutch_crsf, 1360);
|
||||||
|
assert_eq!(st.remote_source, ControlSource::SteamController);
|
||||||
assert_eq!(st.active_toast(), Some("FFB 78%"));
|
assert_eq!(st.active_toast(), Some("FFB 78%"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -455,6 +519,7 @@ mod tests {
|
|||||||
let state = Arc::new(Mutex::new(G29State::default()));
|
let state = Arc::new(Mutex::new(G29State::default()));
|
||||||
G29BridgeReceiver::process_line("$G29_EVT,BTN=CROSS", &state, None, None);
|
G29BridgeReceiver::process_line("$G29_EVT,BTN=CROSS", &state, None, None);
|
||||||
let st = state.lock();
|
let st = state.lock();
|
||||||
|
assert_eq!(st.last_button, "CROSS");
|
||||||
assert_eq!(st.active_toast(), Some("TARE HT OK"));
|
assert_eq!(st.active_toast(), Some("TARE HT OK"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+287
@@ -1,4 +1,5 @@
|
|||||||
use crate::config::AppConfig;
|
use crate::config::AppConfig;
|
||||||
|
use crate::controller::ControlSource;
|
||||||
use crate::dome_projection::ProjectionMode;
|
use crate::dome_projection::ProjectionMode;
|
||||||
use crate::dvr::{DvrContainer, DvrMode};
|
use crate::dvr::{DvrContainer, DvrMode};
|
||||||
use crate::engine::{EngineControlHandle, FpvEngineController, LiveOpticalParams, RuntimeMonitor, SubsystemStatus};
|
use crate::engine::{EngineControlHandle, FpvEngineController, LiveOpticalParams, RuntimeMonitor, SubsystemStatus};
|
||||||
@@ -24,6 +25,8 @@ pub struct SteamFrameGuiApp {
|
|||||||
auto_scroll_logs: bool,
|
auto_scroll_logs: bool,
|
||||||
video_texture: Option<TextureHandle>,
|
video_texture: Option<TextureHandle>,
|
||||||
last_displayed_frame_seq: u64,
|
last_displayed_frame_seq: u64,
|
||||||
|
control_switch_error: String,
|
||||||
|
monitor_source_override: Option<ControlSource>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SteamFrameGuiApp {
|
impl SteamFrameGuiApp {
|
||||||
@@ -51,6 +54,8 @@ impl SteamFrameGuiApp {
|
|||||||
auto_scroll_logs: true,
|
auto_scroll_logs: true,
|
||||||
video_texture: None,
|
video_texture: None,
|
||||||
last_displayed_frame_seq: 0,
|
last_displayed_frame_seq: 0,
|
||||||
|
control_switch_error: String::new(),
|
||||||
|
monitor_source_override: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,6 +288,11 @@ impl eframe::App for SteamFrameGuiApp {
|
|||||||
xr_status,
|
xr_status,
|
||||||
nomad_status,
|
nomad_status,
|
||||||
telem_status,
|
telem_status,
|
||||||
|
g29_status,
|
||||||
|
controller_status,
|
||||||
|
active_ctrl_source,
|
||||||
|
latest_g29,
|
||||||
|
latest_ctrl,
|
||||||
dvr_status,
|
dvr_status,
|
||||||
dvr_recording,
|
dvr_recording,
|
||||||
dvr_secs,
|
dvr_secs,
|
||||||
@@ -318,6 +328,11 @@ impl eframe::App for SteamFrameGuiApp {
|
|||||||
mon.openxr_status.clone(),
|
mon.openxr_status.clone(),
|
||||||
mon.nomad_wifi_status.clone(),
|
mon.nomad_wifi_status.clone(),
|
||||||
mon.telemetry_status.clone(),
|
mon.telemetry_status.clone(),
|
||||||
|
mon.g29_status.clone(),
|
||||||
|
mon.controller_status.clone(),
|
||||||
|
mon.active_control_source,
|
||||||
|
mon.latest_g29.clone(),
|
||||||
|
mon.latest_controller.clone(),
|
||||||
mon.dvr_status.clone(),
|
mon.dvr_status.clone(),
|
||||||
mon.dvr_recording,
|
mon.dvr_recording,
|
||||||
mon.dvr_elapsed_secs,
|
mon.dvr_elapsed_secs,
|
||||||
@@ -488,6 +503,11 @@ impl eframe::App for SteamFrameGuiApp {
|
|||||||
Self::status_badge(ui, "VRX Radxa Zero 3W", &usb_status);
|
Self::status_badge(ui, "VRX Radxa Zero 3W", &usb_status);
|
||||||
Self::status_badge(ui, "Casque OpenXR", &xr_status);
|
Self::status_badge(ui, "Casque OpenXR", &xr_status);
|
||||||
Self::status_badge(ui, "Wi-Fi Nomad ELRS", &nomad_status);
|
Self::status_badge(ui, "Wi-Fi Nomad ELRS", &nomad_status);
|
||||||
|
if active_ctrl_source == ControlSource::SteamController {
|
||||||
|
Self::status_badge(ui, "Steam Controller", &controller_status);
|
||||||
|
} else {
|
||||||
|
Self::status_badge(ui, "Volant G29", &g29_status);
|
||||||
|
}
|
||||||
Self::status_badge(ui, "Télémétrie OSD", &telem_status);
|
Self::status_badge(ui, "Télémétrie OSD", &telem_status);
|
||||||
Self::status_badge(ui, "DVR Vidéo", &dvr_status);
|
Self::status_badge(ui, "DVR Vidéo", &dvr_status);
|
||||||
});
|
});
|
||||||
@@ -854,6 +874,11 @@ impl eframe::App for SteamFrameGuiApp {
|
|||||||
egui::ComboBox::from_id_salt("ht_proto_combo")
|
egui::ComboBox::from_id_salt("ht_proto_combo")
|
||||||
.selected_text(NomadProtocol::from_str(&self.cfg.ht_protocol).label())
|
.selected_text(NomadProtocol::from_str(&self.cfg.ht_protocol).label())
|
||||||
.show_ui(ui, |ui| {
|
.show_ui(ui, |ui| {
|
||||||
|
ui.selectable_value(
|
||||||
|
&mut self.cfg.ht_protocol,
|
||||||
|
"g29".to_string(),
|
||||||
|
"G29 Hub unifié ($HT - UDP 14552)",
|
||||||
|
);
|
||||||
ui.selectable_value(
|
ui.selectable_value(
|
||||||
&mut self.cfg.ht_protocol,
|
&mut self.cfg.ht_protocol,
|
||||||
"msp".to_string(),
|
"msp".to_string(),
|
||||||
@@ -902,6 +927,268 @@ impl eframe::App for SteamFrameGuiApp {
|
|||||||
|
|
||||||
ui.add_space(8.0);
|
ui.add_space(8.0);
|
||||||
|
|
||||||
|
// --- Section 2b : Contrôleur de Conduite (Volant G29 / Steam Controller) ---
|
||||||
|
egui::CollapsingHeader::new(
|
||||||
|
RichText::new("🎮 2b. Contrôleur de Conduite (Volant G29 / Steam Controller)")
|
||||||
|
.strong(),
|
||||||
|
)
|
||||||
|
.default_open(true)
|
||||||
|
.show(ui, |ui| {
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.label(RichText::new("Source active :").strong());
|
||||||
|
if ui
|
||||||
|
.selectable_label(
|
||||||
|
active_ctrl_source == ControlSource::G29,
|
||||||
|
"🏎️ Volant G29",
|
||||||
|
)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
match self.controls.set_control_source(ControlSource::G29) {
|
||||||
|
Ok(()) => {
|
||||||
|
self.cfg.control_source = "g29".to_string();
|
||||||
|
self.control_switch_error.clear();
|
||||||
|
}
|
||||||
|
Err(msg) => self.control_switch_error = msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ui
|
||||||
|
.selectable_label(
|
||||||
|
active_ctrl_source == ControlSource::SteamController,
|
||||||
|
"🎮 Steam Controller",
|
||||||
|
)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
match self
|
||||||
|
.controls
|
||||||
|
.set_control_source(ControlSource::SteamController)
|
||||||
|
{
|
||||||
|
Ok(()) => {
|
||||||
|
self.cfg.control_source = "steam".to_string();
|
||||||
|
self.control_switch_error.clear();
|
||||||
|
}
|
||||||
|
Err(msg) => self.control_switch_error = msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if !self.control_switch_error.is_empty() {
|
||||||
|
ui.colored_label(
|
||||||
|
Color32::from_rgb(255, 85, 85),
|
||||||
|
format!("⚠ {}", self.control_switch_error),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.add_space(4.0);
|
||||||
|
if latest_ctrl.connected {
|
||||||
|
ui.colored_label(
|
||||||
|
Color32::from_rgb(80, 235, 130),
|
||||||
|
format!(
|
||||||
|
"● {} ({}) — [{}] {} | Gaz {}% | Frn {}% | Dir {:+.0}%",
|
||||||
|
latest_ctrl.device_name,
|
||||||
|
latest_ctrl.device_path,
|
||||||
|
latest_ctrl.gear_label(),
|
||||||
|
if latest_ctrl.armed { "ARMED" } else { "SAFE" },
|
||||||
|
latest_ctrl.throttle_pct,
|
||||||
|
latest_ctrl.brake_pct,
|
||||||
|
latest_ctrl.steering_norm * 100.0
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
ui.colored_label(
|
||||||
|
Color32::GRAY,
|
||||||
|
"○ Steam Controller non détecté (dongle / USB)",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.add_space(4.0);
|
||||||
|
egui::Grid::new("ctrl_cfg_grid")
|
||||||
|
.num_columns(2)
|
||||||
|
.spacing([8.0, 6.0])
|
||||||
|
.show(ui, |ui| {
|
||||||
|
ui.label("Expo direction SC :");
|
||||||
|
ui.add(egui::Slider::new(&mut self.cfg.controller_expo, 0.0..=0.8));
|
||||||
|
ui.end_row();
|
||||||
|
|
||||||
|
ui.label("Zone morte stick :");
|
||||||
|
ui.add(egui::Slider::new(
|
||||||
|
&mut self.cfg.controller_deadzone,
|
||||||
|
0.0..=0.4,
|
||||||
|
));
|
||||||
|
ui.end_row();
|
||||||
|
|
||||||
|
ui.label("Inverser direction :");
|
||||||
|
ui.checkbox(&mut self.cfg.controller_invert_steering, "Inversée");
|
||||||
|
ui.end_row();
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.add_space(6.0);
|
||||||
|
egui::Frame::group(ui.style())
|
||||||
|
.fill(Color32::from_rgb(16, 20, 28))
|
||||||
|
.inner_margin(egui::Margin::same(8.0))
|
||||||
|
.show(ui, |ui| {
|
||||||
|
let viewed = self
|
||||||
|
.monitor_source_override
|
||||||
|
.unwrap_or(active_ctrl_source);
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.label(
|
||||||
|
RichText::new(format!(
|
||||||
|
"📊 Moniteur — {}",
|
||||||
|
viewed.label()
|
||||||
|
))
|
||||||
|
.strong()
|
||||||
|
.color(Color32::from_rgb(90, 220, 255)),
|
||||||
|
);
|
||||||
|
ui.selectable_value(
|
||||||
|
&mut self.monitor_source_override,
|
||||||
|
None,
|
||||||
|
"Auto",
|
||||||
|
);
|
||||||
|
ui.selectable_value(
|
||||||
|
&mut self.monitor_source_override,
|
||||||
|
Some(ControlSource::G29),
|
||||||
|
"G29",
|
||||||
|
);
|
||||||
|
ui.selectable_value(
|
||||||
|
&mut self.monitor_source_override,
|
||||||
|
Some(ControlSource::SteamController),
|
||||||
|
"Steam",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
let (
|
||||||
|
online,
|
||||||
|
failsafe,
|
||||||
|
armed,
|
||||||
|
gear_lbl,
|
||||||
|
steer_pct,
|
||||||
|
steer_crsf,
|
||||||
|
throt_pct,
|
||||||
|
throt_crsf,
|
||||||
|
brake_pct,
|
||||||
|
brake_crsf,
|
||||||
|
clutch_pct,
|
||||||
|
clutch_crsf,
|
||||||
|
last_btn,
|
||||||
|
detail,
|
||||||
|
) = if viewed == ControlSource::SteamController {
|
||||||
|
(
|
||||||
|
latest_ctrl.connected,
|
||||||
|
!latest_ctrl.connected,
|
||||||
|
latest_ctrl.armed,
|
||||||
|
latest_ctrl.gear_label(),
|
||||||
|
latest_ctrl.steering_norm * 100.0,
|
||||||
|
latest_ctrl.steer_crsf,
|
||||||
|
latest_ctrl.throttle_pct,
|
||||||
|
latest_ctrl.throttle_crsf,
|
||||||
|
latest_ctrl.brake_pct,
|
||||||
|
latest_ctrl.brake_crsf,
|
||||||
|
latest_ctrl.clutch_pct,
|
||||||
|
latest_ctrl.clutch_crsf,
|
||||||
|
if latest_ctrl.last_button.is_empty() {
|
||||||
|
"Aucun".to_string()
|
||||||
|
} else {
|
||||||
|
latest_ctrl.last_button.clone()
|
||||||
|
},
|
||||||
|
format!(
|
||||||
|
"$RC envoyés : {} (Err : {})",
|
||||||
|
latest_ctrl.packets_sent, latest_ctrl.send_errors
|
||||||
|
),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
let live = latest_g29.is_live();
|
||||||
|
(
|
||||||
|
live,
|
||||||
|
!live || latest_g29.failsafe,
|
||||||
|
latest_g29.armed,
|
||||||
|
latest_g29.gear_label(),
|
||||||
|
latest_g29.steering_pct as f32,
|
||||||
|
latest_g29.steer_crsf,
|
||||||
|
latest_g29.throttle_pct,
|
||||||
|
latest_g29.throttle_crsf,
|
||||||
|
latest_g29.brake_pct,
|
||||||
|
latest_g29.brake_crsf,
|
||||||
|
latest_g29.clutch_pct,
|
||||||
|
latest_g29.clutch_crsf,
|
||||||
|
if latest_g29.last_button.is_empty() {
|
||||||
|
"Aucun".to_string()
|
||||||
|
} else {
|
||||||
|
latest_g29.last_button.clone()
|
||||||
|
},
|
||||||
|
format!(
|
||||||
|
"FFB {}% | Vib {}% | RX {} | RP2350: {}",
|
||||||
|
latest_g29.ffb_pct,
|
||||||
|
latest_g29.vib_pct,
|
||||||
|
latest_g29.packets_received,
|
||||||
|
latest_g29.remote_source.wire_tag()
|
||||||
|
),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
ui.horizontal_wrapped(|ui| {
|
||||||
|
ui.colored_label(
|
||||||
|
if online {
|
||||||
|
Color32::from_rgb(80, 235, 130)
|
||||||
|
} else {
|
||||||
|
Color32::GRAY
|
||||||
|
},
|
||||||
|
if online { "● CONNECTÉ" } else { "○ HORS LIGNE" },
|
||||||
|
);
|
||||||
|
ui.label(RichText::new(format!("BOÎTE [{}]", gear_lbl)).strong());
|
||||||
|
ui.colored_label(
|
||||||
|
if failsafe {
|
||||||
|
Color32::from_rgb(255, 80, 80)
|
||||||
|
} else if armed {
|
||||||
|
Color32::from_rgb(80, 235, 130)
|
||||||
|
} else {
|
||||||
|
Color32::from_rgb(255, 185, 60)
|
||||||
|
},
|
||||||
|
if failsafe {
|
||||||
|
"FAILSAFE (CH5: 172)"
|
||||||
|
} else if armed {
|
||||||
|
"ARMED (CH5: 1811)"
|
||||||
|
} else {
|
||||||
|
"SAFE (CH5: 172)"
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
let steer_frac = ((steer_pct + 100.0) / 200.0).clamp(0.0, 1.0);
|
||||||
|
ui.add(
|
||||||
|
egui::ProgressBar::new(steer_frac)
|
||||||
|
.text(format!(
|
||||||
|
"Direction CH1 : {:+.0}% (CRSF {})",
|
||||||
|
steer_pct, steer_crsf
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
ui.add(
|
||||||
|
egui::ProgressBar::new((throt_pct as f32 / 100.0).clamp(0.0, 1.0))
|
||||||
|
.text(format!(
|
||||||
|
"Accélérateur CH2 : {}% (CRSF {})",
|
||||||
|
throt_pct, throt_crsf
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
ui.add(
|
||||||
|
egui::ProgressBar::new((brake_pct as f32 / 100.0).clamp(0.0, 1.0))
|
||||||
|
.text(format!(
|
||||||
|
"Frein CH3 : {}% (CRSF {})",
|
||||||
|
brake_pct, brake_crsf
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
ui.add(
|
||||||
|
egui::ProgressBar::new((clutch_pct as f32 / 100.0).clamp(0.0, 1.0))
|
||||||
|
.text(format!(
|
||||||
|
"Embrayage CH4 : {}% (CRSF {})",
|
||||||
|
clutch_pct, clutch_crsf
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
ui.small(format!("🔘 Dernier bouton : {} • {}", last_btn, detail));
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.small("Stick G: Dir | R2: Gaz | L2: Frein | RB/LB ou R4/L4: Boîte R/N/1/2/3 | Menu: Armer (au N)");
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.add_space(8.0);
|
||||||
|
|
||||||
// --- Section 3 : Télémétrie (Optionnelle ON/OFF) & Projection VR ---
|
// --- Section 3 : Télémétrie (Optionnelle ON/OFF) & Projection VR ---
|
||||||
egui::CollapsingHeader::new(
|
egui::CollapsingHeader::new(
|
||||||
RichText::new("🥽 3. Projection VR 140° & Télémétrie (Optionnelle)")
|
RichText::new("🥽 3. Projection VR 140° & Télémétrie (Optionnelle)")
|
||||||
|
|||||||
+713
-25
@@ -1,4 +1,5 @@
|
|||||||
use crate::config::AppConfig;
|
use crate::config::AppConfig;
|
||||||
|
use crate::controller::{ControlSource, SteamControllerState};
|
||||||
use crate::dome_projection::ProjectionMode;
|
use crate::dome_projection::ProjectionMode;
|
||||||
use crate::dvr::{DvrContainer, DvrMode};
|
use crate::dvr::{DvrContainer, DvrMode};
|
||||||
use crate::engine::{
|
use crate::engine::{
|
||||||
@@ -70,6 +71,8 @@ pub struct SteamFrameGpuiApp {
|
|||||||
nomad_status: SubsystemStatus,
|
nomad_status: SubsystemStatus,
|
||||||
telem_status: SubsystemStatus,
|
telem_status: SubsystemStatus,
|
||||||
g29_status: SubsystemStatus,
|
g29_status: SubsystemStatus,
|
||||||
|
controller_status: SubsystemStatus,
|
||||||
|
active_control_source: ControlSource,
|
||||||
dvr_status: SubsystemStatus,
|
dvr_status: SubsystemStatus,
|
||||||
dvr_recording: bool,
|
dvr_recording: bool,
|
||||||
dvr_elapsed_secs: u64,
|
dvr_elapsed_secs: u64,
|
||||||
@@ -81,6 +84,9 @@ pub struct SteamFrameGpuiApp {
|
|||||||
latest_pose: HeadPoseSample,
|
latest_pose: HeadPoseSample,
|
||||||
latest_telem: TelemetryState,
|
latest_telem: TelemetryState,
|
||||||
latest_g29: G29State,
|
latest_g29: G29State,
|
||||||
|
latest_controller: SteamControllerState,
|
||||||
|
control_switch_error: String,
|
||||||
|
monitor_source_override: Option<ControlSource>,
|
||||||
log_entries: Vec<LogEntry>,
|
log_entries: Vec<LogEntry>,
|
||||||
log_err_count: usize,
|
log_err_count: usize,
|
||||||
log_warn_count: usize,
|
log_warn_count: usize,
|
||||||
@@ -111,6 +117,7 @@ impl SteamFrameGpuiApp {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
let log_revision = log_buffer.lock().revision.clone();
|
let log_revision = log_buffer.lock().revision.clone();
|
||||||
let target_port_buf = cfg.nomad_port.to_string();
|
let target_port_buf = cfg.nomad_port.to_string();
|
||||||
|
let initial_control_source = ControlSource::from_str(&cfg.control_source);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
cfg,
|
cfg,
|
||||||
@@ -130,6 +137,8 @@ impl SteamFrameGpuiApp {
|
|||||||
nomad_status: SubsystemStatus::Disabled,
|
nomad_status: SubsystemStatus::Disabled,
|
||||||
telem_status: SubsystemStatus::Disabled,
|
telem_status: SubsystemStatus::Disabled,
|
||||||
g29_status: SubsystemStatus::Disabled,
|
g29_status: SubsystemStatus::Disabled,
|
||||||
|
controller_status: SubsystemStatus::Disabled,
|
||||||
|
active_control_source: initial_control_source,
|
||||||
dvr_status: SubsystemStatus::Stopped,
|
dvr_status: SubsystemStatus::Stopped,
|
||||||
dvr_recording: false,
|
dvr_recording: false,
|
||||||
dvr_elapsed_secs: 0,
|
dvr_elapsed_secs: 0,
|
||||||
@@ -141,6 +150,9 @@ impl SteamFrameGpuiApp {
|
|||||||
latest_pose: HeadPoseSample::default(),
|
latest_pose: HeadPoseSample::default(),
|
||||||
latest_telem: TelemetryState::default(),
|
latest_telem: TelemetryState::default(),
|
||||||
latest_g29: G29State::default(),
|
latest_g29: G29State::default(),
|
||||||
|
latest_controller: SteamControllerState::default(),
|
||||||
|
control_switch_error: String::new(),
|
||||||
|
monitor_source_override: None,
|
||||||
log_entries: Vec::new(),
|
log_entries: Vec::new(),
|
||||||
log_err_count: 0,
|
log_err_count: 0,
|
||||||
log_warn_count: 0,
|
log_warn_count: 0,
|
||||||
@@ -188,6 +200,14 @@ impl SteamFrameGpuiApp {
|
|||||||
self.g29_status = mon.g29_status.clone();
|
self.g29_status = mon.g29_status.clone();
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
if self.controller_status != mon.controller_status {
|
||||||
|
self.controller_status = mon.controller_status.clone();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if self.active_control_source != mon.active_control_source {
|
||||||
|
self.active_control_source = mon.active_control_source;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
if self.dvr_recording != mon.dvr_recording
|
if self.dvr_recording != mon.dvr_recording
|
||||||
|| self.dvr_elapsed_secs != mon.dvr_elapsed_secs
|
|| self.dvr_elapsed_secs != mon.dvr_elapsed_secs
|
||||||
|| self.dvr_status != mon.dvr_status
|
|| self.dvr_status != mon.dvr_status
|
||||||
@@ -212,11 +232,28 @@ impl SteamFrameGpuiApp {
|
|||||||
self.latest_telem = mon.latest_telemetry.clone();
|
self.latest_telem = mon.latest_telemetry.clone();
|
||||||
if self.latest_g29.packets_received != mon.latest_g29.packets_received
|
if self.latest_g29.packets_received != mon.latest_g29.packets_received
|
||||||
|| self.latest_g29.connected != mon.latest_g29.connected
|
|| self.latest_g29.connected != mon.latest_g29.connected
|
||||||
|
|| self.latest_g29.last_button != mon.latest_g29.last_button
|
||||||
{
|
{
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
self.latest_g29 = mon.latest_g29.clone();
|
self.latest_g29 = mon.latest_g29.clone();
|
||||||
|
|
||||||
|
if self.latest_controller.connected != mon.latest_controller.connected
|
||||||
|
|| self.latest_controller.armed != mon.latest_controller.armed
|
||||||
|
|| self.latest_controller.gear != mon.latest_controller.gear
|
||||||
|
|| self.latest_controller.throttle_pct != mon.latest_controller.throttle_pct
|
||||||
|
|| self.latest_controller.brake_pct != mon.latest_controller.brake_pct
|
||||||
|
|| self.latest_controller.clutch_pct != mon.latest_controller.clutch_pct
|
||||||
|
|| self.latest_controller.last_button != mon.latest_controller.last_button
|
||||||
|
|| (self.latest_controller.steering_norm - mon.latest_controller.steering_norm).abs()
|
||||||
|
> 0.005
|
||||||
|
|| (self.active_tab == ActiveTab::Settings
|
||||||
|
&& self.latest_controller.packets_sent != mon.latest_controller.packets_sent)
|
||||||
|
{
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
self.latest_controller = mon.latest_controller.clone();
|
||||||
|
|
||||||
// Ne cloner et décoder la trame QUE si l'onglet Cockpit est actif !
|
// Ne cloner et décoder la trame QUE si l'onglet Cockpit est actif !
|
||||||
let frame_data: Option<(u32, u32, Vec<u8>)> = if self.active_tab == ActiveTab::Cockpit
|
let frame_data: Option<(u32, u32, Vec<u8>)> = if self.active_tab == ActiveTab::Cockpit
|
||||||
&& mon.preview_frame_seq != self.last_frame_seq
|
&& mon.preview_frame_seq != self.last_frame_seq
|
||||||
@@ -667,6 +704,44 @@ impl SteamFrameGpuiApp {
|
|||||||
.flex()
|
.flex()
|
||||||
.items_center()
|
.items_center()
|
||||||
.gap_2()
|
.gap_2()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("toggle_ctrl_source_quick")
|
||||||
|
.px_2()
|
||||||
|
.py_0p5()
|
||||||
|
.bg(if self.active_control_source == ControlSource::SteamController {
|
||||||
|
rgb(0x132738)
|
||||||
|
} else {
|
||||||
|
rgb(COLOR_SURFACE_ELEVATED)
|
||||||
|
})
|
||||||
|
.border_1()
|
||||||
|
.border_color(if self.active_control_source == ControlSource::SteamController {
|
||||||
|
rgb(COLOR_CYAN)
|
||||||
|
} else {
|
||||||
|
rgb(COLOR_ORANGE)
|
||||||
|
})
|
||||||
|
.rounded_md()
|
||||||
|
.text_xs()
|
||||||
|
.font_weight(gpui::FontWeight::SEMIBOLD)
|
||||||
|
.text_color(if self.active_control_source == ControlSource::SteamController {
|
||||||
|
rgb(COLOR_CYAN)
|
||||||
|
} else {
|
||||||
|
rgb(COLOR_ORANGE)
|
||||||
|
})
|
||||||
|
.cursor_pointer()
|
||||||
|
.on_click(cx.listener(|this, _, _, cx| {
|
||||||
|
let next = match this.active_control_source {
|
||||||
|
ControlSource::G29 => ControlSource::SteamController,
|
||||||
|
ControlSource::SteamController => ControlSource::G29,
|
||||||
|
};
|
||||||
|
this.switch_control_source(next);
|
||||||
|
cx.notify();
|
||||||
|
}))
|
||||||
|
.child(match self.active_control_source {
|
||||||
|
ControlSource::G29 => "🏎️ G29",
|
||||||
|
ControlSource::SteamController => "🎮 Steam",
|
||||||
|
}),
|
||||||
|
)
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.id("toggle_vr_quick")
|
.id("toggle_vr_quick")
|
||||||
@@ -765,6 +840,19 @@ impl SteamFrameGpuiApp {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn switch_control_source(&mut self, target: ControlSource) {
|
||||||
|
match self.controls.set_control_source(target) {
|
||||||
|
Ok(()) => {
|
||||||
|
self.active_control_source = target;
|
||||||
|
self.cfg.control_source = target.as_str().to_string();
|
||||||
|
self.control_switch_error.clear();
|
||||||
|
}
|
||||||
|
Err(msg) => {
|
||||||
|
self.control_switch_error = msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn render_nav_tab(&self, label: &str, tab: ActiveTab, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render_nav_tab(&self, label: &str, tab: ActiveTab, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
let is_active = self.active_tab == tab;
|
let is_active = self.active_tab == tab;
|
||||||
let tab_id = match tab {
|
let tab_id = match tab {
|
||||||
@@ -1542,6 +1630,132 @@ impl SteamFrameGpuiApp {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
))
|
))
|
||||||
|
// 3.2b Carte Contrôleur de Conduite (Volant G29 / Steam Controller)
|
||||||
|
.child(self.render_settings_card(
|
||||||
|
"🎮 2b. Contrôleur de Conduite (Volant G29 / Steam Controller)",
|
||||||
|
COLOR_GREEN,
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_3()
|
||||||
|
.child(self.render_setting_row(
|
||||||
|
"Source Active (bascule à chaud)",
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_wrap()
|
||||||
|
.gap_2()
|
||||||
|
.child(self.render_selectable_pill(
|
||||||
|
"pill_ctrl_g29",
|
||||||
|
"🏎️ Volant Logitech G29",
|
||||||
|
self.active_control_source == ControlSource::G29,
|
||||||
|
cx.listener(|this, _, _, cx| {
|
||||||
|
this.switch_control_source(ControlSource::G29);
|
||||||
|
cx.notify();
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
.child(self.render_selectable_pill(
|
||||||
|
"pill_ctrl_steam",
|
||||||
|
"🎮 Steam Controller (Boîte séq.)",
|
||||||
|
self.active_control_source == ControlSource::SteamController,
|
||||||
|
cx.listener(|this, _, _, cx| {
|
||||||
|
this.switch_control_source(
|
||||||
|
ControlSource::SteamController,
|
||||||
|
);
|
||||||
|
cx.notify();
|
||||||
|
}),
|
||||||
|
)),
|
||||||
|
))
|
||||||
|
.when(!self.control_switch_error.is_empty(), |d| {
|
||||||
|
d.child(
|
||||||
|
div()
|
||||||
|
.px_2p5()
|
||||||
|
.py_1()
|
||||||
|
.rounded_md()
|
||||||
|
.bg(rgb(0x2a1215))
|
||||||
|
.border_1()
|
||||||
|
.border_color(rgb(COLOR_RED))
|
||||||
|
.text_xs()
|
||||||
|
.text_color(rgb(COLOR_RED))
|
||||||
|
.child(format!("⚠️ {}", self.control_switch_error)),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.child(self.render_setting_row(
|
||||||
|
"État Steam Controller",
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.text_color(if self.latest_controller.connected {
|
||||||
|
rgb(COLOR_GREEN)
|
||||||
|
} else {
|
||||||
|
rgb(COLOR_TEXT_MUTED)
|
||||||
|
})
|
||||||
|
.child(if self.latest_controller.connected {
|
||||||
|
format!(
|
||||||
|
"● {} ({}) — [{}] {} • Gaz {}% • Frn {}% • Dir {:+.0}%",
|
||||||
|
self.latest_controller.device_name,
|
||||||
|
self.latest_controller.device_path,
|
||||||
|
self.latest_controller.gear_label(),
|
||||||
|
if self.latest_controller.armed {
|
||||||
|
"ARMED"
|
||||||
|
} else {
|
||||||
|
"SAFE"
|
||||||
|
},
|
||||||
|
self.latest_controller.throttle_pct,
|
||||||
|
self.latest_controller.brake_pct,
|
||||||
|
self.latest_controller.steering_norm * 100.0
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
"○ Non détecté (branchez le dongle ou allumez la manette)"
|
||||||
|
.to_string()
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
.child(self.render_setting_row(
|
||||||
|
"Sens Direction Steam Controller",
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.gap_2()
|
||||||
|
.child(self.render_selectable_pill(
|
||||||
|
"pill_sc_steer_normal",
|
||||||
|
"Normal (identique G29)",
|
||||||
|
!self.cfg.controller_invert_steering,
|
||||||
|
cx.listener(|this, _, _, cx| {
|
||||||
|
this.cfg.controller_invert_steering = false;
|
||||||
|
cx.notify();
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
.child(self.render_selectable_pill(
|
||||||
|
"pill_sc_steer_inv",
|
||||||
|
"Inversée",
|
||||||
|
self.cfg.controller_invert_steering,
|
||||||
|
cx.listener(|this, _, _, cx| {
|
||||||
|
this.cfg.controller_invert_steering = true;
|
||||||
|
cx.notify();
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.text_color(rgb(COLOR_TEXT_MUTED))
|
||||||
|
.child(format!(
|
||||||
|
"(Expo {:.2} • Deadzone {:.2})",
|
||||||
|
self.cfg.controller_expo,
|
||||||
|
self.cfg.controller_deadzone
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.child(self.render_controller_monitor(cx))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.p_2()
|
||||||
|
.rounded_md()
|
||||||
|
.bg(rgb(COLOR_BG_DARK))
|
||||||
|
.border_1()
|
||||||
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||||||
|
.text_xs()
|
||||||
|
.text_color(rgb(COLOR_TEXT_MUTED))
|
||||||
|
.child("Stick G : Direction | R2 : Gaz | L2 : Frein | RB/LB ou R4/L4 : Boîte R-N-1-2-3 | Menu : Armer (au N) | A : Tare | B : DVR | Y : OSD | X : Proj VR | D-Pad : Trim"),
|
||||||
|
),
|
||||||
|
))
|
||||||
// 3.3 Carte Projection VR Steam Frame & Optique
|
// 3.3 Carte Projection VR Steam Frame & Optique
|
||||||
.child(self.render_settings_card(
|
.child(self.render_settings_card(
|
||||||
"🥽 3. Projection VR & Correction Optique 140°",
|
"🥽 3. Projection VR & Correction Optique 140°",
|
||||||
@@ -2072,31 +2286,63 @@ impl SteamFrameGpuiApp {
|
|||||||
&format!("Cap : {:.0}°", self.latest_telem.drone_heading_deg),
|
&format!("Cap : {:.0}°", self.latest_telem.drone_heading_deg),
|
||||||
COLOR_CYAN,
|
COLOR_CYAN,
|
||||||
))
|
))
|
||||||
.child(self.render_stat_box(
|
.child(if self.active_control_source == ControlSource::SteamController {
|
||||||
"🎮 VOLANT G29",
|
self.render_stat_box(
|
||||||
&if !self.latest_g29.is_live() {
|
"🎮 STEAM CONTROLLER",
|
||||||
"HORS LIGNE".to_string()
|
&if !self.latest_controller.connected {
|
||||||
} else {
|
"NON DÉTECTÉ".to_string()
|
||||||
format!(
|
} else {
|
||||||
"[{}] {}",
|
format!(
|
||||||
self.latest_g29.gear_label(),
|
"[{}] {}",
|
||||||
if self.latest_g29.armed { "ARMED" } else { "SAFE" }
|
self.latest_controller.gear_label(),
|
||||||
)
|
if self.latest_controller.armed {
|
||||||
},
|
"ARMED"
|
||||||
&format!(
|
} else {
|
||||||
"Gaz {}% | Frn {}% | FFB {}%",
|
"SAFE"
|
||||||
self.latest_g29.throttle_pct,
|
}
|
||||||
self.latest_g29.brake_pct,
|
)
|
||||||
self.latest_g29.ffb_pct
|
},
|
||||||
),
|
&format!(
|
||||||
if !self.latest_g29.is_live() {
|
"Gaz {}% | Frn {}% | Dir {:+.0}%",
|
||||||
COLOR_TEXT_MUTED
|
self.latest_controller.throttle_pct,
|
||||||
} else if self.latest_g29.armed {
|
self.latest_controller.brake_pct,
|
||||||
COLOR_GREEN
|
self.latest_controller.steering_norm * 100.0
|
||||||
} else {
|
),
|
||||||
COLOR_ORANGE
|
if !self.latest_controller.connected {
|
||||||
},
|
COLOR_TEXT_MUTED
|
||||||
)),
|
} else if self.latest_controller.armed {
|
||||||
|
COLOR_GREEN
|
||||||
|
} else {
|
||||||
|
COLOR_ORANGE
|
||||||
|
},
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
self.render_stat_box(
|
||||||
|
"🏎️ VOLANT G29",
|
||||||
|
&if !self.latest_g29.is_live() {
|
||||||
|
"HORS LIGNE".to_string()
|
||||||
|
} else {
|
||||||
|
format!(
|
||||||
|
"[{}] {}",
|
||||||
|
self.latest_g29.gear_label(),
|
||||||
|
if self.latest_g29.armed { "ARMED" } else { "SAFE" }
|
||||||
|
)
|
||||||
|
},
|
||||||
|
&format!(
|
||||||
|
"Gaz {}% | Frn {}% | FFB {}%",
|
||||||
|
self.latest_g29.throttle_pct,
|
||||||
|
self.latest_g29.brake_pct,
|
||||||
|
self.latest_g29.ffb_pct
|
||||||
|
),
|
||||||
|
if !self.latest_g29.is_live() {
|
||||||
|
COLOR_TEXT_MUTED
|
||||||
|
} else if self.latest_g29.armed {
|
||||||
|
COLOR_GREEN
|
||||||
|
} else {
|
||||||
|
COLOR_ORANGE
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
// Double Panneau : Suivi de Tête & Radio
|
// Double Panneau : Suivi de Tête & Radio
|
||||||
.child(
|
.child(
|
||||||
@@ -2510,6 +2756,448 @@ impl SteamFrameGpuiApp {
|
|||||||
.child(format!("{} : {}", label, if is_on { "ON" } else { "OFF" }))
|
.child(format!("{} : {}", label, if is_on { "ON" } else { "OFF" }))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn render_monitor_progress_bar(
|
||||||
|
&self,
|
||||||
|
label: &str,
|
||||||
|
pct: u8,
|
||||||
|
crsf: u16,
|
||||||
|
bar_color: u32,
|
||||||
|
) -> impl IntoElement {
|
||||||
|
let frac = (pct as f32 / 100.0).clamp(0.0, 1.0);
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_0p5()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.justify_between()
|
||||||
|
.text_xs()
|
||||||
|
.child(div().text_color(rgb(COLOR_TEXT_MAIN)).child(label.to_string()))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_color(rgb(COLOR_TEXT_MUTED))
|
||||||
|
.child(format!("{:3}% | CRSF {}", pct, crsf)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.w_full()
|
||||||
|
.h(px(7.0))
|
||||||
|
.bg(rgb(COLOR_SURFACE_CARD))
|
||||||
|
.border_1()
|
||||||
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||||||
|
.rounded_full()
|
||||||
|
.overflow_hidden()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.h_full()
|
||||||
|
.w(DefiniteLength::Fraction(frac))
|
||||||
|
.bg(rgb(bar_color)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_monitor_bipolar_bar(
|
||||||
|
&self,
|
||||||
|
label: &str,
|
||||||
|
pct_signed: f32,
|
||||||
|
crsf: u16,
|
||||||
|
bar_color: u32,
|
||||||
|
) -> impl IntoElement {
|
||||||
|
let clamped = pct_signed.clamp(-100.0, 100.0);
|
||||||
|
let left_frac = if clamped < 0.0 {
|
||||||
|
(-clamped / 100.0).clamp(0.0, 1.0)
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
};
|
||||||
|
let right_frac = if clamped > 0.0 {
|
||||||
|
(clamped / 100.0).clamp(0.0, 1.0)
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
};
|
||||||
|
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_0p5()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.justify_between()
|
||||||
|
.text_xs()
|
||||||
|
.child(div().text_color(rgb(COLOR_TEXT_MAIN)).child(label.to_string()))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_color(rgb(COLOR_TEXT_MUTED))
|
||||||
|
.child(format!("{:+.0}% | CRSF {}", clamped, crsf)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.w_full()
|
||||||
|
.h(px(8.0))
|
||||||
|
.bg(rgb(COLOR_SURFACE_CARD))
|
||||||
|
.border_1()
|
||||||
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||||||
|
.rounded_full()
|
||||||
|
.overflow_hidden()
|
||||||
|
// Moitié gauche (remplissage depuis le centre vers la gauche)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.justify_end()
|
||||||
|
.w(DefiniteLength::Fraction(0.5))
|
||||||
|
.h_full()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.h_full()
|
||||||
|
.w(DefiniteLength::Fraction(left_frac))
|
||||||
|
.bg(rgb(bar_color)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
// Repère central
|
||||||
|
.child(div().w(px(2.0)).h_full().bg(rgb(COLOR_TEXT_MUTED)))
|
||||||
|
// Moitié droite (remplissage depuis le centre vers la droite)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.justify_start()
|
||||||
|
.w(DefiniteLength::Fraction(0.5))
|
||||||
|
.h_full()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.h_full()
|
||||||
|
.w(DefiniteLength::Fraction(right_frac))
|
||||||
|
.bg(rgb(bar_color)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_controller_monitor(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
let viewed_source = self.monitor_source_override.unwrap_or_else(|| {
|
||||||
|
if self.active_control_source == ControlSource::G29
|
||||||
|
&& !self.latest_g29.is_live()
|
||||||
|
&& self.latest_controller.connected
|
||||||
|
{
|
||||||
|
ControlSource::SteamController
|
||||||
|
} else {
|
||||||
|
self.active_control_source
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let is_steam_view = viewed_source == ControlSource::SteamController;
|
||||||
|
|
||||||
|
let (
|
||||||
|
is_online,
|
||||||
|
is_failsafe,
|
||||||
|
is_armed,
|
||||||
|
gear,
|
||||||
|
gear_lbl,
|
||||||
|
steer_pct,
|
||||||
|
steer_crsf,
|
||||||
|
throttle_pct,
|
||||||
|
throttle_crsf,
|
||||||
|
brake_pct,
|
||||||
|
brake_crsf,
|
||||||
|
clutch_pct,
|
||||||
|
clutch_crsf,
|
||||||
|
last_btn,
|
||||||
|
detail_line,
|
||||||
|
) = if is_steam_view {
|
||||||
|
let sc = &self.latest_controller;
|
||||||
|
let detail = if sc.connected {
|
||||||
|
format!(
|
||||||
|
"Périphérique : {} ({}) • Trames $RC : {} (Err : {})",
|
||||||
|
sc.device_name, sc.device_path, sc.packets_sent, sc.send_errors
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
"En attente d'un Steam Controller / Gamepad Linux (/dev/input/event*)".to_string()
|
||||||
|
};
|
||||||
|
(
|
||||||
|
sc.connected,
|
||||||
|
!sc.connected,
|
||||||
|
sc.armed,
|
||||||
|
sc.gear,
|
||||||
|
sc.gear_label(),
|
||||||
|
sc.steering_norm * 100.0,
|
||||||
|
sc.steer_crsf,
|
||||||
|
sc.throttle_pct,
|
||||||
|
sc.throttle_crsf,
|
||||||
|
sc.brake_pct,
|
||||||
|
sc.brake_crsf,
|
||||||
|
sc.clutch_pct,
|
||||||
|
sc.clutch_crsf,
|
||||||
|
if sc.last_button.is_empty() {
|
||||||
|
"Aucun".to_string()
|
||||||
|
} else {
|
||||||
|
sc.last_button.clone()
|
||||||
|
},
|
||||||
|
detail,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
let g = &self.latest_g29;
|
||||||
|
let live = g.is_live();
|
||||||
|
let detail = if live {
|
||||||
|
format!(
|
||||||
|
"FFB Ressort : {}% • Vibrations : {}% • Paquets UDP reçus : {}",
|
||||||
|
g.ffb_pct, g.vib_pct, g.packets_received
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
format!(
|
||||||
|
"En attente du pont G29 sur UDP :{} (Paquets reçus : {})",
|
||||||
|
self.cfg.g29_udp_port, g.packets_received
|
||||||
|
)
|
||||||
|
};
|
||||||
|
(
|
||||||
|
live,
|
||||||
|
!live || g.failsafe,
|
||||||
|
g.armed,
|
||||||
|
g.gear,
|
||||||
|
g.gear_label(),
|
||||||
|
g.steering_pct as f32,
|
||||||
|
g.steer_crsf,
|
||||||
|
g.throttle_pct,
|
||||||
|
g.throttle_crsf,
|
||||||
|
g.brake_pct,
|
||||||
|
g.brake_crsf,
|
||||||
|
g.clutch_pct,
|
||||||
|
g.clutch_crsf,
|
||||||
|
if g.last_button.is_empty() {
|
||||||
|
"Aucun".to_string()
|
||||||
|
} else {
|
||||||
|
g.last_button.clone()
|
||||||
|
},
|
||||||
|
detail,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
let gear_color = match gear {
|
||||||
|
-1 => COLOR_RED,
|
||||||
|
0 => COLOR_ORANGE,
|
||||||
|
1 => COLOR_CYAN,
|
||||||
|
2 => COLOR_GREEN,
|
||||||
|
3 => 0xc084fc,
|
||||||
|
_ => COLOR_TEXT_MUTED,
|
||||||
|
};
|
||||||
|
let arm_color = if is_failsafe {
|
||||||
|
COLOR_RED
|
||||||
|
} else if is_armed {
|
||||||
|
COLOR_GREEN
|
||||||
|
} else {
|
||||||
|
COLOR_ORANGE
|
||||||
|
};
|
||||||
|
let arm_text = if is_failsafe {
|
||||||
|
"FAILSAFE (CH5: 172)"
|
||||||
|
} else if is_armed {
|
||||||
|
"ARMED (CH5: 1811)"
|
||||||
|
} else {
|
||||||
|
"SAFE (CH5: 172)"
|
||||||
|
};
|
||||||
|
let throttle_color = if gear == -1 {
|
||||||
|
COLOR_RED
|
||||||
|
} else if is_armed && gear > 0 {
|
||||||
|
COLOR_GREEN
|
||||||
|
} else {
|
||||||
|
COLOR_ORANGE
|
||||||
|
};
|
||||||
|
|
||||||
|
let rp2350_sync_text = if self.latest_g29.is_live() {
|
||||||
|
format!("RP2350 : {}", self.latest_g29.remote_source.wire_tag())
|
||||||
|
} else {
|
||||||
|
"RP2350 : hors ligne".to_string()
|
||||||
|
};
|
||||||
|
let rp2350_sync_color = if !self.latest_g29.is_live() {
|
||||||
|
COLOR_TEXT_MUTED
|
||||||
|
} else if self.latest_g29.remote_source == self.active_control_source {
|
||||||
|
COLOR_GREEN
|
||||||
|
} else {
|
||||||
|
COLOR_ORANGE
|
||||||
|
};
|
||||||
|
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_2()
|
||||||
|
.p_3()
|
||||||
|
.rounded_lg()
|
||||||
|
.bg(rgb(COLOR_BG_DARK))
|
||||||
|
.border_1()
|
||||||
|
.border_color(if is_online {
|
||||||
|
rgb(COLOR_BORDER_ACTIVE)
|
||||||
|
} else {
|
||||||
|
rgb(COLOR_BORDER_SUBTLE)
|
||||||
|
})
|
||||||
|
// En-tête du moniteur + sélecteur de vue (Auto / G29 / Steam)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_wrap()
|
||||||
|
.justify_between()
|
||||||
|
.items_center()
|
||||||
|
.gap_2()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.font_weight(gpui::FontWeight::BOLD)
|
||||||
|
.text_color(rgb(COLOR_CYAN))
|
||||||
|
.child(format!(
|
||||||
|
"📊 Moniteur Temps Réel — {}",
|
||||||
|
viewed_source.label()
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.gap_1()
|
||||||
|
.child(self.render_selectable_pill(
|
||||||
|
"pill_mon_auto",
|
||||||
|
"Auto (actif)",
|
||||||
|
self.monitor_source_override.is_none(),
|
||||||
|
cx.listener(|this, _, _, cx| {
|
||||||
|
this.monitor_source_override = None;
|
||||||
|
cx.notify();
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
.child(self.render_selectable_pill(
|
||||||
|
"pill_mon_g29",
|
||||||
|
"🏎️ G29",
|
||||||
|
self.monitor_source_override == Some(ControlSource::G29),
|
||||||
|
cx.listener(|this, _, _, cx| {
|
||||||
|
this.monitor_source_override = Some(ControlSource::G29);
|
||||||
|
cx.notify();
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
.child(self.render_selectable_pill(
|
||||||
|
"pill_mon_steam",
|
||||||
|
"🎮 Steam",
|
||||||
|
self.monitor_source_override
|
||||||
|
== Some(ControlSource::SteamController),
|
||||||
|
cx.listener(|this, _, _, cx| {
|
||||||
|
this.monitor_source_override =
|
||||||
|
Some(ControlSource::SteamController);
|
||||||
|
cx.notify();
|
||||||
|
}),
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
// Badges d'état (En ligne, Rapport, ARM/CH5, Sync RP2350)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_wrap()
|
||||||
|
.items_center()
|
||||||
|
.gap_2()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.px_2()
|
||||||
|
.py_0p5()
|
||||||
|
.rounded_md()
|
||||||
|
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||||||
|
.border_1()
|
||||||
|
.border_color(if is_online {
|
||||||
|
rgb(COLOR_GREEN)
|
||||||
|
} else {
|
||||||
|
rgb(COLOR_BORDER_SUBTLE)
|
||||||
|
})
|
||||||
|
.text_xs()
|
||||||
|
.font_weight(gpui::FontWeight::BOLD)
|
||||||
|
.text_color(if is_online {
|
||||||
|
rgb(COLOR_GREEN)
|
||||||
|
} else {
|
||||||
|
rgb(COLOR_TEXT_MUTED)
|
||||||
|
})
|
||||||
|
.child(if is_online {
|
||||||
|
"● CONNECTÉ"
|
||||||
|
} else {
|
||||||
|
"○ HORS LIGNE"
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.px_2()
|
||||||
|
.py_0p5()
|
||||||
|
.rounded_md()
|
||||||
|
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||||||
|
.border_1()
|
||||||
|
.border_color(rgb(gear_color))
|
||||||
|
.text_xs()
|
||||||
|
.font_weight(gpui::FontWeight::BOLD)
|
||||||
|
.text_color(rgb(gear_color))
|
||||||
|
.child(format!("BOÎTE [{}]", gear_lbl)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.px_2()
|
||||||
|
.py_0p5()
|
||||||
|
.rounded_md()
|
||||||
|
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||||||
|
.border_1()
|
||||||
|
.border_color(rgb(arm_color))
|
||||||
|
.text_xs()
|
||||||
|
.font_weight(gpui::FontWeight::BOLD)
|
||||||
|
.text_color(rgb(arm_color))
|
||||||
|
.child(arm_text),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.px_2()
|
||||||
|
.py_0p5()
|
||||||
|
.rounded_md()
|
||||||
|
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||||||
|
.border_1()
|
||||||
|
.border_color(rgb(rp2350_sync_color))
|
||||||
|
.text_xs()
|
||||||
|
.text_color(rgb(rp2350_sync_color))
|
||||||
|
.child(rp2350_sync_text),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
// Jauges axes temps réel (CH1..CH4)
|
||||||
|
.child(self.render_monitor_bipolar_bar(
|
||||||
|
"Direction (CH1)",
|
||||||
|
steer_pct,
|
||||||
|
steer_crsf,
|
||||||
|
COLOR_CYAN,
|
||||||
|
))
|
||||||
|
.child(self.render_monitor_progress_bar(
|
||||||
|
"Accélérateur (CH2)",
|
||||||
|
throttle_pct,
|
||||||
|
throttle_crsf,
|
||||||
|
throttle_color,
|
||||||
|
))
|
||||||
|
.child(self.render_monitor_progress_bar(
|
||||||
|
"Frein (CH3)",
|
||||||
|
brake_pct,
|
||||||
|
brake_crsf,
|
||||||
|
COLOR_RED,
|
||||||
|
))
|
||||||
|
.child(self.render_monitor_progress_bar(
|
||||||
|
"Embrayage (CH4)",
|
||||||
|
clutch_pct,
|
||||||
|
clutch_crsf,
|
||||||
|
COLOR_CYAN,
|
||||||
|
))
|
||||||
|
// Pied du moniteur : dernier bouton & détails liaison (sur 2 lignes pour éviter toute troncature)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_1()
|
||||||
|
.pt_1()
|
||||||
|
.border_t_1()
|
||||||
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||||||
|
.text_xs()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_color(rgb(COLOR_ORANGE))
|
||||||
|
.child(format!("🔘 Dernier bouton : {}", last_btn)),
|
||||||
|
)
|
||||||
|
.child(div().text_color(rgb(COLOR_TEXT_MUTED)).child(detail_line)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fn render_crsf_gauge(&self, label: &str, deg: f32, crsf: u16, max_deg: f32) -> impl IntoElement {
|
fn render_crsf_gauge(&self, label: &str, deg: f32, crsf: u16, max_deg: f32) -> impl IntoElement {
|
||||||
let norm = ((deg / max_deg) * 0.5 + 0.5).clamp(0.0, 1.0);
|
let norm = ((deg / max_deg) * 0.5 + 0.5).clamp(0.0, 1.0);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
mod config;
|
mod config;
|
||||||
|
mod controller;
|
||||||
mod dome_projection;
|
mod dome_projection;
|
||||||
mod dvr;
|
mod dvr;
|
||||||
mod engine;
|
mod engine;
|
||||||
|
|||||||
+14
-3
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::controller::ControlSource;
|
||||||
use crate::g29_bridge::G29State;
|
use crate::g29_bridge::G29State;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
@@ -516,12 +517,22 @@ impl OsdOverlay {
|
|||||||
let _ = write!(gear_buf, "[{}]", g29.gear_label());
|
let _ = write!(gear_buf, "[{}]", g29.gear_label());
|
||||||
Self::draw_text(rgba, width, height, 32, gear_y, gear_buf.as_str(), scale, gear_color);
|
Self::draw_text(rgba, width, height, 32, gear_y, gear_buf.as_str(), scale, gear_color);
|
||||||
|
|
||||||
|
let is_steam = g29.remote_source == ControlSource::SteamController;
|
||||||
let (arm_lbl, arm_color) = if !g29.is_live() || g29.failsafe {
|
let (arm_lbl, arm_color) = if !g29.is_live() || g29.failsafe {
|
||||||
("G29 FAIL", [255, 65, 65, 255])
|
(
|
||||||
|
if is_steam { "SC FAIL" } else { "G29 FAIL" },
|
||||||
|
[255, 65, 65, 255],
|
||||||
|
)
|
||||||
} else if g29.armed {
|
} else if g29.armed {
|
||||||
("ARMED", [90, 255, 120, 255])
|
(
|
||||||
|
if is_steam { "SC ARMED" } else { "ARMED" },
|
||||||
|
[90, 255, 120, 255],
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
("SAFE", [255, 180, 50, 255])
|
(
|
||||||
|
if is_steam { "SC SAFE" } else { "SAFE" },
|
||||||
|
[255, 180, 50, 255],
|
||||||
|
)
|
||||||
};
|
};
|
||||||
let arm_x = 32 + (4 * 6 * scale as i32);
|
let arm_x = 32 + (4 * 6 * scale as i32);
|
||||||
Self::draw_text(rgba, width, height, arm_x, gear_y, arm_lbl, scale, arm_color);
|
Self::draw_text(rgba, width, height, arm_x, gear_y, arm_lbl, scale, arm_color);
|
||||||
|
|||||||
Reference in new issue
Block a user