mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
feat(ui,engine): add runtime VR toggle and harden Nomad/GUI concurrency
This commit is contained in:
1 parent
e859d0e21c
commit
b8f2f00f09
4 files changed
+331
-61
No files matched your search
+77
-21
@@ -294,6 +294,9 @@ impl FpvEngineController {
|
||||
SubsystemStatus::Disabled
|
||||
};
|
||||
mon.video_fps = 0.0;
|
||||
mon.dvr_recording = false;
|
||||
mon.dvr_elapsed_secs = 0;
|
||||
mon.dvr_status = SubsystemStatus::Stopped;
|
||||
}
|
||||
|
||||
pub fn start(&mut self, cfg: AppConfig) {
|
||||
@@ -322,7 +325,11 @@ impl FpvEngineController {
|
||||
{
|
||||
let mut mon = self.monitor.lock();
|
||||
mon.usb_video_status = SubsystemStatus::Starting;
|
||||
mon.openxr_status = SubsystemStatus::Starting;
|
||||
mon.openxr_status = if cfg.headless {
|
||||
SubsystemStatus::Disabled
|
||||
} else {
|
||||
SubsystemStatus::Starting
|
||||
};
|
||||
mon.nomad_wifi_status = if cfg.head_tracking_enabled {
|
||||
SubsystemStatus::Starting
|
||||
} else {
|
||||
@@ -371,22 +378,53 @@ impl Drop for FpvEngineController {
|
||||
}
|
||||
}
|
||||
|
||||
struct RetrySlot<T> {
|
||||
inner: Option<T>,
|
||||
last_fail: Option<Instant>,
|
||||
}
|
||||
|
||||
impl<T> RetrySlot<T> {
|
||||
const RETRY_COOLDOWN: Duration = Duration::from_secs(3);
|
||||
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
inner: None,
|
||||
last_fail: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn should_retry(&self) -> bool {
|
||||
self.last_fail
|
||||
.map_or(true, |t| t.elapsed() >= Self::RETRY_COOLDOWN)
|
||||
}
|
||||
|
||||
fn clear(&mut self) {
|
||||
self.inner = None;
|
||||
self.last_fail = None;
|
||||
}
|
||||
}
|
||||
|
||||
fn sync_telemetry_receiver(
|
||||
cfg: &AppConfig,
|
||||
telem_enabled: bool,
|
||||
telem_rx_opt: &mut Option<TelemetryReceiver>,
|
||||
telem_slot: &mut RetrySlot<TelemetryReceiver>,
|
||||
monitor: &Arc<Mutex<RuntimeMonitor>>,
|
||||
) {
|
||||
if telem_enabled && telem_rx_opt.is_none() {
|
||||
if telem_enabled && telem_slot.inner.is_none() {
|
||||
if !telem_slot.should_retry() {
|
||||
return;
|
||||
}
|
||||
match TelemetryReceiver::start(&cfg.usb_bind_ip, cfg.telemetry_udp_port) {
|
||||
Ok(rx) => {
|
||||
monitor.lock().telemetry_status = SubsystemStatus::Running(format!(
|
||||
"ON - UDP {}:{}",
|
||||
cfg.usb_bind_ip, cfg.telemetry_udp_port
|
||||
));
|
||||
*telem_rx_opt = Some(rx);
|
||||
telem_slot.inner = Some(rx);
|
||||
telem_slot.last_fail = None;
|
||||
}
|
||||
Err(e) => {
|
||||
telem_slot.last_fail = Some(Instant::now());
|
||||
log::error!(
|
||||
"[Télémétrie OSD] Échec d'activation sur le port {} : {}",
|
||||
cfg.telemetry_udp_port,
|
||||
@@ -395,8 +433,8 @@ fn sync_telemetry_receiver(
|
||||
monitor.lock().telemetry_status = SubsystemStatus::Error(format!("{}", e));
|
||||
}
|
||||
}
|
||||
} else if !telem_enabled && telem_rx_opt.is_some() {
|
||||
*telem_rx_opt = None;
|
||||
} else if !telem_enabled && (telem_slot.inner.is_some() || telem_slot.last_fail.is_some()) {
|
||||
telem_slot.clear();
|
||||
monitor.lock().telemetry_status = SubsystemStatus::Disabled;
|
||||
}
|
||||
}
|
||||
@@ -404,10 +442,13 @@ fn sync_telemetry_receiver(
|
||||
fn sync_head_tracker(
|
||||
cfg: &AppConfig,
|
||||
ht_enabled: bool,
|
||||
head_tracker_opt: &mut Option<NomadHeadTracker>,
|
||||
ht_slot: &mut RetrySlot<NomadHeadTracker>,
|
||||
monitor: &Arc<Mutex<RuntimeMonitor>>,
|
||||
) {
|
||||
if ht_enabled && head_tracker_opt.is_none() {
|
||||
if ht_enabled && ht_slot.inner.is_none() {
|
||||
if !ht_slot.should_retry() {
|
||||
return;
|
||||
}
|
||||
let protocol = NomadProtocol::from_str(&cfg.ht_protocol);
|
||||
match NomadHeadTracker::new(
|
||||
&cfg.nomad_ip,
|
||||
@@ -424,15 +465,17 @@ fn sync_head_tracker(
|
||||
cfg.nomad_port,
|
||||
protocol.label()
|
||||
));
|
||||
*head_tracker_opt = Some(ht);
|
||||
ht_slot.inner = Some(ht);
|
||||
ht_slot.last_fail = None;
|
||||
}
|
||||
Err(e) => {
|
||||
ht_slot.last_fail = Some(Instant::now());
|
||||
log::error!("[Wi-Fi Nomad] Erreur initialisation RadioMaster Nomad : {}", e);
|
||||
monitor.lock().nomad_wifi_status = SubsystemStatus::Error(format!("{}", e));
|
||||
}
|
||||
}
|
||||
} else if !ht_enabled && head_tracker_opt.is_some() {
|
||||
*head_tracker_opt = None;
|
||||
} else if !ht_enabled && (ht_slot.inner.is_some() || ht_slot.last_fail.is_some()) {
|
||||
ht_slot.clear();
|
||||
monitor.lock().nomad_wifi_status = SubsystemStatus::Disabled;
|
||||
}
|
||||
}
|
||||
@@ -593,7 +636,7 @@ fn run_engine_worker(
|
||||
};
|
||||
|
||||
// 2. Démarrage optionnel Télémétrie OSD
|
||||
let mut telem_rx_opt: Option<TelemetryReceiver> = None;
|
||||
let mut telem_rx_opt = RetrySlot::new();
|
||||
sync_telemetry_receiver(
|
||||
&cfg,
|
||||
telem_enabled_flag.load(Ordering::Relaxed),
|
||||
@@ -602,7 +645,7 @@ fn run_engine_worker(
|
||||
);
|
||||
|
||||
// 3. Démarrage optionnel Émetteur Wi-Fi RadioMaster Nomad (Head-Tracking)
|
||||
let mut head_tracker_opt: Option<NomadHeadTracker> = None;
|
||||
let mut head_tracker_opt = RetrySlot::new();
|
||||
sync_head_tracker(
|
||||
&cfg,
|
||||
ht_enabled_flag.load(Ordering::Relaxed),
|
||||
@@ -610,7 +653,12 @@ fn run_engine_worker(
|
||||
&monitor,
|
||||
);
|
||||
|
||||
// 4. Tentative d'initialisation OpenXR sur le Steam Frame
|
||||
// 4. Tentative d'initialisation OpenXR sur le Steam Frame (sauf si mode VR désactivé / headless)
|
||||
let fallback_needed = if cfg.headless {
|
||||
log::info!("[OpenXR] Mode VR désactivé (Mode Bureau léger actif).");
|
||||
monitor.lock().openxr_status = SubsystemStatus::Disabled;
|
||||
true
|
||||
} else {
|
||||
let xr_res = try_run_openxr_session(
|
||||
&cfg,
|
||||
&monitor,
|
||||
@@ -645,7 +693,13 @@ fn run_engine_worker(
|
||||
SubsystemStatus::Warning("Mode Bureau (Session OpenXR terminée)".to_string());
|
||||
}
|
||||
}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
};
|
||||
|
||||
if fallback_needed && !stop_flag.load(Ordering::Acquire) {
|
||||
run_desktop_fallback_loop(
|
||||
&cfg,
|
||||
&monitor,
|
||||
@@ -686,8 +740,8 @@ fn try_run_openxr_session(
|
||||
telem_enabled_flag: &Arc<AtomicBool>,
|
||||
ht_enabled_flag: &Arc<AtomicBool>,
|
||||
video_rx_opt: Option<&UsbVideoReceiver>,
|
||||
telem_rx_opt: &mut Option<TelemetryReceiver>,
|
||||
head_tracker_opt: &mut Option<NomadHeadTracker>,
|
||||
telem_rx_opt: &mut RetrySlot<TelemetryReceiver>,
|
||||
head_tracker_opt: &mut RetrySlot<NomadHeadTracker>,
|
||||
) -> Result<()> {
|
||||
let entry = unsafe {
|
||||
xr::Entry::load().context("libopenxr_loader.so introuvable sur ce système (normal sur PC sans SteamVR)")?
|
||||
@@ -946,7 +1000,7 @@ fn try_run_openxr_session(
|
||||
let q = location.pose.orientation;
|
||||
let quat = Quat::from_xyzw(q.x, q.y, q.z, q.w);
|
||||
|
||||
if let Some(ref mut ht) = head_tracker_opt {
|
||||
if let Some(ref mut ht) = head_tracker_opt.inner {
|
||||
if first_pose || recenter_flag.swap(false, Ordering::Relaxed) {
|
||||
ht.recenter(quat);
|
||||
first_pose = false;
|
||||
@@ -1011,6 +1065,7 @@ fn try_run_openxr_session(
|
||||
}
|
||||
|
||||
let telem_snapshot = telem_rx_opt
|
||||
.inner
|
||||
.as_ref()
|
||||
.map(|t| t.state().lock().clone())
|
||||
.unwrap_or_default();
|
||||
@@ -1180,8 +1235,8 @@ fn run_desktop_fallback_loop(
|
||||
telem_enabled_flag: &Arc<AtomicBool>,
|
||||
ht_enabled_flag: &Arc<AtomicBool>,
|
||||
video_rx_opt: Option<&UsbVideoReceiver>,
|
||||
telem_rx_opt: &mut Option<TelemetryReceiver>,
|
||||
head_tracker_opt: &mut Option<NomadHeadTracker>,
|
||||
telem_rx_opt: &mut RetrySlot<TelemetryReceiver>,
|
||||
head_tracker_opt: &mut RetrySlot<NomadHeadTracker>,
|
||||
) {
|
||||
let mut dome_lut = DomeWarpLut::new(
|
||||
cfg.video_width,
|
||||
@@ -1238,7 +1293,7 @@ fn run_desktop_fallback_loop(
|
||||
mon.manual_pan_deg = 0.0;
|
||||
mon.manual_tilt_deg = 0.0;
|
||||
mon.manual_roll_deg = 0.0;
|
||||
if let Some(ref mut ht) = head_tracker_opt {
|
||||
if let Some(ref mut ht) = head_tracker_opt.inner {
|
||||
ht.recenter(Quat::IDENTITY);
|
||||
}
|
||||
}
|
||||
@@ -1246,7 +1301,7 @@ fn run_desktop_fallback_loop(
|
||||
};
|
||||
|
||||
let mut current_pose = HeadPoseSample::default();
|
||||
if let Some(ref mut ht) = head_tracker_opt {
|
||||
if let Some(ref mut ht) = head_tracker_opt.inner {
|
||||
let sim_quat = Quat::from_euler(
|
||||
EulerRot::YXZ,
|
||||
(-manual_pan).to_radians(),
|
||||
@@ -1299,6 +1354,7 @@ fn run_desktop_fallback_loop(
|
||||
}
|
||||
|
||||
let telem_snapshot = telem_rx_opt
|
||||
.inner
|
||||
.as_ref()
|
||||
.map(|t| t.state().lock().clone())
|
||||
.unwrap_or_default();
|
||||
|
||||
+120
-25
@@ -1,19 +1,24 @@
|
||||
use crate::config::AppConfig;
|
||||
use crate::dome_projection::ProjectionMode;
|
||||
use crate::dvr::{DvrContainer, DvrMode};
|
||||
use crate::engine::{FpvEngineController, LiveOpticalParams, SubsystemStatus};
|
||||
use crate::engine::{EngineControlHandle, FpvEngineController, LiveOpticalParams, RuntimeMonitor, SubsystemStatus};
|
||||
use crate::logger::{LogBuffer, LogFilter};
|
||||
use crate::nomad_elrs::{NomadHeadTracker, NomadProtocol};
|
||||
use eframe::egui::{self, Color32, RichText, TextureHandle, TextureOptions};
|
||||
use log::Level;
|
||||
use parking_lot::Mutex;
|
||||
use std::process::Command;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
pub struct SteamFrameGuiApp {
|
||||
cfg: AppConfig,
|
||||
engine: FpvEngineController,
|
||||
engine: Arc<Mutex<FpvEngineController>>,
|
||||
controls: EngineControlHandle,
|
||||
engine_monitor: Arc<Mutex<RuntimeMonitor>>,
|
||||
is_restarting: Arc<AtomicBool>,
|
||||
is_closing: Arc<AtomicBool>,
|
||||
log_buffer: Arc<Mutex<LogBuffer>>,
|
||||
log_filter: LogFilter,
|
||||
auto_scroll_logs: bool,
|
||||
@@ -31,10 +36,16 @@ impl SteamFrameGuiApp {
|
||||
|
||||
let mut engine = FpvEngineController::new(cfg.telemetry_enabled, cfg.head_tracking_enabled);
|
||||
engine.start(cfg.clone());
|
||||
let controls = engine.control_handle();
|
||||
let engine_monitor = Arc::clone(&engine.monitor);
|
||||
|
||||
Self {
|
||||
cfg,
|
||||
engine,
|
||||
engine: Arc::new(Mutex::new(engine)),
|
||||
controls,
|
||||
engine_monitor,
|
||||
is_restarting: Arc::new(AtomicBool::new(false)),
|
||||
is_closing: Arc::new(AtomicBool::new(false)),
|
||||
log_buffer,
|
||||
log_filter: LogFilter::All,
|
||||
auto_scroll_logs: true,
|
||||
@@ -43,8 +54,53 @@ impl SteamFrameGuiApp {
|
||||
}
|
||||
}
|
||||
|
||||
fn restart_engine_async(&self, reason: &'static str) {
|
||||
if self.is_closing.load(Ordering::Acquire) {
|
||||
return;
|
||||
}
|
||||
if self
|
||||
.is_restarting
|
||||
.compare_exchange(false, true, Ordering::AcqRel, Ordering::Acquire)
|
||||
.is_err()
|
||||
{
|
||||
log::warn!("[Moteur FPV] Redémarrage déjà en cours, requête ignorée.");
|
||||
return;
|
||||
}
|
||||
let engine_clone = Arc::clone(&self.engine);
|
||||
let cfg_clone = self.cfg.clone();
|
||||
let is_restarting = Arc::clone(&self.is_restarting);
|
||||
let is_closing = Arc::clone(&self.is_closing);
|
||||
std::thread::spawn(move || {
|
||||
{
|
||||
let mut eng = engine_clone.lock();
|
||||
if !is_closing.load(Ordering::Acquire) {
|
||||
log::info!("{}", reason);
|
||||
eng.start(cfg_clone);
|
||||
}
|
||||
}
|
||||
is_restarting.store(false, Ordering::Release);
|
||||
});
|
||||
}
|
||||
|
||||
fn set_vr_enabled(&mut self, enabled: bool) {
|
||||
let target_headless = !enabled;
|
||||
if self.cfg.headless == target_headless {
|
||||
return;
|
||||
}
|
||||
if self.is_restarting.load(Ordering::Acquire) {
|
||||
log::warn!("[Moteur FPV] Bascule VR ignorée pendant un redémarrage en cours.");
|
||||
return;
|
||||
}
|
||||
self.cfg.headless = target_headless;
|
||||
if enabled {
|
||||
self.restart_engine_async("[Action Utilisateur] Mode VR (OpenXR) réactivé, redémarrage du moteur FPV...");
|
||||
} else {
|
||||
self.restart_engine_async("[Action Utilisateur] Mode VR désactivé (Mode Bureau léger), redémarrage du moteur FPV...");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sync_optical_params(&self) {
|
||||
self.engine.update_optical_params(LiveOpticalParams {
|
||||
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,
|
||||
@@ -55,7 +111,7 @@ impl SteamFrameGuiApp {
|
||||
}
|
||||
|
||||
pub fn sync_dvr_config(&self) {
|
||||
self.engine.update_dvr_config(
|
||||
self.controls.update_dvr_config(
|
||||
self.cfg.dvr_dir.clone(),
|
||||
DvrContainer::from_str(&self.cfg.dvr_format),
|
||||
DvrMode::from_str(&self.cfg.dvr_mode),
|
||||
@@ -210,7 +266,8 @@ impl SteamFrameGuiApp {
|
||||
impl eframe::App for SteamFrameGuiApp {
|
||||
fn on_exit(&mut self, _gl: Option<&eframe::glow::Context>) {
|
||||
log::info!("[eframe] Fermeture de la fenêtre principale, arrêt propre du moteur FPV...");
|
||||
self.engine.stop();
|
||||
self.is_closing.store(true, Ordering::Release);
|
||||
self.engine.lock().stop();
|
||||
}
|
||||
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
@@ -231,7 +288,7 @@ impl eframe::App for SteamFrameGuiApp {
|
||||
pose,
|
||||
telem,
|
||||
) = {
|
||||
let mon = self.engine.monitor.lock();
|
||||
let mon = self.engine_monitor.lock();
|
||||
if mon.preview_frame_seq != self.last_displayed_frame_seq
|
||||
&& !mon.preview_rgba.is_empty()
|
||||
&& mon.preview_width > 0
|
||||
@@ -277,7 +334,11 @@ impl eframe::App for SteamFrameGuiApp {
|
||||
ui.heading(RichText::new("🥽 SteamFrame FPV Control Center").strong());
|
||||
ui.separator();
|
||||
|
||||
let is_running = self.engine.is_running();
|
||||
let is_running = self
|
||||
.engine
|
||||
.try_lock()
|
||||
.map(|e| e.is_running())
|
||||
.unwrap_or(true);
|
||||
if is_running {
|
||||
if ui
|
||||
.button(
|
||||
@@ -286,8 +347,7 @@ impl eframe::App for SteamFrameGuiApp {
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
log::info!("[Action Utilisateur] Redémarrage des services avec la nouvelle configuration...");
|
||||
self.engine.start(self.cfg.clone());
|
||||
self.restart_engine_async("[Action Utilisateur] Redémarrage des services avec la nouvelle configuration...");
|
||||
}
|
||||
if ui
|
||||
.button(
|
||||
@@ -296,7 +356,10 @@ impl eframe::App for SteamFrameGuiApp {
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
self.engine.stop();
|
||||
let engine_clone = Arc::clone(&self.engine);
|
||||
std::thread::spawn(move || {
|
||||
engine_clone.lock().stop();
|
||||
});
|
||||
}
|
||||
} else if ui
|
||||
.button(
|
||||
@@ -306,16 +369,32 @@ impl eframe::App for SteamFrameGuiApp {
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
log::info!("[Action Utilisateur] Démarrage manuel des services...");
|
||||
self.engine.start(self.cfg.clone());
|
||||
self.restart_engine_async("[Action Utilisateur] Démarrage manuel des services...");
|
||||
}
|
||||
|
||||
if ui.button("🎯 Recentrer la tête (Tare)").clicked() {
|
||||
self.engine.request_recenter();
|
||||
self.controls.request_recenter();
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
let vr_btn_label = if !self.cfg.headless {
|
||||
RichText::new("🥽 Mode VR : ON")
|
||||
.color(Color32::from_rgb(70, 245, 130))
|
||||
.strong()
|
||||
} else {
|
||||
RichText::new("🖥️ Mode VR : OFF")
|
||||
.color(Color32::from_rgb(180, 180, 190))
|
||||
};
|
||||
|
||||
if ui
|
||||
.button(vr_btn_label)
|
||||
.on_hover_text("Activer ou désactiver le mode VR (OpenXR) pour alléger les tests en local")
|
||||
.clicked()
|
||||
{
|
||||
self.set_vr_enabled(self.cfg.headless);
|
||||
}
|
||||
|
||||
let ht_btn_label = if self.cfg.head_tracking_enabled {
|
||||
RichText::new("🎯 Suivi Tête : ON")
|
||||
.color(Color32::from_rgb(70, 245, 130))
|
||||
@@ -331,7 +410,7 @@ impl eframe::App for SteamFrameGuiApp {
|
||||
.clicked()
|
||||
{
|
||||
self.cfg.head_tracking_enabled = !self.cfg.head_tracking_enabled;
|
||||
self.engine.set_head_tracking_enabled(self.cfg.head_tracking_enabled);
|
||||
self.controls.set_head_tracking_enabled(self.cfg.head_tracking_enabled);
|
||||
}
|
||||
|
||||
let telem_btn_label = if self.cfg.telemetry_enabled {
|
||||
@@ -349,7 +428,7 @@ impl eframe::App for SteamFrameGuiApp {
|
||||
.clicked()
|
||||
{
|
||||
self.cfg.telemetry_enabled = !self.cfg.telemetry_enabled;
|
||||
self.engine.set_telemetry_enabled(self.cfg.telemetry_enabled);
|
||||
self.controls.set_telemetry_enabled(self.cfg.telemetry_enabled);
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
@@ -373,9 +452,9 @@ impl eframe::App for SteamFrameGuiApp {
|
||||
.clicked()
|
||||
{
|
||||
if dvr_recording {
|
||||
self.engine.stop_dvr();
|
||||
self.controls.stop_dvr();
|
||||
} else {
|
||||
self.engine.start_dvr();
|
||||
self.controls.start_dvr();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,7 +468,8 @@ impl eframe::App for SteamFrameGuiApp {
|
||||
.clicked()
|
||||
{
|
||||
log::info!("[Action Utilisateur] Fermeture de l'application demandée.");
|
||||
self.engine.stop();
|
||||
self.is_closing.store(true, Ordering::Release);
|
||||
self.engine.lock().stop();
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
||||
}
|
||||
});
|
||||
@@ -731,7 +811,7 @@ impl eframe::App for SteamFrameGuiApp {
|
||||
};
|
||||
if ui.button(btn_text).clicked() {
|
||||
self.cfg.head_tracking_enabled = !self.cfg.head_tracking_enabled;
|
||||
self.engine.set_head_tracking_enabled(self.cfg.head_tracking_enabled);
|
||||
self.controls.set_head_tracking_enabled(self.cfg.head_tracking_enabled);
|
||||
}
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
@@ -810,6 +890,21 @@ impl eframe::App for SteamFrameGuiApp {
|
||||
)
|
||||
.default_open(true)
|
||||
.show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(RichText::new("Affichage VR (OpenXR) :").strong());
|
||||
let vr_text = if !self.cfg.headless {
|
||||
RichText::new("🥽 Activé (Casque VR)")
|
||||
.color(Color32::from_rgb(80, 240, 120))
|
||||
.strong()
|
||||
} else {
|
||||
RichText::new("🖥️ Désactivé (Mode Bureau léger)")
|
||||
.color(Color32::from_rgb(170, 170, 180))
|
||||
};
|
||||
if ui.button(vr_text).clicked() {
|
||||
self.set_vr_enabled(self.cfg.headless);
|
||||
}
|
||||
});
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(RichText::new("Télémétrie & OSD :").strong());
|
||||
let btn_text = if self.cfg.telemetry_enabled {
|
||||
@@ -822,7 +917,7 @@ impl eframe::App for SteamFrameGuiApp {
|
||||
};
|
||||
if ui.button(btn_text).clicked() {
|
||||
self.cfg.telemetry_enabled = !self.cfg.telemetry_enabled;
|
||||
self.engine.set_telemetry_enabled(self.cfg.telemetry_enabled);
|
||||
self.controls.set_telemetry_enabled(self.cfg.telemetry_enabled);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -912,7 +1007,7 @@ impl eframe::App for SteamFrameGuiApp {
|
||||
.button(RichText::new("✔ Appliquer les changements").strong())
|
||||
.clicked()
|
||||
{
|
||||
self.engine.start(self.cfg.clone());
|
||||
self.restart_engine_async("[Réglages] Application et redémarrage asynchrone du moteur FPV...");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1012,7 +1107,7 @@ impl eframe::App for SteamFrameGuiApp {
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
self.engine.stop_dvr();
|
||||
self.controls.stop_dvr();
|
||||
}
|
||||
} else {
|
||||
if ui
|
||||
@@ -1023,7 +1118,7 @@ impl eframe::App for SteamFrameGuiApp {
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
self.engine.start_dvr();
|
||||
self.controls.start_dvr();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1093,7 +1188,7 @@ impl eframe::App for SteamFrameGuiApp {
|
||||
}
|
||||
|
||||
ui.collapsing("🕹 Simuler les mouvements de tête (Test Bureau)", |ui| {
|
||||
let mut mon = self.engine.monitor.lock();
|
||||
let mut mon = self.engine_monitor.lock();
|
||||
ui.add(
|
||||
egui::Slider::new(
|
||||
&mut mon.manual_pan_deg,
|
||||
|
||||
+119
-11
@@ -16,7 +16,7 @@ use image::{Frame, RgbaImage};
|
||||
use parking_lot::Mutex;
|
||||
use smallvec::smallvec;
|
||||
use std::process::Command;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
@@ -93,6 +93,8 @@ pub struct SteamFrameGpuiApp {
|
||||
mock_tracker: Option<NomadHeadTracker>,
|
||||
mock_last_send: Option<Instant>,
|
||||
mock_status_text: String,
|
||||
is_restarting: Arc<AtomicBool>,
|
||||
is_closing: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
impl SteamFrameGpuiApp {
|
||||
@@ -102,6 +104,7 @@ impl SteamFrameGpuiApp {
|
||||
engine: Arc<Mutex<FpvEngineController>>,
|
||||
controls: EngineControlHandle,
|
||||
engine_monitor: Arc<Mutex<RuntimeMonitor>>,
|
||||
is_closing: Arc<AtomicBool>,
|
||||
) -> Self {
|
||||
let log_revision = log_buffer.lock().revision.clone();
|
||||
let target_port_buf = cfg.nomad_port.to_string();
|
||||
@@ -147,6 +150,8 @@ impl SteamFrameGpuiApp {
|
||||
mock_tracker: None,
|
||||
mock_last_send: None,
|
||||
mock_status_text: String::new(),
|
||||
is_restarting: Arc::new(AtomicBool::new(false)),
|
||||
is_closing,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -436,6 +441,10 @@ impl SteamFrameGpuiApp {
|
||||
}
|
||||
|
||||
fn send_mock_manual(&mut self) {
|
||||
if self.target_edit_field == Some(TargetEditField::Port) {
|
||||
self.commit_port_buf();
|
||||
self.target_edit_field = None;
|
||||
}
|
||||
let protocol = NomadProtocol::from_str(&self.cfg.ht_protocol);
|
||||
if self.mock_tracker.is_none() {
|
||||
match NomadHeadTracker::new(
|
||||
@@ -485,10 +494,62 @@ impl SteamFrameGpuiApp {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn restart_engine_async(&mut self, reason: &'static str) {
|
||||
if self.target_edit_field == Some(TargetEditField::Port) {
|
||||
self.commit_port_buf();
|
||||
}
|
||||
self.target_edit_field = None;
|
||||
|
||||
if self.is_closing.load(Ordering::Acquire) {
|
||||
return;
|
||||
}
|
||||
if self
|
||||
.is_restarting
|
||||
.compare_exchange(false, true, Ordering::AcqRel, Ordering::Acquire)
|
||||
.is_err()
|
||||
{
|
||||
log::warn!("[Moteur FPV] Redémarrage déjà en cours, requête ignorée.");
|
||||
return;
|
||||
}
|
||||
|
||||
let engine_clone = Arc::clone(&self.engine);
|
||||
let cfg_clone = self.cfg.clone();
|
||||
let is_restarting = Arc::clone(&self.is_restarting);
|
||||
let is_closing = Arc::clone(&self.is_closing);
|
||||
std::thread::spawn(move || {
|
||||
{
|
||||
let mut eng = engine_clone.lock();
|
||||
if !is_closing.load(Ordering::Acquire) {
|
||||
log::info!("{}", reason);
|
||||
eng.start(cfg_clone);
|
||||
}
|
||||
}
|
||||
is_restarting.store(false, Ordering::Release);
|
||||
});
|
||||
}
|
||||
|
||||
fn set_vr_enabled(&mut self, enabled: bool) {
|
||||
let target_headless = !enabled;
|
||||
if self.cfg.headless == target_headless {
|
||||
return;
|
||||
}
|
||||
if self.is_restarting.load(Ordering::Acquire) {
|
||||
log::warn!("[Moteur FPV] Bascule VR ignorée pendant un redémarrage en cours.");
|
||||
return;
|
||||
}
|
||||
self.cfg.headless = target_headless;
|
||||
if enabled {
|
||||
self.restart_engine_async("[Action Utilisateur] Mode VR (OpenXR) réactivé, redémarrage du moteur FPV...");
|
||||
} else {
|
||||
self.restart_engine_async("[Action Utilisateur] Mode VR désactivé (Mode Bureau léger), redémarrage du moteur FPV...");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for SteamFrameGpuiApp {
|
||||
fn drop(&mut self) {
|
||||
self.is_closing.store(true, Ordering::Release);
|
||||
log::info!("[SteamFrameGpuiApp] Fermeture de l'interface IHM, arrêt propre du moteur FPV...");
|
||||
self.engine.lock().stop();
|
||||
}
|
||||
@@ -591,6 +652,21 @@ impl SteamFrameGpuiApp {
|
||||
.flex()
|
||||
.items_center()
|
||||
.gap_2()
|
||||
.child(
|
||||
div()
|
||||
.id("toggle_vr_quick")
|
||||
.cursor_pointer()
|
||||
.on_click(cx.listener(|this, _, _, cx| {
|
||||
let vr_on = this.cfg.headless;
|
||||
this.set_vr_enabled(vr_on);
|
||||
cx.notify();
|
||||
}))
|
||||
.child(self.render_toggle_pill(
|
||||
"🥽 VR",
|
||||
!self.cfg.headless,
|
||||
rgb(COLOR_CYAN),
|
||||
)),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.id("toggle_ht_quick")
|
||||
@@ -998,16 +1074,7 @@ impl SteamFrameGpuiApp {
|
||||
.font_weight(gpui::FontWeight::BOLD)
|
||||
.cursor_pointer()
|
||||
.on_click(cx.listener(|this, _, _, cx| {
|
||||
let engine_clone = Arc::clone(&this.engine);
|
||||
let cfg_clone = this.cfg.clone();
|
||||
std::thread::spawn(move || {
|
||||
if let Some(mut eng) = engine_clone.try_lock() {
|
||||
log::info!("[Réglages] Application et redémarrage asynchrone du moteur FPV...");
|
||||
eng.start(cfg_clone);
|
||||
} else {
|
||||
log::warn!("[Réglages] Redémarrage déjà en cours, requête ignorée.");
|
||||
}
|
||||
});
|
||||
this.restart_engine_async("[Réglages] Application et redémarrage asynchrone du moteur FPV...");
|
||||
cx.notify();
|
||||
}))
|
||||
.child("🔄 Appliquer & Redémarrer"),
|
||||
@@ -1207,6 +1274,9 @@ impl SteamFrameGpuiApp {
|
||||
.text_color(rgb(COLOR_TEXT_MAIN))
|
||||
.cursor_pointer()
|
||||
.on_click(cx.listener(|this, _, window, cx| {
|
||||
if this.target_edit_field == Some(TargetEditField::Port) {
|
||||
this.commit_port_buf();
|
||||
}
|
||||
this.target_edit_field = Some(TargetEditField::Ip);
|
||||
if let Some(fh) = &this.target_focus_handle {
|
||||
window.focus(fh);
|
||||
@@ -1369,8 +1439,17 @@ impl SteamFrameGpuiApp {
|
||||
},
|
||||
self.mock_continuous,
|
||||
cx.listener(|this, _, _, cx| {
|
||||
if this.target_edit_field == Some(TargetEditField::Port) {
|
||||
this.commit_port_buf();
|
||||
this.target_edit_field = None;
|
||||
}
|
||||
this.mock_continuous = !this.mock_continuous;
|
||||
this.mock_last_send = None;
|
||||
if this.mock_continuous && this.cfg.head_tracking_enabled {
|
||||
this.cfg.head_tracking_enabled = false;
|
||||
this.controls.set_head_tracking_enabled(false);
|
||||
log::info!("[Mock Manuel] Suivi de tête moteur désactivé automatiquement pour éviter une collision UDP.");
|
||||
}
|
||||
cx.notify();
|
||||
}),
|
||||
)),
|
||||
@@ -1435,6 +1514,31 @@ impl SteamFrameGpuiApp {
|
||||
.flex()
|
||||
.flex_col()
|
||||
.gap_3()
|
||||
// Activation / Désactivation du mode VR OpenXR
|
||||
.child(self.render_setting_row(
|
||||
"Affichage Casque VR (OpenXR)",
|
||||
div()
|
||||
.flex()
|
||||
.gap_2()
|
||||
.child(self.render_selectable_pill(
|
||||
"pill_vr_on",
|
||||
"🥽 Activé (Casque VR)",
|
||||
!self.cfg.headless,
|
||||
cx.listener(|this, _, _, cx| {
|
||||
this.set_vr_enabled(true);
|
||||
cx.notify();
|
||||
}),
|
||||
))
|
||||
.child(self.render_selectable_pill(
|
||||
"pill_vr_off",
|
||||
"🖥️ Désactivé (Mode Bureau léger)",
|
||||
self.cfg.headless,
|
||||
cx.listener(|this, _, _, cx| {
|
||||
this.set_vr_enabled(false);
|
||||
cx.notify();
|
||||
}),
|
||||
)),
|
||||
))
|
||||
// Mode de projection
|
||||
.child(self.render_setting_row(
|
||||
"Mode de Projection VR",
|
||||
@@ -2388,10 +2492,13 @@ pub fn run_gpui_app(cfg: AppConfig, log_buffer: Arc<Mutex<LogBuffer>>) -> Result
|
||||
let engine_monitor = Arc::clone(&engine.monitor);
|
||||
let engine = Arc::new(Mutex::new(engine));
|
||||
let engine_for_close = Arc::clone(&engine);
|
||||
let is_closing = Arc::new(AtomicBool::new(false));
|
||||
let is_closing_for_window = Arc::clone(&is_closing);
|
||||
|
||||
cx.on_window_closed(move |cx| {
|
||||
if cx.windows().is_empty() {
|
||||
log::info!("[GPUI] Dernière fenêtre fermée, arrêt propre et complet du moteur FPV...");
|
||||
is_closing_for_window.store(true, Ordering::Release);
|
||||
engine_for_close.lock().stop();
|
||||
cx.quit();
|
||||
}
|
||||
@@ -2415,6 +2522,7 @@ pub fn run_gpui_app(cfg: AppConfig, log_buffer: Arc<Mutex<LogBuffer>>) -> Result
|
||||
engine,
|
||||
controls,
|
||||
engine_monitor,
|
||||
is_closing,
|
||||
)
|
||||
});
|
||||
|
||||
|
||||
+15
-4
@@ -79,6 +79,7 @@ pub struct NomadHeadTracker {
|
||||
max_roll_deg: f32,
|
||||
protocol: NomadProtocol,
|
||||
mav_seq: u8,
|
||||
last_mav_heartbeat: Option<Instant>,
|
||||
packets_sent: u64,
|
||||
send_errors: u64,
|
||||
last_error_log: Option<Instant>,
|
||||
@@ -102,7 +103,11 @@ impl NomadHeadTracker {
|
||||
})?;
|
||||
socket.set_nonblocking(true)?;
|
||||
|
||||
let host_port = format!("{}:{}", nomad_ip.trim(), nomad_port);
|
||||
let trimmed_ip = nomad_ip.trim();
|
||||
let host_port = format!("{}:{}", trimmed_ip, nomad_port);
|
||||
let target = if let Ok(ip) = trimmed_ip.parse::<std::net::IpAddr>() {
|
||||
SocketAddr::new(ip, nomad_port)
|
||||
} else {
|
||||
let addrs: Vec<SocketAddr> = host_port
|
||||
.to_socket_addrs()
|
||||
.map_err(|e| {
|
||||
@@ -114,12 +119,13 @@ impl NomadHeadTracker {
|
||||
e
|
||||
})?
|
||||
.collect();
|
||||
let target = addrs
|
||||
addrs
|
||||
.iter()
|
||||
.copied()
|
||||
.find(|a| a.is_ipv4())
|
||||
.or_else(|| addrs.into_iter().next())
|
||||
.ok_or_else(|| anyhow!("Aucune adresse IP résolue pour {}", host_port))?;
|
||||
.ok_or_else(|| anyhow!("Aucune adresse IP résolue pour {}", host_port))?
|
||||
};
|
||||
|
||||
log::info!(
|
||||
"[Wi-Fi Nomad] Émetteur prêt vers {} ({}) (Protocole: {})",
|
||||
@@ -137,6 +143,7 @@ impl NomadHeadTracker {
|
||||
max_roll_deg,
|
||||
protocol,
|
||||
mav_seq: 0,
|
||||
last_mav_heartbeat: None,
|
||||
packets_sent: 0,
|
||||
send_errors: 0,
|
||||
last_error_log: None,
|
||||
@@ -183,10 +190,14 @@ impl NomadHeadTracker {
|
||||
self.socket.send_to(&packet, self.target)
|
||||
}
|
||||
NomadProtocol::Mavlink => {
|
||||
if self.packets_sent == 0 {
|
||||
if self
|
||||
.last_mav_heartbeat
|
||||
.map_or(true, |t| t.elapsed() >= Duration::from_secs(1))
|
||||
{
|
||||
let hb = Self::encode_mavlink_heartbeat(self.mav_seq);
|
||||
self.mav_seq = self.mav_seq.wrapping_add(1);
|
||||
let _ = self.socket.send_to(&hb, self.target);
|
||||
self.last_mav_heartbeat = Some(Instant::now());
|
||||
}
|
||||
let packet = Self::encode_mavlink_rc_override(
|
||||
pan_crsf,
|
||||
|
||||
Reference in new issue
Block a user