mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
- LogBuffer: add revision counter and sync only latest 50 entries when revision changes, eliminating ~180k heap string allocations/sec. - Engine: move dome_lut.apply outside of latest_frame lock guard to prevent GStreamer appsink thread contention. - Video: reuse existing Vec buffer in appsink callback, render standby pattern in-place to avoid 3.7MB/frame alloc. - GPUI: remove premature texture drain on idle ticks, spawn background threads for bash/ssh scripts to avoid zombie processes. - Nomad: add NaN guard in deg_to_crsf, track last_send_ok to prevent permanent error state latch, add CRSF packet & CRC8 unit tests. - OpenXR/Engine: enforce Acquire/Release ordering on atomic control flags, join worker thread reliably on stop.
1114 lines
46 KiB
Rust
1114 lines
46 KiB
Rust
use crate::config::AppConfig;
|
|
use crate::engine::{FpvEngineController, SubsystemStatus};
|
|
use crate::logger::{LogBuffer, LogEntry, LogFilter};
|
|
use crate::nomad_elrs::{HeadPoseSample, NomadHeadTracker};
|
|
use crate::telemetry_osd::TelemetryState;
|
|
use anyhow::Result;
|
|
use gpui::{
|
|
div, img, prelude::*, px, rgb, rgba, size, App, Application, Bounds, Context, DefiniteLength,
|
|
RenderImage, Timer, Window, WindowBounds, WindowOptions,
|
|
};
|
|
use image::{Frame, RgbaImage};
|
|
use parking_lot::Mutex;
|
|
use smallvec::smallvec;
|
|
use std::process::Command;
|
|
use std::sync::Arc;
|
|
use std::time::Duration;
|
|
|
|
// =========================================================================
|
|
// Palette Cyberpunk / Aeronautic FPV
|
|
// =========================================================================
|
|
const COLOR_BG_DARK: u32 = 0x090b10;
|
|
const COLOR_SURFACE_CARD: u32 = 0x11151f;
|
|
const COLOR_SURFACE_ELEVATED: u32 = 0x181e2b;
|
|
const COLOR_BORDER_SUBTLE: u32 = 0x1f293d;
|
|
|
|
const COLOR_CYAN: u32 = 0x00e5ff;
|
|
const COLOR_GREEN: u32 = 0x10b981;
|
|
const COLOR_ORANGE: u32 = 0xf97316;
|
|
const COLOR_RED: u32 = 0xef4444;
|
|
const COLOR_TEXT_MUTED: u32 = 0x64748b;
|
|
const COLOR_TEXT_MAIN: u32 = 0xe2e8f0;
|
|
|
|
pub struct SteamFrameGpuiApp {
|
|
cfg: AppConfig,
|
|
engine: FpvEngineController,
|
|
log_buffer: Arc<Mutex<LogBuffer>>,
|
|
log_filter: LogFilter,
|
|
current_render_image: Option<Arc<RenderImage>>,
|
|
images_to_drop: Vec<Arc<RenderImage>>,
|
|
last_frame_seq: u64,
|
|
// Snapshots pour l'affichage réactif
|
|
usb_status: SubsystemStatus,
|
|
xr_status: SubsystemStatus,
|
|
nomad_status: SubsystemStatus,
|
|
telem_status: SubsystemStatus,
|
|
video_fps: f32,
|
|
video_frames_total: u64,
|
|
latest_pose: HeadPoseSample,
|
|
latest_telem: TelemetryState,
|
|
log_entries: Vec<LogEntry>,
|
|
log_err_count: usize,
|
|
log_warn_count: usize,
|
|
last_log_revision: u64,
|
|
}
|
|
|
|
impl SteamFrameGpuiApp {
|
|
pub fn new(cfg: AppConfig, log_buffer: Arc<Mutex<LogBuffer>>) -> Self {
|
|
let mut engine =
|
|
FpvEngineController::new(cfg.telemetry_enabled, cfg.head_tracking_enabled);
|
|
engine.start(cfg.clone());
|
|
|
|
Self {
|
|
cfg,
|
|
engine,
|
|
log_buffer,
|
|
log_filter: LogFilter::All,
|
|
current_render_image: None,
|
|
images_to_drop: Vec::new(),
|
|
last_frame_seq: 0,
|
|
usb_status: SubsystemStatus::Starting,
|
|
xr_status: SubsystemStatus::Starting,
|
|
nomad_status: SubsystemStatus::Disabled,
|
|
telem_status: SubsystemStatus::Disabled,
|
|
video_fps: 0.0,
|
|
video_frames_total: 0,
|
|
latest_pose: HeadPoseSample::default(),
|
|
latest_telem: TelemetryState::default(),
|
|
log_entries: Vec::new(),
|
|
log_err_count: 0,
|
|
log_warn_count: 0,
|
|
last_log_revision: 0,
|
|
}
|
|
}
|
|
|
|
/// Synchronise l'état IHM avec le moteur FPV en tâche de fond
|
|
fn sync_from_engine(&mut self, window: &mut Window) {
|
|
let mon = self.engine.monitor.lock();
|
|
|
|
// 1. Mise à jour de la texture vidéo si une nouvelle trame est arrivée
|
|
if mon.preview_frame_seq != self.last_frame_seq
|
|
&& !mon.preview_rgba.is_empty()
|
|
&& mon.preview_width > 0
|
|
&& mon.preview_height > 0
|
|
{
|
|
if let Some(mut img_buf) = RgbaImage::from_raw(
|
|
mon.preview_width,
|
|
mon.preview_height,
|
|
mon.preview_rgba.clone(),
|
|
) {
|
|
// Conversion RGBA -> BGRA requise par l'atlas polychrome GPUI / Vulkan
|
|
for pixel in img_buf.chunks_exact_mut(4) {
|
|
pixel.swap(0, 2);
|
|
}
|
|
let frame = Frame::new(img_buf);
|
|
let new_render_image = Arc::new(RenderImage::new(smallvec![frame]));
|
|
|
|
if let Some(old) = self.current_render_image.take() {
|
|
self.images_to_drop.push(old);
|
|
}
|
|
self.current_render_image = Some(new_render_image);
|
|
self.last_frame_seq = mon.preview_frame_seq;
|
|
|
|
// Nettoyage de l'atlas texture GPU pour empêcher l'accumulation de VRAM.
|
|
// On conserve les 2 dernières trames pour garantir que le GPU a fini
|
|
// de les projeter à l'écran avant destruction de la texture.
|
|
while self.images_to_drop.len() > 2 {
|
|
let old_img = self.images_to_drop.remove(0);
|
|
let _ = window.drop_image(old_img);
|
|
}
|
|
}
|
|
}
|
|
|
|
self.usb_status = mon.usb_video_status.clone();
|
|
self.xr_status = mon.openxr_status.clone();
|
|
self.nomad_status = mon.nomad_wifi_status.clone();
|
|
self.telem_status = mon.telemetry_status.clone();
|
|
self.video_fps = mon.video_fps;
|
|
self.video_frames_total = mon.video_frames_total;
|
|
self.latest_pose = mon.latest_head_pose;
|
|
self.latest_telem = mon.latest_telemetry.clone();
|
|
|
|
// 2. Synchronisation sélective des logs (uniquement sur nouvelle révision)
|
|
let lb = self.log_buffer.lock();
|
|
if lb.revision != self.last_log_revision {
|
|
self.last_log_revision = lb.revision;
|
|
self.log_err_count = lb.error_count;
|
|
self.log_warn_count = lb.warn_count;
|
|
self.log_entries = lb.entries.iter().rev().take(50).cloned().collect();
|
|
}
|
|
}
|
|
|
|
fn run_usb_rndis_setup(&self) {
|
|
log::info!("[USB RNDIS] Exécution du script de configuration réseau...");
|
|
let script_path = concat!(env!("CARGO_MANIFEST_DIR"), "/scripts/setup_usb_rndis.sh").to_string();
|
|
std::thread::spawn(move || {
|
|
match Command::new("bash").arg(&script_path).output() {
|
|
Ok(out) => {
|
|
let stdout = String::from_utf8_lossy(&out.stdout);
|
|
log::info!("[USB RNDIS] Résultat (exit={}) :\n{}", out.status, stdout.trim());
|
|
}
|
|
Err(e) => log::error!("[USB RNDIS] Échec d'exécution du script : {}", e),
|
|
}
|
|
});
|
|
}
|
|
|
|
fn configure_radxa_ssh(&self) {
|
|
let ch = self.cfg.wifi_channel;
|
|
let ip = self.cfg.radxa_vrx_ip.clone();
|
|
log::info!(
|
|
"[Radxa Zero 3W] Configuration du canal 5.8GHz={} sur root@{}...",
|
|
ch,
|
|
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"
|
|
);
|
|
std::thread::spawn(move || {
|
|
match Command::new("ssh")
|
|
.args([
|
|
"-o",
|
|
"ConnectTimeout=2",
|
|
"-o",
|
|
"StrictHostKeyChecking=no",
|
|
&format!("root@{}", ip),
|
|
&remote_cmd,
|
|
])
|
|
.output()
|
|
{
|
|
Ok(out) if out.status.success() => {
|
|
log::info!("[Radxa Zero 3W] Canal 5.8GHz configuré avec succès sur {}", ip);
|
|
}
|
|
Ok(out) => {
|
|
log::warn!(
|
|
"[Radxa Zero 3W] SSH retour exit={} : {}",
|
|
out.status,
|
|
String::from_utf8_lossy(&out.stderr).trim()
|
|
);
|
|
}
|
|
Err(e) => log::error!("[Radxa Zero 3W] Échec commande SSH : {}", e),
|
|
}
|
|
});
|
|
}
|
|
|
|
fn test_nomad_packet(&self) {
|
|
log::info!(
|
|
"[Wi-Fi Nomad] Envoi d'un paquet de test vers {}:{}...",
|
|
self.cfg.nomad_ip,
|
|
self.cfg.nomad_port
|
|
);
|
|
let use_crsf = self.cfg.ht_protocol.eq_ignore_ascii_case("crsf");
|
|
if let Ok(mut ht) = 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,
|
|
) {
|
|
let _ = ht.send_pose(glam::Quat::IDENTITY);
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Render for SteamFrameGpuiApp {
|
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
|
div()
|
|
.flex()
|
|
.flex_col()
|
|
.size_full()
|
|
.bg(rgb(COLOR_BG_DARK))
|
|
.text_color(rgb(COLOR_TEXT_MAIN))
|
|
.p_3()
|
|
.gap_3()
|
|
// 1. HEADER COCKPIT BAR
|
|
.child(self.render_header(cx))
|
|
// 2. MAIN LAYOUT: SIDEBAR + CENTRAL COCKPIT
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.flex_row()
|
|
.flex_1()
|
|
.gap_3()
|
|
.overflow_hidden()
|
|
// Sidebar (340px)
|
|
.child(self.render_sidebar(cx))
|
|
// Dashboard central (Aperçu Vidéo + HUD)
|
|
.child(self.render_cockpit()),
|
|
)
|
|
// 3. LOG CONSOLE (DRAWER INFERIEUR)
|
|
.child(self.render_logs_drawer(cx))
|
|
}
|
|
}
|
|
|
|
impl SteamFrameGpuiApp {
|
|
// -------------------------------------------------------------------------
|
|
// 1. Barre Supérieure (Header & Cockpit Quick Actions)
|
|
// -------------------------------------------------------------------------
|
|
fn render_header(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
|
div()
|
|
.flex()
|
|
.flex_row()
|
|
.justify_between()
|
|
.items_center()
|
|
.bg(rgb(COLOR_SURFACE_CARD))
|
|
.border_1()
|
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
|
.rounded_xl()
|
|
.px_4()
|
|
.py_2()
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.items_center()
|
|
.gap_3()
|
|
.child(
|
|
div()
|
|
.text_xl()
|
|
.font_weight(gpui::FontWeight::BOLD)
|
|
.text_color(rgb(COLOR_CYAN))
|
|
.child("🥽 SteamFrame FPV"),
|
|
)
|
|
.child(
|
|
div()
|
|
.text_xs()
|
|
.text_color(rgb(COLOR_TEXT_MUTED))
|
|
.child("Eachine Sphere Link • RadioMaster Nomad • OpenXR 140°"),
|
|
),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.items_center()
|
|
.gap_2()
|
|
.child(self.render_status_badge("VRX", &self.usb_status))
|
|
.child(self.render_status_badge("VR Casque", &self.xr_status))
|
|
.child(
|
|
div()
|
|
.id("toggle_ht")
|
|
.cursor_pointer()
|
|
.on_click(cx.listener(|this, _, _, cx| {
|
|
this.cfg.head_tracking_enabled = !this.cfg.head_tracking_enabled;
|
|
this.engine
|
|
.set_head_tracking_enabled(this.cfg.head_tracking_enabled);
|
|
cx.notify();
|
|
}))
|
|
.child(self.render_toggle_pill(
|
|
"🎯 Suivi Tête",
|
|
self.cfg.head_tracking_enabled,
|
|
rgb(COLOR_GREEN),
|
|
)),
|
|
)
|
|
.child(
|
|
div()
|
|
.id("toggle_telem")
|
|
.cursor_pointer()
|
|
.on_click(cx.listener(|this, _, _, cx| {
|
|
this.cfg.telemetry_enabled = !this.cfg.telemetry_enabled;
|
|
this.engine
|
|
.set_telemetry_enabled(this.cfg.telemetry_enabled);
|
|
cx.notify();
|
|
}))
|
|
.child(self.render_toggle_pill(
|
|
"📶 Télémétrie OSD",
|
|
self.cfg.telemetry_enabled,
|
|
rgb(COLOR_CYAN),
|
|
)),
|
|
),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.items_center()
|
|
.gap_2()
|
|
.child(
|
|
div()
|
|
.id("btn_tare")
|
|
.px_3()
|
|
.py_1()
|
|
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
|
.border_1()
|
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
|
.rounded_md()
|
|
.text_xs()
|
|
.font_weight(gpui::FontWeight::SEMIBOLD)
|
|
.cursor_pointer()
|
|
.on_click(cx.listener(|this, _, _, cx| {
|
|
this.engine.request_recenter();
|
|
cx.notify();
|
|
}))
|
|
.child("🎯 Tare (Recentrer)"),
|
|
)
|
|
.child(
|
|
div()
|
|
.id("btn_apply")
|
|
.px_3()
|
|
.py_1()
|
|
.bg(rgb(COLOR_GREEN))
|
|
.text_color(rgb(0x000000))
|
|
.rounded_md()
|
|
.text_xs()
|
|
.font_weight(gpui::FontWeight::BOLD)
|
|
.cursor_pointer()
|
|
.on_click(cx.listener(|this, _, _, cx| {
|
|
this.engine.start(this.cfg.clone());
|
|
cx.notify();
|
|
}))
|
|
.child("🔄 Appliquer"),
|
|
),
|
|
)
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// 2. Panneau Gauche (Sidebar Matérielle & Options)
|
|
// -------------------------------------------------------------------------
|
|
fn render_sidebar(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
|
div()
|
|
.flex()
|
|
.flex_col()
|
|
.w(px(340.0))
|
|
.bg(rgb(COLOR_SURFACE_CARD))
|
|
.border_1()
|
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
|
.rounded_xl()
|
|
.p_3()
|
|
.gap_3()
|
|
.id("sidebar_scroll")
|
|
.overflow_scroll()
|
|
// Section 1 : VRX Eachine Sphere Link
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.flex_col()
|
|
.gap_2()
|
|
.child(
|
|
div()
|
|
.text_sm()
|
|
.font_weight(gpui::FontWeight::BOLD)
|
|
.text_color(rgb(COLOR_CYAN))
|
|
.child("🔌 1. VRX Sphere Link (Radxa 3W)"),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.justify_between()
|
|
.text_xs()
|
|
.child("Mode USB :")
|
|
.child(
|
|
div()
|
|
.text_color(rgb(COLOR_GREEN))
|
|
.child(self.cfg.usb_video_mode.to_uppercase()),
|
|
),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.justify_between()
|
|
.text_xs()
|
|
.child("Canal 5.8 GHz :")
|
|
.child(
|
|
div()
|
|
.text_color(rgb(COLOR_ORANGE))
|
|
.child(format!("Canal {}", self.cfg.wifi_channel)),
|
|
),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.justify_between()
|
|
.text_xs()
|
|
.child("Résolution Cible :")
|
|
.child(format!("{} @ 60 FPS", self.cfg.vrx_video_profile)),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.gap_2()
|
|
.pt_1()
|
|
.child(
|
|
div()
|
|
.id("btn_rndis")
|
|
.flex_1()
|
|
.py_1()
|
|
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
|
.border_1()
|
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
|
.rounded_md()
|
|
.text_xs()
|
|
.cursor_pointer()
|
|
.on_click(cx.listener(|this, _, _, _| {
|
|
this.run_usb_rndis_setup();
|
|
}))
|
|
.child("⚡ Config RNDIS"),
|
|
)
|
|
.child(
|
|
div()
|
|
.id("btn_ssh")
|
|
.flex_1()
|
|
.py_1()
|
|
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
|
.border_1()
|
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
|
.rounded_md()
|
|
.text_xs()
|
|
.cursor_pointer()
|
|
.on_click(cx.listener(|this, _, _, _| {
|
|
this.configure_radxa_ssh();
|
|
}))
|
|
.child("🔧 Config SSH"),
|
|
),
|
|
),
|
|
)
|
|
// Section 2 : Wi-Fi RadioMaster Nomad
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.flex_col()
|
|
.gap_2()
|
|
.pt_2()
|
|
.border_t_1()
|
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
|
.child(
|
|
div()
|
|
.text_sm()
|
|
.font_weight(gpui::FontWeight::BOLD)
|
|
.text_color(rgb(COLOR_ORANGE))
|
|
.child("📡 2. Wi-Fi Nomad (ELRS)"),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.justify_between()
|
|
.text_xs()
|
|
.child("Cible UDP :")
|
|
.child(format!("{}:{}", self.cfg.nomad_ip, self.cfg.nomad_port)),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.justify_between()
|
|
.text_xs()
|
|
.child("Protocole :")
|
|
.child(self.cfg.ht_protocol.to_uppercase()),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.justify_between()
|
|
.text_xs()
|
|
.child("Courses Max :")
|
|
.child(format!(
|
|
"P:{}° T:{}° R:{}°",
|
|
self.cfg.max_pan_deg, self.cfg.max_tilt_deg, self.cfg.max_roll_deg
|
|
)),
|
|
)
|
|
.child(
|
|
div()
|
|
.id("btn_nomad_test")
|
|
.w_full()
|
|
.py_1()
|
|
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
|
.border_1()
|
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
|
.rounded_md()
|
|
.text_xs()
|
|
.cursor_pointer()
|
|
.on_click(cx.listener(|this, _, _, _| {
|
|
this.test_nomad_packet();
|
|
}))
|
|
.child("📡 Envoyer paquet test"),
|
|
),
|
|
)
|
|
// Section 3 : Projection OpenXR 140°
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.flex_col()
|
|
.gap_2()
|
|
.pt_2()
|
|
.border_t_1()
|
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
|
.child(
|
|
div()
|
|
.text_sm()
|
|
.font_weight(gpui::FontWeight::BOLD)
|
|
.text_color(rgb(COLOR_CYAN))
|
|
.child("🥽 3. Projection VR & Optique"),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.justify_between()
|
|
.text_xs()
|
|
.child("Mode Projection :")
|
|
.child(self.cfg.projection_mode.to_uppercase()),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.justify_between()
|
|
.text_xs()
|
|
.child("FOV Caméra :")
|
|
.child(format!("{}°", self.cfg.camera_fov_deg)),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.justify_between()
|
|
.text_xs()
|
|
.child("Distorsion Lentille :")
|
|
.child(format!("k1={:.2} k2={:.2}", self.cfg.lens_k1, self.cfg.lens_k2)),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.justify_between()
|
|
.text_xs()
|
|
.child("Rayon Dôme :")
|
|
.child(format!("{:.1} m", self.cfg.screen_distance_m)),
|
|
),
|
|
)
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// 3. Cockpit Central (Vidéo Haute Fréquence + Jauges Télémetrie)
|
|
// -------------------------------------------------------------------------
|
|
fn render_cockpit(&self) -> impl IntoElement {
|
|
div()
|
|
.flex()
|
|
.flex_col()
|
|
.flex_1()
|
|
.gap_3()
|
|
.overflow_hidden()
|
|
// 3.1 VIEWPORT VIDEO 16:9
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.flex_1()
|
|
.bg(rgb(0x05070a))
|
|
.border_1()
|
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
|
.rounded_xl()
|
|
.relative()
|
|
.overflow_hidden()
|
|
.items_center()
|
|
.justify_center()
|
|
.child(if let Some(ref img_src) = self.current_render_image {
|
|
div().size_full().child(img(img_src.clone()).size_full())
|
|
} else {
|
|
div()
|
|
.flex()
|
|
.flex_col()
|
|
.items_center()
|
|
.gap_2()
|
|
.child(
|
|
div()
|
|
.text_lg()
|
|
.font_weight(gpui::FontWeight::BOLD)
|
|
.text_color(rgb(COLOR_CYAN))
|
|
.child("En attente du flux vidéo 720p60..."),
|
|
)
|
|
.child(
|
|
div()
|
|
.text_xs()
|
|
.text_color(rgb(COLOR_TEXT_MUTED))
|
|
.child("Port UDP 0.0.0.0:5600 (H.264 Raw NAL direct)"),
|
|
)
|
|
})
|
|
// Overlay FPS & Compteur de trames en haut à droite
|
|
.child(
|
|
div()
|
|
.absolute()
|
|
.top_3()
|
|
.right_3()
|
|
.flex()
|
|
.gap_2()
|
|
.child(
|
|
div()
|
|
.px_2()
|
|
.py_0p5()
|
|
.bg(rgba(0x000000bb))
|
|
.border_1()
|
|
.border_color(rgb(COLOR_GREEN))
|
|
.rounded_md()
|
|
.text_xs()
|
|
.font_weight(gpui::FontWeight::BOLD)
|
|
.text_color(rgb(COLOR_GREEN))
|
|
.child(format!("{:.1} FPS", self.video_fps)),
|
|
)
|
|
.child(
|
|
div()
|
|
.px_2()
|
|
.py_0p5()
|
|
.bg(rgba(0x000000bb))
|
|
.border_1()
|
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
|
.rounded_md()
|
|
.text_xs()
|
|
.text_color(rgb(COLOR_TEXT_MUTED))
|
|
.child(format!("{} trames", self.video_frames_total)),
|
|
),
|
|
),
|
|
)
|
|
// 3.2 DOUBLE CARTE DE MONITORING : SUIVI TÊTE & TELEMETRIE
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.flex_row()
|
|
.h(px(160.0))
|
|
.gap_3()
|
|
// Carte Suivi de Tête Nomad
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.flex_col()
|
|
.flex_1()
|
|
.bg(rgb(COLOR_SURFACE_CARD))
|
|
.border_1()
|
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
|
.rounded_xl()
|
|
.p_3()
|
|
.gap_2()
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.justify_between()
|
|
.child(
|
|
div()
|
|
.text_xs()
|
|
.font_weight(gpui::FontWeight::BOLD)
|
|
.text_color(rgb(COLOR_ORANGE))
|
|
.child("🎯 Suivi de Tête -> Nomad (CRSF 172..1811)"),
|
|
)
|
|
.child(
|
|
div()
|
|
.text_xs()
|
|
.text_color(rgb(COLOR_TEXT_MUTED))
|
|
.child(format!(
|
|
"Paquets: {} | Erreurs: {}",
|
|
self.latest_pose.packets_sent,
|
|
self.latest_pose.send_errors
|
|
)),
|
|
),
|
|
)
|
|
.child(self.render_crsf_gauge(
|
|
"PAN (Lacet)",
|
|
self.latest_pose.pan_deg,
|
|
self.latest_pose.pan_crsf,
|
|
self.cfg.max_pan_deg,
|
|
))
|
|
.child(self.render_crsf_gauge(
|
|
"TILT (Tangage)",
|
|
self.latest_pose.tilt_deg,
|
|
self.latest_pose.tilt_crsf,
|
|
self.cfg.max_tilt_deg,
|
|
))
|
|
.child(self.render_crsf_gauge(
|
|
"ROLL (Roulis)",
|
|
self.latest_pose.roll_deg,
|
|
self.latest_pose.roll_crsf,
|
|
self.cfg.max_roll_deg,
|
|
)),
|
|
)
|
|
// Carte Télémétrie OSD
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.flex_col()
|
|
.flex_1()
|
|
.bg(rgb(COLOR_SURFACE_CARD))
|
|
.border_1()
|
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
|
.rounded_xl()
|
|
.p_3()
|
|
.gap_2()
|
|
.child(
|
|
div()
|
|
.text_xs()
|
|
.font_weight(gpui::FontWeight::BOLD)
|
|
.text_color(rgb(COLOR_CYAN))
|
|
.child("📊 Télémétrie Drone & OSD"),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.justify_between()
|
|
.text_xs()
|
|
.child(format!(
|
|
"🔋 Batterie : {:.1} V ({:.1} A)",
|
|
self.latest_telem.battery_voltage_v,
|
|
self.latest_telem.battery_current_a
|
|
))
|
|
.child(format!(
|
|
"📶 Signal : LQ {}% | {} dBm",
|
|
self.latest_telem.link_quality_pct,
|
|
self.latest_telem.rssi_dbm
|
|
)),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.justify_between()
|
|
.text_xs()
|
|
.child(format!(
|
|
"🧭 Altitude : {:.1} m",
|
|
self.latest_telem.altitude_m
|
|
))
|
|
.child(format!(
|
|
"🚀 Vitesse : {:.1} km/h (Gaz {}%)",
|
|
self.latest_telem.groundspeed_ms * 3.6,
|
|
self.latest_telem.throttle_pct
|
|
)),
|
|
)
|
|
.child(
|
|
div()
|
|
.text_xs()
|
|
.text_color(rgb(COLOR_TEXT_MUTED))
|
|
.child(format!(
|
|
"Attitude : R{:+.1}° | P{:+.1}° | Cap {:.0}° ({} trames OSD)",
|
|
self.latest_telem.drone_roll_rad.to_degrees(),
|
|
self.latest_telem.drone_pitch_rad.to_degrees(),
|
|
self.latest_telem.drone_heading_deg,
|
|
self.latest_telem.packets_received
|
|
)),
|
|
),
|
|
),
|
|
)
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// 4. Console de Logs & Diagnostic
|
|
// -------------------------------------------------------------------------
|
|
fn render_logs_drawer(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
|
div()
|
|
.flex()
|
|
.flex_col()
|
|
.h(px(140.0))
|
|
.bg(rgb(COLOR_SURFACE_CARD))
|
|
.border_1()
|
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
|
.rounded_xl()
|
|
.p_2()
|
|
.gap_1()
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.justify_between()
|
|
.items_center()
|
|
.px_2()
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.gap_3()
|
|
.items_center()
|
|
.child(
|
|
div()
|
|
.text_xs()
|
|
.font_weight(gpui::FontWeight::BOLD)
|
|
.child("📋 Journal de Diagnostic"),
|
|
)
|
|
.child(
|
|
div()
|
|
.text_xs()
|
|
.text_color(if self.log_err_count > 0 {
|
|
rgb(COLOR_RED)
|
|
} else {
|
|
rgb(COLOR_GREEN)
|
|
})
|
|
.child(format!("{} Erreurs", self.log_err_count)),
|
|
)
|
|
.child(
|
|
div()
|
|
.text_xs()
|
|
.text_color(if self.log_warn_count > 0 {
|
|
rgb(COLOR_ORANGE)
|
|
} else {
|
|
rgb(COLOR_TEXT_MUTED)
|
|
})
|
|
.child(format!("{} Avertissements", self.log_warn_count)),
|
|
),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.gap_2()
|
|
.child(
|
|
div()
|
|
.id("filter_all")
|
|
.px_2()
|
|
.py_0p5()
|
|
.bg(if self.log_filter == LogFilter::All {
|
|
rgb(0x1e3a5f)
|
|
} else {
|
|
rgb(COLOR_SURFACE_ELEVATED)
|
|
})
|
|
.rounded_md()
|
|
.text_xs()
|
|
.cursor_pointer()
|
|
.on_click(cx.listener(|this, _, _, cx| {
|
|
this.log_filter = LogFilter::All;
|
|
cx.notify();
|
|
}))
|
|
.child("Tous"),
|
|
)
|
|
.child(
|
|
div()
|
|
.id("filter_warn")
|
|
.px_2()
|
|
.py_0p5()
|
|
.bg(if self.log_filter == LogFilter::WarningsAndErrors {
|
|
rgb(0x1e3a5f)
|
|
} else {
|
|
rgb(COLOR_SURFACE_ELEVATED)
|
|
})
|
|
.rounded_md()
|
|
.text_xs()
|
|
.cursor_pointer()
|
|
.on_click(cx.listener(|this, _, _, cx| {
|
|
this.log_filter = LogFilter::WarningsAndErrors;
|
|
cx.notify();
|
|
}))
|
|
.child("Warn/Err"),
|
|
)
|
|
.child(
|
|
div()
|
|
.id("filter_err")
|
|
.px_2()
|
|
.py_0p5()
|
|
.bg(if self.log_filter == LogFilter::ErrorsOnly {
|
|
rgb(0x1e3a5f)
|
|
} else {
|
|
rgb(COLOR_SURFACE_ELEVATED)
|
|
})
|
|
.rounded_md()
|
|
.text_xs()
|
|
.cursor_pointer()
|
|
.on_click(cx.listener(|this, _, _, cx| {
|
|
this.log_filter = LogFilter::ErrorsOnly;
|
|
cx.notify();
|
|
}))
|
|
.child("Err"),
|
|
)
|
|
.child(
|
|
div()
|
|
.id("btn_clear_logs")
|
|
.px_2()
|
|
.py_0p5()
|
|
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
|
.rounded_md()
|
|
.text_xs()
|
|
.cursor_pointer()
|
|
.on_click(cx.listener(|this, _, _, cx| {
|
|
let mut lb = this.log_buffer.lock();
|
|
lb.entries.clear();
|
|
lb.error_count = 0;
|
|
lb.warn_count = 0;
|
|
this.log_entries.clear();
|
|
this.log_err_count = 0;
|
|
this.log_warn_count = 0;
|
|
cx.notify();
|
|
}))
|
|
.child("Effacer"),
|
|
),
|
|
),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.flex_col()
|
|
.flex_1()
|
|
.id("logs_scroll")
|
|
.overflow_scroll()
|
|
.px_2()
|
|
.gap_0p5()
|
|
.children(
|
|
self.log_entries
|
|
.iter()
|
|
.rev()
|
|
.filter(|e| match self.log_filter {
|
|
LogFilter::All => true,
|
|
LogFilter::WarningsAndErrors => {
|
|
matches!(e.level, log::Level::Warn | log::Level::Error)
|
|
}
|
|
LogFilter::ErrorsOnly => matches!(e.level, log::Level::Error),
|
|
})
|
|
.take(40)
|
|
.map(|e| {
|
|
let badge_color = match e.level {
|
|
log::Level::Error => COLOR_RED,
|
|
log::Level::Warn => COLOR_ORANGE,
|
|
_ => COLOR_CYAN,
|
|
};
|
|
div()
|
|
.flex()
|
|
.gap_2()
|
|
.text_xs()
|
|
.child(
|
|
div()
|
|
.text_color(rgb(COLOR_TEXT_MUTED))
|
|
.child(e.timestamp.clone()),
|
|
)
|
|
.child(
|
|
div()
|
|
.font_weight(gpui::FontWeight::BOLD)
|
|
.text_color(rgb(badge_color))
|
|
.child(format!("[{}]", e.level)),
|
|
)
|
|
.child(
|
|
div()
|
|
.text_color(rgb(COLOR_TEXT_MAIN))
|
|
.child(e.message.clone()),
|
|
)
|
|
})),
|
|
)
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// Helpers Composants Graphiques
|
|
// -------------------------------------------------------------------------
|
|
fn render_status_badge(&self, label: &str, status: &SubsystemStatus) -> impl IntoElement {
|
|
let (color, text) = match status {
|
|
SubsystemStatus::Stopped => (COLOR_TEXT_MUTED, "Arrêté"),
|
|
SubsystemStatus::Disabled => (COLOR_TEXT_MUTED, "OFF"),
|
|
SubsystemStatus::Starting => (COLOR_ORANGE, "Démarrage..."),
|
|
SubsystemStatus::Running(_) => (COLOR_GREEN, "Actif"),
|
|
SubsystemStatus::Warning(_) => (COLOR_ORANGE, "Attention"),
|
|
SubsystemStatus::Error(_) => (COLOR_RED, "Erreur"),
|
|
};
|
|
|
|
div()
|
|
.flex()
|
|
.items_center()
|
|
.gap_1p5()
|
|
.px_2()
|
|
.py_0p5()
|
|
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
|
.border_1()
|
|
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
|
.rounded_md()
|
|
.child(
|
|
div()
|
|
.w(px(6.0))
|
|
.h(px(6.0))
|
|
.rounded_full()
|
|
.bg(rgb(color)),
|
|
)
|
|
.child(
|
|
div()
|
|
.text_xs()
|
|
.font_weight(gpui::FontWeight::SEMIBOLD)
|
|
.child(label.to_string()),
|
|
)
|
|
.child(
|
|
div()
|
|
.text_xs()
|
|
.text_color(rgb(color))
|
|
.child(text.to_string()),
|
|
)
|
|
}
|
|
|
|
fn render_toggle_pill(&self, label: &str, is_on: bool, on_color: gpui::Rgba) -> impl IntoElement {
|
|
div()
|
|
.flex()
|
|
.items_center()
|
|
.gap_1p5()
|
|
.px_2()
|
|
.py_0p5()
|
|
.bg(if is_on { rgb(0x132320) } else { rgb(COLOR_SURFACE_ELEVATED) })
|
|
.border_1()
|
|
.border_color(if is_on { on_color } else { rgb(COLOR_BORDER_SUBTLE) })
|
|
.rounded_md()
|
|
.text_xs()
|
|
.font_weight(gpui::FontWeight::SEMIBOLD)
|
|
.text_color(if is_on { on_color } else { rgb(COLOR_TEXT_MUTED) })
|
|
.child(format!("{} : {}", label, if is_on { "ON" } else { "OFF" }))
|
|
}
|
|
|
|
fn render_crsf_gauge(&self, label: &str, deg: f32, crsf: u16, max_deg: f32) -> impl IntoElement {
|
|
let norm = ((deg / max_deg) * 0.5 + 0.5).clamp(0.0, 1.0);
|
|
|
|
div()
|
|
.flex()
|
|
.flex_col()
|
|
.gap_0p5()
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.justify_between()
|
|
.text_xs()
|
|
.child(label.to_string())
|
|
.child(format!("{:+.1}° (CRSF: {})", deg, crsf)),
|
|
)
|
|
.child(
|
|
div()
|
|
.w_full()
|
|
.h(px(6.0))
|
|
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
|
.rounded_full()
|
|
.overflow_hidden()
|
|
.child(
|
|
div()
|
|
.h_full()
|
|
.w(DefiniteLength::Fraction(norm))
|
|
.bg(rgb(COLOR_ORANGE)),
|
|
),
|
|
)
|
|
}
|
|
}
|
|
|
|
pub fn run_gpui_app(cfg: AppConfig, log_buffer: Arc<Mutex<LogBuffer>>) -> Result<()> {
|
|
Application::new().run(move |cx: &mut App| {
|
|
let bounds = Bounds::centered(None, size(px(1240.0), px(840.0)), cx);
|
|
|
|
let window_res = cx.open_window(
|
|
WindowOptions {
|
|
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
|
titlebar: None,
|
|
..Default::default()
|
|
},
|
|
|window, cx| {
|
|
// Création du modèle réactif de l'application
|
|
let app_view = cx.new(|_| SteamFrameGpuiApp::new(cfg.clone(), log_buffer.clone()));
|
|
|
|
// Boucle de rafraîchissement 60 FPS synchronisée avec le moteur FPV
|
|
let weak_view = app_view.downgrade();
|
|
window
|
|
.spawn(cx, async move |cx| {
|
|
loop {
|
|
Timer::after(Duration::from_millis(16)).await;
|
|
let should_continue = cx
|
|
.update(|window, cx| {
|
|
if let Some(view) = weak_view.upgrade() {
|
|
view.update(cx, |this, cx| {
|
|
this.sync_from_engine(window);
|
|
cx.notify();
|
|
});
|
|
true
|
|
} else {
|
|
false
|
|
}
|
|
})
|
|
.unwrap_or(false);
|
|
|
|
if !should_continue {
|
|
break;
|
|
}
|
|
}
|
|
})
|
|
.detach();
|
|
|
|
app_view
|
|
},
|
|
);
|
|
|
|
if let Err(e) = window_res {
|
|
log::error!("Échec d'ouverture de la fenêtre GPUI : {:?}", e);
|
|
}
|
|
|
|
cx.activate(true);
|
|
});
|
|
|
|
Ok(())
|
|
}
|