mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
1718 lines
82 KiB
Rust
1718 lines
82 KiB
Rust
use crate::config::AppConfig;
|
|
use crate::controller::{ControlSource, GearSpeedLimits};
|
|
use crate::nomad_elrs::{CRSF_CHANNEL_MAX, CRSF_CHANNEL_MID, CRSF_CHANNEL_MIN};
|
|
use crate::dome_projection::ProjectionMode;
|
|
use crate::dvr::{DvrContainer, DvrMode};
|
|
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: 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,
|
|
video_texture: Option<TextureHandle>,
|
|
last_displayed_frame_seq: u64,
|
|
control_switch_error: String,
|
|
monitor_source_override: Option<ControlSource>,
|
|
}
|
|
|
|
impl SteamFrameGuiApp {
|
|
pub fn new(
|
|
cc: &eframe::CreationContext<'_>,
|
|
cfg: AppConfig,
|
|
log_buffer: Arc<Mutex<LogBuffer>>,
|
|
) -> Self {
|
|
cc.egui_ctx.set_visuals(egui::Visuals::dark());
|
|
|
|
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: 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,
|
|
video_texture: None,
|
|
last_displayed_frame_seq: 0,
|
|
control_switch_error: String::new(),
|
|
monitor_source_override: None,
|
|
}
|
|
}
|
|
|
|
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.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,
|
|
});
|
|
}
|
|
|
|
pub fn sync_dvr_config(&self) {
|
|
self.controls.update_dvr_config(
|
|
self.cfg.dvr_dir.clone(),
|
|
DvrContainer::from_str(&self.cfg.dvr_format),
|
|
DvrMode::from_str(&self.cfg.dvr_mode),
|
|
);
|
|
}
|
|
|
|
fn status_badge(ui: &mut egui::Ui, title: &str, status: &SubsystemStatus) {
|
|
let (color, text) = match status {
|
|
SubsystemStatus::Stopped => (Color32::from_rgb(130, 130, 140), "Arrêté".to_string()),
|
|
SubsystemStatus::Disabled => (
|
|
Color32::from_rgb(110, 115, 125),
|
|
"OFF (Désactivé)".to_string(),
|
|
),
|
|
SubsystemStatus::Starting => (
|
|
Color32::from_rgb(255, 200, 60),
|
|
"Démarrage...".to_string(),
|
|
),
|
|
SubsystemStatus::Running(msg) => (Color32::from_rgb(70, 230, 120), msg.clone()),
|
|
SubsystemStatus::Warning(msg) => (Color32::from_rgb(255, 180, 50), msg.clone()),
|
|
SubsystemStatus::Error(msg) => (Color32::from_rgb(255, 75, 75), msg.clone()),
|
|
};
|
|
|
|
egui::Frame::group(ui.style())
|
|
.fill(Color32::from_rgb(24, 28, 36))
|
|
.stroke(egui::Stroke::new(1.0, color))
|
|
.inner_margin(egui::Margin::symmetric(8.0, 4.0))
|
|
.show(ui, |ui| {
|
|
ui.horizontal(|ui| {
|
|
ui.colored_label(color, "●");
|
|
ui.label(RichText::new(title).strong());
|
|
ui.label(RichText::new(text).color(color).small());
|
|
});
|
|
});
|
|
}
|
|
|
|
fn run_usb_rndis_setup_script(&self) {
|
|
log::info!("[Action Utilisateur] Exécution du script de configuration USB RNDIS (scripts/setup_usb_rndis.sh)...");
|
|
std::thread::spawn(move || {
|
|
match Command::new("bash")
|
|
.arg("scripts/setup_usb_rndis.sh")
|
|
.output()
|
|
{
|
|
Ok(output) => {
|
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
if output.status.success() {
|
|
log::info!(
|
|
"[USB RNDIS] Interface configurée avec succès : {}",
|
|
stdout.trim()
|
|
);
|
|
} else {
|
|
log::error!(
|
|
"[USB RNDIS] Échec du script (code {:?}) : {}",
|
|
output.status.code(),
|
|
stderr.trim()
|
|
);
|
|
}
|
|
}
|
|
Err(e) => {
|
|
log::error!(
|
|
"[USB RNDIS] Impossible de lancer scripts/setup_usb_rndis.sh : {}",
|
|
e
|
|
);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
/// Configure à distance la carte Radxa Zero 3W (OpenIPC `runcam_wifilink_sdcard.img`) via SSH sur le lien USB OTG
|
|
fn configure_radxa_vrx_over_usb(&self) {
|
|
let ch = self.cfg.wifi_channel;
|
|
let ip = self.cfg.radxa_vrx_ip.clone();
|
|
let port = self.cfg.video_udp_port;
|
|
log::info!(
|
|
"[Radxa Zero 3W] Envoi de la configuration OpenIPC (Canal 5.8GHz={} / Redirection RTP -> 192.168.1.10:{}) vers root@{}...",
|
|
ch,
|
|
port,
|
|
ip
|
|
);
|
|
|
|
let remote_cmd = format!(
|
|
"sed -i 's/^wifi_channel.*/wifi_channel = {ch}/' /etc/wifibroadcast.cfg 2>/dev/null || true; \
|
|
iw dev wlan0 set channel {ch} HT20 2>/dev/null || true; \
|
|
echo 'Radxa Zero 3W 8812EU configurée sur le canal {ch}'"
|
|
);
|
|
|
|
std::thread::spawn(move || {
|
|
match Command::new("ssh")
|
|
.args([
|
|
"-o",
|
|
"ConnectTimeout=2",
|
|
"-o",
|
|
"StrictHostKeyChecking=no",
|
|
"--",
|
|
&format!("root@{}", ip),
|
|
&remote_cmd,
|
|
])
|
|
.output()
|
|
{
|
|
Ok(output) => {
|
|
if output.status.success() {
|
|
log::info!(
|
|
"[Radxa Zero 3W] Succès : {}",
|
|
String::from_utf8_lossy(&output.stdout).trim()
|
|
);
|
|
} else {
|
|
log::error!(
|
|
"[Radxa Zero 3W] Échec SSH vers root@{} : {}",
|
|
ip,
|
|
String::from_utf8_lossy(&output.stderr).trim()
|
|
);
|
|
}
|
|
}
|
|
Err(e) => {
|
|
log::error!("[Radxa Zero 3W] Erreur exécution SSH : {}", e);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
fn test_nomad_udp_packet(&self) {
|
|
let protocol = NomadProtocol::from_str(&self.cfg.ht_protocol);
|
|
log::info!(
|
|
"[Test Nomad] Envoi d'un paquet de test ({}) vers {}:{}...",
|
|
protocol.label(),
|
|
self.cfg.nomad_ip,
|
|
self.cfg.nomad_port
|
|
);
|
|
match NomadHeadTracker::new(
|
|
&self.cfg.nomad_ip,
|
|
self.cfg.nomad_port,
|
|
self.cfg.max_pan_deg,
|
|
self.cfg.max_tilt_deg,
|
|
self.cfg.max_roll_deg,
|
|
protocol,
|
|
) {
|
|
Ok(mut ht) => match ht.send_pose(glam::Quat::IDENTITY) {
|
|
Ok(sample) => {
|
|
if sample.send_errors == 0 {
|
|
log::info!(
|
|
"[Test Nomad] Paquet UDP envoyé avec succès vers {}:{} (Pan={}, Tilt={}, Roll={})",
|
|
self.cfg.nomad_ip,
|
|
self.cfg.nomad_port,
|
|
sample.pan_crsf,
|
|
sample.tilt_crsf,
|
|
sample.roll_crsf
|
|
);
|
|
}
|
|
}
|
|
Err(e) => log::error!("[Test Nomad] Erreur lors de l'envoi : {}", e),
|
|
},
|
|
Err(e) => log::error!("[Test Nomad] Configuration invalide : {}", e),
|
|
}
|
|
}
|
|
}
|
|
|
|
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.is_closing.store(true, Ordering::Release);
|
|
self.engine.lock().stop();
|
|
}
|
|
|
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
|
ctx.request_repaint_after(Duration::from_millis(16));
|
|
|
|
let (
|
|
usb_status,
|
|
xr_status,
|
|
nomad_status,
|
|
telem_status,
|
|
g29_status,
|
|
controller_status,
|
|
active_ctrl_source,
|
|
latest_g29,
|
|
latest_ctrl,
|
|
dvr_status,
|
|
dvr_recording,
|
|
dvr_secs,
|
|
dvr_bytes,
|
|
dvr_frames,
|
|
fps,
|
|
total_frames,
|
|
pose,
|
|
telem,
|
|
) = {
|
|
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
|
|
&& mon.preview_height > 0
|
|
{
|
|
self.last_displayed_frame_seq = mon.preview_frame_seq;
|
|
let image = egui::ColorImage::from_rgba_unmultiplied(
|
|
[mon.preview_width as usize, mon.preview_height as usize],
|
|
&mon.preview_rgba,
|
|
);
|
|
if let Some(ref mut tex) = self.video_texture {
|
|
tex.set(image, TextureOptions::LINEAR);
|
|
} else {
|
|
self.video_texture =
|
|
Some(ctx.load_texture("fpv_preview", image, TextureOptions::LINEAR));
|
|
}
|
|
ctx.request_repaint();
|
|
}
|
|
|
|
(
|
|
mon.usb_video_status.clone(),
|
|
mon.openxr_status.clone(),
|
|
mon.nomad_wifi_status.clone(),
|
|
mon.telemetry_status.clone(),
|
|
mon.g29_status.clone(),
|
|
mon.controller_status.clone(),
|
|
mon.active_control_source,
|
|
mon.latest_g29.clone(),
|
|
mon.latest_controller.clone(),
|
|
mon.dvr_status.clone(),
|
|
mon.dvr_recording,
|
|
mon.dvr_elapsed_secs,
|
|
mon.dvr_file_size_bytes,
|
|
mon.dvr_frames_recorded,
|
|
mon.video_fps,
|
|
mon.video_frames_total,
|
|
mon.latest_head_pose,
|
|
mon.latest_telemetry.clone(),
|
|
)
|
|
};
|
|
|
|
// =========================================================================
|
|
// 1. BARRE SUPÉRIEURE : ÉTAT DES SYSTÈMES + BOUTON TÉLÉMÉTRIE ON/OFF
|
|
// =========================================================================
|
|
egui::TopBottomPanel::top("top_status_bar")
|
|
.show(ctx, |ui| {
|
|
ui.horizontal_wrapped(|ui| {
|
|
ui.heading(
|
|
RichText::new(concat!("🥽 SteamFrame FPV v", env!("CARGO_PKG_VERSION")))
|
|
.strong(),
|
|
);
|
|
ui.separator();
|
|
|
|
let is_running = self
|
|
.engine
|
|
.try_lock()
|
|
.map(|e| e.is_running())
|
|
.unwrap_or(true);
|
|
if is_running {
|
|
if ui
|
|
.button(
|
|
RichText::new("🔄 Appliquer & Redémarrer")
|
|
.color(Color32::from_rgb(100, 230, 140)),
|
|
)
|
|
.clicked()
|
|
{
|
|
self.restart_engine_async("[Action Utilisateur] Redémarrage des services avec la nouvelle configuration...");
|
|
}
|
|
if ui
|
|
.button(
|
|
RichText::new("⏹ Arrêter les services")
|
|
.color(Color32::from_rgb(255, 180, 70)),
|
|
)
|
|
.clicked()
|
|
{
|
|
let engine_clone = Arc::clone(&self.engine);
|
|
std::thread::spawn(move || {
|
|
engine_clone.lock().stop();
|
|
});
|
|
}
|
|
} else if ui
|
|
.button(
|
|
RichText::new("▶ Démarrer les services")
|
|
.color(Color32::from_rgb(80, 240, 130))
|
|
.strong(),
|
|
)
|
|
.clicked()
|
|
{
|
|
self.restart_engine_async("[Action Utilisateur] Démarrage manuel des services...");
|
|
}
|
|
|
|
if ui.button("🎯 Recentrer la tête (Tare)").clicked() {
|
|
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))
|
|
.strong()
|
|
} else {
|
|
RichText::new("🎯 Suivi Tête : OFF")
|
|
.color(Color32::from_rgb(180, 180, 190))
|
|
};
|
|
|
|
if ui
|
|
.button(ht_btn_label)
|
|
.on_hover_text("Activer ou désactiver à chaud le suivi de tête et l'envoi UDP vers le RadioMaster Nomad")
|
|
.clicked()
|
|
{
|
|
self.cfg.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 {
|
|
RichText::new("📶 Télémétrie & OSD : ON")
|
|
.color(Color32::from_rgb(70, 245, 130))
|
|
.strong()
|
|
} else {
|
|
RichText::new("📶 Télémétrie & OSD : OFF")
|
|
.color(Color32::from_rgb(180, 180, 190))
|
|
};
|
|
|
|
if ui
|
|
.button(telem_btn_label)
|
|
.on_hover_text("Activer ou désactiver à chaud l'écoute UDP Télémétrie (14551) et l'affichage OSD")
|
|
.clicked()
|
|
{
|
|
self.cfg.telemetry_enabled = !self.cfg.telemetry_enabled;
|
|
self.controls.set_telemetry_enabled(self.cfg.telemetry_enabled);
|
|
}
|
|
|
|
ui.separator();
|
|
|
|
let dvr_btn_label = if dvr_recording {
|
|
let mb = dvr_bytes as f64 / (1024.0 * 1024.0);
|
|
let mins = dvr_secs / 60;
|
|
let secs = dvr_secs % 60;
|
|
RichText::new(format!("⏹ Arrêter DVR ({:02}:{:02} - {:.1} Mo)", mins, secs, mb))
|
|
.color(Color32::from_rgb(255, 80, 80))
|
|
.strong()
|
|
} else {
|
|
RichText::new("🔴 Enregistrer DVR")
|
|
.color(Color32::from_rgb(255, 120, 120))
|
|
.strong()
|
|
};
|
|
|
|
if ui
|
|
.button(dvr_btn_label)
|
|
.on_hover_text("Démarrer ou arrêter l'enregistrement vidéo DVR à chaud")
|
|
.clicked()
|
|
{
|
|
if dvr_recording {
|
|
self.controls.stop_dvr();
|
|
} else {
|
|
self.controls.start_dvr();
|
|
}
|
|
}
|
|
|
|
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
|
if ui
|
|
.button(
|
|
RichText::new("❌ Quitter l'application")
|
|
.color(Color32::from_rgb(255, 90, 90))
|
|
.strong(),
|
|
)
|
|
.clicked()
|
|
{
|
|
log::info!("[Action Utilisateur] Fermeture de l'application demandée.");
|
|
self.is_closing.store(true, Ordering::Release);
|
|
self.engine.lock().stop();
|
|
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
|
}
|
|
});
|
|
});
|
|
|
|
ui.add_space(6.0);
|
|
ui.horizontal_wrapped(|ui| {
|
|
Self::status_badge(ui, "VRX Radxa Zero 3W", &usb_status);
|
|
Self::status_badge(ui, "Casque OpenXR", &xr_status);
|
|
Self::status_badge(ui, "Wi-Fi Nomad ELRS", &nomad_status);
|
|
if active_ctrl_source == ControlSource::SteamController {
|
|
Self::status_badge(ui, "Steam Controller", &controller_status);
|
|
} else {
|
|
Self::status_badge(ui, "Volant G29", &g29_status);
|
|
}
|
|
Self::status_badge(ui, "Télémétrie OSD", &telem_status);
|
|
Self::status_badge(ui, "DVR Vidéo", &dvr_status);
|
|
});
|
|
});
|
|
|
|
// =========================================================================
|
|
// 2. PANNEAU INFÉRIEUR : JOURNAL D'ÉVÉNEMENTS & DIAGNOSTIC DES ERREURS
|
|
// =========================================================================
|
|
egui::TopBottomPanel::bottom("bottom_logs_panel")
|
|
.resizable(true)
|
|
.default_height(210.0)
|
|
.min_height(120.0)
|
|
.show(ctx, |ui| {
|
|
let (err_count, warn_count) = {
|
|
let lb = self.log_buffer.lock();
|
|
(lb.error_count, lb.warn_count)
|
|
};
|
|
|
|
ui.horizontal(|ui| {
|
|
ui.label(RichText::new("📋 Journal de Diagnostic & Erreurs").strong());
|
|
ui.separator();
|
|
|
|
ui.colored_label(
|
|
if err_count > 0 {
|
|
Color32::from_rgb(255, 80, 80)
|
|
} else {
|
|
Color32::GRAY
|
|
},
|
|
format!("Erreurs : {}", err_count),
|
|
);
|
|
ui.colored_label(
|
|
if warn_count > 0 {
|
|
Color32::from_rgb(255, 190, 60)
|
|
} else {
|
|
Color32::GRAY
|
|
},
|
|
format!("Avertissements : {}", warn_count),
|
|
);
|
|
|
|
ui.separator();
|
|
ui.selectable_value(&mut self.log_filter, LogFilter::All, "Tout afficher");
|
|
ui.selectable_value(
|
|
&mut self.log_filter,
|
|
LogFilter::WarningsAndErrors,
|
|
"Warn + Erreurs",
|
|
);
|
|
ui.selectable_value(
|
|
&mut self.log_filter,
|
|
LogFilter::ErrorsOnly,
|
|
"Erreurs seules",
|
|
);
|
|
|
|
ui.separator();
|
|
ui.checkbox(&mut self.auto_scroll_logs, "Défilement auto");
|
|
|
|
if ui.button("🧹 Effacer").clicked() {
|
|
let mut lb = self.log_buffer.lock();
|
|
lb.entries.clear();
|
|
lb.error_count = 0;
|
|
lb.warn_count = 0;
|
|
}
|
|
|
|
if ui.button("📎 Copier les logs").clicked() {
|
|
let lb = self.log_buffer.lock();
|
|
let dump: String = lb
|
|
.entries
|
|
.iter()
|
|
.map(|e| {
|
|
format!("[{}] [{}] ({}) {}", e.timestamp, e.level, e.target, e.message)
|
|
})
|
|
.collect::<Vec<_>>()
|
|
.join("\n");
|
|
ctx.copy_text(dump);
|
|
}
|
|
});
|
|
|
|
ui.separator();
|
|
|
|
egui::ScrollArea::vertical()
|
|
.auto_shrink([false, false])
|
|
.stick_to_bottom(self.auto_scroll_logs)
|
|
.show(ui, |ui| {
|
|
let lb = self.log_buffer.lock();
|
|
for entry in lb.entries.iter() {
|
|
match self.log_filter {
|
|
LogFilter::All => {}
|
|
LogFilter::WarningsAndErrors => {
|
|
if entry.level > Level::Warn {
|
|
continue;
|
|
}
|
|
}
|
|
LogFilter::ErrorsOnly => {
|
|
if entry.level != Level::Error {
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
|
|
let (lvl_color, badge) = match entry.level {
|
|
Level::Error => (Color32::from_rgb(255, 85, 85), "[ERREUR]"),
|
|
Level::Warn => (Color32::from_rgb(255, 195, 65), "[WARN] "),
|
|
_ => (Color32::from_rgb(130, 200, 255), "[INFO] "),
|
|
};
|
|
|
|
ui.horizontal_wrapped(|ui| {
|
|
ui.label(
|
|
RichText::new(&entry.timestamp)
|
|
.monospace()
|
|
.color(Color32::GRAY),
|
|
);
|
|
ui.label(RichText::new(badge).monospace().strong().color(lvl_color));
|
|
ui.label(
|
|
RichText::new(&entry.message)
|
|
.monospace()
|
|
.color(if entry.level == Level::Error {
|
|
Color32::from_rgb(255, 160, 160)
|
|
} else {
|
|
Color32::LIGHT_GRAY
|
|
}),
|
|
);
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
// =========================================================================
|
|
// 3. PANNEAU GAUCHE : CONFIGURATION RADXA ZERO 3W, WI-FI NOMAD & VR
|
|
// =========================================================================
|
|
egui::SidePanel::left("left_config_panel")
|
|
.resizable(true)
|
|
.default_width(360.0)
|
|
.show(ctx, |ui| {
|
|
egui::ScrollArea::vertical().show(ui, |ui| {
|
|
ui.heading("⚙ Configuration Matérielle");
|
|
ui.add_space(6.0);
|
|
|
|
// --- Section 1 : VRX Eachine Sphere Link (Radxa Zero 3W + 8812EU) ---
|
|
egui::CollapsingHeader::new(
|
|
RichText::new("🔌 1. VRX Sphere Link (Radxa Zero 3W + 8812EU)").strong(),
|
|
)
|
|
.default_open(true)
|
|
.show(ui, |ui| {
|
|
egui::Grid::new("usb_cfg_grid")
|
|
.num_columns(2)
|
|
.spacing([8.0, 6.0])
|
|
.show(ui, |ui| {
|
|
ui.label("Mode Entrée USB :");
|
|
egui::ComboBox::from_id_salt("usb_mode_combo")
|
|
.selected_text(if self.cfg.usb_video_mode == "uvc" {
|
|
"Mini-HDMI -> USB UVC"
|
|
} else {
|
|
"USB-C OTG RNDIS (RTP)"
|
|
})
|
|
.show_ui(ui, |ui| {
|
|
ui.selectable_value(
|
|
&mut self.cfg.usb_video_mode,
|
|
"rndis".to_string(),
|
|
"USB-C OTG RNDIS (Flux RTP direct :5600)",
|
|
);
|
|
ui.selectable_value(
|
|
&mut self.cfg.usb_video_mode,
|
|
"uvc".to_string(),
|
|
"Mini-HDMI -> Carte Capture USB-C UVC (/dev/video0)",
|
|
);
|
|
});
|
|
ui.end_row();
|
|
|
|
if self.cfg.usb_video_mode == "uvc" {
|
|
ui.label("Périphérique V4L2 :");
|
|
ui.text_edit_singleline(&mut self.cfg.uvc_device);
|
|
ui.end_row();
|
|
} else {
|
|
ui.label("IP Écoute SteamFrame :");
|
|
ui.text_edit_singleline(&mut self.cfg.usb_bind_ip);
|
|
ui.end_row();
|
|
|
|
ui.label("IP Radxa Zero 3W :");
|
|
ui.text_edit_singleline(&mut self.cfg.radxa_vrx_ip);
|
|
ui.end_row();
|
|
|
|
ui.label("Port UDP Vidéo RTP :");
|
|
ui.add(
|
|
egui::DragValue::new(&mut self.cfg.video_udp_port)
|
|
.range(1024..=65535),
|
|
);
|
|
ui.end_row();
|
|
|
|
ui.label("Format Transport UDP :");
|
|
egui::ComboBox::from_id_salt("transport_combo")
|
|
.selected_text(if self.cfg.stream_transport == "rtp" {
|
|
"RTP (OpenIPC / WFB)"
|
|
} else {
|
|
"Raw NAL (Ruby FPV direct)"
|
|
})
|
|
.show_ui(ui, |ui| {
|
|
ui.selectable_value(
|
|
&mut self.cfg.stream_transport,
|
|
"raw".to_string(),
|
|
"Raw NAL (Ruby FPV direct)",
|
|
);
|
|
ui.selectable_value(
|
|
&mut self.cfg.stream_transport,
|
|
"rtp".to_string(),
|
|
"RTP (OpenIPC / WFB-ng)",
|
|
);
|
|
});
|
|
ui.end_row();
|
|
|
|
ui.label("Codec Vidéo :");
|
|
egui::ComboBox::from_id_salt("codec_combo")
|
|
.selected_text(self.cfg.codec.to_uppercase())
|
|
.show_ui(ui, |ui| {
|
|
ui.selectable_value(
|
|
&mut self.cfg.codec,
|
|
"h264".to_string(),
|
|
"H.264 (AVC - Défaut Ruby)",
|
|
);
|
|
ui.selectable_value(
|
|
&mut self.cfg.codec,
|
|
"h265".to_string(),
|
|
"H.265 (HEVC)",
|
|
);
|
|
});
|
|
ui.end_row();
|
|
}
|
|
|
|
ui.label("Canal 5.8GHz (8812EU) :");
|
|
egui::ComboBox::from_id_salt("ch_combo")
|
|
.selected_text(format!("Canal {}", self.cfg.wifi_channel))
|
|
.show_ui(ui, |ui| {
|
|
for &(ch, desc) in &[
|
|
(161, "Canal 161 (5805 MHz - Défaut usine)"),
|
|
(149, "Canal 149 (5745 MHz)"),
|
|
(153, "Canal 153 (5765 MHz)"),
|
|
(157, "Canal 157 (5785 MHz)"),
|
|
(165, "Canal 165 (5825 MHz)"),
|
|
(36, "Canal 36 (5180 MHz)"),
|
|
(40, "Canal 40 (5200 MHz)"),
|
|
(44, "Canal 44 (5220 MHz)"),
|
|
(48, "Canal 48 (5240 MHz)"),
|
|
] {
|
|
ui.selectable_value(
|
|
&mut self.cfg.wifi_channel,
|
|
ch,
|
|
desc,
|
|
);
|
|
}
|
|
});
|
|
ui.end_row();
|
|
|
|
ui.label("Profil Résolution VRX :");
|
|
egui::ComboBox::from_id_salt("res_profile_combo")
|
|
.selected_text(&self.cfg.vrx_video_profile)
|
|
.show_ui(ui, |ui| {
|
|
if ui
|
|
.selectable_value(
|
|
&mut self.cfg.vrx_video_profile,
|
|
"720p60".to_string(),
|
|
"720P @ 60 FPS (Défaut)",
|
|
)
|
|
.clicked()
|
|
{
|
|
self.cfg.video_width = 1280;
|
|
self.cfg.video_height = 720;
|
|
}
|
|
if ui
|
|
.selectable_value(
|
|
&mut self.cfg.vrx_video_profile,
|
|
"1080p60".to_string(),
|
|
"1080P @ 60 FPS (Défaut usine)",
|
|
)
|
|
.clicked()
|
|
{
|
|
self.cfg.video_width = 1920;
|
|
self.cfg.video_height = 1080;
|
|
}
|
|
if ui
|
|
.selectable_value(
|
|
&mut self.cfg.vrx_video_profile,
|
|
"1080p90".to_string(),
|
|
"1080P @ 90 FPS (Basse latence)",
|
|
)
|
|
.clicked()
|
|
{
|
|
self.cfg.video_width = 1920;
|
|
self.cfg.video_height = 1080;
|
|
}
|
|
if ui
|
|
.selectable_value(
|
|
&mut self.cfg.vrx_video_profile,
|
|
"720p120".to_string(),
|
|
"720P @ 120 FPS (Latence 40-50 ms)",
|
|
)
|
|
.clicked()
|
|
{
|
|
self.cfg.video_width = 1280;
|
|
self.cfg.video_height = 720;
|
|
}
|
|
});
|
|
ui.end_row();
|
|
});
|
|
|
|
if self.cfg.usb_video_mode != "uvc" {
|
|
ui.add_space(4.0);
|
|
if ui
|
|
.button("⚡ 1. Configurer l'interface usb0 (RNDIS)")
|
|
.clicked()
|
|
{
|
|
self.run_usb_rndis_setup_script();
|
|
}
|
|
if ui
|
|
.button(format!(
|
|
"🔧 2. Appliquer Canal {} sur la Radxa Zero 3W (SSH)",
|
|
self.cfg.wifi_channel
|
|
))
|
|
.clicked()
|
|
{
|
|
self.configure_radxa_vrx_over_usb();
|
|
}
|
|
}
|
|
});
|
|
|
|
ui.add_space(8.0);
|
|
|
|
// --- Section 2 : Wi-Fi RadioMaster Nomad (ELRS Backpack) ---
|
|
egui::CollapsingHeader::new(
|
|
RichText::new("📡 2. Wi-Fi RadioMaster Nomad (Suivi de Tête)").strong(),
|
|
)
|
|
.default_open(true)
|
|
.show(ui, |ui| {
|
|
ui.horizontal(|ui| {
|
|
ui.label(RichText::new("Suivi de Tête Nomad :").strong());
|
|
let btn_text = if self.cfg.head_tracking_enabled {
|
|
RichText::new("🟢 ON (Activé)")
|
|
.color(Color32::from_rgb(80, 240, 120))
|
|
.strong()
|
|
} else {
|
|
RichText::new("⚪ OFF (Désactivé)")
|
|
.color(Color32::from_rgb(170, 170, 180))
|
|
};
|
|
if ui.button(btn_text).clicked() {
|
|
self.cfg.head_tracking_enabled = !self.cfg.head_tracking_enabled;
|
|
self.controls.set_head_tracking_enabled(self.cfg.head_tracking_enabled);
|
|
}
|
|
});
|
|
ui.add_space(4.0);
|
|
|
|
egui::Grid::new("nomad_cfg_grid")
|
|
.num_columns(2)
|
|
.spacing([8.0, 6.0])
|
|
.show(ui, |ui| {
|
|
ui.label("IP Backpack Nomad :");
|
|
ui.text_edit_singleline(&mut self.cfg.nomad_ip);
|
|
ui.end_row();
|
|
|
|
ui.label("Port UDP Nomad :");
|
|
ui.add(
|
|
egui::DragValue::new(&mut self.cfg.nomad_port)
|
|
.range(1024..=65535),
|
|
);
|
|
ui.end_row();
|
|
|
|
ui.label("Protocole Head-Track :");
|
|
egui::ComboBox::from_id_salt("ht_proto_combo")
|
|
.selected_text(NomadProtocol::from_str(&self.cfg.ht_protocol).label())
|
|
.show_ui(ui, |ui| {
|
|
ui.selectable_value(
|
|
&mut self.cfg.ht_protocol,
|
|
"g29".to_string(),
|
|
"G29 Hub unifié ($HT - UDP 14552)",
|
|
);
|
|
ui.selectable_value(
|
|
&mut self.cfg.ht_protocol,
|
|
"msp".to_string(),
|
|
"MSPv2 PTR (0x0383 - Backpack AP)",
|
|
);
|
|
ui.selectable_value(
|
|
&mut self.cfg.ht_protocol,
|
|
"crsf".to_string(),
|
|
"CRSF RC_CHANNELS_PACKED (0x16)",
|
|
);
|
|
ui.selectable_value(
|
|
&mut self.cfg.ht_protocol,
|
|
"mavlink".to_string(),
|
|
"MAVLink v1 RC Override (UDP 14555)",
|
|
);
|
|
});
|
|
ui.end_row();
|
|
|
|
ui.label("Course Max Pan (°) :");
|
|
ui.add(
|
|
egui::Slider::new(&mut self.cfg.max_pan_deg, 15.0..=180.0)
|
|
.suffix("°"),
|
|
);
|
|
ui.end_row();
|
|
|
|
ui.label("Course Max Tilt (°) :");
|
|
ui.add(
|
|
egui::Slider::new(&mut self.cfg.max_tilt_deg, 15.0..=120.0)
|
|
.suffix("°"),
|
|
);
|
|
ui.end_row();
|
|
|
|
ui.label("Course Max Roll (°) :");
|
|
ui.add(
|
|
egui::Slider::new(&mut self.cfg.max_roll_deg, 15.0..=90.0)
|
|
.suffix("°"),
|
|
);
|
|
ui.end_row();
|
|
});
|
|
|
|
ui.add_space(4.0);
|
|
if ui.button("📡 Envoyer un paquet de test au Nomad").clicked() {
|
|
self.test_nomad_udp_packet();
|
|
}
|
|
});
|
|
|
|
ui.add_space(8.0);
|
|
|
|
// --- Section 2b : Contrôleur de Conduite (Volant G29 / Steam Controller) ---
|
|
egui::CollapsingHeader::new(
|
|
RichText::new("🎮 2b. Contrôleur de Conduite (Volant G29 / Steam Controller)")
|
|
.strong(),
|
|
)
|
|
.default_open(true)
|
|
.show(ui, |ui| {
|
|
ui.horizontal(|ui| {
|
|
ui.label(RichText::new("Source active :").strong());
|
|
if ui
|
|
.selectable_label(
|
|
active_ctrl_source == ControlSource::G29,
|
|
"🏎️ Volant G29",
|
|
)
|
|
.clicked()
|
|
{
|
|
match self.controls.set_control_source(ControlSource::G29) {
|
|
Ok(()) => {
|
|
self.cfg.control_source = "g29".to_string();
|
|
self.control_switch_error.clear();
|
|
}
|
|
Err(msg) => self.control_switch_error = msg,
|
|
}
|
|
}
|
|
if ui
|
|
.selectable_label(
|
|
active_ctrl_source == ControlSource::SteamController,
|
|
"🎮 Steam Controller",
|
|
)
|
|
.clicked()
|
|
{
|
|
match self
|
|
.controls
|
|
.set_control_source(ControlSource::SteamController)
|
|
{
|
|
Ok(()) => {
|
|
self.cfg.control_source = "steam".to_string();
|
|
self.control_switch_error.clear();
|
|
}
|
|
Err(msg) => self.control_switch_error = msg,
|
|
}
|
|
}
|
|
});
|
|
|
|
if !self.control_switch_error.is_empty() {
|
|
ui.colored_label(
|
|
Color32::from_rgb(255, 85, 85),
|
|
format!("⚠ {}", self.control_switch_error),
|
|
);
|
|
}
|
|
|
|
ui.add_space(4.0);
|
|
if latest_ctrl.connected {
|
|
ui.colored_label(
|
|
Color32::from_rgb(80, 235, 130),
|
|
format!(
|
|
"● {} ({}) — [{}] {} | Gaz {}% | Frn {}% | Dir {:+.0}%",
|
|
latest_ctrl.device_name,
|
|
latest_ctrl.device_path,
|
|
latest_ctrl.gear_label(),
|
|
if latest_ctrl.armed { "ARMED" } else { "SAFE" },
|
|
latest_ctrl.throttle_pct,
|
|
latest_ctrl.brake_pct,
|
|
latest_ctrl.steering_norm * 100.0
|
|
),
|
|
);
|
|
} else {
|
|
ui.colored_label(
|
|
Color32::GRAY,
|
|
"○ Steam Controller non détecté (dongle / USB)",
|
|
);
|
|
}
|
|
|
|
ui.add_space(4.0);
|
|
egui::Grid::new("ctrl_cfg_grid")
|
|
.num_columns(2)
|
|
.spacing([8.0, 6.0])
|
|
.show(ui, |ui| {
|
|
ui.label("Expo direction SC :");
|
|
ui.add(egui::Slider::new(&mut self.cfg.controller_expo, 0.0..=0.8));
|
|
ui.end_row();
|
|
|
|
ui.label("Zone morte stick :");
|
|
ui.add(egui::Slider::new(
|
|
&mut self.cfg.controller_deadzone,
|
|
0.0..=0.4,
|
|
));
|
|
ui.end_row();
|
|
|
|
ui.label("Inverser direction :");
|
|
ui.checkbox(&mut self.cfg.controller_invert_steering, "Inversée");
|
|
ui.end_row();
|
|
|
|
ui.label("Vibrations SC (%) :");
|
|
ui.horizontal(|ui| {
|
|
if ui
|
|
.add(
|
|
egui::Slider::new(
|
|
&mut self.cfg.controller_vibration,
|
|
0..=100,
|
|
)
|
|
.suffix("%"),
|
|
)
|
|
.changed()
|
|
{
|
|
self.controls.set_controller_vibration_pct(
|
|
self.cfg.controller_vibration,
|
|
);
|
|
}
|
|
if ui.button("📳 Tester Vibrations").clicked() {
|
|
self.controls.trigger_controller_rumble_test();
|
|
}
|
|
});
|
|
ui.end_row();
|
|
});
|
|
|
|
ui.add_space(6.0);
|
|
ui.label(
|
|
RichText::new("Vitesses CRSF (Volant G29 + Steam Controller)")
|
|
.strong(),
|
|
);
|
|
let mut gears_changed = false;
|
|
egui::Grid::new("ctrl_gears_grid")
|
|
.num_columns(2)
|
|
.spacing([8.0, 6.0])
|
|
.show(ui, |ui| {
|
|
ui.label("Seuil Gaz Avant (Min) :");
|
|
gears_changed |= ui
|
|
.add(egui::Slider::new(
|
|
&mut self.cfg.gaz_avant_min,
|
|
CRSF_CHANNEL_MID..=CRSF_CHANNEL_MAX,
|
|
))
|
|
.changed();
|
|
ui.end_row();
|
|
|
|
ui.label("1ère Vitesse (Manœuvre) :");
|
|
gears_changed |= ui
|
|
.add(egui::Slider::new(
|
|
&mut self.cfg.gear_1_max,
|
|
self.cfg.gaz_avant_min..=CRSF_CHANNEL_MAX,
|
|
))
|
|
.changed();
|
|
ui.end_row();
|
|
|
|
ui.label("2ème Vitesse (Normale) :");
|
|
gears_changed |= ui
|
|
.add(egui::Slider::new(
|
|
&mut self.cfg.gear_2_max,
|
|
self.cfg.gaz_avant_min..=CRSF_CHANNEL_MAX,
|
|
))
|
|
.changed();
|
|
ui.end_row();
|
|
|
|
ui.label("3ème Vitesse (Rapide) :");
|
|
gears_changed |= ui
|
|
.add(egui::Slider::new(
|
|
&mut self.cfg.gear_3_max,
|
|
self.cfg.gaz_avant_min..=CRSF_CHANNEL_MAX,
|
|
))
|
|
.changed();
|
|
ui.end_row();
|
|
|
|
ui.label("Seuil Gaz Arrière (Min) :");
|
|
gears_changed |= ui
|
|
.add(egui::Slider::new(
|
|
&mut self.cfg.gaz_arriere_min,
|
|
CRSF_CHANNEL_MIN..=CRSF_CHANNEL_MID,
|
|
))
|
|
.changed();
|
|
ui.end_row();
|
|
|
|
ui.label("Plafond Marche Arrière (R) :");
|
|
gears_changed |= ui
|
|
.add(egui::Slider::new(
|
|
&mut self.cfg.gear_reverse_max,
|
|
CRSF_CHANNEL_MIN..=self.cfg.gaz_arriere_min,
|
|
))
|
|
.changed();
|
|
ui.end_row();
|
|
});
|
|
|
|
if ui.button("↺ Vitesses par défaut").clicked() {
|
|
let def = GearSpeedLimits::default();
|
|
self.cfg.gaz_avant_min = def.forward_min;
|
|
self.cfg.gear_1_max = def.forward_max[0];
|
|
self.cfg.gear_2_max = def.forward_max[1];
|
|
self.cfg.gear_3_max = def.forward_max[2];
|
|
self.cfg.gaz_arriere_min = def.reverse_min;
|
|
self.cfg.gear_reverse_max = def.reverse_max;
|
|
gears_changed = true;
|
|
}
|
|
|
|
if gears_changed {
|
|
let sanitized = GearSpeedLimits {
|
|
forward_min: self.cfg.gaz_avant_min,
|
|
forward_max: [
|
|
self.cfg.gear_1_max,
|
|
self.cfg.gear_2_max,
|
|
self.cfg.gear_3_max,
|
|
],
|
|
reverse_min: self.cfg.gaz_arriere_min,
|
|
reverse_max: self.cfg.gear_reverse_max,
|
|
}
|
|
.sanitized();
|
|
self.cfg.gaz_avant_min = sanitized.forward_min;
|
|
self.cfg.gear_1_max = sanitized.forward_max[0];
|
|
self.cfg.gear_2_max = sanitized.forward_max[1];
|
|
self.cfg.gear_3_max = sanitized.forward_max[2];
|
|
self.cfg.gaz_arriere_min = sanitized.reverse_min;
|
|
self.cfg.gear_reverse_max = sanitized.reverse_max;
|
|
self.controls.set_gear_speed_limits(sanitized);
|
|
}
|
|
|
|
ui.add_space(6.0);
|
|
egui::Frame::group(ui.style())
|
|
.fill(Color32::from_rgb(16, 20, 28))
|
|
.inner_margin(egui::Margin::same(8.0))
|
|
.show(ui, |ui| {
|
|
let viewed = self
|
|
.monitor_source_override
|
|
.unwrap_or(active_ctrl_source);
|
|
ui.horizontal(|ui| {
|
|
ui.label(
|
|
RichText::new(format!(
|
|
"📊 Moniteur — {}",
|
|
viewed.label()
|
|
))
|
|
.strong()
|
|
.color(Color32::from_rgb(90, 220, 255)),
|
|
);
|
|
ui.selectable_value(
|
|
&mut self.monitor_source_override,
|
|
None,
|
|
"Auto",
|
|
);
|
|
ui.selectable_value(
|
|
&mut self.monitor_source_override,
|
|
Some(ControlSource::G29),
|
|
"G29",
|
|
);
|
|
ui.selectable_value(
|
|
&mut self.monitor_source_override,
|
|
Some(ControlSource::SteamController),
|
|
"Steam",
|
|
);
|
|
});
|
|
|
|
let (
|
|
online,
|
|
failsafe,
|
|
armed,
|
|
gear_lbl,
|
|
steer_pct,
|
|
steer_crsf,
|
|
throt_pct,
|
|
throt_crsf,
|
|
brake_pct,
|
|
brake_crsf,
|
|
clutch_pct,
|
|
clutch_crsf,
|
|
last_btn,
|
|
detail,
|
|
) = if viewed == ControlSource::SteamController {
|
|
(
|
|
latest_ctrl.connected,
|
|
!latest_ctrl.connected,
|
|
latest_ctrl.armed,
|
|
latest_ctrl.gear_label(),
|
|
latest_ctrl.steering_norm * 100.0,
|
|
latest_ctrl.steer_crsf,
|
|
latest_ctrl.throttle_pct,
|
|
latest_ctrl.throttle_crsf,
|
|
latest_ctrl.brake_pct,
|
|
latest_ctrl.brake_crsf,
|
|
latest_ctrl.clutch_pct,
|
|
latest_ctrl.clutch_crsf,
|
|
if latest_ctrl.last_button.is_empty() {
|
|
"Aucun".to_string()
|
|
} else {
|
|
latest_ctrl.last_button.clone()
|
|
},
|
|
format!(
|
|
"Vib {}% (G:{}% D:{}%) | $RC envoyés : {} (Err : {})",
|
|
latest_ctrl.vibration_pct,
|
|
latest_ctrl.rumble_left_pct,
|
|
latest_ctrl.rumble_right_pct,
|
|
latest_ctrl.packets_sent,
|
|
latest_ctrl.send_errors
|
|
),
|
|
)
|
|
} else {
|
|
let live = latest_g29.is_live();
|
|
(
|
|
live,
|
|
!live || latest_g29.failsafe,
|
|
latest_g29.armed,
|
|
latest_g29.gear_label(),
|
|
latest_g29.steering_pct as f32,
|
|
latest_g29.steer_crsf,
|
|
latest_g29.throttle_pct,
|
|
latest_g29.throttle_crsf,
|
|
latest_g29.brake_pct,
|
|
latest_g29.brake_crsf,
|
|
latest_g29.clutch_pct,
|
|
latest_g29.clutch_crsf,
|
|
if latest_g29.last_button.is_empty() {
|
|
"Aucun".to_string()
|
|
} else {
|
|
latest_g29.last_button.clone()
|
|
},
|
|
format!(
|
|
"FFB {}% | Vib {}% | RX {} | RP2350: {}",
|
|
latest_g29.ffb_pct,
|
|
latest_g29.vib_pct,
|
|
latest_g29.packets_received,
|
|
latest_g29.remote_source.wire_tag()
|
|
),
|
|
)
|
|
};
|
|
|
|
ui.horizontal_wrapped(|ui| {
|
|
ui.colored_label(
|
|
if online {
|
|
Color32::from_rgb(80, 235, 130)
|
|
} else {
|
|
Color32::GRAY
|
|
},
|
|
if online { "● CONNECTÉ" } else { "○ HORS LIGNE" },
|
|
);
|
|
ui.label(RichText::new(format!("BOÎTE [{}]", gear_lbl)).strong());
|
|
ui.colored_label(
|
|
if failsafe {
|
|
Color32::from_rgb(255, 80, 80)
|
|
} else if armed {
|
|
Color32::from_rgb(80, 235, 130)
|
|
} else {
|
|
Color32::from_rgb(255, 185, 60)
|
|
},
|
|
if failsafe {
|
|
"FAILSAFE (CH5: 172)"
|
|
} else if armed {
|
|
"ARMED (CH5: 1811)"
|
|
} else {
|
|
"SAFE (CH5: 172)"
|
|
},
|
|
);
|
|
});
|
|
|
|
let steer_frac = ((steer_pct + 100.0) / 200.0).clamp(0.0, 1.0);
|
|
ui.add(
|
|
egui::ProgressBar::new(steer_frac)
|
|
.text(format!(
|
|
"Direction CH1 : {:+.0}% (CRSF {})",
|
|
steer_pct, steer_crsf
|
|
)),
|
|
);
|
|
ui.add(
|
|
egui::ProgressBar::new((throt_pct as f32 / 100.0).clamp(0.0, 1.0))
|
|
.text(format!(
|
|
"Accélérateur CH2 : {}% (CRSF {})",
|
|
throt_pct, throt_crsf
|
|
)),
|
|
);
|
|
ui.add(
|
|
egui::ProgressBar::new((brake_pct as f32 / 100.0).clamp(0.0, 1.0))
|
|
.text(format!(
|
|
"Frein CH3 : {}% (CRSF {})",
|
|
brake_pct, brake_crsf
|
|
)),
|
|
);
|
|
ui.add(
|
|
egui::ProgressBar::new((clutch_pct as f32 / 100.0).clamp(0.0, 1.0))
|
|
.text(format!(
|
|
"Embrayage CH4 : {}% (CRSF {})",
|
|
clutch_pct, clutch_crsf
|
|
)),
|
|
);
|
|
ui.small(format!("🔘 Dernier bouton : {} • {}", last_btn, detail));
|
|
});
|
|
|
|
ui.small("Stick G: Dir | R2: Gaz | L2: Frein | RB/LB ou R4/L4: Boîte R/N/1/2/3 | Menu: Armer (au N)");
|
|
});
|
|
|
|
ui.add_space(8.0);
|
|
|
|
// --- Section 3 : Télémétrie (Optionnelle ON/OFF) & Projection VR ---
|
|
egui::CollapsingHeader::new(
|
|
RichText::new("🥽 3. Projection VR 140° & Télémétrie (Optionnelle)")
|
|
.strong(),
|
|
)
|
|
.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 {
|
|
RichText::new("🟢 ON (Activée)")
|
|
.color(Color32::from_rgb(80, 240, 120))
|
|
.strong()
|
|
} else {
|
|
RichText::new("⚪ OFF (Désactivée)")
|
|
.color(Color32::from_rgb(170, 170, 180))
|
|
};
|
|
if ui.button(btn_text).clicked() {
|
|
self.cfg.telemetry_enabled = !self.cfg.telemetry_enabled;
|
|
self.controls.set_telemetry_enabled(self.cfg.telemetry_enabled);
|
|
}
|
|
});
|
|
|
|
if self.cfg.telemetry_enabled {
|
|
ui.horizontal(|ui| {
|
|
ui.label("Port UDP Télémétrie :");
|
|
ui.add(
|
|
egui::DragValue::new(&mut self.cfg.telemetry_udp_port)
|
|
.range(1024..=65535),
|
|
);
|
|
});
|
|
}
|
|
|
|
ui.separator();
|
|
|
|
egui::Grid::new("vr_cfg_grid")
|
|
.num_columns(2)
|
|
.spacing([8.0, 6.0])
|
|
.show(ui, |ui| {
|
|
ui.label("Mode Projection :");
|
|
egui::ComboBox::from_id_salt("proj_combo")
|
|
.selected_text(&self.cfg.projection_mode)
|
|
.show_ui(ui, |ui| {
|
|
ui.selectable_value(
|
|
&mut self.cfg.projection_mode,
|
|
"dome".to_string(),
|
|
"Dôme Sphérique 140° (Equirect2)",
|
|
);
|
|
ui.selectable_value(
|
|
&mut self.cfg.projection_mode,
|
|
"cylinder".to_string(),
|
|
"Cylindre Incurvé 140°",
|
|
);
|
|
ui.selectable_value(
|
|
&mut self.cfg.projection_mode,
|
|
"flat".to_string(),
|
|
"Écran Plat (Quad)",
|
|
);
|
|
});
|
|
ui.end_row();
|
|
|
|
ui.label("FOV Caméra (°) :");
|
|
if ui
|
|
.add(
|
|
egui::Slider::new(&mut self.cfg.camera_fov_deg, 70.0..=180.0)
|
|
.suffix("°"),
|
|
)
|
|
.changed()
|
|
{
|
|
self.sync_optical_params();
|
|
}
|
|
ui.end_row();
|
|
|
|
ui.label("Correction Lentille k1 :");
|
|
if ui
|
|
.add(egui::Slider::new(&mut self.cfg.lens_k1, -0.50..=0.50))
|
|
.changed()
|
|
{
|
|
self.sync_optical_params();
|
|
}
|
|
ui.end_row();
|
|
|
|
ui.label("Correction Lentille k2 :");
|
|
if ui
|
|
.add(egui::Slider::new(&mut self.cfg.lens_k2, -0.25..=0.25))
|
|
.changed()
|
|
{
|
|
self.sync_optical_params();
|
|
}
|
|
ui.end_row();
|
|
|
|
ui.label("Rayon / Distance (m) :");
|
|
if ui
|
|
.add(
|
|
egui::Slider::new(&mut self.cfg.screen_distance_m, 0.8..=4.0)
|
|
.suffix(" m"),
|
|
)
|
|
.changed()
|
|
{
|
|
self.sync_optical_params();
|
|
}
|
|
ui.end_row();
|
|
});
|
|
|
|
ui.add_space(4.0);
|
|
if ui
|
|
.button(RichText::new("✔ Appliquer les changements").strong())
|
|
.clicked()
|
|
{
|
|
self.restart_engine_async("[Réglages] Application et redémarrage asynchrone du moteur FPV...");
|
|
}
|
|
});
|
|
|
|
ui.add_space(8.0);
|
|
|
|
// --- Section 4 : Enregistrement DVR Vidéo ---
|
|
egui::CollapsingHeader::new(
|
|
RichText::new("🔴 4. Enregistrement Vidéo DVR").strong(),
|
|
)
|
|
.default_open(true)
|
|
.show(ui, |ui| {
|
|
egui::Grid::new("dvr_cfg_grid")
|
|
.num_columns(2)
|
|
.spacing([8.0, 6.0])
|
|
.show(ui, |ui| {
|
|
ui.label("Dossier Vidéo :");
|
|
ui.text_edit_singleline(&mut self.cfg.dvr_dir);
|
|
ui.end_row();
|
|
|
|
ui.label("Format Conteneur :");
|
|
egui::ComboBox::from_id_salt("dvr_fmt_combo")
|
|
.selected_text(self.cfg.dvr_format.to_uppercase())
|
|
.show_ui(ui, |ui| {
|
|
if ui
|
|
.selectable_value(
|
|
&mut self.cfg.dvr_format,
|
|
"mkv".to_string(),
|
|
"MKV (Matroska - Résistant coupure batterie)",
|
|
)
|
|
.clicked()
|
|
{
|
|
self.sync_dvr_config();
|
|
}
|
|
if ui
|
|
.selectable_value(
|
|
&mut self.cfg.dvr_format,
|
|
"mp4".to_string(),
|
|
"MP4 (Fragmenté)",
|
|
)
|
|
.clicked()
|
|
{
|
|
self.sync_dvr_config();
|
|
}
|
|
});
|
|
ui.end_row();
|
|
|
|
ui.label("Mode DVR :");
|
|
let mode_label = if self.cfg.dvr_mode == "composited" || self.cfg.dvr_mode == "osd" {
|
|
"Avec OSD incrusté (Re-encodage rapide)"
|
|
} else {
|
|
"Flux natif Zéro-CPU (StreamCopy direct)"
|
|
};
|
|
egui::ComboBox::from_id_salt("dvr_mode_combo")
|
|
.selected_text(mode_label)
|
|
.show_ui(ui, |ui| {
|
|
if ui
|
|
.selectable_value(
|
|
&mut self.cfg.dvr_mode,
|
|
"copy".to_string(),
|
|
"Flux natif Zéro-CPU (StreamCopy direct)",
|
|
)
|
|
.clicked()
|
|
{
|
|
self.sync_dvr_config();
|
|
}
|
|
if ui
|
|
.selectable_value(
|
|
&mut self.cfg.dvr_mode,
|
|
"composited".to_string(),
|
|
"Avec OSD incrusté (Re-encodage rapide)",
|
|
)
|
|
.clicked()
|
|
{
|
|
self.sync_dvr_config();
|
|
}
|
|
});
|
|
ui.end_row();
|
|
});
|
|
|
|
ui.add_space(4.0);
|
|
if dvr_recording {
|
|
let mb = dvr_bytes as f64 / (1024.0 * 1024.0);
|
|
let mins = dvr_secs / 60;
|
|
let secs = dvr_secs % 60;
|
|
ui.colored_label(
|
|
Color32::from_rgb(255, 75, 75),
|
|
format!(
|
|
"● ENREGISTREMENT ACTIF : {:02}:{:02} ({} trames, {:.1} Mo)",
|
|
mins, secs, dvr_frames, mb
|
|
),
|
|
);
|
|
if ui
|
|
.button(
|
|
RichText::new("⏹ Arrêter l'enregistrement DVR")
|
|
.color(Color32::from_rgb(255, 80, 80))
|
|
.strong(),
|
|
)
|
|
.clicked()
|
|
{
|
|
self.controls.stop_dvr();
|
|
}
|
|
} else {
|
|
if ui
|
|
.button(
|
|
RichText::new("🔴 Démarrer l'enregistrement DVR")
|
|
.color(Color32::from_rgb(255, 110, 110))
|
|
.strong(),
|
|
)
|
|
.clicked()
|
|
{
|
|
self.controls.start_dvr();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
// =========================================================================
|
|
// 4. PANNEAU CENTRAL : APERÇU VIDÉO TEMPS RÉEL + JAUGES HEAD-TRACKING & DRONE
|
|
// =========================================================================
|
|
egui::CentralPanel::default().show(ctx, |ui| {
|
|
egui::ScrollArea::vertical().show(ui, |ui| {
|
|
ui.columns(2, |cols| {
|
|
egui::Frame::group(cols[0].style()).show(&mut cols[0], |ui| {
|
|
ui.horizontal(|ui| {
|
|
ui.label(
|
|
RichText::new("🎯 Suivi de Tête -> RadioMaster Nomad")
|
|
.strong(),
|
|
);
|
|
let status_text = if self.cfg.head_tracking_enabled {
|
|
RichText::new("[ON]")
|
|
.color(Color32::from_rgb(80, 240, 120))
|
|
.strong()
|
|
} else {
|
|
RichText::new("[OFF]")
|
|
.color(Color32::from_rgb(170, 170, 180))
|
|
};
|
|
ui.label(status_text);
|
|
});
|
|
ui.add_space(4.0);
|
|
|
|
if self.cfg.head_tracking_enabled {
|
|
let pan_norm = (pose.pan_crsf as f32 - 172.0) / (1811.0 - 172.0);
|
|
ui.add(
|
|
egui::ProgressBar::new(pan_norm.clamp(0.0, 1.0)).text(format!(
|
|
"PAN (Lacet) : {:+5.1}° | CRSF = {}",
|
|
pose.pan_deg, pose.pan_crsf
|
|
)),
|
|
);
|
|
|
|
let tilt_norm = (pose.tilt_crsf as f32 - 172.0) / (1811.0 - 172.0);
|
|
ui.add(
|
|
egui::ProgressBar::new(tilt_norm.clamp(0.0, 1.0)).text(format!(
|
|
"TILT (Tangage) : {:+5.1}° | CRSF = {}",
|
|
pose.tilt_deg, pose.tilt_crsf
|
|
)),
|
|
);
|
|
|
|
let roll_norm = (pose.roll_crsf as f32 - 172.0) / (1811.0 - 172.0);
|
|
ui.add(
|
|
egui::ProgressBar::new(roll_norm.clamp(0.0, 1.0)).text(format!(
|
|
"ROLL (Roulis) : {:+5.1}° | CRSF = {}",
|
|
pose.roll_deg, pose.roll_crsf
|
|
)),
|
|
);
|
|
|
|
ui.add_space(4.0);
|
|
ui.label(format!(
|
|
"Paquets Wi-Fi UDP envoyés : {} | Erreurs d'envoi : {}",
|
|
pose.packets_sent, pose.send_errors
|
|
));
|
|
} else {
|
|
ui.colored_label(
|
|
Color32::GRAY,
|
|
"Suivi de tête désactivé (OFF). Cliquez sur « 🎯 Suivi Tête : OFF » pour l'activer.",
|
|
);
|
|
ui.add_space(4.0);
|
|
}
|
|
|
|
ui.collapsing("🕹 Simuler les mouvements de tête (Test Bureau)", |ui| {
|
|
let mut mon = self.engine_monitor.lock();
|
|
ui.add(
|
|
egui::Slider::new(
|
|
&mut mon.manual_pan_deg,
|
|
-self.cfg.max_pan_deg..=self.cfg.max_pan_deg,
|
|
)
|
|
.text("Simuler Pan (°)"),
|
|
);
|
|
ui.add(
|
|
egui::Slider::new(
|
|
&mut mon.manual_tilt_deg,
|
|
-self.cfg.max_tilt_deg..=self.cfg.max_tilt_deg,
|
|
)
|
|
.text("Simuler Tilt (°)"),
|
|
);
|
|
ui.add(
|
|
egui::Slider::new(
|
|
&mut mon.manual_roll_deg,
|
|
-self.cfg.max_roll_deg..=self.cfg.max_roll_deg,
|
|
)
|
|
.text("Simuler Roll (°)"),
|
|
);
|
|
});
|
|
});
|
|
|
|
egui::Frame::group(cols[1].style()).show(&mut cols[1], |ui| {
|
|
ui.label(
|
|
RichText::new("📊 VRX Radxa Zero 3W (8812EU) & Télémétrie").strong(),
|
|
);
|
|
ui.add_space(4.0);
|
|
|
|
ui.label(format!(
|
|
"🎞 Vidéo USB ({}) : {:.1} FPS | Frames : {} | Canal 5.8GHz : {}",
|
|
self.cfg.vrx_video_profile,
|
|
fps,
|
|
total_frames,
|
|
self.cfg.wifi_channel
|
|
));
|
|
ui.separator();
|
|
|
|
if self.cfg.telemetry_enabled {
|
|
ui.horizontal(|ui| {
|
|
ui.label(format!(
|
|
"🔋 Batterie : {:.1} V ({:.1} A)",
|
|
telem.battery_voltage_v, telem.battery_current_a
|
|
));
|
|
ui.separator();
|
|
ui.label(format!(
|
|
"📶 Lien : LQ {}% | RSSI {} dBm",
|
|
telem.link_quality_pct, telem.rssi_dbm
|
|
));
|
|
});
|
|
|
|
ui.horizontal(|ui| {
|
|
ui.label(format!("🧭 Altitude : {:.1} m", telem.altitude_m));
|
|
ui.separator();
|
|
ui.label(format!(
|
|
"🚀 Vitesse : {:.1} km/h (Gaz {}%)",
|
|
telem.groundspeed_ms * 3.6,
|
|
telem.throttle_pct
|
|
));
|
|
});
|
|
|
|
ui.label(format!(
|
|
"📐 Attitude Drone : Roll {:+.1}° | Pitch {:+.1}° | Cap {:.0}° ({} trames)",
|
|
telem.drone_roll_rad.to_degrees(),
|
|
telem.drone_pitch_rad.to_degrees(),
|
|
telem.drone_heading_deg,
|
|
telem.packets_received
|
|
));
|
|
} else {
|
|
ui.colored_label(
|
|
Color32::GRAY,
|
|
"Télémétrie & OSD désactivés (OFF). Cliquez sur « 📶 Télémétrie & OSD : OFF » pour l'activer.",
|
|
);
|
|
}
|
|
});
|
|
});
|
|
|
|
ui.add_space(8.0);
|
|
|
|
ui.label(
|
|
RichText::new("🖥 Retour Vidéo Temps Réel (Dôme 140°)").strong(),
|
|
);
|
|
if let Some(ref tex) = self.video_texture {
|
|
let avail = ui.available_size();
|
|
let aspect = 16.0 / 9.0;
|
|
let w = avail.x.min(820.0);
|
|
let h = w / aspect;
|
|
ui.image((tex.id(), egui::vec2(w, h)));
|
|
} else {
|
|
ui.label("Initialisation de l'aperçu vidéo...");
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|