mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
feat: initial commit of SteamFrame FPV Control Center
This commit is contained in:
commit
4459f5ffa4
18 files changed
+8571
No files matched your search
+947
@@ -0,0 +1,947 @@
|
||||
use crate::config::AppConfig;
|
||||
use crate::engine::{FpvEngineController, SubsystemStatus};
|
||||
use crate::logger::LogBuffer;
|
||||
use crate::nomad_elrs::NomadHeadTracker;
|
||||
use eframe::egui::{self, Color32, RichText, TextureHandle, TextureOptions};
|
||||
use log::Level;
|
||||
use parking_lot::Mutex;
|
||||
use std::process::Command;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum LogFilter {
|
||||
All,
|
||||
WarningsAndErrors,
|
||||
ErrorsOnly,
|
||||
}
|
||||
|
||||
pub struct SteamFrameGuiApp {
|
||||
cfg: AppConfig,
|
||||
engine: FpvEngineController,
|
||||
log_buffer: Arc<Mutex<LogBuffer>>,
|
||||
log_filter: LogFilter,
|
||||
auto_scroll_logs: bool,
|
||||
video_texture: Option<TextureHandle>,
|
||||
last_displayed_frame_seq: u64,
|
||||
}
|
||||
|
||||
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);
|
||||
engine.start(cfg.clone());
|
||||
|
||||
Self {
|
||||
cfg,
|
||||
engine,
|
||||
log_buffer,
|
||||
log_filter: LogFilter::All,
|
||||
auto_scroll_logs: true,
|
||||
video_texture: None,
|
||||
last_displayed_frame_seq: 0,
|
||||
}
|
||||
}
|
||||
|
||||
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ée)".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)...");
|
||||
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;
|
||||
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}'"
|
||||
);
|
||||
|
||||
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) {
|
||||
log::info!(
|
||||
"[Test Nomad] Envoi d'un paquet de test Head-Tracking (neutre 992) vers {}:{}...",
|
||||
self.cfg.nomad_ip,
|
||||
self.cfg.nomad_port
|
||||
);
|
||||
let use_crsf = self.cfg.ht_protocol.eq_ignore_ascii_case("crsf");
|
||||
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,
|
||||
use_crsf,
|
||||
) {
|
||||
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 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,
|
||||
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.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("🥽 SteamFrame FPV Control Center").strong());
|
||||
ui.separator();
|
||||
|
||||
let is_running = self.engine.is_running();
|
||||
if is_running {
|
||||
if ui
|
||||
.button(
|
||||
RichText::new("🔄 Appliquer & Redémarrer")
|
||||
.color(Color32::from_rgb(100, 230, 140)),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
log::info!("[Action Utilisateur] Redémarrage des services avec la nouvelle configuration...");
|
||||
self.engine.start(self.cfg.clone());
|
||||
}
|
||||
if ui
|
||||
.button(
|
||||
RichText::new("⏹ Arrêter les services")
|
||||
.color(Color32::from_rgb(255, 180, 70)),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
self.engine.stop();
|
||||
}
|
||||
} else if ui
|
||||
.button(
|
||||
RichText::new("▶ Démarrer les services")
|
||||
.color(Color32::from_rgb(80, 240, 130))
|
||||
.strong(),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
log::info!("[Action Utilisateur] Démarrage manuel des services...");
|
||||
self.engine.start(self.cfg.clone());
|
||||
}
|
||||
|
||||
if ui.button("🎯 Recentrer la tête (Tare)").clicked() {
|
||||
self.engine.request_recenter();
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
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.engine.set_telemetry_enabled(self.cfg.telemetry_enabled);
|
||||
}
|
||||
|
||||
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.engine.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);
|
||||
Self::status_badge(ui, "Télémétrie OSD", &telem_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,
|
||||
"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 (ELRS)").strong(),
|
||||
)
|
||||
.default_open(true)
|
||||
.show(ui, |ui| {
|
||||
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(if self.cfg.ht_protocol == "crsf" {
|
||||
"CRSF (0x16)"
|
||||
} else {
|
||||
"MSPv2 PTR (0x0383)"
|
||||
})
|
||||
.show_ui(ui, |ui| {
|
||||
ui.selectable_value(
|
||||
&mut self.cfg.ht_protocol,
|
||||
"msp".to_string(),
|
||||
"MSPv2 PTR (0x0383 - Recommandé)",
|
||||
);
|
||||
ui.selectable_value(
|
||||
&mut self.cfg.ht_protocol,
|
||||
"crsf".to_string(),
|
||||
"CRSF RC_CHANNELS_PACKED (0x16)",
|
||||
);
|
||||
});
|
||||
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 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("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.engine.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 (°) :");
|
||||
ui.add(
|
||||
egui::Slider::new(&mut self.cfg.camera_fov_deg, 70.0..=180.0)
|
||||
.suffix("°"),
|
||||
);
|
||||
ui.end_row();
|
||||
|
||||
ui.label("Correction Lentille k1 :");
|
||||
ui.add(egui::Slider::new(&mut self.cfg.lens_k1, -0.50..=0.50));
|
||||
ui.end_row();
|
||||
|
||||
ui.label("Correction Lentille k2 :");
|
||||
ui.add(egui::Slider::new(&mut self.cfg.lens_k2, -0.25..=0.25));
|
||||
ui.end_row();
|
||||
|
||||
ui.label("Rayon / Distance (m) :");
|
||||
ui.add(
|
||||
egui::Slider::new(&mut self.cfg.screen_distance_m, 0.8..=4.0)
|
||||
.suffix(" m"),
|
||||
);
|
||||
ui.end_row();
|
||||
});
|
||||
|
||||
ui.add_space(6.0);
|
||||
if ui
|
||||
.button(RichText::new("✔ Appliquer les changements").strong())
|
||||
.clicked()
|
||||
{
|
||||
self.engine.start(self.cfg.clone());
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// =========================================================================
|
||||
// 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.label(
|
||||
RichText::new("🎯 Suivi de Tête -> RadioMaster Nomad (172..1811 CRSF)")
|
||||
.strong(),
|
||||
);
|
||||
ui.add_space(4.0);
|
||||
|
||||
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
|
||||
));
|
||||
|
||||
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...");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user