mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
feat(vr-ux,safety,perf): add VR quick menu, P0/P1 safety & perf fixes, unify on GPUI
This commit is contained in:
1 parent
c0bad51d3b
commit
0823a9e682
15 files changed
+1288
-3765
No files matched your search
Generated
+55
-1759
File diff suppressed because it is too large.
Load diff
+1
-2
@@ -2,14 +2,13 @@
|
|||||||
name = "steamframe-fpv"
|
name = "steamframe-fpv"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Application graphique et VR native Steam Frame (OpenXR + Vulkan + egui) pour Eachine Sphere Link (USB RNDIS) et Head-Tracking RadioMaster Nomad (ELRS Wi-Fi)"
|
description = "Application graphique et VR native Steam Frame (OpenXR + Vulkan + GPUI) pour Eachine Sphere Link (USB RNDIS) et Head-Tracking RadioMaster Nomad (ELRS Wi-Fi)"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
ash = "0.38"
|
ash = "0.38"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
clap = { version = "4.5", features = ["derive"] }
|
clap = { version = "4.5", features = ["derive"] }
|
||||||
eframe = { version = "0.29", default-features = true }
|
|
||||||
glam = "0.29"
|
glam = "0.29"
|
||||||
gpui = "0.2.2"
|
gpui = "0.2.2"
|
||||||
gstreamer = "0.23"
|
gstreamer = "0.23"
|
||||||
|
|||||||
@@ -33,12 +33,12 @@ Application graphique et VR native **Linux / SteamOS (ARM64 & x86_64)** en **Rus
|
|||||||
|
|
||||||
## Interfaces Graphiques & Mode CLI
|
## Interfaces Graphiques & Mode CLI
|
||||||
|
|
||||||
1. **GPUI (`--gui-engine gpui`, par défaut)** (`src/gui_gpui.rs`) : Interface GPU-accélérée organisée en 4 onglets :
|
1. **GPUI (Interface unique GPU-accélérée)** (`src/gui_gpui.rs`) : Interface GPU-accélérée organisée en 4 onglets :
|
||||||
- **`📹 Cockpit`** : Retour vidéo plein écran + bandeau HUD flottant activable/désactivable.
|
- **`📹 Cockpit`** : Retour vidéo plein écran + bandeau HUD flottant activable/désactivable.
|
||||||
- **`⚙️ Réglages`** : Configuration VRX/UVC, presets réseau Nomad, édition IP/Port, **Mock Manuel Pan/Tilt/Roll** (envoi unitaire ou continu 50 Hz), projection VR et DVR.
|
- **`⚙️ Réglages`** : Configuration VRX/UVC, presets réseau Nomad, édition IP/Port, **Mock Manuel Pan/Tilt/Roll** (envoi unitaire ou continu 50 Hz), projection VR & optique temps réel, vitesses CRSF et DVR.
|
||||||
- **`📊 Télémétrie`** : Jauges CRSF Pan/Tilt/Roll et métriques de vol/lien radio.
|
- **`📊 Télémétrie`** : Jauges CRSF Pan/Tilt/Roll et métriques de vol/lien radio.
|
||||||
- **`📜 Logs`** : Console filtrable (`Tous`, `Warn / Erreurs`, `Erreurs seules`) synchronisée sans verrou avec `steamframe_fpv.log`.
|
- **`📜 Logs`** : Console filtrable (`Tous`, `Warn / Erreurs`, `Erreurs seules`) synchronisée sans verrou avec `steamframe_fpv.log`.
|
||||||
2. **egui (`--gui-engine egui`)** (`src/gui.rs`) : Interface de contrôle classique complète (sliders optiques temps réel, simulation manuelle, sélecteurs UVC/RNDIS, journal diagnostic).
|
2. **Menu Rapide VR dans le casque (OpenXR)** : Ouverture via `Options`/`L3` (G29) ou `View`/`Select` (Steam Controller), navigable au `D-Pad` sans quitter l'immersion VR (Source, Tare HT, Suivi tête, OSD, Projection, Distance écran, `k1`, FOV, DVR, 3e vitesse, Vibrations).
|
||||||
3. **Mode Ligne de Commande (`--no-gui`)** : Exécution sans fenêtre graphique pour bancs de test ou usage embarqué.
|
3. **Mode Ligne de Commande (`--no-gui`)** : Exécution sans fenêtre graphique pour bancs de test ou usage embarqué.
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -95,7 +95,6 @@ Le script [launch.sh](launch.sh) prépare `libxkbcommon-x11.so` si besoin, compi
|
|||||||
|
|
||||||
| Option | Défaut | Description |
|
| Option | Défaut | Description |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `--gui-engine` | `gpui` | Moteur IHM : `gpui` ou `egui` |
|
|
||||||
| `--no-gui` | `false` | Lance uniquement le moteur sans IHM |
|
| `--no-gui` | `false` | Lance uniquement le moteur sans IHM |
|
||||||
| `--headless` | `false` | Désactive OpenXR (mode Bureau / test) |
|
| `--headless` | `false` | Désactive OpenXR (mode Bureau / test) |
|
||||||
| `--usb-video-mode` | `rndis` | Acquisition vidéo : `rndis` ou `uvc` |
|
| `--usb-video-mode` | `rndis` | Acquisition vidéo : `rndis` ou `uvc` |
|
||||||
|
|||||||
@@ -140,10 +140,6 @@ pub struct AppConfig {
|
|||||||
#[arg(long, default_value_t = false)]
|
#[arg(long, default_value_t = false)]
|
||||||
pub head_tracking_enabled: bool,
|
pub head_tracking_enabled: bool,
|
||||||
|
|
||||||
/// Moteur d'interface graphique : "gpui" (GPU-accéléré moderne Tailwind) ou "egui" (classique)
|
|
||||||
#[arg(long, default_value = "gpui")]
|
|
||||||
pub gui_engine: String,
|
|
||||||
|
|
||||||
/// Adresse IP du pont unifié G29/Radxa (192.168.1.1) ou du Backpack Wi-Fi Nomad (10.0.0.1)
|
/// Adresse IP du pont unifié G29/Radxa (192.168.1.1) ou du Backpack Wi-Fi Nomad (10.0.0.1)
|
||||||
#[arg(long, default_value = "192.168.1.1")]
|
#[arg(long, default_value = "192.168.1.1")]
|
||||||
pub nomad_ip: String,
|
pub nomad_ip: String,
|
||||||
|
|||||||
+74
-2
@@ -1492,6 +1492,35 @@ impl SteamControllerWorker {
|
|||||||
let mut last_haptics_tick = Instant::now() - Duration::from_millis(HAPTICS_INTERVAL_MS);
|
let mut last_haptics_tick = Instant::now() - Duration::from_millis(HAPTICS_INTERVAL_MS);
|
||||||
let mut rumble_is_zero = true;
|
let mut rumble_is_zero = true;
|
||||||
|
|
||||||
|
// Garde RAII garantissant l'envoi d'une trame neutre désarmée même en cas de panic! du worker.
|
||||||
|
struct DisarmOnDrop<'a> {
|
||||||
|
socket: &'a UdpSocket,
|
||||||
|
target: SocketAddr,
|
||||||
|
active_source: &'a AtomicU8,
|
||||||
|
}
|
||||||
|
impl Drop for DisarmOnDrop<'_> {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
if ControlSource::from_u8(self.active_source.load(Ordering::Acquire))
|
||||||
|
== ControlSource::SteamController
|
||||||
|
{
|
||||||
|
let safe_frame = encode_rc_frame(
|
||||||
|
CRSF_CHANNEL_MID,
|
||||||
|
CRSF_CHANNEL_MID,
|
||||||
|
CRSF_CHANNEL_MID,
|
||||||
|
CRSF_CHANNEL_MID,
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
let _ = self.socket.send_to(safe_frame.as_bytes(), self.target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let _disarm_guard = DisarmOnDrop {
|
||||||
|
socket: &socket,
|
||||||
|
target,
|
||||||
|
active_source: &active_source,
|
||||||
|
};
|
||||||
|
|
||||||
// Synchronisation initiale de la source souhaitée et des vitesses auprès de la RP2350
|
// Synchronisation initiale de la source souhaitée et des vitesses auprès de la RP2350
|
||||||
let init_cmd = encode_src_command(last_source);
|
let init_cmd = encode_src_command(last_source);
|
||||||
let _ = socket.send_to(init_cmd.as_bytes(), target);
|
let _ = socket.send_to(init_cmd.as_bytes(), target);
|
||||||
@@ -1596,6 +1625,26 @@ impl SteamControllerWorker {
|
|||||||
gamepad = None;
|
gamepad = None;
|
||||||
haptics.reset();
|
haptics.reset();
|
||||||
rumble_is_zero = true;
|
rumble_is_zero = true;
|
||||||
|
|
||||||
|
// Sécurité critique (< 5 ms) : envoyer immédiatement 3 trames désarmées avant même
|
||||||
|
// l'expiration du watchdog 400 ms sur la RP2350.
|
||||||
|
if desired_source == ControlSource::SteamController {
|
||||||
|
let safe_frame = encode_rc_frame(
|
||||||
|
CRSF_CHANNEL_MID,
|
||||||
|
CRSF_CHANNEL_MID,
|
||||||
|
CRSF_CHANNEL_MID,
|
||||||
|
CRSF_CHANNEL_MID,
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
for i in 0..3 {
|
||||||
|
let _ = socket.send_to(safe_frame.as_bytes(), target);
|
||||||
|
if i < 2 {
|
||||||
|
thread::sleep(Duration::from_millis(2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut st = state.lock();
|
let mut st = state.lock();
|
||||||
st.connected = false;
|
st.connected = false;
|
||||||
st.armed = false;
|
st.armed = false;
|
||||||
@@ -1864,12 +1913,35 @@ impl SteamControllerWorker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Actions Cockpit (identiques au mapping G29)
|
// Actions Cockpit & Menu Rapide VR (identiques au mapping G29)
|
||||||
|
BTN_SELECT => {
|
||||||
|
let open = control.toggle_vr_menu();
|
||||||
|
st.set_toast(if open { "MENU VR ON" } else { "MENU VR OFF" });
|
||||||
|
}
|
||||||
|
BTN_SOUTH if control.is_vr_menu_open() => {
|
||||||
|
control.vr_menu_activate();
|
||||||
|
}
|
||||||
|
BTN_EAST if control.is_vr_menu_open() => {
|
||||||
|
control.close_vr_menu();
|
||||||
|
st.set_toast("MENU VR OFF");
|
||||||
|
}
|
||||||
|
BTN_DPAD_UP if control.is_vr_menu_open() => {
|
||||||
|
control.vr_menu_move(-1);
|
||||||
|
}
|
||||||
|
BTN_DPAD_DOWN if control.is_vr_menu_open() => {
|
||||||
|
control.vr_menu_move(1);
|
||||||
|
}
|
||||||
|
BTN_DPAD_LEFT if control.is_vr_menu_open() => {
|
||||||
|
control.vr_menu_adjust(-1);
|
||||||
|
}
|
||||||
|
BTN_DPAD_RIGHT if control.is_vr_menu_open() => {
|
||||||
|
control.vr_menu_adjust(1);
|
||||||
|
}
|
||||||
BTN_SOUTH | BTN_THUMBR | BTN_MODE => {
|
BTN_SOUTH | BTN_THUMBR | BTN_MODE => {
|
||||||
control.request_recenter();
|
control.request_recenter();
|
||||||
st.set_toast("TARE HT OK");
|
st.set_toast("TARE HT OK");
|
||||||
}
|
}
|
||||||
BTN_EAST | BTN_SELECT => {
|
BTN_EAST => {
|
||||||
let now_rec = control.toggle_dvr();
|
let now_rec = control.toggle_dvr();
|
||||||
st.set_toast(if now_rec { "DVR REC" } else { "DVR STOP" });
|
st.set_toast(if now_rec { "DVR REC" } else { "DVR STOP" });
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-4
@@ -101,13 +101,26 @@ impl DomeWarpLut {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SAFETY: `align_to` / `align_to_mut` découpent proprement les tranches d'octets en préfixe, tranche alignée `u32` et suffixe.
|
||||||
let (src_head, src_u32, src_tail) = unsafe { input_rgba[..expected_bytes].align_to::<u32>() };
|
let (src_head, src_u32, src_tail) = unsafe { input_rgba[..expected_bytes].align_to::<u32>() };
|
||||||
let (dst_head, dst_u32, dst_tail) = unsafe { output_rgba[..expected_bytes].align_to_mut::<u32>() };
|
let (dst_head, dst_u32, dst_tail) = unsafe { output_rgba[..expected_bytes].align_to_mut::<u32>() };
|
||||||
|
|
||||||
if src_head.is_empty() && src_tail.is_empty() && dst_head.is_empty() && dst_tail.is_empty() {
|
if src_head.is_empty()
|
||||||
// Chemin ultra-rapide 32-bit (1 instruction CPU de copie par pixel RGBA)
|
&& src_tail.is_empty()
|
||||||
for (dst, &src_idx) in dst_u32.iter_mut().zip(self.src_pixel_offsets.iter()) {
|
&& dst_head.is_empty()
|
||||||
*dst = src_u32[src_idx as usize];
|
&& dst_tail.is_empty()
|
||||||
|
&& src_u32.len() >= total_pixels
|
||||||
|
&& dst_u32.len() >= total_pixels
|
||||||
|
{
|
||||||
|
// Chemin ultra-rapide 32-bit sans bounds-check par pixel :
|
||||||
|
// `DomeWarpLut::new` garantit que tout offset de `src_pixel_offsets` est < `width * height == total_pixels <= src_u32.len()`.
|
||||||
|
for (dst, &src_idx) in dst_u32[..total_pixels]
|
||||||
|
.iter_mut()
|
||||||
|
.zip(self.src_pixel_offsets.iter())
|
||||||
|
{
|
||||||
|
debug_assert!((src_idx as usize) < src_u32.len());
|
||||||
|
// SAFETY: `src_idx < total_pixels <= src_u32.len()` est invariant par construction de `DomeWarpLut::new`.
|
||||||
|
*dst = unsafe { *src_u32.get_unchecked(src_idx as usize) };
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Repli sécurisé si les tampons ne sont pas alignés sur 32-bit
|
// Repli sécurisé si les tampons ne sont pas alignés sur 32-bit
|
||||||
|
|||||||
+9
-4
@@ -9,7 +9,8 @@ use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
/// Format de conteneur d'enregistrement DVR
|
/// Plafond mémoire de la file `appsrc` DVR (32 Mo) pour empêcher tout OOM si le stockage ralentit.
|
||||||
|
const DVR_MAX_QUEUE_BYTES: u64 = 32 * 1024 * 1024;
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum DvrContainer {
|
pub enum DvrContainer {
|
||||||
Mkv,
|
Mkv,
|
||||||
@@ -104,7 +105,7 @@ impl DvrRecorder {
|
|||||||
let muxer = container.muxer_element();
|
let muxer = container.muxer_element();
|
||||||
|
|
||||||
let pipeline_str = format!(
|
let pipeline_str = format!(
|
||||||
"appsrc name=dvr_src is-live=true format=time do-timestamp=true caps={caps} ! \
|
"appsrc name=dvr_src is-live=true format=time do-timestamp=true max-bytes={DVR_MAX_QUEUE_BYTES} caps={caps} ! \
|
||||||
{parser} config-interval=-1 ! \
|
{parser} config-interval=-1 ! \
|
||||||
{muxer} ! \
|
{muxer} ! \
|
||||||
filesink name=dvr_sink sync=false"
|
filesink name=dvr_sink sync=false"
|
||||||
@@ -135,7 +136,7 @@ impl DvrRecorder {
|
|||||||
let muxer = container.muxer_element();
|
let muxer = container.muxer_element();
|
||||||
|
|
||||||
let pipeline_str = format!(
|
let pipeline_str = format!(
|
||||||
"appsrc name=dvr_src is-live=true format=time do-timestamp=true \
|
"appsrc name=dvr_src is-live=true format=time do-timestamp=true max-bytes={DVR_MAX_QUEUE_BYTES} \
|
||||||
caps=video/x-raw,format=RGBA,width={width},height={height},framerate=60/1 ! \
|
caps=video/x-raw,format=RGBA,width={width},height={height},framerate=60/1 ! \
|
||||||
videoconvert ! \
|
videoconvert ! \
|
||||||
x264enc tune=zerolatency speed-preset=ultrafast bitrate=8000 key-int-max=60 ! \
|
x264enc tune=zerolatency speed-preset=ultrafast bitrate=8000 key-int-max=60 ! \
|
||||||
@@ -236,11 +237,15 @@ impl DvrRecorder {
|
|||||||
self.is_recording.load(Ordering::Relaxed)
|
self.is_recording.load(Ordering::Relaxed)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pousse un buffer GStreamer existant (zéro-copie de pointeur GstBuffer)
|
/// Pousse un buffer GStreamer existant (zéro-copie de pointeur GstBuffer, avec garde-fou anti-OOM)
|
||||||
pub fn push_buffer(&self, buffer: gst::Buffer) {
|
pub fn push_buffer(&self, buffer: gst::Buffer) {
|
||||||
if !self.is_recording.load(Ordering::Relaxed) {
|
if !self.is_recording.load(Ordering::Relaxed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if self.appsrc.current_level_bytes() >= DVR_MAX_QUEUE_BYTES {
|
||||||
|
// File saturée (stockage lent) : abandonner la trame plutôt que saturer la RAM en vol.
|
||||||
|
return;
|
||||||
|
}
|
||||||
self.bytes_written
|
self.bytes_written
|
||||||
.fetch_add(buffer.size() as u64, Ordering::Relaxed);
|
.fetch_add(buffer.size() as u64, Ordering::Relaxed);
|
||||||
self.frames_recorded.fetch_add(1, Ordering::Relaxed);
|
self.frames_recorded.fetch_add(1, Ordering::Relaxed);
|
||||||
|
|||||||
+419
-173
@@ -7,7 +7,9 @@ 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};
|
||||||
use crate::nomad_elrs::{HeadPoseSample, NomadHeadTracker, NomadProtocol};
|
use crate::nomad_elrs::{HeadPoseSample, NomadHeadTracker, NomadProtocol};
|
||||||
use crate::telemetry_osd::{OsdOverlay, TelemetryReceiver, TelemetryState};
|
use crate::telemetry_osd::{
|
||||||
|
OsdOverlay, TelemetryReceiver, TelemetryState, VrMenuRenderData, VR_MENU_ITEM_COUNT,
|
||||||
|
};
|
||||||
use crate::video_usb::{UsbVideoReceiver, VideoLinkState};
|
use crate::video_usb::{UsbVideoReceiver, VideoLinkState};
|
||||||
use crate::vulkan_xr::VulkanXrContext;
|
use crate::vulkan_xr::VulkanXrContext;
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
@@ -46,6 +48,26 @@ pub struct DvrConfig {
|
|||||||
pub mode: DvrMode,
|
pub mode: DvrMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Default)]
|
||||||
|
struct VrMenuState {
|
||||||
|
open: bool,
|
||||||
|
selected_idx: usize,
|
||||||
|
feedback: Option<(&'static str, bool, Instant)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl VrMenuState {
|
||||||
|
fn set_feedback(&mut self, msg: &'static str, is_err: bool) {
|
||||||
|
self.feedback = Some((msg, is_err, Instant::now() + Duration::from_millis(2000)));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn active_feedback(&self) -> Option<(&'static str, bool)> {
|
||||||
|
match self.feedback {
|
||||||
|
Some((msg, is_err, until)) if Instant::now() < until => Some((msg, is_err)),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct RuntimeMonitor {
|
pub struct RuntimeMonitor {
|
||||||
pub usb_video_status: SubsystemStatus,
|
pub usb_video_status: SubsystemStatus,
|
||||||
pub openxr_status: SubsystemStatus,
|
pub openxr_status: SubsystemStatus,
|
||||||
@@ -128,6 +150,8 @@ pub struct EngineControlHandle {
|
|||||||
dvr_config: Arc<Mutex<DvrConfig>>,
|
dvr_config: Arc<Mutex<DvrConfig>>,
|
||||||
dvr_recording_flag: Arc<AtomicBool>,
|
dvr_recording_flag: Arc<AtomicBool>,
|
||||||
head_trim_deg: Arc<Mutex<(f32, f32)>>,
|
head_trim_deg: Arc<Mutex<(f32, f32)>>,
|
||||||
|
preview_active_flag: Arc<AtomicBool>,
|
||||||
|
vr_menu_state: Arc<Mutex<VrMenuState>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EngineControlHandle {
|
impl EngineControlHandle {
|
||||||
@@ -285,6 +309,183 @@ impl EngineControlHandle {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Indique au moteur si l'aperçu vidéo GPUI (onglet Cockpit) consomme les frames.
|
||||||
|
pub fn set_preview_active(&self, active: bool) {
|
||||||
|
self.preview_active_flag.store(active, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_preview_active(&self) -> bool {
|
||||||
|
self.preview_active_flag.load(Ordering::Relaxed)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_vr_menu_open(&self) -> bool {
|
||||||
|
self.vr_menu_state.lock().open
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn toggle_vr_menu(&self) -> bool {
|
||||||
|
let mut st = self.vr_menu_state.lock();
|
||||||
|
st.open = !st.open;
|
||||||
|
if st.open {
|
||||||
|
st.feedback = None;
|
||||||
|
}
|
||||||
|
let open = st.open;
|
||||||
|
drop(st);
|
||||||
|
log::info!(
|
||||||
|
"[Menu VR] {}",
|
||||||
|
if open { "Ouvert dans le casque" } else { "Fermé" }
|
||||||
|
);
|
||||||
|
open
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn close_vr_menu(&self) {
|
||||||
|
let mut st = self.vr_menu_state.lock();
|
||||||
|
if st.open {
|
||||||
|
st.open = false;
|
||||||
|
log::info!("[Menu VR] Fermé");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn vr_menu_move(&self, delta: isize) {
|
||||||
|
let mut st = self.vr_menu_state.lock();
|
||||||
|
if !st.open {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let count = VR_MENU_ITEM_COUNT as isize;
|
||||||
|
let next = ((st.selected_idx as isize + delta).rem_euclid(count)) as usize;
|
||||||
|
st.selected_idx = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn vr_menu_activate(&self) {
|
||||||
|
self.vr_menu_adjust(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn vr_menu_adjust(&self, delta: i32) {
|
||||||
|
let idx = {
|
||||||
|
let st = self.vr_menu_state.lock();
|
||||||
|
if !st.open {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
st.selected_idx % VR_MENU_ITEM_COUNT
|
||||||
|
};
|
||||||
|
let step: i32 = if delta >= 0 { 1 } else { -1 };
|
||||||
|
|
||||||
|
match idx {
|
||||||
|
// 0: Source pilotage (G29 <-> Steam Controller)
|
||||||
|
0 => {
|
||||||
|
let target = match self.active_control_source() {
|
||||||
|
ControlSource::G29 => ControlSource::SteamController,
|
||||||
|
ControlSource::SteamController => ControlSource::G29,
|
||||||
|
};
|
||||||
|
match self.set_control_source(target) {
|
||||||
|
Ok(()) => self.vr_menu_state.lock().set_feedback("SOURCE CHANGEE", false),
|
||||||
|
Err(_) => self.vr_menu_state.lock().set_feedback("DESARMER D'ABORD!", true),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 1: Centrer Vue HT (Tare)
|
||||||
|
1 => {
|
||||||
|
self.request_recenter();
|
||||||
|
self.vr_menu_state.lock().set_feedback("TARE HT OK", false);
|
||||||
|
}
|
||||||
|
// 2: Suivi Tête ON/OFF
|
||||||
|
2 => {
|
||||||
|
let next = !self.head_tracking_enabled_flag.load(Ordering::Acquire);
|
||||||
|
self.set_head_tracking_enabled(next);
|
||||||
|
self.vr_menu_state
|
||||||
|
.lock()
|
||||||
|
.set_feedback(if next { "SUIVI HT: ON" } else { "SUIVI HT: OFF" }, false);
|
||||||
|
}
|
||||||
|
// 3: OSD Télémétrie ON/OFF
|
||||||
|
3 => {
|
||||||
|
let next = self.toggle_telemetry();
|
||||||
|
self.vr_menu_state
|
||||||
|
.lock()
|
||||||
|
.set_feedback(if next { "OSD: ON" } else { "OSD: OFF" }, false);
|
||||||
|
}
|
||||||
|
// 4: Mode Projection VR
|
||||||
|
4 => {
|
||||||
|
let mut opt = self.optical_params.lock();
|
||||||
|
opt.projection_mode = match (opt.projection_mode, step > 0) {
|
||||||
|
(ProjectionMode::Dome140, true) | (ProjectionMode::FlatQuad, false) => {
|
||||||
|
ProjectionMode::Cylinder140
|
||||||
|
}
|
||||||
|
(ProjectionMode::Cylinder140, true) | (ProjectionMode::Dome140, false) => {
|
||||||
|
ProjectionMode::FlatQuad
|
||||||
|
}
|
||||||
|
_ => ProjectionMode::Dome140,
|
||||||
|
};
|
||||||
|
let lbl = opt.projection_mode.label();
|
||||||
|
drop(opt);
|
||||||
|
log::info!("[Menu VR] Mode de projection VR : {}", lbl);
|
||||||
|
self.vr_menu_state.lock().set_feedback("PROJECTION MAJ", false);
|
||||||
|
}
|
||||||
|
// 5: Distance Écran Virtuel (0.8..=4.0 m)
|
||||||
|
5 => {
|
||||||
|
let mut opt = self.optical_params.lock();
|
||||||
|
opt.screen_distance_m =
|
||||||
|
((opt.screen_distance_m + step as f32 * 0.2) * 10.0).round() / 10.0;
|
||||||
|
opt.screen_distance_m = opt.screen_distance_m.clamp(0.8, 4.0);
|
||||||
|
}
|
||||||
|
// 6: Correction optique k1 (-0.50..=0.50)
|
||||||
|
6 => {
|
||||||
|
let mut opt = self.optical_params.lock();
|
||||||
|
opt.lens_k1 = ((opt.lens_k1 + step as f32 * 0.02) * 100.0).round() / 100.0;
|
||||||
|
opt.lens_k1 = opt.lens_k1.clamp(-0.50, 0.50);
|
||||||
|
}
|
||||||
|
// 7: FOV Caméra (70..=180 deg)
|
||||||
|
7 => {
|
||||||
|
let mut opt = self.optical_params.lock();
|
||||||
|
opt.camera_fov_deg = (opt.camera_fov_deg + step as f32 * 5.0).clamp(70.0, 180.0);
|
||||||
|
}
|
||||||
|
// 8: Enregistreur DVR
|
||||||
|
8 => {
|
||||||
|
let rec = self.toggle_dvr();
|
||||||
|
self.vr_menu_state
|
||||||
|
.lock()
|
||||||
|
.set_feedback(if rec { "DVR DEMARRE" } else { "DVR ARRETE" }, false);
|
||||||
|
}
|
||||||
|
// 9: Plafond 3ème vitesse CRSF
|
||||||
|
9 => {
|
||||||
|
let mut limits = *self.gear_speed_limits.lock();
|
||||||
|
limits.forward_max[2] =
|
||||||
|
limits.forward_max[2].saturating_add_signed((step * 10) as i16);
|
||||||
|
self.set_gear_speed_limits(limits);
|
||||||
|
}
|
||||||
|
// 10: Vibrations Steam Controller (0..=100%)
|
||||||
|
_ => {
|
||||||
|
let cur = self.controller_vibration_pct.load(Ordering::Acquire) as i32;
|
||||||
|
let next = (cur + step * 10).clamp(0, 100) as u8;
|
||||||
|
self.set_controller_vibration_pct(next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn vr_menu_render_data(&self) -> Option<VrMenuRenderData> {
|
||||||
|
let st = self.vr_menu_state.lock();
|
||||||
|
if !st.open {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let selected_idx = st.selected_idx;
|
||||||
|
let feedback_msg = st.active_feedback();
|
||||||
|
drop(st);
|
||||||
|
|
||||||
|
let opt = self.optical_params.lock().clone();
|
||||||
|
let limits = *self.gear_speed_limits.lock();
|
||||||
|
Some(VrMenuRenderData {
|
||||||
|
selected_idx,
|
||||||
|
control_source: self.active_control_source(),
|
||||||
|
head_tracking_on: self.head_tracking_enabled_flag.load(Ordering::Relaxed),
|
||||||
|
telemetry_osd_on: self.telemetry_enabled_flag.load(Ordering::Relaxed),
|
||||||
|
projection_label: opt.projection_mode.label(),
|
||||||
|
screen_distance_m: opt.screen_distance_m,
|
||||||
|
lens_k1: opt.lens_k1,
|
||||||
|
camera_fov_deg: opt.camera_fov_deg,
|
||||||
|
dvr_recording: self.dvr_recording_flag.load(Ordering::Relaxed),
|
||||||
|
gear_3_max: limits.forward_max[2],
|
||||||
|
vibration_pct: self.controller_vibration_pct.load(Ordering::Relaxed).min(100),
|
||||||
|
feedback_msg,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FpvEngineController {
|
pub struct FpvEngineController {
|
||||||
@@ -302,6 +503,8 @@ pub struct FpvEngineController {
|
|||||||
controller_vibration_pct: Arc<AtomicU8>,
|
controller_vibration_pct: Arc<AtomicU8>,
|
||||||
controller_rumble_test: Arc<AtomicBool>,
|
controller_rumble_test: Arc<AtomicBool>,
|
||||||
gear_speed_limits: Arc<Mutex<GearSpeedLimits>>,
|
gear_speed_limits: Arc<Mutex<GearSpeedLimits>>,
|
||||||
|
preview_active_flag: Arc<AtomicBool>,
|
||||||
|
vr_menu_state: Arc<Mutex<VrMenuState>>,
|
||||||
worker_handle: Option<JoinHandle<()>>,
|
worker_handle: Option<JoinHandle<()>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,6 +539,8 @@ impl FpvEngineController {
|
|||||||
controller_vibration_pct: Arc::new(AtomicU8::new(100)),
|
controller_vibration_pct: Arc::new(AtomicU8::new(100)),
|
||||||
controller_rumble_test: Arc::new(AtomicBool::new(false)),
|
controller_rumble_test: Arc::new(AtomicBool::new(false)),
|
||||||
gear_speed_limits: Arc::new(Mutex::new(GearSpeedLimits::default())),
|
gear_speed_limits: Arc::new(Mutex::new(GearSpeedLimits::default())),
|
||||||
|
preview_active_flag: Arc::new(AtomicBool::new(true)),
|
||||||
|
vr_menu_state: Arc::new(Mutex::new(VrMenuState::default())),
|
||||||
worker_handle: None,
|
worker_handle: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -355,6 +560,8 @@ impl FpvEngineController {
|
|||||||
dvr_config: Arc::clone(&self.dvr_config),
|
dvr_config: Arc::clone(&self.dvr_config),
|
||||||
dvr_recording_flag: Arc::clone(&self.dvr_recording_flag),
|
dvr_recording_flag: Arc::clone(&self.dvr_recording_flag),
|
||||||
head_trim_deg: Arc::clone(&self.head_trim_deg),
|
head_trim_deg: Arc::clone(&self.head_trim_deg),
|
||||||
|
preview_active_flag: Arc::clone(&self.preview_active_flag),
|
||||||
|
vr_menu_state: Arc::clone(&self.vr_menu_state),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -464,6 +671,7 @@ impl FpvEngineController {
|
|||||||
|
|
||||||
let control_for_g29 = self.control_handle();
|
let control_for_g29 = self.control_handle();
|
||||||
let control_for_ctrl = self.control_handle();
|
let control_for_ctrl = self.control_handle();
|
||||||
|
let control_for_loop = 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);
|
||||||
@@ -492,6 +700,7 @@ impl FpvEngineController {
|
|||||||
head_trim_clone,
|
head_trim_clone,
|
||||||
control_for_g29,
|
control_for_g29,
|
||||||
control_for_ctrl,
|
control_for_ctrl,
|
||||||
|
control_for_loop,
|
||||||
stop_clone,
|
stop_clone,
|
||||||
recenter_clone,
|
recenter_clone,
|
||||||
telem_flag_clone,
|
telem_flag_clone,
|
||||||
@@ -727,11 +936,21 @@ fn handle_dvr_lifecycle(
|
|||||||
if let Some(rx) = video_rx {
|
if let Some(rx) = video_rx {
|
||||||
rx.set_dvr_sink(None);
|
rx.set_dvr_sink(None);
|
||||||
}
|
}
|
||||||
recorder.stop();
|
{
|
||||||
log::info!("[DVR] Enregistrement finalisé avec succès : {:?}", recorder.file_path());
|
let mut mon = monitor.lock();
|
||||||
let mut mon = monitor.lock();
|
mon.dvr_recording = false;
|
||||||
mon.dvr_recording = false;
|
mon.dvr_status = SubsystemStatus::Stopped;
|
||||||
mon.dvr_status = SubsystemStatus::Stopped;
|
}
|
||||||
|
// Détacher la finalisation EOS (jusqu'à 1.5s) pour ne jamais figer la boucle OpenXR VR.
|
||||||
|
let _ = thread::Builder::new()
|
||||||
|
.name("dvr-finalize".into())
|
||||||
|
.spawn(move || {
|
||||||
|
recorder.stop();
|
||||||
|
log::info!(
|
||||||
|
"[DVR] Enregistrement finalisé avec succès : {:?}",
|
||||||
|
recorder.file_path()
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -833,6 +1052,7 @@ fn run_engine_worker(
|
|||||||
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,
|
control_for_ctrl: EngineControlHandle,
|
||||||
|
control_for_loop: 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>,
|
||||||
@@ -969,6 +1189,7 @@ fn run_engine_worker(
|
|||||||
&dvr_rec_flag,
|
&dvr_rec_flag,
|
||||||
&head_trim_deg,
|
&head_trim_deg,
|
||||||
&mut active_dvr,
|
&mut active_dvr,
|
||||||
|
&control_for_loop,
|
||||||
&stop_flag,
|
&stop_flag,
|
||||||
&recenter_flag,
|
&recenter_flag,
|
||||||
&telem_enabled_flag,
|
&telem_enabled_flag,
|
||||||
@@ -1016,6 +1237,7 @@ fn run_engine_worker(
|
|||||||
&dvr_rec_flag,
|
&dvr_rec_flag,
|
||||||
&head_trim_deg,
|
&head_trim_deg,
|
||||||
&mut active_dvr,
|
&mut active_dvr,
|
||||||
|
&control_for_loop,
|
||||||
&stop_flag,
|
&stop_flag,
|
||||||
&recenter_flag,
|
&recenter_flag,
|
||||||
&telem_enabled_flag,
|
&telem_enabled_flag,
|
||||||
@@ -1040,6 +1262,140 @@ fn run_engine_worker(
|
|||||||
log::info!("[Moteur FPV] Tous les sous-systèmes ont été arrêtés.");
|
log::info!("[Moteur FPV] Tous les sous-systèmes ont été arrêtés.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
fn compose_and_publish_frame<'a>(
|
||||||
|
cfg: &AppConfig,
|
||||||
|
monitor: &Arc<Mutex<RuntimeMonitor>>,
|
||||||
|
control: &EngineControlHandle,
|
||||||
|
active_dvr: &Option<Arc<DvrRecorder>>,
|
||||||
|
video_rx_opt: Option<&UsbVideoReceiver>,
|
||||||
|
telem_rx_opt: &RetrySlot<TelemetryReceiver>,
|
||||||
|
shared_telem_state: &Arc<Mutex<TelemetryState>>,
|
||||||
|
g29_rx_opt: Option<&G29BridgeReceiver>,
|
||||||
|
ctrl_worker_opt: Option<&SteamControllerWorker>,
|
||||||
|
control_source_flag: &Arc<AtomicU8>,
|
||||||
|
dvr_rec_flag: &Arc<AtomicBool>,
|
||||||
|
telem_on: bool,
|
||||||
|
active_proj_label: &'static str,
|
||||||
|
current_pose: HeadPoseSample,
|
||||||
|
has_new_raw_frame: bool,
|
||||||
|
has_video_stream: bool,
|
||||||
|
last_frame_id: u64,
|
||||||
|
fps_counter: &mut u32,
|
||||||
|
fps_timer: &mut Instant,
|
||||||
|
last_preview_push: &mut Instant,
|
||||||
|
warped_rgba: &'a [u8],
|
||||||
|
composited_rgba: &'a mut Vec<u8>,
|
||||||
|
) -> &'a [u8] {
|
||||||
|
dvr_rec_flag.store(active_dvr.is_some(), Ordering::Release);
|
||||||
|
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
|
||||||
|
.inner
|
||||||
|
.as_ref()
|
||||||
|
.map(|t| t.state().lock().clone())
|
||||||
|
.unwrap_or_default();
|
||||||
|
if telem_snapshot.packets_received == 0 {
|
||||||
|
let g29_telem = shared_telem_state.lock();
|
||||||
|
if g29_telem.packets_received > 0 {
|
||||||
|
telem_snapshot = g29_telem.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let (dvr_rec, dvr_secs) = {
|
||||||
|
let mon = monitor.lock();
|
||||||
|
(mon.dvr_recording, mon.dvr_elapsed_secs)
|
||||||
|
};
|
||||||
|
|
||||||
|
let vr_menu_data = control.vr_menu_render_data();
|
||||||
|
let frame_slice: &[u8] = if telem_on || vr_menu_data.is_some() {
|
||||||
|
// Copier la trame vidéo dé-distordue propre avant incrustation OSD/Menu VR : zéro bavure à 90/120 Hz.
|
||||||
|
composited_rgba.copy_from_slice(warped_rgba);
|
||||||
|
if telem_on {
|
||||||
|
OsdOverlay::render(
|
||||||
|
composited_rgba,
|
||||||
|
cfg.video_width,
|
||||||
|
cfg.video_height,
|
||||||
|
&telem_snapshot,
|
||||||
|
&hud_ctrl_snapshot,
|
||||||
|
current_pose.pan_deg,
|
||||||
|
current_pose.tilt_deg,
|
||||||
|
current_pose.roll_deg,
|
||||||
|
cfg.max_pan_deg,
|
||||||
|
cfg.max_tilt_deg,
|
||||||
|
active_proj_label,
|
||||||
|
dvr_rec,
|
||||||
|
dvr_secs,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if let Some(ref menu) = vr_menu_data {
|
||||||
|
OsdOverlay::render_vr_menu(composited_rgba, cfg.video_width, cfg.video_height, menu);
|
||||||
|
}
|
||||||
|
composited_rgba.as_slice()
|
||||||
|
} else {
|
||||||
|
warped_rgba
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(ref dvr) = *active_dvr {
|
||||||
|
if dvr.mode() == DvrMode::CompositedOsd && has_new_raw_frame {
|
||||||
|
dvr.push_slice(frame_slice);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let push_preview = control.is_preview_active()
|
||||||
|
&& (has_new_raw_frame
|
||||||
|
|| vr_menu_data.is_some()
|
||||||
|
|| last_preview_push.elapsed() >= Duration::from_millis(33));
|
||||||
|
|
||||||
|
if push_preview || fps_timer.elapsed() >= Duration::from_secs(1) {
|
||||||
|
sync_video_status(cfg, video_rx_opt, monitor);
|
||||||
|
let preview_arc = if push_preview {
|
||||||
|
*last_preview_push = Instant::now();
|
||||||
|
Some(Arc::new(frame_slice.to_vec()))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
let mut mon = monitor.lock();
|
||||||
|
if fps_timer.elapsed() >= Duration::from_secs(1) {
|
||||||
|
if has_video_stream {
|
||||||
|
mon.video_fps = *fps_counter as f32 / fps_timer.elapsed().as_secs_f32();
|
||||||
|
} else {
|
||||||
|
mon.video_fps = 0.0;
|
||||||
|
}
|
||||||
|
*fps_counter = 0;
|
||||||
|
*fps_timer = Instant::now();
|
||||||
|
}
|
||||||
|
if current_pose.last_send_ok {
|
||||||
|
mon.nomad_wifi_status = SubsystemStatus::Running(format!(
|
||||||
|
"ON - Cible {}:{} ({} paquets)",
|
||||||
|
cfg.nomad_ip, cfg.nomad_port, current_pose.packets_sent
|
||||||
|
));
|
||||||
|
} else if current_pose.send_errors > 0 {
|
||||||
|
mon.nomad_wifi_status = SubsystemStatus::Error(format!(
|
||||||
|
"Erreur d'envoi UDP vers {}:{} ({} échecs)",
|
||||||
|
cfg.nomad_ip, cfg.nomad_port, current_pose.send_errors
|
||||||
|
));
|
||||||
|
}
|
||||||
|
mon.video_frames_total = last_frame_id;
|
||||||
|
mon.latest_head_pose = current_pose;
|
||||||
|
mon.latest_telemetry = telem_snapshot;
|
||||||
|
if let Some(arc) = preview_arc {
|
||||||
|
mon.preview_width = cfg.video_width;
|
||||||
|
mon.preview_height = cfg.video_height;
|
||||||
|
mon.preview_rgba = arc;
|
||||||
|
mon.preview_frame_seq = mon.preview_frame_seq.wrapping_add(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
frame_slice
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn try_run_openxr_session(
|
fn try_run_openxr_session(
|
||||||
cfg: &AppConfig,
|
cfg: &AppConfig,
|
||||||
@@ -1050,6 +1406,7 @@ fn try_run_openxr_session(
|
|||||||
dvr_rec_flag: &Arc<AtomicBool>,
|
dvr_rec_flag: &Arc<AtomicBool>,
|
||||||
head_trim_deg: &Arc<Mutex<(f32, f32)>>,
|
head_trim_deg: &Arc<Mutex<(f32, f32)>>,
|
||||||
active_dvr: &mut Option<Arc<DvrRecorder>>,
|
active_dvr: &mut Option<Arc<DvrRecorder>>,
|
||||||
|
control: &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>,
|
||||||
@@ -1146,7 +1503,9 @@ fn try_run_openxr_session(
|
|||||||
);
|
);
|
||||||
let mut raw_frame_buf: Vec<u8> =
|
let mut raw_frame_buf: Vec<u8> =
|
||||||
Vec::with_capacity((cfg.video_width * cfg.video_height * 4) as usize);
|
Vec::with_capacity((cfg.video_width * cfg.video_height * 4) as usize);
|
||||||
|
let mut warped_rgba = vec![0u8; (cfg.video_width * cfg.video_height * 4) as usize];
|
||||||
let mut composited_rgba = vec![0u8; (cfg.video_width * cfg.video_height * 4) as usize];
|
let mut composited_rgba = vec![0u8; (cfg.video_width * cfg.video_height * 4) as usize];
|
||||||
|
let mut last_preview_push = Instant::now() - Duration::from_secs(1);
|
||||||
|
|
||||||
let session = vk_xr
|
let session = vk_xr
|
||||||
.session
|
.session
|
||||||
@@ -1370,17 +1729,17 @@ fn try_run_openxr_session(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if has_new_raw_frame {
|
if has_new_raw_frame {
|
||||||
dome_lut.apply(&raw_frame_buf, &mut composited_rgba);
|
dome_lut.apply(&raw_frame_buf, &mut warped_rgba);
|
||||||
} else if !has_video_stream {
|
} else if !has_video_stream {
|
||||||
standby_tick = standby_tick.wrapping_add(1);
|
standby_tick = standby_tick.wrapping_add(1);
|
||||||
UsbVideoReceiver::render_standby_pattern(
|
UsbVideoReceiver::render_standby_pattern(
|
||||||
cfg.video_width,
|
cfg.video_width,
|
||||||
cfg.video_height,
|
cfg.video_height,
|
||||||
standby_tick,
|
standby_tick,
|
||||||
&mut composited_rgba,
|
&mut warped_rgba,
|
||||||
);
|
);
|
||||||
OsdOverlay::draw_text(
|
OsdOverlay::draw_text(
|
||||||
&mut composited_rgba,
|
&mut warped_rgba,
|
||||||
cfg.video_width,
|
cfg.video_width,
|
||||||
cfg.video_height,
|
cfg.video_height,
|
||||||
(cfg.video_width as i32 / 2) - 230,
|
(cfg.video_width as i32 / 2) - 230,
|
||||||
@@ -1391,90 +1750,32 @@ fn try_run_openxr_session(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
dvr_rec_flag.store(active_dvr.is_some(), Ordering::Release);
|
let upload_slice = compose_and_publish_frame(
|
||||||
let g29_snapshot = sync_g29_status(cfg, g29_rx_opt, monitor);
|
cfg,
|
||||||
let hud_ctrl_snapshot = sync_controller_status(
|
|
||||||
control_source_flag,
|
|
||||||
ctrl_worker_opt,
|
|
||||||
&g29_snapshot,
|
|
||||||
monitor,
|
monitor,
|
||||||
|
control,
|
||||||
|
active_dvr,
|
||||||
|
video_rx_opt,
|
||||||
|
telem_rx_opt,
|
||||||
|
shared_telem_state,
|
||||||
|
g29_rx_opt,
|
||||||
|
ctrl_worker_opt,
|
||||||
|
control_source_flag,
|
||||||
|
dvr_rec_flag,
|
||||||
|
telem_on,
|
||||||
|
active_proj.label(),
|
||||||
|
current_pose,
|
||||||
|
has_new_raw_frame,
|
||||||
|
has_video_stream,
|
||||||
|
last_frame_id,
|
||||||
|
&mut fps_counter,
|
||||||
|
&mut fps_timer,
|
||||||
|
&mut last_preview_push,
|
||||||
|
&warped_rgba,
|
||||||
|
&mut composited_rgba,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut telem_snapshot = telem_rx_opt
|
vk_xr.upload_rgba_to_swapchain(upload_slice)?;
|
||||||
.inner
|
|
||||||
.as_ref()
|
|
||||||
.map(|t| t.state().lock().clone())
|
|
||||||
.unwrap_or_default();
|
|
||||||
if telem_snapshot.packets_received == 0 {
|
|
||||||
let g29_telem = shared_telem_state.lock();
|
|
||||||
if g29_telem.packets_received > 0 {
|
|
||||||
telem_snapshot = g29_telem.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let (dvr_rec, dvr_secs) = {
|
|
||||||
let mon = monitor.lock();
|
|
||||||
(mon.dvr_recording, mon.dvr_elapsed_secs)
|
|
||||||
};
|
|
||||||
|
|
||||||
if telem_on {
|
|
||||||
OsdOverlay::render(
|
|
||||||
&mut composited_rgba,
|
|
||||||
cfg.video_width,
|
|
||||||
cfg.video_height,
|
|
||||||
&telem_snapshot,
|
|
||||||
&hud_ctrl_snapshot,
|
|
||||||
current_pose.pan_deg,
|
|
||||||
current_pose.tilt_deg,
|
|
||||||
current_pose.roll_deg,
|
|
||||||
cfg.max_pan_deg,
|
|
||||||
cfg.max_tilt_deg,
|
|
||||||
active_proj.label(),
|
|
||||||
dvr_rec,
|
|
||||||
dvr_secs,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(ref dvr) = *active_dvr {
|
|
||||||
if dvr.mode() == DvrMode::CompositedOsd && has_new_raw_frame {
|
|
||||||
dvr.push_slice(&composited_rgba);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vk_xr.upload_rgba_to_swapchain(&composited_rgba)?;
|
|
||||||
|
|
||||||
if standby_tick % 2 == 0 || last_frame_id % 2 == 0 {
|
|
||||||
sync_video_status(cfg, video_rx_opt, monitor);
|
|
||||||
let preview_arc = Arc::new(composited_rgba.clone());
|
|
||||||
let mut mon = monitor.lock();
|
|
||||||
if fps_timer.elapsed() >= Duration::from_secs(1) {
|
|
||||||
if has_video_stream {
|
|
||||||
mon.video_fps = fps_counter as f32 / fps_timer.elapsed().as_secs_f32();
|
|
||||||
} else {
|
|
||||||
mon.video_fps = 0.0;
|
|
||||||
}
|
|
||||||
fps_counter = 0;
|
|
||||||
fps_timer = Instant::now();
|
|
||||||
}
|
|
||||||
if current_pose.last_send_ok {
|
|
||||||
mon.nomad_wifi_status = SubsystemStatus::Running(format!(
|
|
||||||
"ON - Cible {}:{} ({} paquets)",
|
|
||||||
cfg.nomad_ip, cfg.nomad_port, current_pose.packets_sent
|
|
||||||
));
|
|
||||||
} else if current_pose.send_errors > 0 {
|
|
||||||
mon.nomad_wifi_status = SubsystemStatus::Error(format!(
|
|
||||||
"Erreur d'envoi UDP vers {}:{} ({} échecs)",
|
|
||||||
cfg.nomad_ip, cfg.nomad_port, current_pose.send_errors
|
|
||||||
));
|
|
||||||
}
|
|
||||||
mon.video_frames_total = last_frame_id;
|
|
||||||
mon.latest_head_pose = current_pose;
|
|
||||||
mon.latest_telemetry = telem_snapshot;
|
|
||||||
mon.preview_width = cfg.video_width;
|
|
||||||
mon.preview_height = cfg.video_height;
|
|
||||||
mon.preview_rgba = preview_arc;
|
|
||||||
mon.preview_frame_seq = mon.preview_frame_seq.wrapping_add(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
let swapchain_ref = vk_xr
|
let swapchain_ref = vk_xr
|
||||||
.swapchain
|
.swapchain
|
||||||
@@ -1589,6 +1890,7 @@ fn run_desktop_fallback_loop(
|
|||||||
dvr_rec_flag: &Arc<AtomicBool>,
|
dvr_rec_flag: &Arc<AtomicBool>,
|
||||||
head_trim_deg: &Arc<Mutex<(f32, f32)>>,
|
head_trim_deg: &Arc<Mutex<(f32, f32)>>,
|
||||||
active_dvr: &mut Option<Arc<DvrRecorder>>,
|
active_dvr: &mut Option<Arc<DvrRecorder>>,
|
||||||
|
control: &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>,
|
||||||
@@ -1610,7 +1912,9 @@ fn run_desktop_fallback_loop(
|
|||||||
);
|
);
|
||||||
let mut raw_frame_buf: Vec<u8> =
|
let mut raw_frame_buf: Vec<u8> =
|
||||||
Vec::with_capacity((cfg.video_width * cfg.video_height * 4) as usize);
|
Vec::with_capacity((cfg.video_width * cfg.video_height * 4) as usize);
|
||||||
|
let mut warped_rgba = vec![0u8; (cfg.video_width * cfg.video_height * 4) as usize];
|
||||||
let mut composited_rgba = vec![0u8; (cfg.video_width * cfg.video_height * 4) as usize];
|
let mut composited_rgba = vec![0u8; (cfg.video_width * cfg.video_height * 4) as usize];
|
||||||
|
let mut last_preview_push = Instant::now() - Duration::from_secs(1);
|
||||||
let mut standby_tick: u32 = 0;
|
let mut standby_tick: u32 = 0;
|
||||||
let mut last_frame_id: u64 = 0;
|
let mut last_frame_id: u64 = 0;
|
||||||
let mut fps_counter: u32 = 0;
|
let mut fps_counter: u32 = 0;
|
||||||
@@ -1700,17 +2004,17 @@ fn run_desktop_fallback_loop(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if has_new_raw_frame {
|
if has_new_raw_frame {
|
||||||
dome_lut.apply(&raw_frame_buf, &mut composited_rgba);
|
dome_lut.apply(&raw_frame_buf, &mut warped_rgba);
|
||||||
} else if !has_video_stream {
|
} else if !has_video_stream {
|
||||||
standby_tick = standby_tick.wrapping_add(1);
|
standby_tick = standby_tick.wrapping_add(1);
|
||||||
UsbVideoReceiver::render_standby_pattern(
|
UsbVideoReceiver::render_standby_pattern(
|
||||||
cfg.video_width,
|
cfg.video_width,
|
||||||
cfg.video_height,
|
cfg.video_height,
|
||||||
standby_tick,
|
standby_tick,
|
||||||
&mut composited_rgba,
|
&mut warped_rgba,
|
||||||
);
|
);
|
||||||
OsdOverlay::draw_text(
|
OsdOverlay::draw_text(
|
||||||
&mut composited_rgba,
|
&mut warped_rgba,
|
||||||
cfg.video_width,
|
cfg.video_width,
|
||||||
cfg.video_height,
|
cfg.video_height,
|
||||||
(cfg.video_width as i32 / 2) - 230,
|
(cfg.video_width as i32 / 2) - 230,
|
||||||
@@ -1721,89 +2025,31 @@ fn run_desktop_fallback_loop(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
dvr_rec_flag.store(active_dvr.is_some(), Ordering::Release);
|
let _ = compose_and_publish_frame(
|
||||||
let g29_snapshot = sync_g29_status(cfg, g29_rx_opt, monitor);
|
cfg,
|
||||||
let hud_ctrl_snapshot = sync_controller_status(
|
|
||||||
control_source_flag,
|
|
||||||
ctrl_worker_opt,
|
|
||||||
&g29_snapshot,
|
|
||||||
monitor,
|
monitor,
|
||||||
|
control,
|
||||||
|
active_dvr,
|
||||||
|
video_rx_opt,
|
||||||
|
telem_rx_opt,
|
||||||
|
shared_telem_state,
|
||||||
|
g29_rx_opt,
|
||||||
|
ctrl_worker_opt,
|
||||||
|
control_source_flag,
|
||||||
|
dvr_rec_flag,
|
||||||
|
telem_on,
|
||||||
|
active_proj.label(),
|
||||||
|
current_pose,
|
||||||
|
has_new_raw_frame,
|
||||||
|
has_video_stream,
|
||||||
|
last_frame_id,
|
||||||
|
&mut fps_counter,
|
||||||
|
&mut fps_timer,
|
||||||
|
&mut last_preview_push,
|
||||||
|
&warped_rgba,
|
||||||
|
&mut composited_rgba,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut telem_snapshot = telem_rx_opt
|
|
||||||
.inner
|
|
||||||
.as_ref()
|
|
||||||
.map(|t| t.state().lock().clone())
|
|
||||||
.unwrap_or_default();
|
|
||||||
if telem_snapshot.packets_received == 0 {
|
|
||||||
let g29_telem = shared_telem_state.lock();
|
|
||||||
if g29_telem.packets_received > 0 {
|
|
||||||
telem_snapshot = g29_telem.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let (dvr_rec, dvr_secs) = {
|
|
||||||
let mon = monitor.lock();
|
|
||||||
(mon.dvr_recording, mon.dvr_elapsed_secs)
|
|
||||||
};
|
|
||||||
|
|
||||||
if telem_on {
|
|
||||||
OsdOverlay::render(
|
|
||||||
&mut composited_rgba,
|
|
||||||
cfg.video_width,
|
|
||||||
cfg.video_height,
|
|
||||||
&telem_snapshot,
|
|
||||||
&hud_ctrl_snapshot,
|
|
||||||
current_pose.pan_deg,
|
|
||||||
current_pose.tilt_deg,
|
|
||||||
current_pose.roll_deg,
|
|
||||||
cfg.max_pan_deg,
|
|
||||||
cfg.max_tilt_deg,
|
|
||||||
active_proj.label(),
|
|
||||||
dvr_rec,
|
|
||||||
dvr_secs,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(ref dvr) = *active_dvr {
|
|
||||||
if dvr.mode() == DvrMode::CompositedOsd && has_new_raw_frame {
|
|
||||||
dvr.push_slice(&composited_rgba);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sync_video_status(cfg, video_rx_opt, monitor);
|
|
||||||
let preview_arc = Arc::new(composited_rgba.clone());
|
|
||||||
{
|
|
||||||
let mut mon = monitor.lock();
|
|
||||||
if fps_timer.elapsed() >= Duration::from_secs(1) {
|
|
||||||
if has_video_stream {
|
|
||||||
mon.video_fps = fps_counter as f32 / fps_timer.elapsed().as_secs_f32();
|
|
||||||
} else {
|
|
||||||
mon.video_fps = 0.0;
|
|
||||||
}
|
|
||||||
fps_counter = 0;
|
|
||||||
fps_timer = Instant::now();
|
|
||||||
}
|
|
||||||
if current_pose.last_send_ok {
|
|
||||||
mon.nomad_wifi_status = SubsystemStatus::Running(format!(
|
|
||||||
"ON - Cible {}:{} ({} paquets)",
|
|
||||||
cfg.nomad_ip, cfg.nomad_port, current_pose.packets_sent
|
|
||||||
));
|
|
||||||
} else if current_pose.send_errors > 0 {
|
|
||||||
mon.nomad_wifi_status = SubsystemStatus::Error(format!(
|
|
||||||
"Erreur d'envoi UDP vers {}:{} ({} échecs)",
|
|
||||||
cfg.nomad_ip, cfg.nomad_port, current_pose.send_errors
|
|
||||||
));
|
|
||||||
}
|
|
||||||
mon.video_frames_total = last_frame_id;
|
|
||||||
mon.latest_head_pose = current_pose;
|
|
||||||
mon.latest_telemetry = telem_snapshot;
|
|
||||||
mon.preview_width = cfg.video_width;
|
|
||||||
mon.preview_height = cfg.video_height;
|
|
||||||
mon.preview_rgba = preview_arc;
|
|
||||||
mon.preview_frame_seq = mon.preview_frame_seq.wrapping_add(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
let elapsed = loop_start.elapsed();
|
let elapsed = loop_start.elapsed();
|
||||||
let target_dt = Duration::from_millis(16);
|
let target_dt = Duration::from_millis(16);
|
||||||
if elapsed < target_dt {
|
if elapsed < target_dt {
|
||||||
|
|||||||
+72
-1
@@ -399,7 +399,56 @@ impl G29BridgeReceiver {
|
|||||||
|
|
||||||
log::info!("[G29 Bridge] Bouton volant reçu : {:?}", btn);
|
log::info!("[G29 Bridge] Bouton volant reçu : {:?}", btn);
|
||||||
|
|
||||||
|
let menu_open = control.map(|c| c.is_vr_menu_open()).unwrap_or(false);
|
||||||
let toast = match btn {
|
let toast = match btn {
|
||||||
|
G29ButtonEvent::Options | G29ButtonEvent::L3 => {
|
||||||
|
if let Some(ctrl) = control {
|
||||||
|
let open = ctrl.toggle_vr_menu();
|
||||||
|
Some(if open {
|
||||||
|
"MENU VR ON".to_string()
|
||||||
|
} else {
|
||||||
|
"MENU VR OFF".to_string()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Some("MENU VR".to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
G29ButtonEvent::Cross if menu_open => {
|
||||||
|
if let Some(ctrl) = control {
|
||||||
|
ctrl.vr_menu_activate();
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
G29ButtonEvent::Circle if menu_open => {
|
||||||
|
if let Some(ctrl) = control {
|
||||||
|
ctrl.close_vr_menu();
|
||||||
|
}
|
||||||
|
Some("MENU VR OFF".to_string())
|
||||||
|
}
|
||||||
|
G29ButtonEvent::DpadUp if menu_open => {
|
||||||
|
if let Some(ctrl) = control {
|
||||||
|
ctrl.vr_menu_move(-1);
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
G29ButtonEvent::DpadDown if menu_open => {
|
||||||
|
if let Some(ctrl) = control {
|
||||||
|
ctrl.vr_menu_move(1);
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
G29ButtonEvent::DpadLeft if menu_open => {
|
||||||
|
if let Some(ctrl) = control {
|
||||||
|
ctrl.vr_menu_adjust(-1);
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
G29ButtonEvent::DpadRight if menu_open => {
|
||||||
|
if let Some(ctrl) = control {
|
||||||
|
ctrl.vr_menu_adjust(1);
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
G29ButtonEvent::Cross | G29ButtonEvent::Ps | G29ButtonEvent::R3 => {
|
G29ButtonEvent::Cross | G29ButtonEvent::Ps | G29ButtonEvent::R3 => {
|
||||||
if let Some(ctrl) = control {
|
if let Some(ctrl) = control {
|
||||||
ctrl.request_recenter();
|
ctrl.request_recenter();
|
||||||
@@ -462,7 +511,6 @@ impl G29BridgeReceiver {
|
|||||||
}
|
}
|
||||||
Some("PAN +1".to_string())
|
Some("PAN +1".to_string())
|
||||||
}
|
}
|
||||||
G29ButtonEvent::Options | G29ButtonEvent::L3 => None,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -595,4 +643,27 @@ mod tests {
|
|||||||
&[]
|
&[]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_vr_menu_g29_navigation() {
|
||||||
|
let engine = crate::engine::FpvEngineController::new(true, true);
|
||||||
|
let ctrl = engine.control_handle();
|
||||||
|
let state = Arc::new(Mutex::new(G29State::default()));
|
||||||
|
|
||||||
|
assert!(!ctrl.is_vr_menu_open());
|
||||||
|
G29BridgeReceiver::process_line("$G29_EVT,BTN=OPTIONS", &state, Some(&ctrl), None);
|
||||||
|
assert!(ctrl.is_vr_menu_open());
|
||||||
|
|
||||||
|
// Descendre 4 fois (0 -> 4 : PROJECTION VR) puis flèche droite (DOME 140 -> CYL 140)
|
||||||
|
for _ in 0..4 {
|
||||||
|
G29BridgeReceiver::process_line("$G29_EVT,BTN=DPAD_DOWN", &state, Some(&ctrl), None);
|
||||||
|
}
|
||||||
|
G29BridgeReceiver::process_line("$G29_EVT,BTN=DPAD_RIGHT", &state, Some(&ctrl), None);
|
||||||
|
let data = ctrl.vr_menu_render_data().unwrap();
|
||||||
|
assert_eq!(data.selected_idx, 4);
|
||||||
|
assert_eq!(data.projection_label, "CYL 140");
|
||||||
|
|
||||||
|
G29BridgeReceiver::process_line("$G29_EVT,BTN=CIRCLE", &state, Some(&ctrl), None);
|
||||||
|
assert!(!ctrl.is_vr_menu_open());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
-1717
File diff suppressed because it is too large.
Load diff
+184
-28
@@ -175,6 +175,8 @@ impl SteamFrameGpuiApp {
|
|||||||
/// Synchronise l'état IHM avec le moteur FPV en minimisant au maximum la contention des verrous
|
/// Synchronise l'état IHM avec le moteur FPV en minimisant au maximum la contention des verrous
|
||||||
fn sync_from_engine(&mut self, window: &mut Window) -> bool {
|
fn sync_from_engine(&mut self, window: &mut Window) -> bool {
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
|
self.controls
|
||||||
|
.set_preview_active(self.active_tab == ActiveTab::Cockpit);
|
||||||
|
|
||||||
// 1. Snapshot rapide avec maintien minimal du verrou monitor
|
// 1. Snapshot rapide avec maintien minimal du verrou monitor
|
||||||
let (preview_frame_seq, new_frame_data) = {
|
let (preview_frame_seq, new_frame_data) = {
|
||||||
@@ -273,11 +275,20 @@ impl SteamFrameGpuiApp {
|
|||||||
(mon.preview_frame_seq, frame_data)
|
(mon.preview_frame_seq, frame_data)
|
||||||
}; // Verrou `engine_monitor` immédiatement libéré !
|
}; // Verrou `engine_monitor` immédiatement libéré !
|
||||||
|
|
||||||
// 2. Conversion BGRA et allocation GPU hors du verrou monitor
|
// 2. Conversion BGRA vectorisable (u32) et allocation GPU hors du verrou monitor
|
||||||
if let Some((w, h, raw_arc)) = new_frame_data {
|
if let Some((w, h, raw_arc)) = new_frame_data {
|
||||||
let mut raw_buf = (*raw_arc).clone();
|
let mut raw_buf = (*raw_arc).clone();
|
||||||
for pixel in raw_buf.chunks_exact_mut(4) {
|
// SAFETY: `align_to_mut::<u32>` découpe proprement préfixe, tranche u32 alignée et suffixe.
|
||||||
pixel.swap(0, 2);
|
let (head, pixels_u32, tail) = unsafe { raw_buf.align_to_mut::<u32>() };
|
||||||
|
if head.is_empty() && tail.is_empty() {
|
||||||
|
for px in pixels_u32 {
|
||||||
|
let v = *px;
|
||||||
|
*px = (v & 0xFF00_FF00) | ((v & 0x00FF_0000) >> 16) | ((v & 0x0000_00FF) << 16);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for pixel in raw_buf.chunks_exact_mut(4) {
|
||||||
|
pixel.swap(0, 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let Some(img_buf) = RgbaImage::from_raw(w, h, raw_buf) {
|
if let Some(img_buf) = RgbaImage::from_raw(w, h, raw_buf) {
|
||||||
let frame = Frame::new(img_buf);
|
let frame = Frame::new(img_buf);
|
||||||
@@ -330,17 +341,19 @@ impl SteamFrameGpuiApp {
|
|||||||
.ok()
|
.ok()
|
||||||
.and_then(|p| p.parent().map(|d| d.join("scripts/setup_usb_rndis.sh")))
|
.and_then(|p| p.parent().map(|d| d.join("scripts/setup_usb_rndis.sh")))
|
||||||
.filter(|p| p.exists())
|
.filter(|p| p.exists())
|
||||||
.unwrap_or_else(|| {
|
.or_else(|| {
|
||||||
let candidate = std::path::PathBuf::from("scripts/setup_usb_rndis.sh");
|
let installed = std::path::PathBuf::from("/usr/share/steamframe-fpv/scripts/setup_usb_rndis.sh");
|
||||||
if candidate.exists() {
|
if installed.exists() {
|
||||||
candidate
|
Some(installed)
|
||||||
} else {
|
} else {
|
||||||
std::path::PathBuf::from(concat!(
|
let local = std::path::PathBuf::from("scripts/setup_usb_rndis.sh");
|
||||||
env!("CARGO_MANIFEST_DIR"),
|
local.exists().then_some(local)
|
||||||
"/scripts/setup_usb_rndis.sh"
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
let Some(script_path) = script_path else {
|
||||||
|
log::error!("[USB RNDIS] Script setup_usb_rndis.sh introuvable à côté du binaire ni dans /usr/share/steamframe-fpv/scripts.");
|
||||||
|
return;
|
||||||
|
};
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
match Command::new("bash").arg(&script_path).output() {
|
match Command::new("bash").arg(&script_path).output() {
|
||||||
Ok(out) => {
|
Ok(out) => {
|
||||||
@@ -358,7 +371,13 @@ impl SteamFrameGpuiApp {
|
|||||||
|
|
||||||
fn configure_radxa_ssh(&self) {
|
fn configure_radxa_ssh(&self) {
|
||||||
let ch = self.cfg.wifi_channel;
|
let ch = self.cfg.wifi_channel;
|
||||||
let ip = self.cfg.radxa_vrx_ip.clone();
|
let Ok(ip) = self.cfg.radxa_vrx_ip.trim().parse::<std::net::IpAddr>() else {
|
||||||
|
log::error!(
|
||||||
|
"[Radxa Zero 3W] Adresse IP invalide pour SSH : '{}'",
|
||||||
|
self.cfg.radxa_vrx_ip
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
};
|
||||||
log::info!(
|
log::info!(
|
||||||
"[Radxa Zero 3W] Configuration du canal 5.8GHz={} sur root@{}...",
|
"[Radxa Zero 3W] Configuration du canal 5.8GHz={} sur root@{}...",
|
||||||
ch,
|
ch,
|
||||||
@@ -371,10 +390,12 @@ impl SteamFrameGpuiApp {
|
|||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
match Command::new("ssh")
|
match Command::new("ssh")
|
||||||
.args([
|
.args([
|
||||||
|
"-o",
|
||||||
|
"BatchMode=yes",
|
||||||
"-o",
|
"-o",
|
||||||
"ConnectTimeout=2",
|
"ConnectTimeout=2",
|
||||||
"-o",
|
"-o",
|
||||||
"StrictHostKeyChecking=no",
|
"StrictHostKeyChecking=accept-new",
|
||||||
"--",
|
"--",
|
||||||
&format!("root@{}", ip),
|
&format!("root@{}", ip),
|
||||||
&remote_cmd,
|
&remote_cmd,
|
||||||
@@ -800,6 +821,20 @@ impl SteamFrameGpuiApp {
|
|||||||
rgb(COLOR_CYAN),
|
rgb(COLOR_CYAN),
|
||||||
)),
|
)),
|
||||||
)
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("btn_vr_menu_quick")
|
||||||
|
.cursor_pointer()
|
||||||
|
.on_click(cx.listener(|this, _, _, cx| {
|
||||||
|
this.controls.toggle_vr_menu();
|
||||||
|
cx.notify();
|
||||||
|
}))
|
||||||
|
.child(self.render_toggle_pill(
|
||||||
|
"📋 Menu VR",
|
||||||
|
self.controls.is_vr_menu_open(),
|
||||||
|
rgb(COLOR_ORANGE),
|
||||||
|
)),
|
||||||
|
)
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.id("btn_tare_quick")
|
.id("btn_tare_quick")
|
||||||
@@ -2094,24 +2129,66 @@ impl SteamFrameGpuiApp {
|
|||||||
}),
|
}),
|
||||||
)),
|
)),
|
||||||
))
|
))
|
||||||
// Lentille et FOV
|
// Champ de vision, Lentille k1/k2 et Distance virtuelle (réglables à chaud en VR)
|
||||||
.child(self.render_setting_row(
|
.child(self.render_setting_row(
|
||||||
"Champ de Vision & Optique",
|
"Optique & Écran VR (Réglage à chaud)",
|
||||||
div()
|
div()
|
||||||
.text_xs()
|
.flex()
|
||||||
.text_color(rgb(COLOR_TEXT_MAIN))
|
.flex_col()
|
||||||
.child(format!(
|
.gap_2()
|
||||||
"FOV : {}° | Lentille : k1={:.2}, k2={:.2}",
|
.p_2p5()
|
||||||
self.cfg.camera_fov_deg, self.cfg.lens_k1, self.cfg.lens_k2
|
.rounded_md()
|
||||||
|
.bg(rgb(COLOR_BG_DARK))
|
||||||
|
.border_1()
|
||||||
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||||||
|
.child(self.render_optical_stepper_row(
|
||||||
|
"opt_fov",
|
||||||
|
"FOV Caméra",
|
||||||
|
format!("{:.0}°", self.cfg.camera_fov_deg),
|
||||||
|
|cfg, step| {
|
||||||
|
cfg.camera_fov_deg =
|
||||||
|
(cfg.camera_fov_deg + step * 5.0).clamp(70.0, 180.0);
|
||||||
|
},
|
||||||
|
cx,
|
||||||
|
))
|
||||||
|
.child(self.render_optical_stepper_row(
|
||||||
|
"opt_k1",
|
||||||
|
"Distorsion k1",
|
||||||
|
format!("{:+.2}", self.cfg.lens_k1),
|
||||||
|
|cfg, step| {
|
||||||
|
cfg.lens_k1 = (((cfg.lens_k1 + step * 0.02) * 100.0)
|
||||||
|
.round()
|
||||||
|
/ 100.0)
|
||||||
|
.clamp(-0.50, 0.50);
|
||||||
|
},
|
||||||
|
cx,
|
||||||
|
))
|
||||||
|
.child(self.render_optical_stepper_row(
|
||||||
|
"opt_k2",
|
||||||
|
"Distorsion k2",
|
||||||
|
format!("{:+.2}", self.cfg.lens_k2),
|
||||||
|
|cfg, step| {
|
||||||
|
cfg.lens_k2 = (((cfg.lens_k2 + step * 0.01) * 100.0)
|
||||||
|
.round()
|
||||||
|
/ 100.0)
|
||||||
|
.clamp(-0.25, 0.25);
|
||||||
|
},
|
||||||
|
cx,
|
||||||
|
))
|
||||||
|
.child(self.render_optical_stepper_row(
|
||||||
|
"opt_dist",
|
||||||
|
"Distance Écran",
|
||||||
|
format!("{:.1} m", self.cfg.screen_distance_m),
|
||||||
|
|cfg, step| {
|
||||||
|
cfg.screen_distance_m = (((cfg.screen_distance_m
|
||||||
|
+ step * 0.2)
|
||||||
|
* 10.0)
|
||||||
|
.round()
|
||||||
|
/ 10.0)
|
||||||
|
.clamp(0.8, 4.0);
|
||||||
|
},
|
||||||
|
cx,
|
||||||
)),
|
)),
|
||||||
))
|
|
||||||
// Distance virtuelle
|
|
||||||
.child(self.render_setting_row(
|
|
||||||
"Distance Virtuelle Écran",
|
|
||||||
div()
|
|
||||||
.text_xs()
|
|
||||||
.text_color(rgb(COLOR_TEXT_MAIN))
|
|
||||||
.child(format!("{:.1} mètres", self.cfg.screen_distance_m)),
|
|
||||||
)),
|
)),
|
||||||
))
|
))
|
||||||
// 3.4 Carte Télémétrie OSD & MAVLink
|
// 3.4 Carte Télémétrie OSD & MAVLink
|
||||||
@@ -2425,6 +2502,85 @@ impl SteamFrameGpuiApp {
|
|||||||
self.controls.set_gear_speed_limits(def);
|
self.controls.set_gear_speed_limits(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn sync_optical_params(&self) {
|
||||||
|
self.controls.update_optical_params(LiveOpticalParams {
|
||||||
|
projection_mode: ProjectionMode::from_str(&self.cfg.projection_mode),
|
||||||
|
camera_fov_deg: self.cfg.camera_fov_deg,
|
||||||
|
lens_k1: self.cfg.lens_k1,
|
||||||
|
lens_k2: self.cfg.lens_k2,
|
||||||
|
screen_distance_m: self.cfg.screen_distance_m,
|
||||||
|
screen_width_m: self.cfg.screen_width_m,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_optical_stepper_row(
|
||||||
|
&self,
|
||||||
|
id_prefix: &'static str,
|
||||||
|
label: &'static str,
|
||||||
|
value_text: String,
|
||||||
|
mutator: fn(&mut AppConfig, f32),
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) -> impl IntoElement {
|
||||||
|
let step_btn = |suffix: &'static str, txt: &'static str, step: f32| {
|
||||||
|
let btn_id = gpui::SharedString::from(format!("btn_opt_{}_{}", id_prefix, suffix));
|
||||||
|
div()
|
||||||
|
.id(btn_id)
|
||||||
|
.px_2p5()
|
||||||
|
.py_1()
|
||||||
|
.rounded_md()
|
||||||
|
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||||||
|
.border_1()
|
||||||
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||||||
|
.text_xs()
|
||||||
|
.font_weight(gpui::FontWeight::BOLD)
|
||||||
|
.cursor_pointer()
|
||||||
|
.on_click(cx.listener(move |this, _, _, cx| {
|
||||||
|
mutator(&mut this.cfg, step);
|
||||||
|
this.sync_optical_params();
|
||||||
|
cx.notify();
|
||||||
|
}))
|
||||||
|
.child(txt)
|
||||||
|
};
|
||||||
|
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_wrap()
|
||||||
|
.items_center()
|
||||||
|
.justify_between()
|
||||||
|
.gap_2()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.text_color(rgb(COLOR_TEXT_MAIN))
|
||||||
|
.child(label),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.gap_1p5()
|
||||||
|
.child(step_btn("m2", "−−", -2.0))
|
||||||
|
.child(step_btn("m1", "−", -1.0))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.w(px(64.0))
|
||||||
|
.py_0p5()
|
||||||
|
.rounded_md()
|
||||||
|
.bg(rgb(COLOR_SURFACE_CARD))
|
||||||
|
.border_1()
|
||||||
|
.border_color(rgb(COLOR_CYAN))
|
||||||
|
.text_xs()
|
||||||
|
.font_weight(gpui::FontWeight::BOLD)
|
||||||
|
.text_color(rgb(COLOR_CYAN))
|
||||||
|
.flex()
|
||||||
|
.justify_center()
|
||||||
|
.child(value_text),
|
||||||
|
)
|
||||||
|
.child(step_btn("p1", "+", 1.0))
|
||||||
|
.child(step_btn("p2", "++", 2.0)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fn render_gear_stepper_row(
|
fn render_gear_stepper_row(
|
||||||
&self,
|
&self,
|
||||||
id_prefix: &'static str,
|
id_prefix: &'static str,
|
||||||
|
|||||||
+48
-22
@@ -2,10 +2,12 @@ use chrono::Local;
|
|||||||
use log::{Level, LevelFilter, Log, Metadata, Record};
|
use log::{Level, LevelFilter, Log, Metadata, Record};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::fs::{File, OpenOptions};
|
use std::fs::OpenOptions;
|
||||||
use std::io::{BufWriter, Write};
|
use std::io::{BufWriter, Write};
|
||||||
use std::sync::atomic::{AtomicU64, Ordering};
|
use std::sync::atomic::{AtomicU64, Ordering};
|
||||||
|
use std::sync::mpsc::{self, SyncSender};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::thread;
|
||||||
|
|
||||||
const MAX_LOG_ENTRIES: usize = 1000;
|
const MAX_LOG_ENTRIES: usize = 1000;
|
||||||
|
|
||||||
@@ -42,27 +44,55 @@ impl Default for LogBuffer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum FileLogCmd {
|
||||||
|
Line { text: String, flush: bool },
|
||||||
|
Flush,
|
||||||
|
}
|
||||||
|
|
||||||
/// Logger centralisé capturant tous les événements et erreurs pour l'interface graphique
|
/// Logger centralisé capturant tous les événements et erreurs pour l'interface graphique
|
||||||
/// et les enregistrant simultanément dans un fichier persistant sans réouverture synchrone.
|
/// et les enregistrant sur un thread I/O dédié sans jamais bloquer les boucles temps réel.
|
||||||
pub struct GuiLogger {
|
pub struct GuiLogger {
|
||||||
buffer: Arc<Mutex<LogBuffer>>,
|
buffer: Arc<Mutex<LogBuffer>>,
|
||||||
file_writer: Mutex<Option<BufWriter<File>>>,
|
file_tx: Option<SyncSender<FileLogCmd>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GuiLogger {
|
impl GuiLogger {
|
||||||
pub fn init(log_file_path: &str) -> Arc<Mutex<LogBuffer>> {
|
pub fn init(log_file_path: &str) -> Arc<Mutex<LogBuffer>> {
|
||||||
let buffer = Arc::new(Mutex::new(LogBuffer::default()));
|
let buffer = Arc::new(Mutex::new(LogBuffer::default()));
|
||||||
|
|
||||||
let file_writer = OpenOptions::new()
|
let file_tx = OpenOptions::new()
|
||||||
.create(true)
|
.create(true)
|
||||||
.append(true)
|
.append(true)
|
||||||
.open(log_file_path)
|
.open(log_file_path)
|
||||||
.ok()
|
.ok()
|
||||||
.map(BufWriter::new);
|
.and_then(|file| {
|
||||||
|
let (tx, rx) = mpsc::sync_channel::<FileLogCmd>(512);
|
||||||
|
thread::Builder::new()
|
||||||
|
.name("fpv-log-writer".into())
|
||||||
|
.spawn(move || {
|
||||||
|
let mut writer = BufWriter::new(file);
|
||||||
|
while let Ok(cmd) = rx.recv() {
|
||||||
|
match cmd {
|
||||||
|
FileLogCmd::Line { text, flush } => {
|
||||||
|
let _ = writer.write_all(text.as_bytes());
|
||||||
|
if flush {
|
||||||
|
let _ = writer.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FileLogCmd::Flush => {
|
||||||
|
let _ = writer.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let _ = writer.flush();
|
||||||
|
})
|
||||||
|
.ok()
|
||||||
|
.map(|_| tx)
|
||||||
|
});
|
||||||
|
|
||||||
let logger = Box::new(Self {
|
let logger = Box::new(Self {
|
||||||
buffer: Arc::clone(&buffer),
|
buffer: Arc::clone(&buffer),
|
||||||
file_writer: Mutex::new(file_writer),
|
file_tx,
|
||||||
});
|
});
|
||||||
|
|
||||||
if log::set_boxed_logger(logger).is_ok() {
|
if log::set_boxed_logger(logger).is_ok() {
|
||||||
@@ -107,19 +137,16 @@ impl Log for GuiLogger {
|
|||||||
entry.timestamp, entry.level, entry.target, entry.message
|
entry.timestamp, entry.level, entry.target, entry.message
|
||||||
);
|
);
|
||||||
|
|
||||||
// Écriture persistante sur descripteur ouvert avec tampon BufWriter
|
// Envoi non-bloquant vers le thread d'écriture disque (jamais d'I/O sur thread temps réel)
|
||||||
{
|
if let Some(ref tx) = self.file_tx {
|
||||||
let mut writer_lock = self.file_writer.lock();
|
let line = format!(
|
||||||
if let Some(ref mut writer) = *writer_lock {
|
"[{}] [{:<5}] ({}) {}\n",
|
||||||
let _ = writeln!(
|
entry.timestamp, entry.level, entry.target, entry.message
|
||||||
writer,
|
);
|
||||||
"[{}] [{:<5}] ({}) {}",
|
let _ = tx.try_send(FileLogCmd::Line {
|
||||||
entry.timestamp, entry.level, entry.target, entry.message
|
text: line,
|
||||||
);
|
flush: record.level() <= Level::Warn,
|
||||||
if record.level() <= Level::Warn {
|
});
|
||||||
let _ = writer.flush();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ajout dans le tampon de l'interface graphique
|
// Ajout dans le tampon de l'interface graphique
|
||||||
@@ -144,9 +171,8 @@ impl Log for GuiLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn flush(&self) {
|
fn flush(&self) {
|
||||||
let mut writer_lock = self.file_writer.lock();
|
if let Some(ref tx) = self.file_tx {
|
||||||
if let Some(ref mut writer) = *writer_lock {
|
let _ = tx.try_send(FileLogCmd::Flush);
|
||||||
let _ = writer.flush();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+27
-33
@@ -4,7 +4,6 @@ mod dome_projection;
|
|||||||
mod dvr;
|
mod dvr;
|
||||||
mod engine;
|
mod engine;
|
||||||
mod g29_bridge;
|
mod g29_bridge;
|
||||||
mod gui;
|
|
||||||
mod gui_gpui;
|
mod gui_gpui;
|
||||||
mod logger;
|
mod logger;
|
||||||
mod nomad_elrs;
|
mod nomad_elrs;
|
||||||
@@ -16,57 +15,52 @@ use anyhow::Result;
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use config::AppConfig;
|
use config::AppConfig;
|
||||||
use engine::FpvEngineController;
|
use engine::FpvEngineController;
|
||||||
use gui::SteamFrameGuiApp;
|
|
||||||
use logger::GuiLogger;
|
use logger::GuiLogger;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
static SHUTDOWN_REQUESTED: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
||||||
|
extern "C" fn on_termination_signal(_sig: std::ffi::c_int) {
|
||||||
|
SHUTDOWN_REQUESTED.store(true, Ordering::Release);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn install_signal_handlers() {
|
||||||
|
extern "C" {
|
||||||
|
fn signal(sig: std::ffi::c_int, handler: extern "C" fn(std::ffi::c_int)) -> usize;
|
||||||
|
}
|
||||||
|
const SIGINT: std::ffi::c_int = 2;
|
||||||
|
const SIGTERM: std::ffi::c_int = 15;
|
||||||
|
// SAFETY: `on_termination_signal` est async-signal-safe (uniquement un store atomique sur une statique).
|
||||||
|
unsafe {
|
||||||
|
signal(SIGINT, on_termination_signal);
|
||||||
|
signal(SIGTERM, on_termination_signal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let cfg = AppConfig::parse();
|
let cfg = AppConfig::parse();
|
||||||
let log_buffer = GuiLogger::init(&cfg.log_file);
|
let log_buffer = GuiLogger::init(&cfg.log_file);
|
||||||
|
|
||||||
log::info!(
|
log::info!(
|
||||||
"=== Démarrage de SteamFrame FPV v{} (Moteur IHM : {}, Fichier journal : {}) ===",
|
"=== Démarrage de SteamFrame FPV v{} (IHM : GPUI, Fichier journal : {}) ===",
|
||||||
env!("CARGO_PKG_VERSION"),
|
env!("CARGO_PKG_VERSION"),
|
||||||
cfg.gui_engine,
|
|
||||||
cfg.log_file
|
cfg.log_file
|
||||||
);
|
);
|
||||||
|
|
||||||
if cfg.no_gui {
|
if cfg.no_gui {
|
||||||
log::info!("Mode ligne de commande (--no-gui) activé.");
|
install_signal_handlers();
|
||||||
|
log::info!("Mode ligne de commande (--no-gui) activé. Ctrl+C ou SIGTERM pour un arrêt sécurisé.");
|
||||||
let mut engine = FpvEngineController::new(cfg.telemetry_enabled, cfg.head_tracking_enabled);
|
let mut engine = FpvEngineController::new(cfg.telemetry_enabled, cfg.head_tracking_enabled);
|
||||||
engine.start(cfg);
|
engine.start(cfg);
|
||||||
|
|
||||||
let running = Arc::new(AtomicBool::new(true));
|
while !SHUTDOWN_REQUESTED.load(Ordering::Acquire) && engine.is_running() {
|
||||||
while running.load(Ordering::Relaxed) && engine.is_running() {
|
std::thread::sleep(Duration::from_millis(100));
|
||||||
std::thread::sleep(Duration::from_millis(200));
|
|
||||||
}
|
}
|
||||||
|
log::info!("[CLI] Signal d'arrêt reçu, fermeture sécurisée du moteur FPV...");
|
||||||
|
engine.stop();
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.gui_engine.eq_ignore_ascii_case("gpui") {
|
gui_gpui::run_gpui_app(cfg, log_buffer)
|
||||||
log::info!("Démarrage de l'interface moderne GPU-accélérée (GPUI)...");
|
|
||||||
return gui_gpui::run_gpui_app(cfg, log_buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
let native_options = eframe::NativeOptions {
|
|
||||||
viewport: eframe::egui::ViewportBuilder::default()
|
|
||||||
.with_title(format!(
|
|
||||||
"SteamFrame FPV v{} - Eachine Sphere Link & RadioMaster Nomad",
|
|
||||||
env!("CARGO_PKG_VERSION")
|
|
||||||
))
|
|
||||||
.with_inner_size([1220.0, 820.0])
|
|
||||||
.with_min_inner_size([920.0, 620.0]),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
eframe::run_native(
|
|
||||||
"SteamFrame FPV",
|
|
||||||
native_options,
|
|
||||||
Box::new(move |cc| Ok(Box::new(SteamFrameGuiApp::new(cc, cfg, log_buffer)))),
|
|
||||||
)
|
|
||||||
.map_err(|e| anyhow::anyhow!("Erreur interface graphique eframe : {}", e))?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
@@ -397,6 +397,26 @@ impl Drop for TelemetryReceiver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Nombre d'entrées interactives dans le Menu Rapide VR intégré à l'OSD OpenXR.
|
||||||
|
pub const VR_MENU_ITEM_COUNT: usize = 11;
|
||||||
|
|
||||||
|
/// Données d'affichage zéro-allocation (`Copy`) pour le Menu Rapide VR dans le casque.
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub struct VrMenuRenderData {
|
||||||
|
pub selected_idx: usize,
|
||||||
|
pub control_source: ControlSource,
|
||||||
|
pub head_tracking_on: bool,
|
||||||
|
pub telemetry_osd_on: bool,
|
||||||
|
pub projection_label: &'static str,
|
||||||
|
pub screen_distance_m: f32,
|
||||||
|
pub lens_k1: f32,
|
||||||
|
pub camera_fov_deg: f32,
|
||||||
|
pub dvr_recording: bool,
|
||||||
|
pub gear_3_max: u16,
|
||||||
|
pub vibration_pct: u8,
|
||||||
|
pub feedback_msg: Option<(&'static str, bool)>,
|
||||||
|
}
|
||||||
|
|
||||||
/// Moteur d'incrustation graphique OSD (HUD vectoriel + police bitmap 5x7 avec contour)
|
/// Moteur d'incrustation graphique OSD (HUD vectoriel + police bitmap 5x7 avec contour)
|
||||||
pub struct OsdOverlay;
|
pub struct OsdOverlay;
|
||||||
|
|
||||||
@@ -569,6 +589,306 @@ impl OsdOverlay {
|
|||||||
Self::draw_g29_hud(rgba, width, height, g29, scale, bottom_y);
|
Self::draw_g29_hud(rgba, width, height, g29, scale, bottom_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Dessine le Menu Rapide VR superposé (utilisable au D-Pad volant G29 ou Steam Controller sans quitter OpenXR).
|
||||||
|
pub fn render_vr_menu(
|
||||||
|
rgba: &mut [u8],
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
|
menu: &VrMenuRenderData,
|
||||||
|
) {
|
||||||
|
let scale = (height / 360).max(1);
|
||||||
|
let s = scale as i32;
|
||||||
|
let char_w = 6 * s;
|
||||||
|
let row_h = 11 * s;
|
||||||
|
|
||||||
|
let panel_w = (304 * s).min(width as i32 - 16).max(180);
|
||||||
|
let header_h = 18 * s;
|
||||||
|
let footer_h = 20 * s;
|
||||||
|
let panel_h = (header_h + (VR_MENU_ITEM_COUNT as i32 * row_h) + footer_h)
|
||||||
|
.min(height as i32 - 12);
|
||||||
|
|
||||||
|
let px0 = (width as i32 - panel_w) / 2;
|
||||||
|
let py0 = (height as i32 - panel_h) / 2;
|
||||||
|
|
||||||
|
// 1. Fond assombri translucide haute lisibilité (assombrissement 75% + teinte cockpit bleu nuit)
|
||||||
|
Self::darken_rect(rgba, width, height, px0, py0, panel_w, panel_h, [6, 10, 18]);
|
||||||
|
|
||||||
|
// Bandeau titre supérieur
|
||||||
|
Self::fill_rect(
|
||||||
|
rgba,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
px0 + 1,
|
||||||
|
py0 + 1,
|
||||||
|
panel_w - 2,
|
||||||
|
header_h - 2,
|
||||||
|
[12, 28, 46, 255],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Double bordure cyan lumineuse
|
||||||
|
Self::draw_rect_outline(
|
||||||
|
rgba,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
px0,
|
||||||
|
py0,
|
||||||
|
panel_w,
|
||||||
|
panel_h,
|
||||||
|
[0, 229, 255, 255],
|
||||||
|
);
|
||||||
|
Self::draw_rect_outline(
|
||||||
|
rgba,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
px0 + 2,
|
||||||
|
py0 + 2,
|
||||||
|
panel_w - 4,
|
||||||
|
panel_h - 4,
|
||||||
|
[25, 75, 110, 255],
|
||||||
|
);
|
||||||
|
|
||||||
|
let title = "[ STEAMFRAME VR QUICK MENU ]";
|
||||||
|
let title_x = px0 + (panel_w - (title.len() as i32 * char_w)) / 2;
|
||||||
|
Self::draw_text(
|
||||||
|
rgba,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
title_x.max(px0 + 6),
|
||||||
|
py0 + 5 * s,
|
||||||
|
title,
|
||||||
|
scale,
|
||||||
|
[0, 235, 255, 255],
|
||||||
|
);
|
||||||
|
|
||||||
|
let selected = menu.selected_idx % VR_MENU_ITEM_COUNT;
|
||||||
|
|
||||||
|
for idx in 0..VR_MENU_ITEM_COUNT {
|
||||||
|
let ry = py0 + header_h + (idx as i32 * row_h);
|
||||||
|
if ry + row_h > py0 + panel_h - footer_h + 2 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let is_sel = idx == selected;
|
||||||
|
if is_sel {
|
||||||
|
Self::fill_rect(
|
||||||
|
rgba,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
px0 + 4,
|
||||||
|
ry,
|
||||||
|
panel_w - 8,
|
||||||
|
row_h - 1,
|
||||||
|
[20, 58, 86, 255],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut label_buf = StackStr::<32>::new();
|
||||||
|
let mut val_buf = StackStr::<32>::new();
|
||||||
|
let prefix = if is_sel { "> " } else { " " };
|
||||||
|
|
||||||
|
let val_color = match idx {
|
||||||
|
0 => {
|
||||||
|
let _ = write!(label_buf, "{}SOURCE PILOTAGE", prefix);
|
||||||
|
let src_lbl = match menu.control_source {
|
||||||
|
ControlSource::G29 => "< G29 VOLANT >",
|
||||||
|
ControlSource::SteamController => "< STEAM CTRL >",
|
||||||
|
};
|
||||||
|
let _ = write!(val_buf, "{}", src_lbl);
|
||||||
|
[255, 190, 60, 255]
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
let _ = write!(label_buf, "{}CENTRER VUE HT", prefix);
|
||||||
|
let _ = write!(val_buf, "[ A / CROIX ]");
|
||||||
|
[0, 235, 255, 255]
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
let _ = write!(label_buf, "{}SUIVI TETE (HT)", prefix);
|
||||||
|
let _ = write!(
|
||||||
|
val_buf,
|
||||||
|
"{}",
|
||||||
|
if menu.head_tracking_on { "< ON >" } else { "< OFF >" }
|
||||||
|
);
|
||||||
|
if menu.head_tracking_on {
|
||||||
|
[90, 255, 130, 255]
|
||||||
|
} else {
|
||||||
|
[160, 175, 195, 255]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
let _ = write!(label_buf, "{}OSD TELEMETRIE", prefix);
|
||||||
|
let _ = write!(
|
||||||
|
val_buf,
|
||||||
|
"{}",
|
||||||
|
if menu.telemetry_osd_on { "< ON >" } else { "< OFF >" }
|
||||||
|
);
|
||||||
|
if menu.telemetry_osd_on {
|
||||||
|
[90, 255, 130, 255]
|
||||||
|
} else {
|
||||||
|
[160, 175, 195, 255]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
4 => {
|
||||||
|
let _ = write!(label_buf, "{}PROJECTION VR", prefix);
|
||||||
|
let _ = write!(val_buf, "< {} >", menu.projection_label);
|
||||||
|
[100, 225, 255, 255]
|
||||||
|
}
|
||||||
|
5 => {
|
||||||
|
let _ = write!(label_buf, "{}DISTANCE ECRAN", prefix);
|
||||||
|
let _ = write!(val_buf, "< {:.1} M >", menu.screen_distance_m);
|
||||||
|
[235, 240, 250, 255]
|
||||||
|
}
|
||||||
|
6 => {
|
||||||
|
let _ = write!(label_buf, "{}CORRECTION K1", prefix);
|
||||||
|
let _ = write!(val_buf, "< {:+.2} >", menu.lens_k1);
|
||||||
|
[235, 240, 250, 255]
|
||||||
|
}
|
||||||
|
7 => {
|
||||||
|
let _ = write!(label_buf, "{}FOV CAMERA", prefix);
|
||||||
|
let _ = write!(val_buf, "< {:.0}° >", menu.camera_fov_deg);
|
||||||
|
[235, 240, 250, 255]
|
||||||
|
}
|
||||||
|
8 => {
|
||||||
|
let _ = write!(label_buf, "{}ENREGISTREUR DVR", prefix);
|
||||||
|
let _ = write!(
|
||||||
|
val_buf,
|
||||||
|
"{}",
|
||||||
|
if menu.dvr_recording { "< REC >" } else { "< STOP >" }
|
||||||
|
);
|
||||||
|
if menu.dvr_recording {
|
||||||
|
[255, 70, 70, 255]
|
||||||
|
} else {
|
||||||
|
[180, 190, 205, 255]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
9 => {
|
||||||
|
let _ = write!(label_buf, "{}PLAFOND 3E VIT.", prefix);
|
||||||
|
let _ = write!(val_buf, "< {} >", menu.gear_3_max);
|
||||||
|
[255, 190, 60, 255]
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
let _ = write!(label_buf, "{}VIBRATIONS SC", prefix);
|
||||||
|
let _ = write!(val_buf, "< {}% >", menu.vibration_pct);
|
||||||
|
[100, 225, 255, 255]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let lbl_color = if is_sel {
|
||||||
|
[255, 255, 255, 255]
|
||||||
|
} else {
|
||||||
|
[195, 210, 228, 255]
|
||||||
|
};
|
||||||
|
let text_y = ry + 2 * s;
|
||||||
|
Self::draw_text(
|
||||||
|
rgba,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
px0 + 8 * s,
|
||||||
|
text_y,
|
||||||
|
label_buf.as_str(),
|
||||||
|
scale,
|
||||||
|
lbl_color,
|
||||||
|
);
|
||||||
|
|
||||||
|
let vx = (px0 + panel_w - 8 * s) - (val_buf.as_str().chars().count() as i32 * char_w);
|
||||||
|
Self::draw_text(
|
||||||
|
rgba,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
vx.max(px0 + panel_w / 2),
|
||||||
|
text_y,
|
||||||
|
val_buf.as_str(),
|
||||||
|
scale,
|
||||||
|
val_color,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pied du menu : message de retour (erreur d'armement / confirmation) ou aide touches
|
||||||
|
let footer_y = py0 + panel_h - footer_h + 6 * s;
|
||||||
|
if let Some((msg, is_err)) = menu.feedback_msg {
|
||||||
|
let color = if is_err {
|
||||||
|
[255, 75, 75, 255]
|
||||||
|
} else {
|
||||||
|
[90, 255, 130, 255]
|
||||||
|
};
|
||||||
|
let fx = px0 + (panel_w - (msg.chars().count() as i32 * char_w)) / 2;
|
||||||
|
Self::draw_text(
|
||||||
|
rgba,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
fx.max(px0 + 6),
|
||||||
|
footer_y,
|
||||||
|
msg,
|
||||||
|
scale,
|
||||||
|
color,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
let help = "DPAD H/B:CHOIX G/D/A:REGLER B/OPT:FERMER";
|
||||||
|
let hx = px0 + (panel_w - (help.len() as i32 * char_w)) / 2;
|
||||||
|
Self::draw_text(
|
||||||
|
rgba,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
hx.max(px0 + 6),
|
||||||
|
footer_y,
|
||||||
|
help,
|
||||||
|
scale,
|
||||||
|
[150, 180, 210, 255],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn darken_rect(
|
||||||
|
rgba: &mut [u8],
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
|
x: i32,
|
||||||
|
y: i32,
|
||||||
|
w: i32,
|
||||||
|
h: i32,
|
||||||
|
tint: [u8; 3],
|
||||||
|
) {
|
||||||
|
let x0 = x.clamp(0, width as i32) as u32;
|
||||||
|
let y0 = y.clamp(0, height as i32) as u32;
|
||||||
|
let x1 = (x + w).clamp(0, width as i32) as u32;
|
||||||
|
let y1 = (y + h).clamp(0, height as i32) as u32;
|
||||||
|
for row in y0..y1 {
|
||||||
|
let row_start = (row * width + x0) as usize * 4;
|
||||||
|
let row_end = (row * width + x1) as usize * 4;
|
||||||
|
if row_end <= rgba.len() {
|
||||||
|
for px in rgba[row_start..row_end].chunks_exact_mut(4) {
|
||||||
|
px[0] = (px[0] >> 2).saturating_add(tint[0]);
|
||||||
|
px[1] = (px[1] >> 2).saturating_add(tint[1]);
|
||||||
|
px[2] = (px[2] >> 2).saturating_add(tint[2]);
|
||||||
|
px[3] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fill_rect(
|
||||||
|
rgba: &mut [u8],
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
|
x: i32,
|
||||||
|
y: i32,
|
||||||
|
w: i32,
|
||||||
|
h: i32,
|
||||||
|
color: [u8; 4],
|
||||||
|
) {
|
||||||
|
let x0 = x.clamp(0, width as i32) as u32;
|
||||||
|
let y0 = y.clamp(0, height as i32) as u32;
|
||||||
|
let x1 = (x + w).clamp(0, width as i32) as u32;
|
||||||
|
let y1 = (y + h).clamp(0, height as i32) as u32;
|
||||||
|
for row in y0..y1 {
|
||||||
|
let row_start = (row * width + x0) as usize * 4;
|
||||||
|
let row_end = (row * width + x1) as usize * 4;
|
||||||
|
if row_end <= rgba.len() {
|
||||||
|
for px in rgba[row_start..row_end].chunks_exact_mut(4) {
|
||||||
|
px.copy_from_slice(&color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn draw_g29_hud(
|
fn draw_g29_hud(
|
||||||
rgba: &mut [u8],
|
rgba: &mut [u8],
|
||||||
width: u32,
|
width: u32,
|
||||||
@@ -871,6 +1191,10 @@ impl OsdOverlay {
|
|||||||
',' => [0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00100, 0b01000],
|
',' => [0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00100, 0b01000],
|
||||||
'*' => [0b00000, 0b10101, 0b01110, 0b11111, 0b01110, 0b10101, 0b00000],
|
'*' => [0b00000, 0b10101, 0b01110, 0b11111, 0b01110, 0b10101, 0b00000],
|
||||||
'°' => [0b01100, 0b10010, 0b10010, 0b01100, 0b00000, 0b00000, 0b00000],
|
'°' => [0b01100, 0b10010, 0b10010, 0b01100, 0b00000, 0b00000, 0b00000],
|
||||||
|
'<' => [0b00010, 0b00100, 0b01000, 0b10000, 0b01000, 0b00100, 0b00010],
|
||||||
|
'>' => [0b01000, 0b00100, 0b00010, 0b00001, 0b00010, 0b00100, 0b01000],
|
||||||
|
'=' => [0b00000, 0b00000, 0b11111, 0b00000, 0b11111, 0b00000, 0b00000],
|
||||||
|
'\'' => [0b00100, 0b00100, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000],
|
||||||
|
|
||||||
_ => [0b00000; 7],
|
_ => [0b00000; 7],
|
||||||
}
|
}
|
||||||
@@ -892,6 +1216,29 @@ mod tests {
|
|||||||
assert_eq!(s4.as_str(), "12°");
|
assert_eq!(s4.as_str(), "12°");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_render_vr_menu_bounds_and_output() {
|
||||||
|
let mut rgba = vec![100u8; 1280 * 720 * 4];
|
||||||
|
let menu = VrMenuRenderData {
|
||||||
|
selected_idx: 0,
|
||||||
|
control_source: ControlSource::SteamController,
|
||||||
|
head_tracking_on: true,
|
||||||
|
telemetry_osd_on: true,
|
||||||
|
projection_label: "DOME 140",
|
||||||
|
screen_distance_m: 1.6,
|
||||||
|
lens_k1: -0.14,
|
||||||
|
camera_fov_deg: 140.0,
|
||||||
|
dvr_recording: false,
|
||||||
|
gear_3_max: 1220,
|
||||||
|
vibration_pct: 100,
|
||||||
|
feedback_msg: Some(("TARE HT OK", false)),
|
||||||
|
};
|
||||||
|
OsdOverlay::render_vr_menu(&mut rgba, 1280, 720, &menu);
|
||||||
|
// Le centre de l'écran doit avoir été assombri/dessiné par le panneau VR
|
||||||
|
let center_idx = ((720 / 2) * 1280 + (1280 / 2)) * 4;
|
||||||
|
assert_ne!(&rgba[center_idx..center_idx + 3], &[100, 100, 100]);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_datagram_crsf_crc_validation() {
|
fn test_parse_datagram_crsf_crc_validation() {
|
||||||
let state = Arc::new(Mutex::new(TelemetryState::default()));
|
let state = Arc::new(Mutex::new(TelemetryState::default()));
|
||||||
|
|||||||
+32
-12
@@ -189,17 +189,17 @@ impl Drop for UsbVideoReceiver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construit la description textuelle du pipeline GStreamer selon le mode choisi.
|
/// Construit la description textuelle du pipeline GStreamer sans interpoler de chaînes externes non sûres
|
||||||
|
/// (`device`, `address` et `port` sont injectés par `set_property` après création).
|
||||||
fn pipeline_description(p: &PipelineParams) -> String {
|
fn pipeline_description(p: &PipelineParams) -> String {
|
||||||
let (w, h) = (p.target_width, p.target_height);
|
let (w, h) = (p.target_width, p.target_height);
|
||||||
if p.usb_video_mode.eq_ignore_ascii_case("uvc") {
|
if p.usb_video_mode.eq_ignore_ascii_case("uvc") {
|
||||||
return format!(
|
return format!(
|
||||||
"v4l2src device={dev} do-timestamp=true ! \
|
"v4l2src name=uvc_src do-timestamp=true ! \
|
||||||
decodebin ! \
|
decodebin ! \
|
||||||
videoconvert ! videoscale ! \
|
videoconvert ! videoscale ! \
|
||||||
video/x-raw,format=RGBA,width={w},height={h} ! \
|
video/x-raw,format=RGBA,width={w},height={h} ! \
|
||||||
appsink name=fpv_sink sync=false max-buffers=1 drop=true emit-signals=false",
|
appsink name=fpv_sink sync=false max-buffers=1 drop=true emit-signals=false"
|
||||||
dev = p.uvc_device
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,18 +224,16 @@ fn pipeline_description(p: &PipelineParams) -> String {
|
|||||||
};
|
};
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
"udpsrc address={ip} port={port} buffer-size=4194304 retrieve-sender-address=false ! \
|
"udpsrc name=udp_src buffer-size=4194304 retrieve-sender-address=false ! \
|
||||||
{depay_and_parse} ! \
|
{depay_and_parse} ! \
|
||||||
{decoder} ! \
|
{decoder} ! \
|
||||||
videoscale ! videoconvert ! \
|
videoscale ! videoconvert ! \
|
||||||
video/x-raw,format=RGBA,width={w},height={h} ! \
|
video/x-raw,format=RGBA,width={w},height={h} ! \
|
||||||
appsink name=fpv_sink sync=false max-buffers=1 drop=true emit-signals=false",
|
appsink name=fpv_sink sync=false max-buffers=1 drop=true emit-signals=false"
|
||||||
ip = p.bind_ip,
|
|
||||||
port = p.port
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construit le pipeline, branche l'appsink sur `latest_frame` et le passe en PLAYING.
|
/// Construit le pipeline, configure les propriétés sources de façon sécurisée, branche l'appsink et passe en PLAYING.
|
||||||
fn build_pipeline(
|
fn build_pipeline(
|
||||||
params: &PipelineParams,
|
params: &PipelineParams,
|
||||||
latest_frame: &Arc<Mutex<Option<VideoFrame>>>,
|
latest_frame: &Arc<Mutex<Option<VideoFrame>>>,
|
||||||
@@ -251,6 +249,24 @@ fn build_pipeline(
|
|||||||
.dynamic_cast::<gst::Pipeline>()
|
.dynamic_cast::<gst::Pipeline>()
|
||||||
.map_err(|_| anyhow::anyhow!("L'élément GStreamer n'est pas un Pipeline"))?;
|
.map_err(|_| anyhow::anyhow!("L'élément GStreamer n'est pas un Pipeline"))?;
|
||||||
|
|
||||||
|
if params.usb_video_mode.eq_ignore_ascii_case("uvc") {
|
||||||
|
let uvc_src = pipeline
|
||||||
|
.by_name("uvc_src")
|
||||||
|
.context("Élément 'uvc_src' introuvable dans le pipeline")?;
|
||||||
|
uvc_src.set_property("device", params.uvc_device.trim());
|
||||||
|
} else {
|
||||||
|
let parsed_ip: std::net::IpAddr = params
|
||||||
|
.bind_ip
|
||||||
|
.trim()
|
||||||
|
.parse()
|
||||||
|
.with_context(|| format!("Adresse IP d'écoute vidéo invalide : '{}'", params.bind_ip))?;
|
||||||
|
let udp_src = pipeline
|
||||||
|
.by_name("udp_src")
|
||||||
|
.context("Élément 'udp_src' introuvable dans le pipeline")?;
|
||||||
|
udp_src.set_property("address", parsed_ip.to_string());
|
||||||
|
udp_src.set_property("port", params.port as i32);
|
||||||
|
}
|
||||||
|
|
||||||
let appsink = pipeline
|
let appsink = pipeline
|
||||||
.by_name("fpv_sink")
|
.by_name("fpv_sink")
|
||||||
.context("Appsink 'fpv_sink' introuvable dans le pipeline")?
|
.context("Appsink 'fpv_sink' introuvable dans le pipeline")?
|
||||||
@@ -548,7 +564,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_pipeline_description_raw_h264() {
|
fn test_pipeline_description_raw_h264() {
|
||||||
let d = pipeline_description(¶ms("rndis", "h264", "raw"));
|
let d = pipeline_description(¶ms("rndis", "h264", "raw"));
|
||||||
assert!(d.starts_with("udpsrc address=0.0.0.0 port=5600"));
|
assert!(d.starts_with("udpsrc name=udp_src"));
|
||||||
|
assert!(!d.contains("0.0.0.0"));
|
||||||
assert!(d.contains("h264parse"));
|
assert!(d.contains("h264parse"));
|
||||||
assert!(d.contains("avdec_h264"));
|
assert!(d.contains("avdec_h264"));
|
||||||
assert!(!d.contains("rtph264depay"));
|
assert!(!d.contains("rtph264depay"));
|
||||||
@@ -565,8 +582,11 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pipeline_description_uvc() {
|
fn test_pipeline_description_uvc() {
|
||||||
let d = pipeline_description(¶ms("UVC", "h264", "raw"));
|
let mut p = params("UVC", "h264", "raw");
|
||||||
assert!(d.starts_with("v4l2src device=/dev/video0"));
|
p.uvc_device = "/dev/video0 ! filesink location=/tmp/pwn".into();
|
||||||
|
let d = pipeline_description(&p);
|
||||||
|
assert!(d.starts_with("v4l2src name=uvc_src"));
|
||||||
|
assert!(!d.contains("filesink"));
|
||||||
assert!(!d.contains("udpsrc"));
|
assert!(!d.contains("udpsrc"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user