mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
3847 lines
174 KiB
Rust
3847 lines
174 KiB
Rust
use crate::config::AppConfig;
|
||
use crate::controller::{ControlSource, GearSpeedLimits, SteamControllerState};
|
||
use crate::dome_projection::ProjectionMode;
|
||
use crate::dvr::{DvrContainer, DvrMode};
|
||
use crate::engine::{
|
||
EngineControlHandle, FpvEngineController, LiveOpticalParams, RuntimeMonitor, SubsystemStatus,
|
||
};
|
||
use crate::g29_bridge::G29State;
|
||
use crate::logger::{LogBuffer, LogEntry, LogFilter};
|
||
use crate::nomad_elrs::{HeadPoseSample, NomadHeadTracker, NomadProtocol};
|
||
use crate::telemetry_osd::TelemetryState;
|
||
use anyhow::Result;
|
||
use gpui::{
|
||
div, img, prelude::*, px, rgb, rgba, size, App, Application, Bounds, Context, DefiniteLength,
|
||
FocusHandle, KeyDownEvent, RenderImage, Timer, Window, WindowBounds, WindowOptions,
|
||
};
|
||
use image::{Frame, RgbaImage};
|
||
use parking_lot::Mutex;
|
||
use smallvec::smallvec;
|
||
use std::process::Command;
|
||
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
||
use std::sync::Arc;
|
||
use std::time::{Duration, Instant};
|
||
|
||
// =========================================================================
|
||
// Palette Cyberpunk / Aeronautic FPV
|
||
// =========================================================================
|
||
const COLOR_BG_DARK: u32 = 0x07090e;
|
||
const COLOR_SURFACE_CARD: u32 = 0x0f131c;
|
||
const COLOR_SURFACE_ELEVATED: u32 = 0x161c28;
|
||
const COLOR_BORDER_SUBTLE: u32 = 0x1d2636;
|
||
const COLOR_BORDER_ACTIVE: u32 = 0x00e5ff;
|
||
|
||
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;
|
||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||
pub enum ActiveTab {
|
||
Cockpit,
|
||
Settings,
|
||
Telemetry,
|
||
Logs,
|
||
}
|
||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||
enum TargetEditField {
|
||
Ip,
|
||
Port,
|
||
}
|
||
|
||
pub struct SteamFrameGpuiApp {
|
||
cfg: AppConfig,
|
||
engine: Arc<Mutex<FpvEngineController>>,
|
||
controls: EngineControlHandle,
|
||
engine_monitor: Arc<Mutex<RuntimeMonitor>>,
|
||
log_buffer: Arc<Mutex<LogBuffer>>,
|
||
log_revision: Arc<AtomicU64>,
|
||
log_filter: LogFilter,
|
||
current_render_image: Option<Arc<RenderImage>>,
|
||
images_to_drop: Vec<Arc<RenderImage>>,
|
||
last_frame_seq: u64,
|
||
active_tab: ActiveTab,
|
||
show_hud_overlay: bool,
|
||
// Snapshots pour l'affichage réactif
|
||
usb_status: SubsystemStatus,
|
||
xr_status: SubsystemStatus,
|
||
nomad_status: SubsystemStatus,
|
||
telem_status: SubsystemStatus,
|
||
g29_status: SubsystemStatus,
|
||
controller_status: SubsystemStatus,
|
||
active_control_source: ControlSource,
|
||
dvr_status: SubsystemStatus,
|
||
dvr_recording: bool,
|
||
dvr_elapsed_secs: u64,
|
||
dvr_file_size_bytes: u64,
|
||
dvr_frames_recorded: u64,
|
||
dvr_filename: String,
|
||
video_fps: f32,
|
||
video_frames_total: u64,
|
||
latest_pose: HeadPoseSample,
|
||
latest_telem: TelemetryState,
|
||
latest_g29: G29State,
|
||
latest_controller: SteamControllerState,
|
||
control_switch_error: String,
|
||
monitor_source_override: Option<ControlSource>,
|
||
log_entries: Vec<LogEntry>,
|
||
log_err_count: usize,
|
||
log_warn_count: usize,
|
||
last_log_revision: u64,
|
||
// Cible réseau éditable & Mock Manuel Nomad
|
||
target_edit_field: Option<TargetEditField>,
|
||
target_port_buf: String,
|
||
target_focus_handle: Option<FocusHandle>,
|
||
mock_pan_deg: f32,
|
||
mock_tilt_deg: f32,
|
||
mock_roll_deg: f32,
|
||
mock_continuous: bool,
|
||
mock_tracker: Option<NomadHeadTracker>,
|
||
mock_last_send: Option<Instant>,
|
||
mock_status_text: String,
|
||
is_restarting: Arc<AtomicBool>,
|
||
is_closing: Arc<AtomicBool>,
|
||
}
|
||
|
||
impl SteamFrameGpuiApp {
|
||
pub fn new(
|
||
cfg: AppConfig,
|
||
log_buffer: Arc<Mutex<LogBuffer>>,
|
||
engine: Arc<Mutex<FpvEngineController>>,
|
||
controls: EngineControlHandle,
|
||
engine_monitor: Arc<Mutex<RuntimeMonitor>>,
|
||
is_closing: Arc<AtomicBool>,
|
||
) -> Self {
|
||
let log_revision = log_buffer.lock().revision.clone();
|
||
let target_port_buf = cfg.nomad_port.to_string();
|
||
let initial_control_source = ControlSource::from_str(&cfg.control_source);
|
||
|
||
Self {
|
||
cfg,
|
||
engine,
|
||
controls,
|
||
engine_monitor,
|
||
log_buffer,
|
||
log_revision,
|
||
log_filter: LogFilter::All,
|
||
current_render_image: None,
|
||
images_to_drop: Vec::new(),
|
||
last_frame_seq: 0,
|
||
active_tab: ActiveTab::Cockpit,
|
||
show_hud_overlay: true,
|
||
usb_status: SubsystemStatus::Starting,
|
||
xr_status: SubsystemStatus::Starting,
|
||
nomad_status: SubsystemStatus::Disabled,
|
||
telem_status: SubsystemStatus::Disabled,
|
||
g29_status: SubsystemStatus::Disabled,
|
||
controller_status: SubsystemStatus::Disabled,
|
||
active_control_source: initial_control_source,
|
||
dvr_status: SubsystemStatus::Stopped,
|
||
dvr_recording: false,
|
||
dvr_elapsed_secs: 0,
|
||
dvr_file_size_bytes: 0,
|
||
dvr_frames_recorded: 0,
|
||
dvr_filename: String::new(),
|
||
video_fps: 0.0,
|
||
video_frames_total: 0,
|
||
latest_pose: HeadPoseSample::default(),
|
||
latest_telem: TelemetryState::default(),
|
||
latest_g29: G29State::default(),
|
||
latest_controller: SteamControllerState::default(),
|
||
control_switch_error: String::new(),
|
||
monitor_source_override: None,
|
||
log_entries: Vec::new(),
|
||
log_err_count: 0,
|
||
log_warn_count: 0,
|
||
last_log_revision: 0,
|
||
target_edit_field: None,
|
||
target_port_buf,
|
||
target_focus_handle: None,
|
||
mock_pan_deg: 0.0,
|
||
mock_tilt_deg: 0.0,
|
||
mock_roll_deg: 0.0,
|
||
mock_continuous: false,
|
||
mock_tracker: None,
|
||
mock_last_send: None,
|
||
mock_status_text: String::new(),
|
||
is_restarting: Arc::new(AtomicBool::new(false)),
|
||
is_closing,
|
||
}
|
||
}
|
||
|
||
/// Synchronise l'état IHM avec le moteur FPV en minimisant au maximum la contention des verrous
|
||
fn sync_from_engine(&mut self, window: &mut Window) -> bool {
|
||
let mut changed = false;
|
||
self.controls
|
||
.set_preview_active(self.active_tab == ActiveTab::Cockpit);
|
||
|
||
// 1. Snapshot rapide avec maintien minimal du verrou monitor
|
||
let (preview_frame_seq, new_frame_data) = {
|
||
let mon = self.engine_monitor.lock();
|
||
|
||
if self.usb_status != mon.usb_video_status {
|
||
self.usb_status = mon.usb_video_status.clone();
|
||
changed = true;
|
||
}
|
||
if self.xr_status != mon.openxr_status {
|
||
self.xr_status = mon.openxr_status.clone();
|
||
changed = true;
|
||
}
|
||
if self.nomad_status != mon.nomad_wifi_status {
|
||
self.nomad_status = mon.nomad_wifi_status.clone();
|
||
changed = true;
|
||
}
|
||
if self.telem_status != mon.telemetry_status {
|
||
self.telem_status = mon.telemetry_status.clone();
|
||
changed = true;
|
||
}
|
||
if self.g29_status != mon.g29_status {
|
||
self.g29_status = mon.g29_status.clone();
|
||
changed = true;
|
||
}
|
||
if self.controller_status != mon.controller_status {
|
||
self.controller_status = mon.controller_status.clone();
|
||
changed = true;
|
||
}
|
||
if self.active_control_source != mon.active_control_source {
|
||
self.active_control_source = mon.active_control_source;
|
||
changed = true;
|
||
}
|
||
if self.dvr_recording != mon.dvr_recording
|
||
|| self.dvr_elapsed_secs != mon.dvr_elapsed_secs
|
||
|| self.dvr_status != mon.dvr_status
|
||
{
|
||
self.dvr_recording = mon.dvr_recording;
|
||
self.dvr_elapsed_secs = mon.dvr_elapsed_secs;
|
||
self.dvr_file_size_bytes = mon.dvr_file_size_bytes;
|
||
self.dvr_frames_recorded = mon.dvr_frames_recorded;
|
||
self.dvr_filename = mon.dvr_filename.clone();
|
||
self.dvr_status = mon.dvr_status.clone();
|
||
changed = true;
|
||
}
|
||
if (self.video_fps - mon.video_fps).abs() > 0.1 {
|
||
self.video_fps = mon.video_fps;
|
||
changed = true;
|
||
}
|
||
if self.video_frames_total != mon.video_frames_total {
|
||
self.video_frames_total = mon.video_frames_total;
|
||
changed = true;
|
||
}
|
||
self.latest_pose = mon.latest_head_pose;
|
||
self.latest_telem = mon.latest_telemetry.clone();
|
||
if self.latest_g29.connected != mon.latest_g29.connected
|
||
|| self.latest_g29.last_button != mon.latest_g29.last_button
|
||
|| (self.active_tab == ActiveTab::Settings
|
||
&& self.latest_g29.packets_received != mon.latest_g29.packets_received)
|
||
{
|
||
changed = true;
|
||
}
|
||
self.latest_g29 = mon.latest_g29.clone();
|
||
|
||
if self.latest_controller.connected != mon.latest_controller.connected
|
||
|| self.latest_controller.armed != mon.latest_controller.armed
|
||
|| self.latest_controller.gear != mon.latest_controller.gear
|
||
|| self.latest_controller.throttle_pct != mon.latest_controller.throttle_pct
|
||
|| self.latest_controller.brake_pct != mon.latest_controller.brake_pct
|
||
|| self.latest_controller.clutch_pct != mon.latest_controller.clutch_pct
|
||
|| self.latest_controller.vibration_pct != mon.latest_controller.vibration_pct
|
||
|| self.latest_controller.rumble_left_pct != mon.latest_controller.rumble_left_pct
|
||
|| self.latest_controller.rumble_right_pct != mon.latest_controller.rumble_right_pct
|
||
|| self.latest_controller.last_button != mon.latest_controller.last_button
|
||
|| (self.latest_controller.steering_norm - mon.latest_controller.steering_norm).abs()
|
||
> 0.005
|
||
|| (self.active_tab == ActiveTab::Settings
|
||
&& self.latest_controller.packets_sent != mon.latest_controller.packets_sent)
|
||
{
|
||
changed = true;
|
||
}
|
||
self.latest_controller = mon.latest_controller.clone();
|
||
|
||
// Ne cloner que le pointeur Arc sous verrou ; la copie/conversion BGRA se fait hors verrou !
|
||
let frame_data: Option<(u32, u32, Arc<Vec<u8>>)> = if self.active_tab == ActiveTab::Cockpit
|
||
&& mon.preview_frame_seq != self.last_frame_seq
|
||
&& !mon.preview_rgba.is_empty()
|
||
&& mon.preview_width > 0
|
||
&& mon.preview_height > 0
|
||
{
|
||
Some((mon.preview_width, mon.preview_height, Arc::clone(&mon.preview_rgba)))
|
||
} else {
|
||
None
|
||
};
|
||
|
||
(mon.preview_frame_seq, frame_data)
|
||
}; // Verrou `engine_monitor` immédiatement libéré !
|
||
|
||
// 2. Conversion BGRA vectorisable (u32) et allocation GPU hors du verrou monitor
|
||
if let Some((w, h, raw_arc)) = new_frame_data {
|
||
let mut raw_buf = (*raw_arc).clone();
|
||
// SAFETY: `align_to_mut::<u32>` découpe proprement préfixe, tranche u32 alignée et suffixe.
|
||
let (head, pixels_u32, tail) = unsafe { raw_buf.align_to_mut::<u32>() };
|
||
if head.is_empty() && tail.is_empty() {
|
||
for px in pixels_u32 {
|
||
let v = *px;
|
||
*px = (v & 0xFF00_FF00) | ((v & 0x00FF_0000) >> 16) | ((v & 0x0000_00FF) << 16);
|
||
}
|
||
} else {
|
||
for pixel in raw_buf.chunks_exact_mut(4) {
|
||
pixel.swap(0, 2);
|
||
}
|
||
}
|
||
if let Some(img_buf) = RgbaImage::from_raw(w, h, raw_buf) {
|
||
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 = preview_frame_seq;
|
||
changed = true;
|
||
|
||
while self.images_to_drop.len() > 2 {
|
||
let old_img = self.images_to_drop.remove(0);
|
||
let _ = window.drop_image(old_img);
|
||
}
|
||
}
|
||
}
|
||
|
||
// 3. Synchronisation lock-free des logs via AtomicU64
|
||
let current_log_rev = self.log_revision.load(Ordering::Acquire);
|
||
if current_log_rev != self.last_log_revision {
|
||
let lb = self.log_buffer.lock();
|
||
self.last_log_revision = current_log_rev;
|
||
self.log_err_count = lb.error_count;
|
||
self.log_warn_count = lb.warn_count;
|
||
self.log_entries = lb.entries.iter().rev().take(60).cloned().collect();
|
||
changed = true;
|
||
}
|
||
|
||
// 4. Envoi continu du Mock Manuel Nomad à 50 Hz si activé
|
||
if self.mock_continuous {
|
||
let due = self
|
||
.mock_last_send
|
||
.map(|t| t.elapsed() >= Duration::from_millis(20))
|
||
.unwrap_or(true);
|
||
if due {
|
||
self.send_mock_manual();
|
||
self.mock_last_send = Some(Instant::now());
|
||
changed = true;
|
||
}
|
||
}
|
||
|
||
changed
|
||
}
|
||
|
||
fn run_usb_rndis_setup(&self) {
|
||
log::info!("[USB RNDIS] Exécution du script de configuration réseau...");
|
||
let script_path = std::env::current_exe()
|
||
.ok()
|
||
.and_then(|p| p.parent().map(|d| d.join("scripts/setup_usb_rndis.sh")))
|
||
.filter(|p| p.exists())
|
||
.or_else(|| {
|
||
let installed = std::path::PathBuf::from("/usr/share/steamframe-fpv/scripts/setup_usb_rndis.sh");
|
||
if installed.exists() {
|
||
Some(installed)
|
||
} else {
|
||
let local = std::path::PathBuf::from("scripts/setup_usb_rndis.sh");
|
||
local.exists().then_some(local)
|
||
}
|
||
});
|
||
let Some(script_path) = script_path else {
|
||
log::error!("[USB RNDIS] Script setup_usb_rndis.sh introuvable à côté du binaire ni dans /usr/share/steamframe-fpv/scripts.");
|
||
return;
|
||
};
|
||
std::thread::spawn(move || {
|
||
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 {:?} : {}", script_path, e),
|
||
}
|
||
});
|
||
}
|
||
|
||
fn configure_radxa_ssh(&self) {
|
||
let ch = self.cfg.wifi_channel;
|
||
let Ok(ip) = self.cfg.radxa_vrx_ip.trim().parse::<std::net::IpAddr>() else {
|
||
log::error!(
|
||
"[Radxa Zero 3W] Adresse IP invalide pour SSH : '{}'",
|
||
self.cfg.radxa_vrx_ip
|
||
);
|
||
return;
|
||
};
|
||
log::info!(
|
||
"[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",
|
||
"BatchMode=yes",
|
||
"-o",
|
||
"ConnectTimeout=2",
|
||
"-o",
|
||
"StrictHostKeyChecking=accept-new",
|
||
"--",
|
||
&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) {
|
||
let protocol = NomadProtocol::from_str(&self.cfg.ht_protocol);
|
||
log::info!(
|
||
"[Wi-Fi 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) => {
|
||
let _ = ht.send_pose(glam::Quat::IDENTITY);
|
||
}
|
||
Err(e) => log::error!("[Wi-Fi Nomad] Cible invalide : {}", e),
|
||
}
|
||
}
|
||
|
||
fn set_nomad_target(&mut self, ip: &str, port: u16, proto: Option<&str>) {
|
||
self.cfg.nomad_ip = ip.to_string();
|
||
self.cfg.nomad_port = port;
|
||
self.target_port_buf = port.to_string();
|
||
if let Some(p) = proto {
|
||
self.cfg.ht_protocol = p.to_string();
|
||
}
|
||
self.target_edit_field = None;
|
||
self.mock_tracker = None;
|
||
log::info!(
|
||
"[Wi-Fi Nomad] Cible réseau mise à jour : {}:{} ({})",
|
||
self.cfg.nomad_ip,
|
||
self.cfg.nomad_port,
|
||
NomadProtocol::from_str(&self.cfg.ht_protocol).label()
|
||
);
|
||
}
|
||
|
||
fn commit_port_buf(&mut self) {
|
||
if let Ok(p) = self.target_port_buf.trim().parse::<u16>() {
|
||
if p >= 1 {
|
||
self.cfg.nomad_port = p;
|
||
self.mock_tracker = None;
|
||
}
|
||
}
|
||
self.target_port_buf = self.cfg.nomad_port.to_string();
|
||
}
|
||
|
||
fn handle_target_key_down(&mut self, ev: &KeyDownEvent) {
|
||
let Some(field) = self.target_edit_field else {
|
||
return;
|
||
};
|
||
let key = ev.keystroke.key.as_str();
|
||
match key {
|
||
"escape" => {
|
||
self.target_port_buf = self.cfg.nomad_port.to_string();
|
||
self.target_edit_field = None;
|
||
}
|
||
"enter" => {
|
||
if field == TargetEditField::Port {
|
||
self.commit_port_buf();
|
||
} else {
|
||
self.mock_tracker = None;
|
||
}
|
||
self.target_edit_field = None;
|
||
}
|
||
"backspace" => {
|
||
match field {
|
||
TargetEditField::Ip => {
|
||
self.cfg.nomad_ip.pop();
|
||
self.mock_tracker = None;
|
||
}
|
||
TargetEditField::Port => {
|
||
self.target_port_buf.pop();
|
||
}
|
||
}
|
||
}
|
||
_ => {
|
||
if let Some(ch_str) = &ev.keystroke.key_char {
|
||
for ch in ch_str.chars() {
|
||
match field {
|
||
TargetEditField::Ip => {
|
||
if ch.is_ascii_alphanumeric() || ch == '.' || ch == '-' || ch == '_' {
|
||
self.cfg.nomad_ip.push(ch);
|
||
self.mock_tracker = None;
|
||
}
|
||
}
|
||
TargetEditField::Port => {
|
||
if ch.is_ascii_digit() && self.target_port_buf.len() < 5 {
|
||
self.target_port_buf.push(ch);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
fn send_mock_manual(&mut self) {
|
||
if self.target_edit_field == Some(TargetEditField::Port) {
|
||
self.commit_port_buf();
|
||
self.target_edit_field = None;
|
||
}
|
||
let protocol = NomadProtocol::from_str(&self.cfg.ht_protocol);
|
||
if self.mock_tracker.is_none() {
|
||
match NomadHeadTracker::new(
|
||
&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(ht) => self.mock_tracker = Some(ht),
|
||
Err(e) => {
|
||
self.mock_status_text = format!("Erreur cible : {}", e);
|
||
self.mock_continuous = false;
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
|
||
if let Some(ht) = self.mock_tracker.as_mut() {
|
||
match ht.send_manual_angles(self.mock_pan_deg, self.mock_tilt_deg, self.mock_roll_deg) {
|
||
Ok(sample) => {
|
||
self.latest_pose = sample;
|
||
if sample.last_send_ok {
|
||
self.mock_status_text = format!(
|
||
"OK #{} -> {}:{} | Pan {} ({}µs) | Tilt {} ({}µs) | Roll {} ({}µs)",
|
||
sample.packets_sent,
|
||
self.cfg.nomad_ip,
|
||
self.cfg.nomad_port,
|
||
sample.pan_crsf,
|
||
NomadHeadTracker::crsf_to_pwm_us(sample.pan_crsf),
|
||
sample.tilt_crsf,
|
||
NomadHeadTracker::crsf_to_pwm_us(sample.tilt_crsf),
|
||
sample.roll_crsf,
|
||
NomadHeadTracker::crsf_to_pwm_us(sample.roll_crsf),
|
||
);
|
||
} else {
|
||
self.mock_status_text = format!(
|
||
"Échec envoi UDP ({} erreurs) vers {}:{}",
|
||
sample.send_errors, self.cfg.nomad_ip, self.cfg.nomad_port
|
||
);
|
||
}
|
||
}
|
||
Err(e) => {
|
||
self.mock_status_text = format!("Erreur : {}", e);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
fn restart_engine_async(&mut self, reason: &'static str) {
|
||
if self.target_edit_field == Some(TargetEditField::Port) {
|
||
self.commit_port_buf();
|
||
}
|
||
self.target_edit_field = None;
|
||
|
||
if self.is_closing.load(Ordering::Acquire) {
|
||
return;
|
||
}
|
||
if self
|
||
.is_restarting
|
||
.compare_exchange(false, true, Ordering::AcqRel, Ordering::Acquire)
|
||
.is_err()
|
||
{
|
||
log::warn!("[Moteur FPV] Redémarrage déjà en cours, requête ignorée.");
|
||
return;
|
||
}
|
||
|
||
let engine_clone = Arc::clone(&self.engine);
|
||
let cfg_clone = self.cfg.clone();
|
||
let is_restarting = Arc::clone(&self.is_restarting);
|
||
let is_closing = Arc::clone(&self.is_closing);
|
||
std::thread::spawn(move || {
|
||
{
|
||
let mut eng = engine_clone.lock();
|
||
if !is_closing.load(Ordering::Acquire) {
|
||
log::info!("{}", reason);
|
||
eng.start(cfg_clone);
|
||
}
|
||
}
|
||
is_restarting.store(false, Ordering::Release);
|
||
});
|
||
}
|
||
|
||
fn set_vr_enabled(&mut self, enabled: bool) {
|
||
let target_headless = !enabled;
|
||
if self.cfg.headless == target_headless {
|
||
return;
|
||
}
|
||
if self.is_restarting.load(Ordering::Acquire) {
|
||
log::warn!("[Moteur FPV] Bascule VR ignorée pendant un redémarrage en cours.");
|
||
return;
|
||
}
|
||
self.cfg.headless = target_headless;
|
||
if enabled {
|
||
self.restart_engine_async("[Action Utilisateur] Mode VR (OpenXR) réactivé, redémarrage du moteur FPV...");
|
||
} else {
|
||
self.restart_engine_async("[Action Utilisateur] Mode VR désactivé (Mode Bureau léger), redémarrage du moteur FPV...");
|
||
}
|
||
}
|
||
}
|
||
|
||
impl Drop for SteamFrameGpuiApp {
|
||
fn drop(&mut self) {
|
||
self.is_closing.store(true, Ordering::Release);
|
||
log::info!("[SteamFrameGpuiApp] Fermeture de l'interface IHM, arrêt propre du moteur FPV...");
|
||
self.engine.lock().stop();
|
||
}
|
||
}
|
||
|
||
impl Render for SteamFrameGpuiApp {
|
||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||
if self.target_focus_handle.is_none() {
|
||
self.target_focus_handle = Some(cx.focus_handle());
|
||
}
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.size_full()
|
||
.bg(rgb(COLOR_BG_DARK))
|
||
.text_color(rgb(COLOR_TEXT_MAIN))
|
||
.p_3()
|
||
.gap_3()
|
||
.overflow_hidden()
|
||
// 1. HEADER COCKPIT BAR AVEC MENU D'ONGLETS
|
||
.child(self.render_header(cx))
|
||
// 2. VUE ACTIVE (Cockpit plein format, Réglages, Télémétrie, Logs)
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.flex_1()
|
||
.min_h_0()
|
||
.min_w_0()
|
||
.overflow_hidden()
|
||
.child(match self.active_tab {
|
||
ActiveTab::Cockpit => self.render_cockpit_view(cx).into_any_element(),
|
||
ActiveTab::Settings => self.render_settings_view(cx).into_any_element(),
|
||
ActiveTab::Telemetry => self.render_telemetry_view().into_any_element(),
|
||
ActiveTab::Logs => self.render_logs_view(cx).into_any_element(),
|
||
}),
|
||
)
|
||
}
|
||
}
|
||
|
||
impl SteamFrameGpuiApp {
|
||
// -------------------------------------------------------------------------
|
||
// 1. Barre Supérieure (Header & Navigation par Onglets)
|
||
// -------------------------------------------------------------------------
|
||
fn render_header(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
||
div()
|
||
.flex()
|
||
.flex_row()
|
||
.flex_wrap()
|
||
.justify_between()
|
||
.items_center()
|
||
.bg(rgb(COLOR_SURFACE_CARD))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.rounded_xl()
|
||
.px_3()
|
||
.py_2()
|
||
.gap_2()
|
||
// GAUCHE : Identité & Badges Statut
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.items_center()
|
||
.gap_2p5()
|
||
.child(
|
||
div()
|
||
.text_base()
|
||
.font_weight(gpui::FontWeight::BOLD)
|
||
.text_color(rgb(COLOR_CYAN))
|
||
.child(concat!("🥽 SteamFrame FPV v", env!("CARGO_PKG_VERSION"))),
|
||
)
|
||
.child(self.render_status_badge("VRX", &self.usb_status))
|
||
.child(self.render_status_badge("VR", &self.xr_status))
|
||
.child(self.render_status_badge("DVR", &self.dvr_status)),
|
||
)
|
||
// CENTRE : Barre d'onglets épurée
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.items_center()
|
||
.gap_1()
|
||
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||
.p_1()
|
||
.rounded_lg()
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.child(self.render_nav_tab("📹 Cockpit", ActiveTab::Cockpit, cx))
|
||
.child(self.render_nav_tab("⚙️ Réglages", ActiveTab::Settings, cx))
|
||
.child(self.render_nav_tab("📊 Télémétrie", ActiveTab::Telemetry, cx))
|
||
.child(self.render_nav_tab(
|
||
&if self.log_err_count > 0 {
|
||
format!("📜 Logs ({})", self.log_err_count)
|
||
} else {
|
||
"📜 Logs".to_string()
|
||
},
|
||
ActiveTab::Logs,
|
||
cx,
|
||
)),
|
||
)
|
||
// DROITE : Quick Actions & Tare
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.items_center()
|
||
.gap_2()
|
||
.child(
|
||
div()
|
||
.id("toggle_ctrl_source_quick")
|
||
.px_2()
|
||
.py_0p5()
|
||
.bg(if self.active_control_source == ControlSource::SteamController {
|
||
rgb(0x132738)
|
||
} else {
|
||
rgb(COLOR_SURFACE_ELEVATED)
|
||
})
|
||
.border_1()
|
||
.border_color(if self.active_control_source == ControlSource::SteamController {
|
||
rgb(COLOR_CYAN)
|
||
} else {
|
||
rgb(COLOR_ORANGE)
|
||
})
|
||
.rounded_md()
|
||
.text_xs()
|
||
.font_weight(gpui::FontWeight::SEMIBOLD)
|
||
.text_color(if self.active_control_source == ControlSource::SteamController {
|
||
rgb(COLOR_CYAN)
|
||
} else {
|
||
rgb(COLOR_ORANGE)
|
||
})
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(|this, _, _, cx| {
|
||
let next = match this.active_control_source {
|
||
ControlSource::G29 => ControlSource::SteamController,
|
||
ControlSource::SteamController => ControlSource::G29,
|
||
};
|
||
this.switch_control_source(next);
|
||
cx.notify();
|
||
}))
|
||
.child(match self.active_control_source {
|
||
ControlSource::G29 => "🏎️ G29",
|
||
ControlSource::SteamController => "🎮 Steam",
|
||
}),
|
||
)
|
||
.child(
|
||
div()
|
||
.id("toggle_vr_quick")
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(|this, _, _, cx| {
|
||
let vr_on = this.cfg.headless;
|
||
this.set_vr_enabled(vr_on);
|
||
cx.notify();
|
||
}))
|
||
.child(self.render_toggle_pill(
|
||
"🥽 VR",
|
||
!self.cfg.headless,
|
||
rgb(COLOR_CYAN),
|
||
)),
|
||
)
|
||
.child(
|
||
div()
|
||
.id("toggle_ht_quick")
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(|this, _, _, cx| {
|
||
this.cfg.head_tracking_enabled = !this.cfg.head_tracking_enabled;
|
||
this.controls
|
||
.set_head_tracking_enabled(this.cfg.head_tracking_enabled);
|
||
cx.notify();
|
||
}))
|
||
.child(self.render_toggle_pill(
|
||
"🎯 Suivi",
|
||
self.cfg.head_tracking_enabled,
|
||
rgb(COLOR_GREEN),
|
||
)),
|
||
)
|
||
.child(
|
||
div()
|
||
.id("toggle_telem_quick")
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(|this, _, _, cx| {
|
||
this.cfg.telemetry_enabled = !this.cfg.telemetry_enabled;
|
||
this.controls
|
||
.set_telemetry_enabled(this.cfg.telemetry_enabled);
|
||
cx.notify();
|
||
}))
|
||
.child(self.render_toggle_pill(
|
||
"📶 OSD",
|
||
self.cfg.telemetry_enabled,
|
||
rgb(COLOR_CYAN),
|
||
)),
|
||
)
|
||
.child(
|
||
div()
|
||
.id("btn_vr_menu_quick")
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(|this, _, _, cx| {
|
||
this.controls.toggle_vr_menu();
|
||
cx.notify();
|
||
}))
|
||
.child(self.render_toggle_pill(
|
||
"📋 Menu VR",
|
||
self.controls.is_vr_menu_open(),
|
||
rgb(COLOR_ORANGE),
|
||
)),
|
||
)
|
||
.child(
|
||
div()
|
||
.id("btn_tare_quick")
|
||
.px_2p5()
|
||
.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.controls.request_recenter();
|
||
cx.notify();
|
||
}))
|
||
.child("🎯 Tare"),
|
||
)
|
||
.child(
|
||
div()
|
||
.id("btn_dvr_quick")
|
||
.px_2p5()
|
||
.py_1()
|
||
.bg(if self.dvr_recording { rgb(COLOR_RED) } else { rgb(COLOR_SURFACE_ELEVATED) })
|
||
.border_1()
|
||
.border_color(if self.dvr_recording { rgb(COLOR_RED) } else { rgb(COLOR_BORDER_SUBTLE) })
|
||
.rounded_md()
|
||
.text_xs()
|
||
.font_weight(gpui::FontWeight::SEMIBOLD)
|
||
.text_color(if self.dvr_recording { rgb(0xffffff) } else { rgb(COLOR_TEXT_MAIN) })
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(|this, _, _, cx| {
|
||
if this.dvr_recording {
|
||
this.controls.stop_dvr();
|
||
} else {
|
||
this.controls.start_dvr();
|
||
}
|
||
cx.notify();
|
||
}))
|
||
.child(if self.dvr_recording {
|
||
let mins = self.dvr_elapsed_secs / 60;
|
||
let secs = self.dvr_elapsed_secs % 60;
|
||
let mb = self.dvr_file_size_bytes as f64 / (1024.0 * 1024.0);
|
||
format!("⏹ DVR ({:02}:{:02} - {:.1}Mo)", mins, secs, mb)
|
||
} else {
|
||
"🔴 DVR".to_string()
|
||
}),
|
||
),
|
||
)
|
||
}
|
||
|
||
fn switch_control_source(&mut self, target: ControlSource) {
|
||
match self.controls.set_control_source(target) {
|
||
Ok(()) => {
|
||
self.active_control_source = target;
|
||
self.cfg.control_source = target.as_str().to_string();
|
||
self.control_switch_error.clear();
|
||
}
|
||
Err(msg) => {
|
||
self.control_switch_error = msg;
|
||
}
|
||
}
|
||
}
|
||
|
||
fn render_nav_tab(&self, label: &str, tab: ActiveTab, cx: &mut Context<Self>) -> impl IntoElement {
|
||
let is_active = self.active_tab == tab;
|
||
let tab_id = match tab {
|
||
ActiveTab::Cockpit => "tab_btn_cockpit",
|
||
ActiveTab::Settings => "tab_btn_settings",
|
||
ActiveTab::Telemetry => "tab_btn_telemetry",
|
||
ActiveTab::Logs => "tab_btn_logs",
|
||
};
|
||
div()
|
||
.id(tab_id)
|
||
.px_3()
|
||
.py_1()
|
||
.rounded_md()
|
||
.text_xs()
|
||
.font_weight(if is_active {
|
||
gpui::FontWeight::BOLD
|
||
} else {
|
||
gpui::FontWeight::NORMAL
|
||
})
|
||
.bg(if is_active {
|
||
rgb(0x1a2638)
|
||
} else {
|
||
rgba(0x00000000)
|
||
})
|
||
.border_1()
|
||
.border_color(if is_active {
|
||
rgb(COLOR_BORDER_ACTIVE)
|
||
} else {
|
||
rgba(0x00000000)
|
||
})
|
||
.text_color(if is_active {
|
||
rgb(COLOR_CYAN)
|
||
} else {
|
||
rgb(COLOR_TEXT_MUTED)
|
||
})
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(move |this, _, _, cx| {
|
||
this.active_tab = tab;
|
||
cx.notify();
|
||
}))
|
||
.child(label.to_string())
|
||
}
|
||
|
||
// -------------------------------------------------------------------------
|
||
// 2. Vue Cockpit : Plein Format Vidéo + Overlay HUD Discret
|
||
// -------------------------------------------------------------------------
|
||
fn render_cockpit_view(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.size_full()
|
||
.min_h_0()
|
||
.min_w_0()
|
||
.relative()
|
||
.bg(rgb(0x030508))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.rounded_xl()
|
||
.overflow_hidden()
|
||
.items_center()
|
||
.justify_center()
|
||
// 2.1 Flux Vidéo (cadrage proportionnel intégral sans rognage)
|
||
.child(if let Some(ref img_src) = self.current_render_image {
|
||
div()
|
||
.flex()
|
||
.items_center()
|
||
.justify_center()
|
||
.size_full()
|
||
.min_h_0()
|
||
.min_w_0()
|
||
.child(
|
||
img(img_src.clone())
|
||
.size_full()
|
||
.object_fit(gpui::ObjectFit::Contain),
|
||
)
|
||
} else {
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.items_center()
|
||
.gap_3()
|
||
.child(
|
||
div()
|
||
.text_xl()
|
||
.font_weight(gpui::FontWeight::BOLD)
|
||
.text_color(rgb(COLOR_CYAN))
|
||
.child("🥽 En attente du flux Eachine Sphere Link..."),
|
||
)
|
||
.child(
|
||
div()
|
||
.text_xs()
|
||
.text_color(rgb(COLOR_TEXT_MUTED))
|
||
.child("Réception active sur UDP 0.0.0.0:5600 (H.264 Raw direct)"),
|
||
)
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.justify_center()
|
||
.gap_2()
|
||
.pt_2()
|
||
.child(
|
||
div()
|
||
.px_3()
|
||
.py_1p5()
|
||
.bg(rgb(COLOR_SURFACE_CARD))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.rounded_lg()
|
||
.text_xs()
|
||
.child("1. Branchez le câble USB-C OTG ou Mini-HDMI"),
|
||
)
|
||
.child(
|
||
div()
|
||
.px_3()
|
||
.py_1p5()
|
||
.bg(rgb(COLOR_SURFACE_CARD))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.rounded_lg()
|
||
.text_xs()
|
||
.child("2. Vérifiez le canal 5.8 GHz (Canal 161)"),
|
||
),
|
||
)
|
||
})
|
||
// 2.2 Overlay Supérieur Gauche (FPS & Trames)
|
||
.child(
|
||
div()
|
||
.absolute()
|
||
.top_3()
|
||
.left_3()
|
||
.flex()
|
||
.gap_2()
|
||
.child(
|
||
div()
|
||
.px_2p5()
|
||
.py_1()
|
||
.bg(rgba(0x0a101abb))
|
||
.border_1()
|
||
.border_color(if self.video_fps > 0.1 {
|
||
rgb(COLOR_GREEN)
|
||
} else {
|
||
rgb(COLOR_ORANGE)
|
||
})
|
||
.rounded_md()
|
||
.text_xs()
|
||
.font_weight(gpui::FontWeight::BOLD)
|
||
.text_color(if self.video_fps > 0.1 {
|
||
rgb(COLOR_GREEN)
|
||
} else {
|
||
rgb(COLOR_ORANGE)
|
||
})
|
||
.child(if self.video_fps > 0.1 {
|
||
format!("{:.1} FPS", self.video_fps)
|
||
} else {
|
||
"⚠️ RECHERCHE SIGNAL".to_string()
|
||
}),
|
||
)
|
||
.child(
|
||
div()
|
||
.px_2p5()
|
||
.py_1()
|
||
.bg(rgba(0x0a101abb))
|
||
.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)),
|
||
),
|
||
)
|
||
// 2.3 Overlay Supérieur Droit (VR & Format)
|
||
.child(
|
||
div()
|
||
.absolute()
|
||
.top_3()
|
||
.right_3()
|
||
.flex()
|
||
.gap_2()
|
||
.child(
|
||
div()
|
||
.px_2p5()
|
||
.py_1()
|
||
.bg(rgba(0x0a101abb))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.rounded_md()
|
||
.text_xs()
|
||
.text_color(rgb(COLOR_CYAN))
|
||
.child(format!(
|
||
"{} • {}",
|
||
self.cfg.vrx_video_profile,
|
||
self.cfg.projection_mode.to_uppercase()
|
||
)),
|
||
)
|
||
.child(
|
||
div()
|
||
.id("btn_toggle_hud")
|
||
.px_2p5()
|
||
.py_1()
|
||
.bg(rgba(0x0a101abb))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.rounded_md()
|
||
.text_xs()
|
||
.text_color(rgb(COLOR_TEXT_MUTED))
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(|this, _, _, cx| {
|
||
this.show_hud_overlay = !this.show_hud_overlay;
|
||
cx.notify();
|
||
}))
|
||
.child(if self.show_hud_overlay {
|
||
"👁️ HUD ON"
|
||
} else {
|
||
"👁️ HUD OFF"
|
||
}),
|
||
),
|
||
)
|
||
// 2.4 Bandeau Flottant Inférieur (HUD Télémetrie & Suivi Tête discret)
|
||
.child(if self.show_hud_overlay {
|
||
div()
|
||
.absolute()
|
||
.bottom_3()
|
||
.flex()
|
||
.items_center()
|
||
.gap_3()
|
||
.px_4()
|
||
.py_1p5()
|
||
.bg(rgba(0x090e18ee))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.rounded_full()
|
||
.text_xs()
|
||
.child(
|
||
div()
|
||
.text_color(rgb(COLOR_GREEN))
|
||
.child(format!("🔋 {:.1} V", self.latest_telem.battery_voltage_v)),
|
||
)
|
||
.child(
|
||
div()
|
||
.text_color(rgb(COLOR_TEXT_MUTED))
|
||
.child("•"),
|
||
)
|
||
.child(
|
||
div()
|
||
.text_color(rgb(COLOR_CYAN))
|
||
.child(format!("📶 LQ {}%", self.latest_telem.link_quality_pct)),
|
||
)
|
||
.child(
|
||
div()
|
||
.text_color(rgb(COLOR_TEXT_MUTED))
|
||
.child("•"),
|
||
)
|
||
.child(
|
||
div()
|
||
.text_color(rgb(COLOR_TEXT_MAIN))
|
||
.child(format!(
|
||
"🚀 {:.0} km/h • ⛰️ {:.0} m",
|
||
self.latest_telem.groundspeed_ms * 3.6,
|
||
self.latest_telem.altitude_m
|
||
)),
|
||
)
|
||
.child(
|
||
div()
|
||
.text_color(rgb(COLOR_TEXT_MUTED))
|
||
.child("•"),
|
||
)
|
||
.child(
|
||
div()
|
||
.text_color(rgb(COLOR_ORANGE))
|
||
.child(format!(
|
||
"🎯 P:{:+.0}° T:{:+.0}° R:{:+.0}°",
|
||
self.latest_pose.pan_deg,
|
||
self.latest_pose.tilt_deg,
|
||
self.latest_pose.roll_deg
|
||
)),
|
||
)
|
||
.into_any_element()
|
||
} else {
|
||
div().into_any_element()
|
||
})
|
||
}
|
||
|
||
// -------------------------------------------------------------------------
|
||
// 3. Vue Réglages (Menus Déroulants & Paramètres Configurables)
|
||
// -------------------------------------------------------------------------
|
||
fn render_settings_view(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.size_full()
|
||
.min_h_0()
|
||
.min_w_0()
|
||
.id("settings_view_scroll")
|
||
.overflow_y_scroll()
|
||
.bg(rgb(COLOR_SURFACE_CARD))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.rounded_xl()
|
||
.p_4()
|
||
.gap_4()
|
||
// Titre & En-tête
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.justify_between()
|
||
.items_center()
|
||
.gap_2()
|
||
.border_b_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.pb_3()
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.gap_0p5()
|
||
.child(
|
||
div()
|
||
.text_base()
|
||
.font_weight(gpui::FontWeight::BOLD)
|
||
.text_color(rgb(COLOR_CYAN))
|
||
.child("⚙️ Paramètres et Réglages FPV"),
|
||
)
|
||
.child(
|
||
div()
|
||
.text_xs()
|
||
.text_color(rgb(COLOR_TEXT_MUTED))
|
||
.child("Configurez le récepteur VRX, le Wi-Fi Nomad, la projection VR et l'OSD."),
|
||
),
|
||
)
|
||
.child(
|
||
div()
|
||
.id("btn_apply_settings")
|
||
.px_4()
|
||
.py_1p5()
|
||
.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.restart_engine_async("[Réglages] Application et redémarrage asynchrone du moteur FPV...");
|
||
cx.notify();
|
||
}))
|
||
.child("🔄 Appliquer & Redémarrer"),
|
||
),
|
||
)
|
||
// Grille des réglages (Cartes thématiques)
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.flex_row()
|
||
.flex_wrap()
|
||
.gap_3()
|
||
// 3.1 Carte VRX Eachine Sphere Link
|
||
.child(self.render_settings_card(
|
||
"🔌 1. Récepteur VRX Sphere Link (Radxa Zero 3W)",
|
||
COLOR_CYAN,
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.gap_3()
|
||
// Mode d'acquisition
|
||
.child(self.render_setting_row(
|
||
"Mode Acquisition Vidéo",
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.gap_2()
|
||
.child(self.render_selectable_pill(
|
||
"pill_mode_rndis",
|
||
"USB OTG (RNDIS)",
|
||
self.cfg.usb_video_mode.eq_ignore_ascii_case("rndis"),
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.usb_video_mode = "rndis".into();
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(self.render_selectable_pill(
|
||
"pill_mode_uvc",
|
||
"Mini-HDMI (UVC)",
|
||
self.cfg.usb_video_mode.eq_ignore_ascii_case("uvc"),
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.usb_video_mode = "uvc".into();
|
||
cx.notify();
|
||
}),
|
||
)),
|
||
))
|
||
// Canal 5.8 GHz
|
||
.child(self.render_setting_row(
|
||
"Canal 5.8 GHz (RTL8812EU)",
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.gap_1p5()
|
||
.child(self.render_channel_button(149, 5745, cx))
|
||
.child(self.render_channel_button(153, 5765, cx))
|
||
.child(self.render_channel_button(157, 5785, cx))
|
||
.child(self.render_channel_button(161, 5805, cx)),
|
||
))
|
||
// Codec & Transport
|
||
.child(self.render_setting_row(
|
||
"Codec Décodage",
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.gap_2()
|
||
.child(self.render_selectable_pill(
|
||
"pill_codec_h264",
|
||
"H.264 (Faible Latence)",
|
||
self.cfg.codec.eq_ignore_ascii_case("h264"),
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.codec = "h264".into();
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(self.render_selectable_pill(
|
||
"pill_codec_h265",
|
||
"H.265 (HEVC)",
|
||
self.cfg.codec.eq_ignore_ascii_case("h265"),
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.codec = "h265".into();
|
||
cx.notify();
|
||
}),
|
||
)),
|
||
))
|
||
// Actions matérielles
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.gap_2()
|
||
.pt_2()
|
||
.child(
|
||
div()
|
||
.id("btn_rndis_setup")
|
||
.flex_1()
|
||
.py_1p5()
|
||
.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, _, _, _| {
|
||
this.run_usb_rndis_setup();
|
||
}))
|
||
.child("⚡ Lancer setup_usb_rndis.sh"),
|
||
)
|
||
.child(
|
||
div()
|
||
.id("btn_ssh_setup")
|
||
.flex_1()
|
||
.py_1p5()
|
||
.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, _, _, _| {
|
||
this.configure_radxa_ssh();
|
||
}))
|
||
.child("🔧 Config Canal par SSH"),
|
||
),
|
||
),
|
||
))
|
||
// 3.2 Carte Wi-Fi RadioMaster Nomad (ELRS)
|
||
.child(self.render_settings_card(
|
||
"📡 2. Suivi de Tête & Radio (Nomad ELRS)",
|
||
COLOR_ORANGE,
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.gap_3()
|
||
.when_some(self.target_focus_handle.as_ref(), |d, fh| {
|
||
d.track_focus(fh).on_key_down(cx.listener(|this, ev: &KeyDownEvent, _, cx| {
|
||
this.handle_target_key_down(ev);
|
||
cx.notify();
|
||
}))
|
||
})
|
||
// Protocole
|
||
.child(self.render_setting_row(
|
||
"Protocole Wi-Fi",
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.gap_2()
|
||
.child(self.render_selectable_pill(
|
||
"pill_proto_g29",
|
||
"G29 Hub ($HT)",
|
||
self.cfg.ht_protocol.eq_ignore_ascii_case("g29")
|
||
|| self.cfg.ht_protocol.eq_ignore_ascii_case("g29_bridge")
|
||
|| self.cfg.ht_protocol.eq_ignore_ascii_case("radxa"),
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.ht_protocol = "g29".into();
|
||
this.mock_tracker = None;
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(self.render_selectable_pill(
|
||
"pill_proto_msp",
|
||
"MSPv2 0x0383",
|
||
self.cfg.ht_protocol.eq_ignore_ascii_case("msp"),
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.ht_protocol = "msp".into();
|
||
this.mock_tracker = None;
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(self.render_selectable_pill(
|
||
"pill_proto_crsf",
|
||
"CRSF 0x16",
|
||
self.cfg.ht_protocol.eq_ignore_ascii_case("crsf"),
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.ht_protocol = "crsf".into();
|
||
this.mock_tracker = None;
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(self.render_selectable_pill(
|
||
"pill_proto_mavlink",
|
||
"MAVLink v1 (14555)",
|
||
self.cfg.ht_protocol.eq_ignore_ascii_case("mavlink"),
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.ht_protocol = "mavlink".into();
|
||
this.mock_tracker = None;
|
||
cx.notify();
|
||
}),
|
||
)),
|
||
))
|
||
// Cible UDP éditable (clic pour taper IP/hostname ou port)
|
||
.child(self.render_setting_row(
|
||
"Cible Réseau (clic pour éditer)",
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.items_center()
|
||
.gap_1()
|
||
.child(
|
||
div()
|
||
.id("input_nomad_ip")
|
||
.px_2()
|
||
.py_1()
|
||
.rounded_md()
|
||
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||
.border_1()
|
||
.border_color(if self.target_edit_field == Some(TargetEditField::Ip) {
|
||
rgb(COLOR_BORDER_ACTIVE)
|
||
} else {
|
||
rgb(COLOR_BORDER_SUBTLE)
|
||
})
|
||
.text_xs()
|
||
.text_color(rgb(COLOR_TEXT_MAIN))
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(|this, _, window, cx| {
|
||
if this.target_edit_field == Some(TargetEditField::Port) {
|
||
this.commit_port_buf();
|
||
}
|
||
this.target_edit_field = Some(TargetEditField::Ip);
|
||
if let Some(fh) = &this.target_focus_handle {
|
||
window.focus(fh);
|
||
}
|
||
cx.notify();
|
||
}))
|
||
.child(if self.target_edit_field == Some(TargetEditField::Ip) {
|
||
format!("{}|", self.cfg.nomad_ip)
|
||
} else {
|
||
self.cfg.nomad_ip.clone()
|
||
}),
|
||
)
|
||
.child(div().text_xs().text_color(rgb(COLOR_TEXT_MUTED)).child(":"))
|
||
.child(
|
||
div()
|
||
.id("input_nomad_port")
|
||
.px_2()
|
||
.py_1()
|
||
.rounded_md()
|
||
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||
.border_1()
|
||
.border_color(if self.target_edit_field == Some(TargetEditField::Port) {
|
||
rgb(COLOR_BORDER_ACTIVE)
|
||
} else {
|
||
rgb(COLOR_BORDER_SUBTLE)
|
||
})
|
||
.text_xs()
|
||
.text_color(rgb(COLOR_TEXT_MAIN))
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(|this, _, window, cx| {
|
||
this.target_port_buf = this.cfg.nomad_port.to_string();
|
||
this.target_edit_field = Some(TargetEditField::Port);
|
||
if let Some(fh) = &this.target_focus_handle {
|
||
window.focus(fh);
|
||
}
|
||
cx.notify();
|
||
}))
|
||
.child(if self.target_edit_field == Some(TargetEditField::Port) {
|
||
format!("{}|", self.target_port_buf)
|
||
} else {
|
||
self.cfg.nomad_port.to_string()
|
||
}),
|
||
),
|
||
))
|
||
// Presets réseau rapides
|
||
.child(self.render_setting_row(
|
||
"Presets Cible",
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.gap_2()
|
||
.child(self.render_selectable_pill(
|
||
"preset_radxa_g29_unified",
|
||
"Tout-en-un Radxa usb0 (192.168.1.1:14552)",
|
||
self.cfg.nomad_ip == "192.168.1.1" && self.cfg.nomad_port == 14552,
|
||
cx.listener(|this, _, _, cx| {
|
||
this.set_nomad_target("192.168.1.1", 14552, Some("g29"));
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(self.render_selectable_pill(
|
||
"preset_ap_default",
|
||
"AP Défaut (10.0.0.1:14550)",
|
||
self.cfg.nomad_ip == "10.0.0.1" && self.cfg.nomad_port == 14550,
|
||
cx.listener(|this, _, _, cx| {
|
||
this.set_nomad_target("10.0.0.1", 14550, Some("msp"));
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(self.render_selectable_pill(
|
||
"preset_local_bp",
|
||
"Backpack LAN (elrs_txbp.local:14555)",
|
||
self.cfg.nomad_ip == "elrs_txbp.local" && self.cfg.nomad_port == 14555,
|
||
cx.listener(|this, _, _, cx| {
|
||
this.set_nomad_target("elrs_txbp.local", 14555, Some("mavlink"));
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(self.render_selectable_pill(
|
||
"preset_localhost",
|
||
"Test Local (127.0.0.1:14550)",
|
||
self.cfg.nomad_ip == "127.0.0.1" && self.cfg.nomad_port == 14550,
|
||
cx.listener(|this, _, _, cx| {
|
||
this.set_nomad_target("127.0.0.1", 14550, None);
|
||
cx.notify();
|
||
}),
|
||
)),
|
||
))
|
||
// Courses maximales
|
||
.child(self.render_setting_row(
|
||
"Débattements Max",
|
||
div()
|
||
.text_xs()
|
||
.text_color(rgb(COLOR_TEXT_MAIN))
|
||
.child(format!(
|
||
"Pan : {}° | Tilt : {}° | Roll : {}°",
|
||
self.cfg.max_pan_deg, self.cfg.max_tilt_deg, self.cfg.max_roll_deg
|
||
)),
|
||
))
|
||
// Mock Manuel Pan/Tilt/Roll
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.gap_2()
|
||
.p_2()
|
||
.rounded_md()
|
||
.bg(rgb(COLOR_BG_DARK))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.child(
|
||
div()
|
||
.text_xs()
|
||
.font_weight(gpui::FontWeight::SEMIBOLD)
|
||
.text_color(rgb(COLOR_ORANGE))
|
||
.child("🎛️ Mock Manuel (Envoi direct vers Nomad / Backpack)"),
|
||
)
|
||
.child(self.render_mock_axis_row(
|
||
"pan",
|
||
"Pan (Yaw)",
|
||
self.mock_pan_deg,
|
||
self.cfg.max_pan_deg,
|
||
cx,
|
||
))
|
||
.child(self.render_mock_axis_row(
|
||
"tilt",
|
||
"Tilt (Pitch)",
|
||
self.mock_tilt_deg,
|
||
self.cfg.max_tilt_deg,
|
||
cx,
|
||
))
|
||
.child(self.render_mock_axis_row(
|
||
"roll",
|
||
"Roll",
|
||
self.mock_roll_deg,
|
||
self.cfg.max_roll_deg,
|
||
cx,
|
||
))
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.gap_2()
|
||
.pt_1()
|
||
.child(
|
||
div()
|
||
.id("btn_send_mock_manual")
|
||
.flex_1()
|
||
.py_1p5()
|
||
.px_2()
|
||
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_ORANGE))
|
||
.rounded_md()
|
||
.text_xs()
|
||
.font_weight(gpui::FontWeight::SEMIBOLD)
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(|this, _, _, cx| {
|
||
this.send_mock_manual();
|
||
cx.notify();
|
||
}))
|
||
.child("📤 Envoyer Mock Manuel"),
|
||
)
|
||
.child(self.render_selectable_pill(
|
||
"pill_mock_continuous",
|
||
if self.mock_continuous {
|
||
"🔄 Continu 50 Hz : ON"
|
||
} else {
|
||
"🔄 Continu 50 Hz : OFF"
|
||
},
|
||
self.mock_continuous,
|
||
cx.listener(|this, _, _, cx| {
|
||
if this.target_edit_field == Some(TargetEditField::Port) {
|
||
this.commit_port_buf();
|
||
this.target_edit_field = None;
|
||
}
|
||
this.mock_continuous = !this.mock_continuous;
|
||
this.mock_last_send = None;
|
||
if this.mock_continuous && this.cfg.head_tracking_enabled {
|
||
this.cfg.head_tracking_enabled = false;
|
||
this.controls.set_head_tracking_enabled(false);
|
||
log::info!("[Mock Manuel] Suivi de tête moteur désactivé automatiquement pour éviter une collision UDP.");
|
||
}
|
||
cx.notify();
|
||
}),
|
||
)),
|
||
)
|
||
.when(!self.mock_status_text.is_empty(), |d| {
|
||
d.child(
|
||
div()
|
||
.text_xs()
|
||
.text_color(rgb(COLOR_GREEN))
|
||
.child(self.mock_status_text.clone()),
|
||
)
|
||
}),
|
||
)
|
||
// Actions Nomad
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.gap_2()
|
||
.pt_1()
|
||
.child(
|
||
div()
|
||
.id("btn_test_packet_settings")
|
||
.flex_1()
|
||
.py_1p5()
|
||
.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, _, _, _| {
|
||
this.test_nomad_packet();
|
||
}))
|
||
.child("📡 Envoyer paquet neutre"),
|
||
)
|
||
.child(
|
||
div()
|
||
.id("btn_tare_settings")
|
||
.flex_1()
|
||
.py_1p5()
|
||
.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.controls.request_recenter();
|
||
cx.notify();
|
||
}))
|
||
.child("🎯 Réinitialiser Zéro (Tare)"),
|
||
),
|
||
),
|
||
))
|
||
// 3.2b Carte Contrôleur de Conduite (Volant G29 / Steam Controller)
|
||
.child(self.render_settings_card(
|
||
"🎮 2b. Contrôleur de Conduite (Volant G29 / Steam Controller)",
|
||
COLOR_GREEN,
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.gap_3()
|
||
.child(self.render_setting_row(
|
||
"Source Active (bascule à chaud)",
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.gap_2()
|
||
.child(self.render_selectable_pill(
|
||
"pill_ctrl_g29",
|
||
"🏎️ Volant Logitech G29",
|
||
self.active_control_source == ControlSource::G29,
|
||
cx.listener(|this, _, _, cx| {
|
||
this.switch_control_source(ControlSource::G29);
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(self.render_selectable_pill(
|
||
"pill_ctrl_steam",
|
||
"🎮 Steam Controller (Boîte séq.)",
|
||
self.active_control_source == ControlSource::SteamController,
|
||
cx.listener(|this, _, _, cx| {
|
||
this.switch_control_source(
|
||
ControlSource::SteamController,
|
||
);
|
||
cx.notify();
|
||
}),
|
||
)),
|
||
))
|
||
.when(!self.control_switch_error.is_empty(), |d| {
|
||
d.child(
|
||
div()
|
||
.px_2p5()
|
||
.py_1()
|
||
.rounded_md()
|
||
.bg(rgb(0x2a1215))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_RED))
|
||
.text_xs()
|
||
.text_color(rgb(COLOR_RED))
|
||
.child(format!("⚠️ {}", self.control_switch_error)),
|
||
)
|
||
})
|
||
.child(self.render_setting_row(
|
||
"État Steam Controller",
|
||
div()
|
||
.text_xs()
|
||
.text_color(if self.latest_controller.connected {
|
||
rgb(COLOR_GREEN)
|
||
} else {
|
||
rgb(COLOR_TEXT_MUTED)
|
||
})
|
||
.child(if self.latest_controller.connected {
|
||
format!(
|
||
"● {} ({}) — [{}] {} • Gaz {}% • Frn {}% • Dir {:+.0}%",
|
||
self.latest_controller.device_name,
|
||
self.latest_controller.device_path,
|
||
self.latest_controller.gear_label(),
|
||
if self.latest_controller.armed {
|
||
"ARMED"
|
||
} else {
|
||
"SAFE"
|
||
},
|
||
self.latest_controller.throttle_pct,
|
||
self.latest_controller.brake_pct,
|
||
self.latest_controller.steering_norm * 100.0
|
||
)
|
||
} else {
|
||
"○ Non détecté (branchez le dongle ou allumez la manette)"
|
||
.to_string()
|
||
}),
|
||
))
|
||
.child(self.render_setting_row(
|
||
"Sens Direction Steam Controller",
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.items_center()
|
||
.gap_2()
|
||
.child(self.render_selectable_pill(
|
||
"pill_sc_steer_normal",
|
||
"Normal (identique G29)",
|
||
!self.cfg.controller_invert_steering,
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.controller_invert_steering = false;
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(self.render_selectable_pill(
|
||
"pill_sc_steer_inv",
|
||
"Inversée",
|
||
self.cfg.controller_invert_steering,
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.controller_invert_steering = true;
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(
|
||
div()
|
||
.text_xs()
|
||
.text_color(rgb(COLOR_TEXT_MUTED))
|
||
.child(format!(
|
||
"(Expo {:.2} • Deadzone {:.2})",
|
||
self.cfg.controller_expo,
|
||
self.cfg.controller_deadzone
|
||
)),
|
||
),
|
||
))
|
||
.child(self.render_setting_row(
|
||
"Vibrations Haptiques SC (25 Hz)",
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.items_center()
|
||
.gap_2()
|
||
.child(self.render_selectable_pill(
|
||
"pill_sc_vib_0",
|
||
"OFF",
|
||
self.cfg.controller_vibration == 0,
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.controller_vibration = 0;
|
||
this.controls.set_controller_vibration_pct(0);
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(
|
||
div()
|
||
.id("btn_sc_vib_dec")
|
||
.px_2()
|
||
.py_1()
|
||
.rounded_md()
|
||
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.text_xs()
|
||
.font_weight(gpui::FontWeight::BOLD)
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(|this, _, _, cx| {
|
||
let next = this.cfg.controller_vibration.saturating_sub(10);
|
||
this.cfg.controller_vibration = next;
|
||
this.controls.set_controller_vibration_pct(next);
|
||
cx.notify();
|
||
}))
|
||
.child("−10%"),
|
||
)
|
||
.child(
|
||
div()
|
||
.px_2p5()
|
||
.py_1()
|
||
.rounded_md()
|
||
.bg(rgb(COLOR_BG_DARK))
|
||
.border_1()
|
||
.border_color(if self.cfg.controller_vibration > 0 {
|
||
rgb(COLOR_CYAN)
|
||
} else {
|
||
rgb(COLOR_BORDER_SUBTLE)
|
||
})
|
||
.text_xs()
|
||
.font_weight(gpui::FontWeight::BOLD)
|
||
.text_color(if self.cfg.controller_vibration > 0 {
|
||
rgb(COLOR_CYAN)
|
||
} else {
|
||
rgb(COLOR_TEXT_MUTED)
|
||
})
|
||
.child(if self.cfg.controller_vibration == 0 {
|
||
"0% (OFF)".to_string()
|
||
} else {
|
||
format!("{}%", self.cfg.controller_vibration)
|
||
}),
|
||
)
|
||
.child(
|
||
div()
|
||
.id("btn_sc_vib_inc")
|
||
.px_2()
|
||
.py_1()
|
||
.rounded_md()
|
||
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.text_xs()
|
||
.font_weight(gpui::FontWeight::BOLD)
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(|this, _, _, cx| {
|
||
let next = (this.cfg.controller_vibration + 10).min(100);
|
||
this.cfg.controller_vibration = next;
|
||
this.controls.set_controller_vibration_pct(next);
|
||
cx.notify();
|
||
}))
|
||
.child("+10%"),
|
||
)
|
||
.child(self.render_selectable_pill(
|
||
"pill_sc_vib_50",
|
||
"50%",
|
||
self.cfg.controller_vibration == 50,
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.controller_vibration = 50;
|
||
this.controls.set_controller_vibration_pct(50);
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(self.render_selectable_pill(
|
||
"pill_sc_vib_100",
|
||
"100%",
|
||
self.cfg.controller_vibration == 100,
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.controller_vibration = 100;
|
||
this.controls.set_controller_vibration_pct(100);
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(
|
||
div()
|
||
.id("btn_sc_vib_test")
|
||
.px_2p5()
|
||
.py_1()
|
||
.rounded_md()
|
||
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_ORANGE))
|
||
.text_xs()
|
||
.font_weight(gpui::FontWeight::SEMIBOLD)
|
||
.text_color(rgb(COLOR_ORANGE))
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(|this, _, _, cx| {
|
||
this.controls.trigger_controller_rumble_test();
|
||
cx.notify();
|
||
}))
|
||
.child("📳 Tester Vibrations"),
|
||
),
|
||
))
|
||
.child(self.render_setting_row(
|
||
"Réglage des Vitesses CRSF (G29 + Steam Controller)",
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.gap_2()
|
||
.p_2p5()
|
||
.rounded_md()
|
||
.bg(rgb(COLOR_BG_DARK))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.child(self.render_gear_stepper_row(
|
||
"av_min",
|
||
"Seuil Gaz Avant (Min)",
|
||
self.cfg.gaz_avant_min,
|
||
COLOR_TEXT_MAIN,
|
||
|cfg, d| cfg.gaz_avant_min = cfg.gaz_avant_min.saturating_add_signed(d),
|
||
cx,
|
||
))
|
||
.child(self.render_gear_stepper_row(
|
||
"g1",
|
||
"1ère Vitesse (Manœuvre)",
|
||
self.cfg.gear_1_max,
|
||
COLOR_CYAN,
|
||
|cfg, d| cfg.gear_1_max = cfg.gear_1_max.saturating_add_signed(d),
|
||
cx,
|
||
))
|
||
.child(self.render_gear_stepper_row(
|
||
"g2",
|
||
"2ème Vitesse (Normale)",
|
||
self.cfg.gear_2_max,
|
||
COLOR_GREEN,
|
||
|cfg, d| cfg.gear_2_max = cfg.gear_2_max.saturating_add_signed(d),
|
||
cx,
|
||
))
|
||
.child(self.render_gear_stepper_row(
|
||
"g3",
|
||
"3ème Vitesse (Rapide)",
|
||
self.cfg.gear_3_max,
|
||
COLOR_ORANGE,
|
||
|cfg, d| cfg.gear_3_max = cfg.gear_3_max.saturating_add_signed(d),
|
||
cx,
|
||
))
|
||
.child(self.render_gear_stepper_row(
|
||
"ar_min",
|
||
"Seuil Gaz Arrière (Min)",
|
||
self.cfg.gaz_arriere_min,
|
||
COLOR_TEXT_MAIN,
|
||
|cfg, d| cfg.gaz_arriere_min = cfg.gaz_arriere_min.saturating_add_signed(d),
|
||
cx,
|
||
))
|
||
.child(self.render_gear_stepper_row(
|
||
"ar_max",
|
||
"Plafond Marche Arrière (R)",
|
||
self.cfg.gear_reverse_max,
|
||
COLOR_RED,
|
||
|cfg, d| cfg.gear_reverse_max = cfg.gear_reverse_max.saturating_add_signed(d),
|
||
cx,
|
||
))
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.justify_end()
|
||
.pt_1()
|
||
.child(
|
||
div()
|
||
.id("btn_gears_reset_default")
|
||
.px_2p5()
|
||
.py_1()
|
||
.rounded_md()
|
||
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.text_xs()
|
||
.font_weight(gpui::FontWeight::SEMIBOLD)
|
||
.text_color(rgb(COLOR_TEXT_MAIN))
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(|this, _, _, cx| {
|
||
this.reset_gear_speed_limits();
|
||
cx.notify();
|
||
}))
|
||
.child("↺ Valeurs par défaut (1065 / 1100-1150-1220 / 905-800)"),
|
||
),
|
||
),
|
||
))
|
||
.child(self.render_controller_monitor(cx))
|
||
.child(
|
||
div()
|
||
.p_2()
|
||
.rounded_md()
|
||
.bg(rgb(COLOR_BG_DARK))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.text_xs()
|
||
.text_color(rgb(COLOR_TEXT_MUTED))
|
||
.child("Stick G : Direction | R2 : Gaz | L2 : Frein | RB/LB ou R4/L4 : Boîte R-N-1-2-3 | Menu : Armer (au N) | A : Tare | B : DVR | Y : OSD | X : Proj VR | D-Pad : Trim"),
|
||
),
|
||
))
|
||
// 3.3 Carte Projection VR Steam Frame & Optique
|
||
.child(self.render_settings_card(
|
||
"🥽 3. Projection VR & Correction Optique 140°",
|
||
COLOR_CYAN,
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.gap_3()
|
||
// Activation / Désactivation du mode VR OpenXR
|
||
.child(self.render_setting_row(
|
||
"Affichage Casque VR (OpenXR)",
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.gap_2()
|
||
.child(self.render_selectable_pill(
|
||
"pill_vr_on",
|
||
"🥽 Activé (Casque VR)",
|
||
!self.cfg.headless,
|
||
cx.listener(|this, _, _, cx| {
|
||
this.set_vr_enabled(true);
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(self.render_selectable_pill(
|
||
"pill_vr_off",
|
||
"🖥️ Désactivé (Mode Bureau léger)",
|
||
self.cfg.headless,
|
||
cx.listener(|this, _, _, cx| {
|
||
this.set_vr_enabled(false);
|
||
cx.notify();
|
||
}),
|
||
)),
|
||
))
|
||
// Mode de projection
|
||
.child(self.render_setting_row(
|
||
"Mode de Projection VR",
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.gap_2()
|
||
.child(self.render_selectable_pill(
|
||
"pill_proj_dome",
|
||
"Dôme 140° (Equirect2)",
|
||
self.cfg.projection_mode.eq_ignore_ascii_case("dome"),
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.projection_mode = "dome".into();
|
||
this.controls.update_optical_params(LiveOpticalParams {
|
||
camera_fov_deg: this.cfg.camera_fov_deg,
|
||
lens_k1: this.cfg.lens_k1,
|
||
lens_k2: this.cfg.lens_k2,
|
||
screen_distance_m: this.cfg.screen_distance_m,
|
||
screen_width_m: this.cfg.screen_width_m,
|
||
projection_mode: ProjectionMode::Dome140,
|
||
});
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(self.render_selectable_pill(
|
||
"pill_proj_cyl",
|
||
"Cylindre 140°",
|
||
self.cfg.projection_mode.eq_ignore_ascii_case("cylinder"),
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.projection_mode = "cylinder".into();
|
||
this.controls.update_optical_params(LiveOpticalParams {
|
||
camera_fov_deg: this.cfg.camera_fov_deg,
|
||
lens_k1: this.cfg.lens_k1,
|
||
lens_k2: this.cfg.lens_k2,
|
||
screen_distance_m: this.cfg.screen_distance_m,
|
||
screen_width_m: this.cfg.screen_width_m,
|
||
projection_mode: ProjectionMode::Cylinder140,
|
||
});
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(self.render_selectable_pill(
|
||
"pill_proj_flat",
|
||
"Quad Plat",
|
||
self.cfg.projection_mode.eq_ignore_ascii_case("flat"),
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.projection_mode = "flat".into();
|
||
this.controls.update_optical_params(LiveOpticalParams {
|
||
camera_fov_deg: this.cfg.camera_fov_deg,
|
||
lens_k1: this.cfg.lens_k1,
|
||
lens_k2: this.cfg.lens_k2,
|
||
screen_distance_m: this.cfg.screen_distance_m,
|
||
screen_width_m: this.cfg.screen_width_m,
|
||
projection_mode: ProjectionMode::FlatQuad,
|
||
});
|
||
cx.notify();
|
||
}),
|
||
)),
|
||
))
|
||
// Champ de vision, Lentille k1/k2 et Distance virtuelle (réglables à chaud en VR)
|
||
.child(self.render_setting_row(
|
||
"Optique & Écran VR (Réglage à chaud)",
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.gap_2()
|
||
.p_2p5()
|
||
.rounded_md()
|
||
.bg(rgb(COLOR_BG_DARK))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.child(self.render_optical_stepper_row(
|
||
"opt_fov",
|
||
"FOV Caméra",
|
||
format!("{:.0}°", self.cfg.camera_fov_deg),
|
||
|cfg, step| {
|
||
cfg.camera_fov_deg =
|
||
(cfg.camera_fov_deg + step * 5.0).clamp(70.0, 180.0);
|
||
},
|
||
cx,
|
||
))
|
||
.child(self.render_optical_stepper_row(
|
||
"opt_k1",
|
||
"Distorsion k1",
|
||
format!("{:+.2}", self.cfg.lens_k1),
|
||
|cfg, step| {
|
||
cfg.lens_k1 = (((cfg.lens_k1 + step * 0.02) * 100.0)
|
||
.round()
|
||
/ 100.0)
|
||
.clamp(-0.50, 0.50);
|
||
},
|
||
cx,
|
||
))
|
||
.child(self.render_optical_stepper_row(
|
||
"opt_k2",
|
||
"Distorsion k2",
|
||
format!("{:+.2}", self.cfg.lens_k2),
|
||
|cfg, step| {
|
||
cfg.lens_k2 = (((cfg.lens_k2 + step * 0.01) * 100.0)
|
||
.round()
|
||
/ 100.0)
|
||
.clamp(-0.25, 0.25);
|
||
},
|
||
cx,
|
||
))
|
||
.child(self.render_optical_stepper_row(
|
||
"opt_dist",
|
||
"Distance Écran",
|
||
format!("{:.1} m", self.cfg.screen_distance_m),
|
||
|cfg, step| {
|
||
cfg.screen_distance_m = (((cfg.screen_distance_m
|
||
+ step * 0.2)
|
||
* 10.0)
|
||
.round()
|
||
/ 10.0)
|
||
.clamp(0.8, 4.0);
|
||
},
|
||
cx,
|
||
)),
|
||
)),
|
||
))
|
||
// 3.4 Carte Télémétrie OSD & MAVLink
|
||
.child(self.render_settings_card(
|
||
"📊 4. Télémétrie OSD & MAVLink",
|
||
COLOR_GREEN,
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.gap_3()
|
||
.child(self.render_setting_row(
|
||
"État Télémétrie & OSD",
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.gap_2()
|
||
.child(self.render_selectable_pill(
|
||
"pill_telem_on",
|
||
"Activé (ON)",
|
||
self.cfg.telemetry_enabled,
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.telemetry_enabled = true;
|
||
this.controls.set_telemetry_enabled(true);
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(self.render_selectable_pill(
|
||
"pill_telem_off",
|
||
"Désactivé (OFF)",
|
||
!self.cfg.telemetry_enabled,
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.telemetry_enabled = false;
|
||
this.controls.set_telemetry_enabled(false);
|
||
cx.notify();
|
||
}),
|
||
)),
|
||
))
|
||
.child(self.render_setting_row(
|
||
"Port UDP Écoute MAVLink",
|
||
div()
|
||
.text_xs()
|
||
.text_color(rgb(COLOR_TEXT_MAIN))
|
||
.child(format!("0.0.0.0:{}", self.cfg.telemetry_udp_port)),
|
||
)),
|
||
))
|
||
// 3.5 Carte Enregistreur Vidéo DVR
|
||
.child(self.render_settings_card(
|
||
"🎥 5. Enregistreur Vidéo DVR",
|
||
COLOR_RED,
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.gap_3()
|
||
// Format de conteneur
|
||
.child(self.render_setting_row(
|
||
"Format Conteneur",
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.gap_2()
|
||
.child(self.render_selectable_pill(
|
||
"pill_dvr_mkv",
|
||
"MKV (Résistant)",
|
||
self.cfg.dvr_format.eq_ignore_ascii_case("mkv"),
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.dvr_format = "mkv".into();
|
||
this.controls.update_dvr_config(
|
||
this.cfg.dvr_dir.clone(),
|
||
DvrContainer::Mkv,
|
||
DvrMode::from_str(&this.cfg.dvr_mode),
|
||
);
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(self.render_selectable_pill(
|
||
"pill_dvr_mp4",
|
||
"MP4 (Standard)",
|
||
self.cfg.dvr_format.eq_ignore_ascii_case("mp4"),
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.dvr_format = "mp4".into();
|
||
this.controls.update_dvr_config(
|
||
this.cfg.dvr_dir.clone(),
|
||
DvrContainer::Mp4,
|
||
DvrMode::from_str(&this.cfg.dvr_mode),
|
||
);
|
||
cx.notify();
|
||
}),
|
||
)),
|
||
))
|
||
// Mode d'enregistrement
|
||
.child(self.render_setting_row(
|
||
"Mode Enregistrement",
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.gap_2()
|
||
.child(self.render_selectable_pill(
|
||
"pill_dvr_copy",
|
||
"Direct 0% CPU",
|
||
self.cfg.dvr_mode.eq_ignore_ascii_case("copy"),
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.dvr_mode = "copy".into();
|
||
this.controls.update_dvr_config(
|
||
this.cfg.dvr_dir.clone(),
|
||
DvrContainer::from_str(&this.cfg.dvr_format),
|
||
DvrMode::StreamCopy,
|
||
);
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(self.render_selectable_pill(
|
||
"pill_dvr_osd",
|
||
"Avec OSD incrusté",
|
||
self.cfg.dvr_mode.eq_ignore_ascii_case("composited") || self.cfg.dvr_mode.eq_ignore_ascii_case("osd"),
|
||
cx.listener(|this, _, _, cx| {
|
||
this.cfg.dvr_mode = "composited".into();
|
||
this.controls.update_dvr_config(
|
||
this.cfg.dvr_dir.clone(),
|
||
DvrContainer::from_str(&this.cfg.dvr_format),
|
||
DvrMode::CompositedOsd,
|
||
);
|
||
cx.notify();
|
||
}),
|
||
)),
|
||
))
|
||
// Statut & Action
|
||
.child(self.render_setting_row(
|
||
"Statut DVR",
|
||
div()
|
||
.text_xs()
|
||
.text_color(if self.dvr_recording { rgb(COLOR_RED) } else { rgb(COLOR_TEXT_MUTED) })
|
||
.child(if self.dvr_recording {
|
||
let mins = self.dvr_elapsed_secs / 60;
|
||
let secs = self.dvr_elapsed_secs % 60;
|
||
let mb = self.dvr_file_size_bytes as f64 / (1024.0 * 1024.0);
|
||
format!("● ACTIF : {:02}:{:02} ({} frames, {:.1} Mo)", mins, secs, self.dvr_frames_recorded, mb)
|
||
} else {
|
||
"Inactif (Prêt à enregistrer)".to_string()
|
||
}),
|
||
))
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.pt_1()
|
||
.child(
|
||
div()
|
||
.id("btn_toggle_dvr_card")
|
||
.flex_1()
|
||
.py_1p5()
|
||
.bg(if self.dvr_recording { rgb(COLOR_RED) } else { rgb(COLOR_SURFACE_CARD) })
|
||
.border_1()
|
||
.border_color(if self.dvr_recording { rgb(COLOR_RED) } else { rgb(COLOR_BORDER_SUBTLE) })
|
||
.rounded_md()
|
||
.text_xs()
|
||
.font_weight(gpui::FontWeight::BOLD)
|
||
.text_color(if self.dvr_recording { rgb(0xffffff) } else { rgb(COLOR_TEXT_MAIN) })
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(|this, _, _, cx| {
|
||
if this.dvr_recording {
|
||
this.controls.stop_dvr();
|
||
} else {
|
||
this.controls.start_dvr();
|
||
}
|
||
cx.notify();
|
||
}))
|
||
.child(if self.dvr_recording {
|
||
"⏹ Arrêter l'enregistrement DVR"
|
||
} else {
|
||
"🔴 Démarrer l'enregistrement DVR"
|
||
}),
|
||
),
|
||
),
|
||
)),
|
||
)
|
||
}
|
||
|
||
fn render_settings_card(&self, title: &str, accent_color: u32, content: impl IntoElement) -> impl IntoElement {
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.min_w(px(300.0))
|
||
.flex_1()
|
||
.overflow_hidden()
|
||
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.rounded_xl()
|
||
.p_4()
|
||
.gap_3()
|
||
.child(
|
||
div()
|
||
.text_sm()
|
||
.font_weight(gpui::FontWeight::BOLD)
|
||
.text_color(rgb(accent_color))
|
||
.child(title.to_string()),
|
||
)
|
||
.child(content)
|
||
}
|
||
|
||
fn render_mock_axis_row(
|
||
&self,
|
||
axis: &'static str,
|
||
label: &str,
|
||
value_deg: f32,
|
||
max_deg: f32,
|
||
cx: &mut Context<Self>,
|
||
) -> impl IntoElement {
|
||
let crsf = NomadHeadTracker::deg_to_crsf(value_deg, max_deg);
|
||
let pwm = NomadHeadTracker::crsf_to_pwm_us(crsf);
|
||
let step_btn = |suffix: &'static str, text: &'static str, delta: f32, reset: bool| {
|
||
let id = match (axis, suffix) {
|
||
("pan", "m10") => "mock_pan_m10",
|
||
("pan", "m1") => "mock_pan_m1",
|
||
("pan", "0") => "mock_pan_0",
|
||
("pan", "p1") => "mock_pan_p1",
|
||
("pan", "p10") => "mock_pan_p10",
|
||
("tilt", "m10") => "mock_tilt_m10",
|
||
("tilt", "m1") => "mock_tilt_m1",
|
||
("tilt", "0") => "mock_tilt_0",
|
||
("tilt", "p1") => "mock_tilt_p1",
|
||
("tilt", "p10") => "mock_tilt_p10",
|
||
("roll", "m10") => "mock_roll_m10",
|
||
("roll", "m1") => "mock_roll_m1",
|
||
("roll", "0") => "mock_roll_0",
|
||
("roll", "p1") => "mock_roll_p1",
|
||
_ => "mock_roll_p10",
|
||
};
|
||
div()
|
||
.id(id)
|
||
.px_2()
|
||
.py_0p5()
|
||
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.rounded_md()
|
||
.text_xs()
|
||
.text_color(rgb(COLOR_TEXT_MAIN))
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(move |this, _, _, cx| {
|
||
let (target, max_val) = match axis {
|
||
"pan" => (&mut this.mock_pan_deg, this.cfg.max_pan_deg),
|
||
"tilt" => (&mut this.mock_tilt_deg, this.cfg.max_tilt_deg),
|
||
_ => (&mut this.mock_roll_deg, this.cfg.max_roll_deg),
|
||
};
|
||
if reset {
|
||
*target = 0.0;
|
||
} else {
|
||
*target = (*target + delta).clamp(-max_val, max_val);
|
||
}
|
||
cx.notify();
|
||
}))
|
||
.child(text)
|
||
};
|
||
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.items_center()
|
||
.justify_between()
|
||
.gap_2()
|
||
.child(
|
||
div()
|
||
.text_xs()
|
||
.text_color(rgb(COLOR_TEXT_MAIN))
|
||
.child(format!(
|
||
"{} : {:+.0}° (CRSF {} / {}µs)",
|
||
label, value_deg, crsf, pwm
|
||
)),
|
||
)
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.gap_1()
|
||
.child(step_btn("m10", "-10°", -10.0, false))
|
||
.child(step_btn("m1", "-1°", -1.0, false))
|
||
.child(step_btn("0", "0°", 0.0, true))
|
||
.child(step_btn("p1", "+1°", 1.0, false))
|
||
.child(step_btn("p10", "+10°", 10.0, false)),
|
||
)
|
||
}
|
||
|
||
fn apply_gear_speed_limits(&mut self) {
|
||
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);
|
||
}
|
||
|
||
fn reset_gear_speed_limits(&mut self) {
|
||
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;
|
||
self.controls.set_gear_speed_limits(def);
|
||
}
|
||
|
||
fn sync_optical_params(&self) {
|
||
self.controls.update_optical_params(LiveOpticalParams {
|
||
projection_mode: ProjectionMode::from_str(&self.cfg.projection_mode),
|
||
camera_fov_deg: self.cfg.camera_fov_deg,
|
||
lens_k1: self.cfg.lens_k1,
|
||
lens_k2: self.cfg.lens_k2,
|
||
screen_distance_m: self.cfg.screen_distance_m,
|
||
screen_width_m: self.cfg.screen_width_m,
|
||
});
|
||
}
|
||
|
||
fn render_optical_stepper_row(
|
||
&self,
|
||
id_prefix: &'static str,
|
||
label: &'static str,
|
||
value_text: String,
|
||
mutator: fn(&mut AppConfig, f32),
|
||
cx: &mut Context<Self>,
|
||
) -> impl IntoElement {
|
||
let step_btn = |suffix: &'static str, txt: &'static str, step: f32| {
|
||
let btn_id = gpui::SharedString::from(format!("btn_opt_{}_{}", id_prefix, suffix));
|
||
div()
|
||
.id(btn_id)
|
||
.px_2p5()
|
||
.py_1()
|
||
.rounded_md()
|
||
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.text_xs()
|
||
.font_weight(gpui::FontWeight::BOLD)
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(move |this, _, _, cx| {
|
||
mutator(&mut this.cfg, step);
|
||
this.sync_optical_params();
|
||
cx.notify();
|
||
}))
|
||
.child(txt)
|
||
};
|
||
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.items_center()
|
||
.justify_between()
|
||
.gap_2()
|
||
.child(
|
||
div()
|
||
.text_xs()
|
||
.text_color(rgb(COLOR_TEXT_MAIN))
|
||
.child(label),
|
||
)
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.items_center()
|
||
.gap_1p5()
|
||
.child(step_btn("m2", "−−", -2.0))
|
||
.child(step_btn("m1", "−", -1.0))
|
||
.child(
|
||
div()
|
||
.w(px(64.0))
|
||
.py_0p5()
|
||
.rounded_md()
|
||
.bg(rgb(COLOR_SURFACE_CARD))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_CYAN))
|
||
.text_xs()
|
||
.font_weight(gpui::FontWeight::BOLD)
|
||
.text_color(rgb(COLOR_CYAN))
|
||
.flex()
|
||
.justify_center()
|
||
.child(value_text),
|
||
)
|
||
.child(step_btn("p1", "+", 1.0))
|
||
.child(step_btn("p2", "++", 2.0)),
|
||
)
|
||
}
|
||
|
||
fn render_gear_stepper_row(
|
||
&self,
|
||
id_prefix: &'static str,
|
||
label: &'static str,
|
||
value: u16,
|
||
accent_color: u32,
|
||
mutator: fn(&mut AppConfig, i16),
|
||
cx: &mut Context<Self>,
|
||
) -> impl IntoElement {
|
||
let step_btn = |suffix: &'static str, txt: &'static str, delta: i16| {
|
||
let btn_id = gpui::SharedString::from(format!("btn_gear_{}_{}", id_prefix, suffix));
|
||
div()
|
||
.id(btn_id)
|
||
.px_2()
|
||
.py_0p5()
|
||
.rounded_md()
|
||
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.text_xs()
|
||
.font_weight(gpui::FontWeight::BOLD)
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(move |this, _, _, cx| {
|
||
mutator(&mut this.cfg, delta);
|
||
this.apply_gear_speed_limits();
|
||
cx.notify();
|
||
}))
|
||
.child(txt)
|
||
};
|
||
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.items_center()
|
||
.justify_between()
|
||
.gap_2()
|
||
.child(
|
||
div()
|
||
.text_xs()
|
||
.text_color(rgb(COLOR_TEXT_MAIN))
|
||
.child(label),
|
||
)
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.items_center()
|
||
.gap_1p5()
|
||
.child(step_btn("m10", "−10", -10))
|
||
.child(step_btn("m5", "−5", -5))
|
||
.child(
|
||
div()
|
||
.w(px(56.0))
|
||
.py_0p5()
|
||
.rounded_md()
|
||
.bg(rgb(COLOR_SURFACE_CARD))
|
||
.border_1()
|
||
.border_color(rgb(accent_color))
|
||
.text_xs()
|
||
.font_weight(gpui::FontWeight::BOLD)
|
||
.text_color(rgb(accent_color))
|
||
.flex()
|
||
.justify_center()
|
||
.child(format!("{}", value)),
|
||
)
|
||
.child(step_btn("p5", "+5", 5))
|
||
.child(step_btn("p10", "+10", 10)),
|
||
)
|
||
}
|
||
|
||
fn render_setting_row(&self, label: &str, control: impl IntoElement) -> impl IntoElement {
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.gap_1p5()
|
||
.child(
|
||
div()
|
||
.text_xs()
|
||
.font_weight(gpui::FontWeight::SEMIBOLD)
|
||
.text_color(rgb(COLOR_TEXT_MUTED))
|
||
.child(label.to_string()),
|
||
)
|
||
.child(control)
|
||
}
|
||
|
||
fn render_selectable_pill(
|
||
&self,
|
||
id: &'static str,
|
||
label: &str,
|
||
is_selected: bool,
|
||
on_click: impl Fn(&gpui::ClickEvent, &mut Window, &mut App) + 'static,
|
||
) -> impl IntoElement {
|
||
div()
|
||
.id(id)
|
||
.px_3()
|
||
.py_1()
|
||
.bg(if is_selected {
|
||
rgb(0x132738)
|
||
} else {
|
||
rgb(COLOR_SURFACE_CARD)
|
||
})
|
||
.border_1()
|
||
.border_color(if is_selected {
|
||
rgb(COLOR_CYAN)
|
||
} else {
|
||
rgb(COLOR_BORDER_SUBTLE)
|
||
})
|
||
.rounded_md()
|
||
.text_xs()
|
||
.font_weight(if is_selected {
|
||
gpui::FontWeight::BOLD
|
||
} else {
|
||
gpui::FontWeight::NORMAL
|
||
})
|
||
.text_color(if is_selected {
|
||
rgb(COLOR_CYAN)
|
||
} else {
|
||
rgb(COLOR_TEXT_MUTED)
|
||
})
|
||
.cursor_pointer()
|
||
.on_click(on_click)
|
||
.child(label.to_string())
|
||
}
|
||
|
||
fn render_channel_button(&self, ch: u16, freq_mhz: u32, cx: &mut Context<Self>) -> impl IntoElement {
|
||
let is_selected = self.cfg.wifi_channel == ch;
|
||
let btn_id = match ch {
|
||
149 => "btn_ch_149",
|
||
153 => "btn_ch_153",
|
||
157 => "btn_ch_157",
|
||
_ => "btn_ch_161",
|
||
};
|
||
div()
|
||
.id(btn_id)
|
||
.flex_1()
|
||
.px_2()
|
||
.py_1()
|
||
.bg(if is_selected {
|
||
rgb(0x28190d)
|
||
} else {
|
||
rgb(COLOR_SURFACE_CARD)
|
||
})
|
||
.border_1()
|
||
.border_color(if is_selected {
|
||
rgb(COLOR_ORANGE)
|
||
} else {
|
||
rgb(COLOR_BORDER_SUBTLE)
|
||
})
|
||
.rounded_md()
|
||
.text_xs()
|
||
.text_center()
|
||
.font_weight(if is_selected {
|
||
gpui::FontWeight::BOLD
|
||
} else {
|
||
gpui::FontWeight::NORMAL
|
||
})
|
||
.text_color(if is_selected {
|
||
rgb(COLOR_ORANGE)
|
||
} else {
|
||
rgb(COLOR_TEXT_MUTED)
|
||
})
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(move |this, _, _, cx| {
|
||
this.cfg.wifi_channel = ch;
|
||
cx.notify();
|
||
}))
|
||
.child(format!("CH {} ({}MHz)", ch, freq_mhz))
|
||
}
|
||
|
||
// -------------------------------------------------------------------------
|
||
// 4. Vue Télémétrie Détaillée & Jauges Vol
|
||
// -------------------------------------------------------------------------
|
||
fn render_telemetry_view(&self) -> impl IntoElement {
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.size_full()
|
||
.min_h_0()
|
||
.min_w_0()
|
||
.id("telemetry_view_scroll")
|
||
.overflow_y_scroll()
|
||
.bg(rgb(COLOR_SURFACE_CARD))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.rounded_xl()
|
||
.p_4()
|
||
.gap_4()
|
||
// Bandeau supérieur des données batterie et signal
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.gap_3()
|
||
.child(self.render_stat_box(
|
||
"🔋 BATTERIE DRONE",
|
||
&format!("{:.2} V", self.latest_telem.battery_voltage_v),
|
||
&format!("{:.1} A débit", self.latest_telem.battery_current_a),
|
||
COLOR_GREEN,
|
||
))
|
||
.child(self.render_stat_box(
|
||
"📶 QUALITÉ DU LIEN",
|
||
&format!("{} %", self.latest_telem.link_quality_pct),
|
||
&format!("{} dBm (RSSI)", self.latest_telem.rssi_dbm),
|
||
COLOR_CYAN,
|
||
))
|
||
.child(self.render_stat_box(
|
||
"🚀 VITESSE SOL",
|
||
&format!("{:.1} km/h", self.latest_telem.groundspeed_ms * 3.6),
|
||
&format!("Gaz : {}%", self.latest_telem.throttle_pct),
|
||
COLOR_ORANGE,
|
||
))
|
||
.child(self.render_stat_box(
|
||
"⛰️ ALTITUDE & CAP",
|
||
&format!("{:.1} m", self.latest_telem.altitude_m),
|
||
&format!("Cap : {:.0}°", self.latest_telem.drone_heading_deg),
|
||
COLOR_CYAN,
|
||
))
|
||
.child(if self.active_control_source == ControlSource::SteamController {
|
||
self.render_stat_box(
|
||
"🎮 STEAM CONTROLLER",
|
||
&if !self.latest_controller.connected {
|
||
"NON DÉTECTÉ".to_string()
|
||
} else {
|
||
format!(
|
||
"[{}] {}",
|
||
self.latest_controller.gear_label(),
|
||
if self.latest_controller.armed {
|
||
"ARMED"
|
||
} else {
|
||
"SAFE"
|
||
}
|
||
)
|
||
},
|
||
&format!(
|
||
"Gaz {}% | Frn {}% | Dir {:+.0}%",
|
||
self.latest_controller.throttle_pct,
|
||
self.latest_controller.brake_pct,
|
||
self.latest_controller.steering_norm * 100.0
|
||
),
|
||
if !self.latest_controller.connected {
|
||
COLOR_TEXT_MUTED
|
||
} else if self.latest_controller.armed {
|
||
COLOR_GREEN
|
||
} else {
|
||
COLOR_ORANGE
|
||
},
|
||
)
|
||
} else {
|
||
self.render_stat_box(
|
||
"🏎️ VOLANT G29",
|
||
&if !self.latest_g29.is_live() {
|
||
"HORS LIGNE".to_string()
|
||
} else {
|
||
format!(
|
||
"[{}] {}",
|
||
self.latest_g29.gear_label(),
|
||
if self.latest_g29.armed { "ARMED" } else { "SAFE" }
|
||
)
|
||
},
|
||
&format!(
|
||
"Gaz {}% | Frn {}% | FFB {}%",
|
||
self.latest_g29.throttle_pct,
|
||
self.latest_g29.brake_pct,
|
||
self.latest_g29.ffb_pct
|
||
),
|
||
if !self.latest_g29.is_live() {
|
||
COLOR_TEXT_MUTED
|
||
} else if self.latest_g29.armed {
|
||
COLOR_GREEN
|
||
} else {
|
||
COLOR_ORANGE
|
||
},
|
||
)
|
||
}),
|
||
)
|
||
// Double Panneau : Suivi de Tête & Radio
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.gap_4()
|
||
// Panneau Jauges Suivi de Tête
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.flex_1()
|
||
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.rounded_xl()
|
||
.p_4()
|
||
.gap_3()
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.justify_between()
|
||
.items_center()
|
||
.child(
|
||
div()
|
||
.text_sm()
|
||
.font_weight(gpui::FontWeight::BOLD)
|
||
.text_color(rgb(COLOR_ORANGE))
|
||
.child("🎯 Canaux CRSF Suivi de Tête (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 / Direction)",
|
||
self.latest_pose.pan_deg,
|
||
self.latest_pose.pan_crsf,
|
||
self.cfg.max_pan_deg,
|
||
))
|
||
.child(self.render_crsf_gauge(
|
||
"TILT (Tangage / Élévation)",
|
||
self.latest_pose.tilt_deg,
|
||
self.latest_pose.tilt_crsf,
|
||
self.cfg.max_tilt_deg,
|
||
))
|
||
.child(self.render_crsf_gauge(
|
||
"ROLL (Roulis / Inclinaison)",
|
||
self.latest_pose.roll_deg,
|
||
self.latest_pose.roll_crsf,
|
||
self.cfg.max_roll_deg,
|
||
)),
|
||
)
|
||
// Panneau État Liaison Nomad
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.w(px(340.0))
|
||
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.rounded_xl()
|
||
.p_4()
|
||
.gap_3()
|
||
.child(
|
||
div()
|
||
.text_sm()
|
||
.font_weight(gpui::FontWeight::BOLD)
|
||
.text_color(rgb(COLOR_CYAN))
|
||
.child("📡 État RadioMaster Nomad"),
|
||
)
|
||
.child(self.render_stat_row("Statut Réseau :", &format!("{:?}", self.nomad_status)))
|
||
.child(self.render_stat_row("Cible UDP :", &format!("{}:{}", self.cfg.nomad_ip, self.cfg.nomad_port)))
|
||
.child(self.render_stat_row("Protocole :", &self.cfg.ht_protocol.to_uppercase()))
|
||
.child(self.render_stat_row("Fréquence d'Émission :", "60 Hz (Sync OpenXR)"))
|
||
.child(self.render_stat_row("Dernière émission :", if self.latest_pose.last_send_ok { "Succès (OK)" } else { "En attente" })),
|
||
),
|
||
)
|
||
}
|
||
|
||
fn render_stat_box(&self, title: &str, value: &str, sub: &str, color: u32) -> impl IntoElement {
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.flex_1()
|
||
.min_w(px(200.0))
|
||
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.rounded_xl()
|
||
.p_3()
|
||
.gap_1()
|
||
.child(
|
||
div()
|
||
.text_xs()
|
||
.font_weight(gpui::FontWeight::SEMIBOLD)
|
||
.text_color(rgb(COLOR_TEXT_MUTED))
|
||
.child(title.to_string()),
|
||
)
|
||
.child(
|
||
div()
|
||
.text_xl()
|
||
.font_weight(gpui::FontWeight::BOLD)
|
||
.text_color(rgb(color))
|
||
.child(value.to_string()),
|
||
)
|
||
.child(
|
||
div()
|
||
.text_xs()
|
||
.text_color(rgb(COLOR_TEXT_MUTED))
|
||
.child(sub.to_string()),
|
||
)
|
||
}
|
||
|
||
fn render_stat_row(&self, label: &str, val: &str) -> impl IntoElement {
|
||
div()
|
||
.flex()
|
||
.justify_between()
|
||
.text_xs()
|
||
.child(
|
||
div()
|
||
.text_color(rgb(COLOR_TEXT_MUTED))
|
||
.child(label.to_string()),
|
||
)
|
||
.child(
|
||
div()
|
||
.font_weight(gpui::FontWeight::SEMIBOLD)
|
||
.text_color(rgb(COLOR_TEXT_MAIN))
|
||
.child(val.to_string()),
|
||
)
|
||
}
|
||
|
||
// -------------------------------------------------------------------------
|
||
// 5. Vue Console de Logs Complète
|
||
// -------------------------------------------------------------------------
|
||
fn render_logs_view(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.size_full()
|
||
.bg(rgb(COLOR_SURFACE_CARD))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.rounded_xl()
|
||
.p_4()
|
||
.gap_3()
|
||
.overflow_hidden()
|
||
// Barre d'outils
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.justify_between()
|
||
.items_center()
|
||
.border_b_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.pb_3()
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.items_center()
|
||
.gap_3()
|
||
.child(
|
||
div()
|
||
.text_sm()
|
||
.font_weight(gpui::FontWeight::BOLD)
|
||
.text_color(rgb(COLOR_CYAN))
|
||
.child("📜 Console de Diagnostic et Journal Système"),
|
||
)
|
||
.child(
|
||
div()
|
||
.text_xs()
|
||
.text_color(if self.log_err_count > 0 {
|
||
rgb(COLOR_RED)
|
||
} else {
|
||
rgb(COLOR_TEXT_MUTED)
|
||
})
|
||
.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_tab")
|
||
.px_3()
|
||
.py_1()
|
||
.bg(if self.log_filter == LogFilter::All {
|
||
rgb(0x1e3a5f)
|
||
} else {
|
||
rgb(COLOR_SURFACE_ELEVATED)
|
||
})
|
||
.border_1()
|
||
.border_color(if self.log_filter == LogFilter::All {
|
||
rgb(COLOR_CYAN)
|
||
} else {
|
||
rgb(COLOR_BORDER_SUBTLE)
|
||
})
|
||
.rounded_md()
|
||
.text_xs()
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(|this, _, _, cx| {
|
||
this.log_filter = LogFilter::All;
|
||
cx.notify();
|
||
}))
|
||
.child("Tous les logs"),
|
||
)
|
||
.child(
|
||
div()
|
||
.id("filter_warn_tab")
|
||
.px_3()
|
||
.py_1()
|
||
.bg(if self.log_filter == LogFilter::WarningsAndErrors {
|
||
rgb(0x1e3a5f)
|
||
} else {
|
||
rgb(COLOR_SURFACE_ELEVATED)
|
||
})
|
||
.border_1()
|
||
.border_color(if self.log_filter == LogFilter::WarningsAndErrors {
|
||
rgb(COLOR_ORANGE)
|
||
} else {
|
||
rgb(COLOR_BORDER_SUBTLE)
|
||
})
|
||
.rounded_md()
|
||
.text_xs()
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(|this, _, _, cx| {
|
||
this.log_filter = LogFilter::WarningsAndErrors;
|
||
cx.notify();
|
||
}))
|
||
.child("Warn / Erreurs"),
|
||
)
|
||
.child(
|
||
div()
|
||
.id("filter_err_tab")
|
||
.px_3()
|
||
.py_1()
|
||
.bg(if self.log_filter == LogFilter::ErrorsOnly {
|
||
rgb(0x1e3a5f)
|
||
} else {
|
||
rgb(COLOR_SURFACE_ELEVATED)
|
||
})
|
||
.border_1()
|
||
.border_color(if self.log_filter == LogFilter::ErrorsOnly {
|
||
rgb(COLOR_RED)
|
||
} else {
|
||
rgb(COLOR_BORDER_SUBTLE)
|
||
})
|
||
.rounded_md()
|
||
.text_xs()
|
||
.cursor_pointer()
|
||
.on_click(cx.listener(|this, _, _, cx| {
|
||
this.log_filter = LogFilter::ErrorsOnly;
|
||
cx.notify();
|
||
}))
|
||
.child("Erreurs seules"),
|
||
)
|
||
.child(
|
||
div()
|
||
.id("btn_clear_logs_tab")
|
||
.px_3()
|
||
.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, _, _, 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"),
|
||
),
|
||
),
|
||
)
|
||
// Liste scrollable des messages
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.flex_1()
|
||
.min_h_0()
|
||
.min_w_0()
|
||
.id("logs_scroll_tab")
|
||
.overflow_y_scroll()
|
||
.px_2()
|
||
.gap_1()
|
||
.children(
|
||
self.log_entries
|
||
.iter()
|
||
.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),
|
||
})
|
||
.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!("[{:<5}]", 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_monitor_progress_bar(
|
||
&self,
|
||
label: &str,
|
||
pct: u8,
|
||
crsf: u16,
|
||
bar_color: u32,
|
||
) -> impl IntoElement {
|
||
let frac = (pct as f32 / 100.0).clamp(0.0, 1.0);
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.gap_0p5()
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.justify_between()
|
||
.text_xs()
|
||
.child(div().text_color(rgb(COLOR_TEXT_MAIN)).child(label.to_string()))
|
||
.child(
|
||
div()
|
||
.text_color(rgb(COLOR_TEXT_MUTED))
|
||
.child(format!("{:3}% | CRSF {}", pct, crsf)),
|
||
),
|
||
)
|
||
.child(
|
||
div()
|
||
.w_full()
|
||
.h(px(7.0))
|
||
.bg(rgb(COLOR_SURFACE_CARD))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.rounded_full()
|
||
.overflow_hidden()
|
||
.child(
|
||
div()
|
||
.h_full()
|
||
.w(DefiniteLength::Fraction(frac))
|
||
.bg(rgb(bar_color)),
|
||
),
|
||
)
|
||
}
|
||
|
||
fn render_monitor_bipolar_bar(
|
||
&self,
|
||
label: &str,
|
||
pct_signed: f32,
|
||
crsf: u16,
|
||
bar_color: u32,
|
||
) -> impl IntoElement {
|
||
let clamped = pct_signed.clamp(-100.0, 100.0);
|
||
let left_frac = if clamped < 0.0 {
|
||
(-clamped / 100.0).clamp(0.0, 1.0)
|
||
} else {
|
||
0.0
|
||
};
|
||
let right_frac = if clamped > 0.0 {
|
||
(clamped / 100.0).clamp(0.0, 1.0)
|
||
} else {
|
||
0.0
|
||
};
|
||
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.gap_0p5()
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.justify_between()
|
||
.text_xs()
|
||
.child(div().text_color(rgb(COLOR_TEXT_MAIN)).child(label.to_string()))
|
||
.child(
|
||
div()
|
||
.text_color(rgb(COLOR_TEXT_MUTED))
|
||
.child(format!("{:+.0}% | CRSF {}", clamped, crsf)),
|
||
),
|
||
)
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.items_center()
|
||
.w_full()
|
||
.h(px(8.0))
|
||
.bg(rgb(COLOR_SURFACE_CARD))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.rounded_full()
|
||
.overflow_hidden()
|
||
// Moitié gauche (remplissage depuis le centre vers la gauche)
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.justify_end()
|
||
.w(DefiniteLength::Fraction(0.5))
|
||
.h_full()
|
||
.child(
|
||
div()
|
||
.h_full()
|
||
.w(DefiniteLength::Fraction(left_frac))
|
||
.bg(rgb(bar_color)),
|
||
),
|
||
)
|
||
// Repère central
|
||
.child(div().w(px(2.0)).h_full().bg(rgb(COLOR_TEXT_MUTED)))
|
||
// Moitié droite (remplissage depuis le centre vers la droite)
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.justify_start()
|
||
.w(DefiniteLength::Fraction(0.5))
|
||
.h_full()
|
||
.child(
|
||
div()
|
||
.h_full()
|
||
.w(DefiniteLength::Fraction(right_frac))
|
||
.bg(rgb(bar_color)),
|
||
),
|
||
),
|
||
)
|
||
}
|
||
|
||
fn render_controller_monitor(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
||
let viewed_source = self.monitor_source_override.unwrap_or_else(|| {
|
||
if self.active_control_source == ControlSource::G29
|
||
&& !self.latest_g29.is_live()
|
||
&& self.latest_controller.connected
|
||
{
|
||
ControlSource::SteamController
|
||
} else {
|
||
self.active_control_source
|
||
}
|
||
});
|
||
let is_steam_view = viewed_source == ControlSource::SteamController;
|
||
|
||
let (
|
||
is_online,
|
||
is_failsafe,
|
||
is_armed,
|
||
gear,
|
||
gear_lbl,
|
||
steer_pct,
|
||
steer_crsf,
|
||
throttle_pct,
|
||
throttle_crsf,
|
||
brake_pct,
|
||
brake_crsf,
|
||
clutch_pct,
|
||
clutch_crsf,
|
||
last_btn,
|
||
detail_line,
|
||
) = if is_steam_view {
|
||
let sc = &self.latest_controller;
|
||
let detail = if sc.connected {
|
||
format!(
|
||
"Périphérique : {} ({}) • Vib {}% (G:{}% / D:{}%) • Trames $RC : {} (Err : {})",
|
||
sc.device_name,
|
||
sc.device_path,
|
||
sc.vibration_pct,
|
||
sc.rumble_left_pct,
|
||
sc.rumble_right_pct,
|
||
sc.packets_sent,
|
||
sc.send_errors
|
||
)
|
||
} else {
|
||
"En attente d'un Steam Controller / Gamepad Linux (/dev/hidraw* ou /dev/input/event*)".to_string()
|
||
};
|
||
(
|
||
sc.connected,
|
||
!sc.connected,
|
||
sc.armed,
|
||
sc.gear,
|
||
sc.gear_label(),
|
||
sc.steering_norm * 100.0,
|
||
sc.steer_crsf,
|
||
sc.throttle_pct,
|
||
sc.throttle_crsf,
|
||
sc.brake_pct,
|
||
sc.brake_crsf,
|
||
sc.clutch_pct,
|
||
sc.clutch_crsf,
|
||
if sc.last_button.is_empty() {
|
||
"Aucun".to_string()
|
||
} else {
|
||
sc.last_button.clone()
|
||
},
|
||
detail,
|
||
)
|
||
} else {
|
||
let g = &self.latest_g29;
|
||
let live = g.is_live();
|
||
let detail = if live {
|
||
format!(
|
||
"FFB Ressort : {}% • Vibrations : {}% • Paquets UDP reçus : {}",
|
||
g.ffb_pct, g.vib_pct, g.packets_received
|
||
)
|
||
} else {
|
||
format!(
|
||
"En attente du pont G29 sur UDP :{} (Paquets reçus : {})",
|
||
self.cfg.g29_udp_port, g.packets_received
|
||
)
|
||
};
|
||
(
|
||
live,
|
||
!live || g.failsafe,
|
||
g.armed,
|
||
g.gear,
|
||
g.gear_label(),
|
||
g.steering_pct as f32,
|
||
g.steer_crsf,
|
||
g.throttle_pct,
|
||
g.throttle_crsf,
|
||
g.brake_pct,
|
||
g.brake_crsf,
|
||
g.clutch_pct,
|
||
g.clutch_crsf,
|
||
if g.last_button.is_empty() {
|
||
"Aucun".to_string()
|
||
} else {
|
||
g.last_button.clone()
|
||
},
|
||
detail,
|
||
)
|
||
};
|
||
|
||
let gear_color = match gear {
|
||
-1 => COLOR_RED,
|
||
0 => COLOR_ORANGE,
|
||
1 => COLOR_CYAN,
|
||
2 => COLOR_GREEN,
|
||
3 => 0xc084fc,
|
||
_ => COLOR_TEXT_MUTED,
|
||
};
|
||
let arm_color = if is_failsafe {
|
||
COLOR_RED
|
||
} else if is_armed {
|
||
COLOR_GREEN
|
||
} else {
|
||
COLOR_ORANGE
|
||
};
|
||
let arm_text = if is_failsafe {
|
||
"FAILSAFE (CH5: 172)"
|
||
} else if is_armed {
|
||
"ARMED (CH5: 1811)"
|
||
} else {
|
||
"SAFE (CH5: 172)"
|
||
};
|
||
let throttle_color = if gear == -1 {
|
||
COLOR_RED
|
||
} else if is_armed && gear > 0 {
|
||
COLOR_GREEN
|
||
} else {
|
||
COLOR_ORANGE
|
||
};
|
||
|
||
let rp2350_sync_text = if self.latest_g29.is_live() {
|
||
format!("RP2350 : {}", self.latest_g29.remote_source.wire_tag())
|
||
} else {
|
||
"RP2350 : hors ligne".to_string()
|
||
};
|
||
let rp2350_sync_color = if !self.latest_g29.is_live() {
|
||
COLOR_TEXT_MUTED
|
||
} else if self.latest_g29.remote_source == self.active_control_source {
|
||
COLOR_GREEN
|
||
} else {
|
||
COLOR_ORANGE
|
||
};
|
||
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.gap_2()
|
||
.p_3()
|
||
.rounded_lg()
|
||
.bg(rgb(COLOR_BG_DARK))
|
||
.border_1()
|
||
.border_color(if is_online {
|
||
rgb(COLOR_BORDER_ACTIVE)
|
||
} else {
|
||
rgb(COLOR_BORDER_SUBTLE)
|
||
})
|
||
// En-tête du moniteur + sélecteur de vue (Auto / G29 / Steam)
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.justify_between()
|
||
.items_center()
|
||
.gap_2()
|
||
.child(
|
||
div()
|
||
.text_xs()
|
||
.font_weight(gpui::FontWeight::BOLD)
|
||
.text_color(rgb(COLOR_CYAN))
|
||
.child(format!(
|
||
"📊 Moniteur Temps Réel — {}",
|
||
viewed_source.label()
|
||
)),
|
||
)
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.gap_1()
|
||
.child(self.render_selectable_pill(
|
||
"pill_mon_auto",
|
||
"Auto (actif)",
|
||
self.monitor_source_override.is_none(),
|
||
cx.listener(|this, _, _, cx| {
|
||
this.monitor_source_override = None;
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(self.render_selectable_pill(
|
||
"pill_mon_g29",
|
||
"🏎️ G29",
|
||
self.monitor_source_override == Some(ControlSource::G29),
|
||
cx.listener(|this, _, _, cx| {
|
||
this.monitor_source_override = Some(ControlSource::G29);
|
||
cx.notify();
|
||
}),
|
||
))
|
||
.child(self.render_selectable_pill(
|
||
"pill_mon_steam",
|
||
"🎮 Steam",
|
||
self.monitor_source_override
|
||
== Some(ControlSource::SteamController),
|
||
cx.listener(|this, _, _, cx| {
|
||
this.monitor_source_override =
|
||
Some(ControlSource::SteamController);
|
||
cx.notify();
|
||
}),
|
||
)),
|
||
),
|
||
)
|
||
// Badges d'état (En ligne, Rapport, ARM/CH5, Sync RP2350)
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.flex_wrap()
|
||
.items_center()
|
||
.gap_2()
|
||
.child(
|
||
div()
|
||
.px_2()
|
||
.py_0p5()
|
||
.rounded_md()
|
||
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||
.border_1()
|
||
.border_color(if is_online {
|
||
rgb(COLOR_GREEN)
|
||
} else {
|
||
rgb(COLOR_BORDER_SUBTLE)
|
||
})
|
||
.text_xs()
|
||
.font_weight(gpui::FontWeight::BOLD)
|
||
.text_color(if is_online {
|
||
rgb(COLOR_GREEN)
|
||
} else {
|
||
rgb(COLOR_TEXT_MUTED)
|
||
})
|
||
.child(if is_online {
|
||
"● CONNECTÉ"
|
||
} else {
|
||
"○ HORS LIGNE"
|
||
}),
|
||
)
|
||
.child(
|
||
div()
|
||
.px_2()
|
||
.py_0p5()
|
||
.rounded_md()
|
||
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||
.border_1()
|
||
.border_color(rgb(gear_color))
|
||
.text_xs()
|
||
.font_weight(gpui::FontWeight::BOLD)
|
||
.text_color(rgb(gear_color))
|
||
.child(format!("BOÎTE [{}]", gear_lbl)),
|
||
)
|
||
.child(
|
||
div()
|
||
.px_2()
|
||
.py_0p5()
|
||
.rounded_md()
|
||
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||
.border_1()
|
||
.border_color(rgb(arm_color))
|
||
.text_xs()
|
||
.font_weight(gpui::FontWeight::BOLD)
|
||
.text_color(rgb(arm_color))
|
||
.child(arm_text),
|
||
)
|
||
.child(
|
||
div()
|
||
.px_2()
|
||
.py_0p5()
|
||
.rounded_md()
|
||
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
||
.border_1()
|
||
.border_color(rgb(rp2350_sync_color))
|
||
.text_xs()
|
||
.text_color(rgb(rp2350_sync_color))
|
||
.child(rp2350_sync_text),
|
||
),
|
||
)
|
||
// Jauges axes temps réel (CH1..CH4)
|
||
.child(self.render_monitor_bipolar_bar(
|
||
"Direction (CH1)",
|
||
steer_pct,
|
||
steer_crsf,
|
||
COLOR_CYAN,
|
||
))
|
||
.child(self.render_monitor_progress_bar(
|
||
"Accélérateur (CH2)",
|
||
throttle_pct,
|
||
throttle_crsf,
|
||
throttle_color,
|
||
))
|
||
.child(self.render_monitor_progress_bar(
|
||
"Frein (CH3)",
|
||
brake_pct,
|
||
brake_crsf,
|
||
COLOR_RED,
|
||
))
|
||
.child(self.render_monitor_progress_bar(
|
||
"Embrayage (CH4)",
|
||
clutch_pct,
|
||
clutch_crsf,
|
||
COLOR_CYAN,
|
||
))
|
||
// Pied du moniteur : dernier bouton & détails liaison (sur 2 lignes pour éviter toute troncature)
|
||
.child(
|
||
div()
|
||
.flex()
|
||
.flex_col()
|
||
.gap_1()
|
||
.pt_1()
|
||
.border_t_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.text_xs()
|
||
.child(
|
||
div()
|
||
.text_color(rgb(COLOR_ORANGE))
|
||
.child(format!("🔘 Dernier bouton : {}", last_btn)),
|
||
)
|
||
.child(div().text_color(rgb(COLOR_TEXT_MUTED)).child(detail_line)),
|
||
)
|
||
}
|
||
|
||
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_CARD))
|
||
.border_1()
|
||
.border_color(rgb(COLOR_BORDER_SUBTLE))
|
||
.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 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);
|
||
let engine = Arc::new(Mutex::new(engine));
|
||
let engine_for_close = Arc::clone(&engine);
|
||
let is_closing = Arc::new(AtomicBool::new(false));
|
||
let is_closing_for_window = Arc::clone(&is_closing);
|
||
|
||
cx.on_window_closed(move |cx| {
|
||
if cx.windows().is_empty() {
|
||
log::info!("[GPUI] Dernière fenêtre fermée, arrêt propre et complet du moteur FPV...");
|
||
is_closing_for_window.store(true, Ordering::Release);
|
||
engine_for_close.lock().stop();
|
||
cx.quit();
|
||
}
|
||
})
|
||
.detach();
|
||
|
||
let bounds = Bounds::centered(None, size(px(1240.0), px(820.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(),
|
||
engine,
|
||
controls,
|
||
engine_monitor,
|
||
is_closing,
|
||
)
|
||
});
|
||
|
||
// 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() {
|
||
let mut exit_now = false;
|
||
view.update(cx, |this, cx| {
|
||
if this.controls.is_exit_requested() {
|
||
exit_now = true;
|
||
return;
|
||
}
|
||
if this.sync_from_engine(window) {
|
||
cx.notify();
|
||
}
|
||
});
|
||
if exit_now {
|
||
window.remove_window();
|
||
return false;
|
||
}
|
||
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(())
|
||
}
|