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
+61
-3
@@ -1,5 +1,6 @@
|
||||
use crate::controller::ControlSource;
|
||||
use crate::engine::EngineControlHandle;
|
||||
use crate::nomad_elrs::{CRSF_CHANNEL_MAX, CRSF_CHANNEL_MID, CRSF_CHANNEL_MIN};
|
||||
use crate::telemetry_osd::{TelemetryReceiver, TelemetryState};
|
||||
use anyhow::Result;
|
||||
use parking_lot::Mutex;
|
||||
@@ -19,14 +20,22 @@ pub struct G29State {
|
||||
pub failsafe: bool,
|
||||
pub armed: bool,
|
||||
pub gear: i8,
|
||||
pub steering_pct: i8,
|
||||
pub throttle_pct: u8,
|
||||
pub brake_pct: u8,
|
||||
pub clutch_pct: u8,
|
||||
pub steer_crsf: u16,
|
||||
pub throttle_crsf: u16,
|
||||
pub brake_crsf: u16,
|
||||
pub clutch_crsf: u16,
|
||||
pub ffb_raw: u8,
|
||||
pub ffb_pct: u8,
|
||||
pub vib_pct: u8,
|
||||
pub remote_source: ControlSource,
|
||||
pub packets_received: u64,
|
||||
pub last_packet: Option<Instant>,
|
||||
pub last_button: String,
|
||||
pub last_button_at: Option<Instant>,
|
||||
pub toast_text: String,
|
||||
pub toast_until: Option<Instant>,
|
||||
}
|
||||
@@ -38,14 +47,22 @@ impl Default for G29State {
|
||||
failsafe: false,
|
||||
armed: false,
|
||||
gear: 0,
|
||||
steering_pct: 0,
|
||||
throttle_pct: 0,
|
||||
brake_pct: 0,
|
||||
clutch_pct: 0,
|
||||
steer_crsf: CRSF_CHANNEL_MID,
|
||||
throttle_crsf: CRSF_CHANNEL_MID,
|
||||
brake_crsf: CRSF_CHANNEL_MID,
|
||||
clutch_crsf: CRSF_CHANNEL_MID,
|
||||
ffb_raw: 140,
|
||||
ffb_pct: 55,
|
||||
vib_pct: 50,
|
||||
remote_source: ControlSource::G29,
|
||||
packets_received: 0,
|
||||
last_packet: None,
|
||||
last_button: String::new(),
|
||||
last_button_at: None,
|
||||
toast_text: String::new(),
|
||||
toast_until: None,
|
||||
}
|
||||
@@ -279,6 +296,36 @@ impl G29BridgeReceiver {
|
||||
st.brake_pct = val.min(100);
|
||||
}
|
||||
}
|
||||
"CLUTCH" => {
|
||||
if let Ok(val) = v.trim().parse::<u8>() {
|
||||
st.clutch_pct = val.min(100);
|
||||
}
|
||||
}
|
||||
"STEER" => {
|
||||
if let Ok(val) = v.trim().parse::<i8>() {
|
||||
st.steering_pct = val.clamp(-100, 100);
|
||||
}
|
||||
}
|
||||
"CH1" => {
|
||||
if let Ok(val) = v.trim().parse::<u16>() {
|
||||
st.steer_crsf = val.clamp(CRSF_CHANNEL_MIN, CRSF_CHANNEL_MAX);
|
||||
}
|
||||
}
|
||||
"CH2" => {
|
||||
if let Ok(val) = v.trim().parse::<u16>() {
|
||||
st.throttle_crsf = val.clamp(CRSF_CHANNEL_MIN, CRSF_CHANNEL_MAX);
|
||||
}
|
||||
}
|
||||
"CH3" => {
|
||||
if let Ok(val) = v.trim().parse::<u16>() {
|
||||
st.brake_crsf = val.clamp(CRSF_CHANNEL_MIN, CRSF_CHANNEL_MAX);
|
||||
}
|
||||
}
|
||||
"CH4" => {
|
||||
if let Ok(val) = v.trim().parse::<u16>() {
|
||||
st.clutch_crsf = val.clamp(CRSF_CHANNEL_MIN, CRSF_CHANNEL_MAX);
|
||||
}
|
||||
}
|
||||
"FFB" => {
|
||||
if let Ok(val) = v.trim().parse::<u8>() {
|
||||
st.ffb_raw = val;
|
||||
@@ -398,11 +445,15 @@ impl G29BridgeReceiver {
|
||||
G29ButtonEvent::Options | G29ButtonEvent::L3 => None,
|
||||
};
|
||||
|
||||
if let Some(msg) = toast {
|
||||
{
|
||||
let mut st = state.lock();
|
||||
st.connected = true;
|
||||
st.last_packet = Some(Instant::now());
|
||||
st.set_toast(msg);
|
||||
st.last_button = btn_name.trim().to_string();
|
||||
st.last_button_at = Some(Instant::now());
|
||||
if let Some(msg) = toast {
|
||||
st.set_toast(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -443,7 +494,7 @@ mod tests {
|
||||
}
|
||||
|
||||
G29BridgeReceiver::process_line(
|
||||
"$G29,ARM=1,GEAR=-1,THROT=0,BRAKE=80,FFB=200,VIB=50,FAIL=0,SRC=EXT",
|
||||
"$G29,ARM=1,GEAR=-1,THROT=0,BRAKE=80,CLUTCH=45,STEER=-35,CH1=1280,CH2=890,CH3=1640,CH4=1360,FFB=200,VIB=50,FAIL=0,SRC=EXT",
|
||||
&state,
|
||||
None,
|
||||
None,
|
||||
@@ -452,6 +503,12 @@ mod tests {
|
||||
let st = state.lock();
|
||||
assert_eq!(st.gear_label(), "R");
|
||||
assert_eq!(st.brake_pct, 80);
|
||||
assert_eq!(st.clutch_pct, 45);
|
||||
assert_eq!(st.steering_pct, -35);
|
||||
assert_eq!(st.steer_crsf, 1280);
|
||||
assert_eq!(st.throttle_crsf, 890);
|
||||
assert_eq!(st.brake_crsf, 1640);
|
||||
assert_eq!(st.clutch_crsf, 1360);
|
||||
assert_eq!(st.remote_source, ControlSource::SteamController);
|
||||
assert_eq!(st.active_toast(), Some("FFB 78%"));
|
||||
}
|
||||
@@ -462,6 +519,7 @@ mod tests {
|
||||
let state = Arc::new(Mutex::new(G29State::default()));
|
||||
G29BridgeReceiver::process_line("$G29_EVT,BTN=CROSS", &state, None, None);
|
||||
let st = state.lock();
|
||||
assert_eq!(st.last_button, "CROSS");
|
||||
assert_eq!(st.active_toast(), Some("TARE HT OK"));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user