mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
feat(gui): add live G29 / Steam Controller input & CRSF monitor in Settings
This commit is contained in:
1 parent
23e24cab5d
commit
ebe0d9889f
5 files changed
+796
-30
No files matched your search
+446
-1
@@ -86,6 +86,7 @@ pub struct SteamFrameGpuiApp {
|
||||
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,
|
||||
@@ -151,6 +152,7 @@ impl SteamFrameGpuiApp {
|
||||
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,
|
||||
@@ -230,6 +232,7 @@ impl SteamFrameGpuiApp {
|
||||
self.latest_telem = mon.latest_telemetry.clone();
|
||||
if self.latest_g29.packets_received != mon.latest_g29.packets_received
|
||||
|| self.latest_g29.connected != mon.latest_g29.connected
|
||||
|| self.latest_g29.last_button != mon.latest_g29.last_button
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
@@ -240,8 +243,12 @@ impl SteamFrameGpuiApp {
|
||||
|| 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.last_button != mon.latest_controller.last_button
|
||||
|| (self.latest_controller.steering_norm - mon.latest_controller.steering_norm).abs()
|
||||
> 0.02
|
||||
> 0.005
|
||||
|| (self.active_tab == ActiveTab::Settings
|
||||
&& self.latest_controller.packets_sent != mon.latest_controller.packets_sent)
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
@@ -1736,6 +1743,7 @@ impl SteamFrameGpuiApp {
|
||||
)),
|
||||
),
|
||||
))
|
||||
.child(self.render_controller_monitor(cx))
|
||||
.child(
|
||||
div()
|
||||
.p_2()
|
||||
@@ -2748,6 +2756,443 @@ impl SteamFrameGpuiApp {
|
||||
.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(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 : {} ({}) • Trames $RC : {} (Err : {})",
|
||||
sc.device_name, sc.device_path, sc.packets_sent, sc.send_errors
|
||||
)
|
||||
} else {
|
||||
"En attente d'un Steam Controller / Gamepad Linux (/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
|
||||
.child(
|
||||
div()
|
||||
.flex()
|
||||
.flex_wrap()
|
||||
.justify_between()
|
||||
.items_center()
|
||||
.gap_2()
|
||||
.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);
|
||||
|
||||
|
||||
Reference in new issue
Block a user