mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
feat(nomad): add editable network target, 50Hz manual mock, MAVLink protocol & ELRS Backpack UDP MSPv2 patch
This commit is contained in:
1 parent
7bee072e21
commit
e859d0e21c
7 files changed
+860
-57
No files matched your search
+476
-17
@@ -5,12 +5,12 @@ use crate::engine::{
|
||||
EngineControlHandle, FpvEngineController, LiveOpticalParams, RuntimeMonitor, SubsystemStatus,
|
||||
};
|
||||
use crate::logger::{LogBuffer, LogEntry, LogFilter};
|
||||
use crate::nomad_elrs::{HeadPoseSample, NomadHeadTracker};
|
||||
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,
|
||||
RenderImage, Timer, Window, WindowBounds, WindowOptions,
|
||||
FocusHandle, KeyDownEvent, RenderImage, Timer, Window, WindowBounds, WindowOptions,
|
||||
};
|
||||
use image::{Frame, RgbaImage};
|
||||
use parking_lot::Mutex;
|
||||
@@ -18,7 +18,7 @@ use smallvec::smallvec;
|
||||
use std::process::Command;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
// =========================================================================
|
||||
// Palette Cyberpunk / Aeronautic FPV
|
||||
@@ -44,6 +44,12 @@ pub enum ActiveTab {
|
||||
Logs,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum TargetEditField {
|
||||
Ip,
|
||||
Port,
|
||||
}
|
||||
|
||||
pub struct SteamFrameGpuiApp {
|
||||
cfg: AppConfig,
|
||||
engine: Arc<Mutex<FpvEngineController>>,
|
||||
@@ -76,6 +82,17 @@ pub struct SteamFrameGpuiApp {
|
||||
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,
|
||||
}
|
||||
|
||||
impl SteamFrameGpuiApp {
|
||||
@@ -87,6 +104,7 @@ impl SteamFrameGpuiApp {
|
||||
engine_monitor: Arc<Mutex<RuntimeMonitor>>,
|
||||
) -> Self {
|
||||
let log_revision = log_buffer.lock().revision.clone();
|
||||
let target_port_buf = cfg.nomad_port.to_string();
|
||||
|
||||
Self {
|
||||
cfg,
|
||||
@@ -119,6 +137,16 @@ impl SteamFrameGpuiApp {
|
||||
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(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,6 +246,19 @@ impl SteamFrameGpuiApp {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -294,21 +335,154 @@ impl SteamFrameGpuiApp {
|
||||
}
|
||||
|
||||
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 {}:{}...",
|
||||
"[Wi-Fi Nomad] Envoi d'un paquet de test ({}) vers {}:{}...",
|
||||
protocol.label(),
|
||||
self.cfg.nomad_ip,
|
||||
self.cfg.nomad_port
|
||||
);
|
||||
let use_crsf = self.cfg.ht_protocol.eq_ignore_ascii_case("crsf");
|
||||
if let Ok(mut ht) = NomadHeadTracker::new(
|
||||
match NomadHeadTracker::new(
|
||||
&self.cfg.nomad_ip,
|
||||
self.cfg.nomad_port,
|
||||
self.cfg.max_pan_deg,
|
||||
self.cfg.max_tilt_deg,
|
||||
self.cfg.max_roll_deg,
|
||||
use_crsf,
|
||||
protocol,
|
||||
) {
|
||||
let _ = ht.send_pose(glam::Quat::IDENTITY);
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -322,6 +496,9 @@ impl Drop for SteamFrameGpuiApp {
|
||||
|
||||
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()
|
||||
@@ -962,38 +1139,152 @@ impl SteamFrameGpuiApp {
|
||||
.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_msp",
|
||||
"MSPv2 0x0383 (ELRS Backpack)",
|
||||
"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 (RC Channels)",
|
||||
"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
|
||||
// Cible UDP éditable (clic pour taper IP/hostname ou port)
|
||||
.child(self.render_setting_row(
|
||||
"Cible Réseau",
|
||||
"Cible Réseau (clic pour éditer)",
|
||||
div()
|
||||
.text_xs()
|
||||
.text_color(rgb(COLOR_TEXT_MAIN))
|
||||
.child(format!("{}:{} (Backpack AP)", self.cfg.nomad_ip, self.cfg.nomad_port)),
|
||||
.flex()
|
||||
.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| {
|
||||
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_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(
|
||||
@@ -1006,12 +1297,99 @@ impl SteamFrameGpuiApp {
|
||||
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()
|
||||
.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| {
|
||||
this.mock_continuous = !this.mock_continuous;
|
||||
this.mock_last_send = None;
|
||||
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()
|
||||
.gap_2()
|
||||
.pt_2()
|
||||
.pt_1()
|
||||
.child(
|
||||
div()
|
||||
.id("btn_test_packet_settings")
|
||||
@@ -1027,7 +1405,7 @@ impl SteamFrameGpuiApp {
|
||||
.on_click(cx.listener(|this, _, _, _| {
|
||||
this.test_nomad_packet();
|
||||
}))
|
||||
.child("📡 Envoyer paquet test"),
|
||||
.child("📡 Envoyer paquet neutre"),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
@@ -1328,6 +1706,87 @@ impl SteamFrameGpuiApp {
|
||||
.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()
|
||||
.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 render_setting_row(&self, label: &str, control: impl IntoElement) -> impl IntoElement {
|
||||
div()
|
||||
.flex()
|
||||
|
||||
Reference in new issue
Block a user