mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
feat(unified): add 100% wired Radxa/G29 hub (HT, cockpit OSD, CRSF telemetry) & update README
This commit is contained in:
1 parent
f01bf1aeb3
commit
51a5d0c7ad
10 files changed
+1012
-26
No files matched your search
+14
-6
@@ -40,6 +40,14 @@ pub struct AppConfig {
|
||||
#[arg(long, default_value_t = 14551)]
|
||||
pub telemetry_udp_port: u16,
|
||||
|
||||
/// Activer la passerelle Wi-Fi UDP du volant Logitech G29 (g29_crsf)
|
||||
#[arg(long, default_value_t = true)]
|
||||
pub g29_enabled: bool,
|
||||
|
||||
/// Port UDP d'écoute pour la télémétrie et les boutons du volant G29
|
||||
#[arg(long, default_value_t = 14552)]
|
||||
pub g29_udp_port: u16,
|
||||
|
||||
/// Codec vidéo reçu depuis le VRX OpenIPC / Ruby ("h264" ou "h265")
|
||||
#[arg(long, default_value = "h264")]
|
||||
pub codec: String,
|
||||
@@ -88,16 +96,16 @@ pub struct AppConfig {
|
||||
#[arg(long, default_value = "gpui")]
|
||||
pub gui_engine: String,
|
||||
|
||||
/// Adresse IP du Backpack Wi-Fi du module RadioMaster Nomad (en mode AP ELRS : 10.0.0.1)
|
||||
#[arg(long, default_value = "10.0.0.1")]
|
||||
/// Adresse IP du pont unifié G29/Radxa (192.168.1.1) ou du Backpack Wi-Fi Nomad (10.0.0.1)
|
||||
#[arg(long, default_value = "192.168.1.1")]
|
||||
pub nomad_ip: String,
|
||||
|
||||
/// Port UDP du Backpack ELRS du RadioMaster Nomad
|
||||
#[arg(long, default_value_t = 14550)]
|
||||
/// Port UDP cible du Head-Tracking (14552 = pont unifié Radxa/G29, 14550 = Backpack Nomad)
|
||||
#[arg(long, default_value_t = 14552)]
|
||||
pub nomad_port: u16,
|
||||
|
||||
/// Protocole Head-Tracking / Données vers le Nomad : "msp" (MSP_ELRS_BACKPACK_SET_PTR 0x0383), "crsf" ou "mavlink"
|
||||
#[arg(long, default_value = "msp")]
|
||||
/// Protocole Head-Tracking / Données : "g29" (pont unifié $HT), "msp", "crsf" ou "mavlink"
|
||||
#[arg(long, default_value = "g29")]
|
||||
pub ht_protocol: String,
|
||||
|
||||
/// Angle maximal Pan (Lacet/Yaw) en degrés correspondant à la course complète servo (172..1811 CRSF)
|
||||
|
||||
+169
-7
@@ -1,6 +1,7 @@
|
||||
use crate::config::AppConfig;
|
||||
use crate::dome_projection::{DomeWarpLut, ProjectionMode};
|
||||
use crate::dvr::{DvrContainer, DvrMode, DvrRecorder};
|
||||
use crate::g29_bridge::{G29BridgeReceiver, G29State};
|
||||
use crate::nomad_elrs::{HeadPoseSample, NomadHeadTracker, NomadProtocol};
|
||||
use crate::telemetry_osd::{OsdOverlay, TelemetryReceiver, TelemetryState};
|
||||
use crate::video_usb::{UsbVideoReceiver, VideoLinkState};
|
||||
@@ -46,6 +47,7 @@ pub struct RuntimeMonitor {
|
||||
pub openxr_status: SubsystemStatus,
|
||||
pub nomad_wifi_status: SubsystemStatus,
|
||||
pub telemetry_status: SubsystemStatus,
|
||||
pub g29_status: SubsystemStatus,
|
||||
pub dvr_status: SubsystemStatus,
|
||||
pub dvr_recording: bool,
|
||||
pub dvr_elapsed_secs: u64,
|
||||
@@ -57,6 +59,7 @@ pub struct RuntimeMonitor {
|
||||
pub video_frames_total: u64,
|
||||
pub latest_head_pose: HeadPoseSample,
|
||||
pub latest_telemetry: TelemetryState,
|
||||
pub latest_g29: G29State,
|
||||
pub preview_rgba: Vec<u8>,
|
||||
pub preview_width: u32,
|
||||
pub preview_height: u32,
|
||||
@@ -73,6 +76,7 @@ impl Default for RuntimeMonitor {
|
||||
openxr_status: SubsystemStatus::Stopped,
|
||||
nomad_wifi_status: SubsystemStatus::Stopped,
|
||||
telemetry_status: SubsystemStatus::Disabled,
|
||||
g29_status: SubsystemStatus::Disabled,
|
||||
dvr_status: SubsystemStatus::Stopped,
|
||||
dvr_recording: false,
|
||||
dvr_elapsed_secs: 0,
|
||||
@@ -84,6 +88,7 @@ impl Default for RuntimeMonitor {
|
||||
video_frames_total: 0,
|
||||
latest_head_pose: HeadPoseSample::default(),
|
||||
latest_telemetry: TelemetryState::default(),
|
||||
latest_g29: G29State::default(),
|
||||
preview_rgba: Vec::new(),
|
||||
preview_width: 0,
|
||||
preview_height: 0,
|
||||
@@ -106,10 +111,13 @@ pub struct EngineControlHandle {
|
||||
optical_params: Arc<Mutex<LiveOpticalParams>>,
|
||||
dvr_toggle_cmd: Arc<Mutex<Option<bool>>>,
|
||||
dvr_config: Arc<Mutex<DvrConfig>>,
|
||||
dvr_recording_flag: Arc<AtomicBool>,
|
||||
head_trim_deg: Arc<Mutex<(f32, f32)>>,
|
||||
}
|
||||
|
||||
impl EngineControlHandle {
|
||||
pub fn request_recenter(&self) {
|
||||
*self.head_trim_deg.lock() = (0.0, 0.0);
|
||||
self.recenter_flag.store(true, Ordering::Release);
|
||||
}
|
||||
|
||||
@@ -123,6 +131,16 @@ impl EngineControlHandle {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn toggle_telemetry(&self) -> bool {
|
||||
let prev = self.telemetry_enabled_flag.fetch_xor(true, Ordering::AcqRel);
|
||||
let now_on = !prev;
|
||||
log::info!(
|
||||
"[Action Volant] Télémétrie & OSD basculés sur : {}",
|
||||
if now_on { "ON" } else { "OFF" }
|
||||
);
|
||||
now_on
|
||||
}
|
||||
|
||||
pub fn set_head_tracking_enabled(&self, enabled: bool) {
|
||||
let prev = self.head_tracking_enabled_flag.swap(enabled, Ordering::AcqRel);
|
||||
if prev != enabled {
|
||||
@@ -137,6 +155,24 @@ impl EngineControlHandle {
|
||||
*self.optical_params.lock() = opt;
|
||||
}
|
||||
|
||||
pub fn cycle_projection_mode(&self) -> &'static str {
|
||||
let mut opt = self.optical_params.lock();
|
||||
opt.projection_mode = match opt.projection_mode {
|
||||
ProjectionMode::Dome140 => ProjectionMode::Cylinder140,
|
||||
ProjectionMode::Cylinder140 => ProjectionMode::FlatQuad,
|
||||
ProjectionMode::FlatQuad => ProjectionMode::Dome140,
|
||||
};
|
||||
let lbl = opt.projection_mode.label();
|
||||
log::info!("[Action Volant] Mode de projection VR : {}", lbl);
|
||||
lbl
|
||||
}
|
||||
|
||||
pub fn adjust_head_trim(&self, delta_pan_deg: f32, delta_tilt_deg: f32) {
|
||||
let mut trim = self.head_trim_deg.lock();
|
||||
trim.0 = (trim.0 + delta_pan_deg).clamp(-30.0, 30.0);
|
||||
trim.1 = (trim.1 + delta_tilt_deg).clamp(-30.0, 30.0);
|
||||
}
|
||||
|
||||
pub fn update_dvr_config(&self, dir: String, container: DvrContainer, mode: DvrMode) {
|
||||
*self.dvr_config.lock() = DvrConfig { dir, container, mode };
|
||||
}
|
||||
@@ -148,6 +184,13 @@ impl EngineControlHandle {
|
||||
pub fn stop_dvr(&self) {
|
||||
*self.dvr_toggle_cmd.lock() = Some(false);
|
||||
}
|
||||
|
||||
pub fn toggle_dvr(&self) -> bool {
|
||||
let is_rec = self.dvr_recording_flag.load(Ordering::Acquire);
|
||||
let next = !is_rec;
|
||||
*self.dvr_toggle_cmd.lock() = Some(next);
|
||||
next
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FpvEngineController {
|
||||
@@ -155,6 +198,8 @@ pub struct FpvEngineController {
|
||||
optical_params: Arc<Mutex<LiveOpticalParams>>,
|
||||
dvr_toggle_cmd: Arc<Mutex<Option<bool>>>,
|
||||
dvr_config: Arc<Mutex<DvrConfig>>,
|
||||
dvr_recording_flag: Arc<AtomicBool>,
|
||||
head_trim_deg: Arc<Mutex<(f32, f32)>>,
|
||||
stop_flag: Arc<AtomicBool>,
|
||||
recenter_flag: Arc<AtomicBool>,
|
||||
telemetry_enabled_flag: Arc<AtomicBool>,
|
||||
@@ -183,6 +228,8 @@ impl FpvEngineController {
|
||||
optical_params: Arc::new(Mutex::new(opt)),
|
||||
dvr_toggle_cmd: Arc::new(Mutex::new(None)),
|
||||
dvr_config: Arc::new(Mutex::new(dvr_cfg)),
|
||||
dvr_recording_flag: Arc::new(AtomicBool::new(false)),
|
||||
head_trim_deg: Arc::new(Mutex::new((0.0, 0.0))),
|
||||
stop_flag: Arc::new(AtomicBool::new(false)),
|
||||
recenter_flag: Arc::new(AtomicBool::new(false)),
|
||||
telemetry_enabled_flag: Arc::new(AtomicBool::new(initial_telemetry_enabled)),
|
||||
@@ -199,6 +246,8 @@ impl FpvEngineController {
|
||||
optical_params: Arc::clone(&self.optical_params),
|
||||
dvr_toggle_cmd: Arc::clone(&self.dvr_toggle_cmd),
|
||||
dvr_config: Arc::clone(&self.dvr_config),
|
||||
dvr_recording_flag: Arc::clone(&self.dvr_recording_flag),
|
||||
head_trim_deg: Arc::clone(&self.head_trim_deg),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,12 +333,20 @@ impl FpvEngineController {
|
||||
} else {
|
||||
SubsystemStatus::Disabled
|
||||
};
|
||||
mon.g29_status = if cfg.g29_enabled {
|
||||
SubsystemStatus::Starting
|
||||
} else {
|
||||
SubsystemStatus::Disabled
|
||||
};
|
||||
}
|
||||
|
||||
let control_for_g29 = self.control_handle();
|
||||
let monitor_clone = Arc::clone(&self.monitor);
|
||||
let optical_clone = Arc::clone(&self.optical_params);
|
||||
let dvr_cmd_clone = Arc::clone(&self.dvr_toggle_cmd);
|
||||
let dvr_cfg_clone = Arc::clone(&self.dvr_config);
|
||||
let dvr_rec_flag_clone = Arc::clone(&self.dvr_recording_flag);
|
||||
let head_trim_clone = Arc::clone(&self.head_trim_deg);
|
||||
let stop_clone = Arc::clone(&self.stop_flag);
|
||||
let recenter_clone = Arc::clone(&self.recenter_flag);
|
||||
let telem_flag_clone = Arc::clone(&self.telemetry_enabled_flag);
|
||||
@@ -304,6 +361,9 @@ impl FpvEngineController {
|
||||
optical_clone,
|
||||
dvr_cmd_clone,
|
||||
dvr_cfg_clone,
|
||||
dvr_rec_flag_clone,
|
||||
head_trim_clone,
|
||||
control_for_g29,
|
||||
stop_clone,
|
||||
recenter_clone,
|
||||
telem_flag_clone,
|
||||
@@ -538,12 +598,46 @@ fn handle_dvr_lifecycle(
|
||||
}
|
||||
}
|
||||
|
||||
fn sync_g29_status(
|
||||
cfg: &AppConfig,
|
||||
g29_rx_opt: Option<&G29BridgeReceiver>,
|
||||
monitor: &Arc<Mutex<RuntimeMonitor>>,
|
||||
) -> G29State {
|
||||
if !cfg.g29_enabled {
|
||||
return G29State::default();
|
||||
}
|
||||
let Some(rx) = g29_rx_opt else {
|
||||
return G29State::default();
|
||||
};
|
||||
let st = rx.state().lock().clone();
|
||||
let status = if st.is_live() {
|
||||
SubsystemStatus::Running(format!(
|
||||
"Hub :{} ({}, {})",
|
||||
cfg.g29_udp_port,
|
||||
st.gear_label(),
|
||||
if st.armed { "ARMED" } else { "SAFE" }
|
||||
))
|
||||
} else if st.packets_received > 0 {
|
||||
SubsystemStatus::Warning(format!("Signal G29 perdu (UDP :{})", cfg.g29_udp_port))
|
||||
} else {
|
||||
SubsystemStatus::Warning(format!("En attente G29 (UDP :{})", cfg.g29_udp_port))
|
||||
};
|
||||
let mut mon = monitor.lock();
|
||||
mon.g29_status = status;
|
||||
mon.latest_g29 = st.clone();
|
||||
st
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn run_engine_worker(
|
||||
cfg: AppConfig,
|
||||
monitor: Arc<Mutex<RuntimeMonitor>>,
|
||||
optical_params: Arc<Mutex<LiveOpticalParams>>,
|
||||
dvr_cmd: Arc<Mutex<Option<bool>>>,
|
||||
dvr_cfg: Arc<Mutex<DvrConfig>>,
|
||||
dvr_rec_flag: Arc<AtomicBool>,
|
||||
head_trim_deg: Arc<Mutex<(f32, f32)>>,
|
||||
control_for_g29: EngineControlHandle,
|
||||
stop_flag: Arc<AtomicBool>,
|
||||
recenter_flag: Arc<AtomicBool>,
|
||||
telem_enabled_flag: Arc<AtomicBool>,
|
||||
@@ -579,7 +673,8 @@ fn run_engine_worker(
|
||||
}
|
||||
};
|
||||
|
||||
// 2. Démarrage optionnel Télémétrie OSD
|
||||
// 2. Démarrage optionnel Télémétrie OSD (partagée avec le pont unifié G29/CRSF)
|
||||
let shared_telem_state = Arc::new(Mutex::new(TelemetryState::default()));
|
||||
let mut telem_rx_opt = RetrySlot::new();
|
||||
sync_telemetry_receiver(
|
||||
&cfg,
|
||||
@@ -588,7 +683,7 @@ fn run_engine_worker(
|
||||
&monitor,
|
||||
);
|
||||
|
||||
// 3. Démarrage optionnel Émetteur Wi-Fi RadioMaster Nomad (Head-Tracking)
|
||||
// 3. Démarrage optionnel Émetteur Head-Tracking (G29 Hub / RadioMaster Nomad)
|
||||
let mut head_tracker_opt = RetrySlot::new();
|
||||
sync_head_tracker(
|
||||
&cfg,
|
||||
@@ -597,6 +692,29 @@ fn run_engine_worker(
|
||||
&monitor,
|
||||
);
|
||||
|
||||
// 3b. Démarrage optionnel Passerelle Unifiée UDP G29 + Télémétrie CRSF
|
||||
let g29_rx_opt = if cfg.g29_enabled {
|
||||
match G29BridgeReceiver::start(
|
||||
&cfg.usb_bind_ip,
|
||||
cfg.g29_udp_port,
|
||||
control_for_g29,
|
||||
Some(Arc::clone(&shared_telem_state)),
|
||||
) {
|
||||
Ok(rx) => {
|
||||
sync_g29_status(&cfg, Some(&rx), &monitor);
|
||||
Some(rx)
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("[G29 Bridge] Erreur écoute UDP : {}", e);
|
||||
monitor.lock().g29_status = SubsystemStatus::Error(format!("{}", e));
|
||||
None
|
||||
}
|
||||
}
|
||||
} else {
|
||||
monitor.lock().g29_status = SubsystemStatus::Disabled;
|
||||
None
|
||||
};
|
||||
|
||||
// 4. Tentative d'initialisation OpenXR sur le Steam Frame (sauf si mode VR désactivé / headless)
|
||||
let fallback_needed = if cfg.headless {
|
||||
log::info!("[OpenXR] Mode VR désactivé (Mode Bureau léger actif).");
|
||||
@@ -609,6 +727,8 @@ fn run_engine_worker(
|
||||
&optical_params,
|
||||
&dvr_cmd,
|
||||
&dvr_cfg,
|
||||
&dvr_rec_flag,
|
||||
&head_trim_deg,
|
||||
&mut active_dvr,
|
||||
&stop_flag,
|
||||
&recenter_flag,
|
||||
@@ -616,7 +736,9 @@ fn run_engine_worker(
|
||||
&ht_enabled_flag,
|
||||
video_rx_opt.as_ref(),
|
||||
&mut telem_rx_opt,
|
||||
&shared_telem_state,
|
||||
&mut head_tracker_opt,
|
||||
g29_rx_opt.as_ref(),
|
||||
);
|
||||
|
||||
if !stop_flag.load(Ordering::Acquire) {
|
||||
@@ -650,6 +772,8 @@ fn run_engine_worker(
|
||||
&optical_params,
|
||||
&dvr_cmd,
|
||||
&dvr_cfg,
|
||||
&dvr_rec_flag,
|
||||
&head_trim_deg,
|
||||
&mut active_dvr,
|
||||
&stop_flag,
|
||||
&recenter_flag,
|
||||
@@ -657,7 +781,9 @@ fn run_engine_worker(
|
||||
&ht_enabled_flag,
|
||||
video_rx_opt.as_ref(),
|
||||
&mut telem_rx_opt,
|
||||
&shared_telem_state,
|
||||
&mut head_tracker_opt,
|
||||
g29_rx_opt.as_ref(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -678,6 +804,8 @@ fn try_run_openxr_session(
|
||||
optical_params: &Arc<Mutex<LiveOpticalParams>>,
|
||||
dvr_cmd: &Arc<Mutex<Option<bool>>>,
|
||||
dvr_cfg: &Arc<Mutex<DvrConfig>>,
|
||||
dvr_rec_flag: &Arc<AtomicBool>,
|
||||
head_trim_deg: &Arc<Mutex<(f32, f32)>>,
|
||||
active_dvr: &mut Option<Arc<DvrRecorder>>,
|
||||
stop_flag: &Arc<AtomicBool>,
|
||||
recenter_flag: &Arc<AtomicBool>,
|
||||
@@ -685,7 +813,9 @@ fn try_run_openxr_session(
|
||||
ht_enabled_flag: &Arc<AtomicBool>,
|
||||
video_rx_opt: Option<&UsbVideoReceiver>,
|
||||
telem_rx_opt: &mut RetrySlot<TelemetryReceiver>,
|
||||
shared_telem_state: &Arc<Mutex<TelemetryState>>,
|
||||
head_tracker_opt: &mut RetrySlot<NomadHeadTracker>,
|
||||
g29_rx_opt: Option<&G29BridgeReceiver>,
|
||||
) -> Result<()> {
|
||||
let entry = unsafe {
|
||||
xr::Entry::load().context("libopenxr_loader.so introuvable sur ce système (normal sur PC sans SteamVR)")?
|
||||
@@ -952,7 +1082,14 @@ fn try_run_openxr_session(
|
||||
ht.recenter(quat);
|
||||
first_pose = false;
|
||||
}
|
||||
if let Ok(sample) = ht.send_pose(quat) {
|
||||
let (trim_pan, trim_tilt) = *head_trim_deg.lock();
|
||||
let trim_q = Quat::from_euler(
|
||||
EulerRot::YXZ,
|
||||
(-trim_pan).to_radians(),
|
||||
trim_tilt.to_radians(),
|
||||
0.0,
|
||||
);
|
||||
if let Ok(sample) = ht.send_pose(quat * trim_q) {
|
||||
current_pose = sample;
|
||||
}
|
||||
}
|
||||
@@ -1009,11 +1146,20 @@ fn try_run_openxr_session(
|
||||
);
|
||||
}
|
||||
|
||||
let telem_snapshot = telem_rx_opt
|
||||
dvr_rec_flag.store(active_dvr.is_some(), Ordering::Release);
|
||||
let g29_snapshot = sync_g29_status(cfg, g29_rx_opt, monitor);
|
||||
|
||||
let mut telem_snapshot = telem_rx_opt
|
||||
.inner
|
||||
.as_ref()
|
||||
.map(|t| t.state().lock().clone())
|
||||
.unwrap_or_default();
|
||||
if telem_snapshot.packets_received == 0 {
|
||||
let g29_telem = shared_telem_state.lock();
|
||||
if g29_telem.packets_received > 0 {
|
||||
telem_snapshot = g29_telem.clone();
|
||||
}
|
||||
}
|
||||
|
||||
let (dvr_rec, dvr_secs) = {
|
||||
let mon = monitor.lock();
|
||||
@@ -1026,6 +1172,7 @@ fn try_run_openxr_session(
|
||||
cfg.video_width,
|
||||
cfg.video_height,
|
||||
&telem_snapshot,
|
||||
&g29_snapshot,
|
||||
current_pose.pan_deg,
|
||||
current_pose.tilt_deg,
|
||||
current_pose.roll_deg,
|
||||
@@ -1187,6 +1334,8 @@ fn run_desktop_fallback_loop(
|
||||
optical_params: &Arc<Mutex<LiveOpticalParams>>,
|
||||
dvr_cmd: &Arc<Mutex<Option<bool>>>,
|
||||
dvr_cfg: &Arc<Mutex<DvrConfig>>,
|
||||
dvr_rec_flag: &Arc<AtomicBool>,
|
||||
head_trim_deg: &Arc<Mutex<(f32, f32)>>,
|
||||
active_dvr: &mut Option<Arc<DvrRecorder>>,
|
||||
stop_flag: &Arc<AtomicBool>,
|
||||
recenter_flag: &Arc<AtomicBool>,
|
||||
@@ -1194,7 +1343,9 @@ fn run_desktop_fallback_loop(
|
||||
ht_enabled_flag: &Arc<AtomicBool>,
|
||||
video_rx_opt: Option<&UsbVideoReceiver>,
|
||||
telem_rx_opt: &mut RetrySlot<TelemetryReceiver>,
|
||||
shared_telem_state: &Arc<Mutex<TelemetryState>>,
|
||||
head_tracker_opt: &mut RetrySlot<NomadHeadTracker>,
|
||||
g29_rx_opt: Option<&G29BridgeReceiver>,
|
||||
) {
|
||||
let mut dome_lut = DomeWarpLut::new(
|
||||
cfg.video_width,
|
||||
@@ -1262,10 +1413,11 @@ fn run_desktop_fallback_loop(
|
||||
|
||||
let mut current_pose = HeadPoseSample::default();
|
||||
if let Some(ref mut ht) = head_tracker_opt.inner {
|
||||
let (trim_pan, trim_tilt) = *head_trim_deg.lock();
|
||||
let sim_quat = Quat::from_euler(
|
||||
EulerRot::YXZ,
|
||||
(-manual_pan).to_radians(),
|
||||
manual_tilt.to_radians(),
|
||||
(-(manual_pan + trim_pan)).to_radians(),
|
||||
(manual_tilt + trim_tilt).to_radians(),
|
||||
(-manual_roll).to_radians(),
|
||||
);
|
||||
if let Ok(sample) = ht.send_pose(sim_quat) {
|
||||
@@ -1315,11 +1467,20 @@ fn run_desktop_fallback_loop(
|
||||
);
|
||||
}
|
||||
|
||||
let telem_snapshot = telem_rx_opt
|
||||
dvr_rec_flag.store(active_dvr.is_some(), Ordering::Release);
|
||||
let g29_snapshot = sync_g29_status(cfg, g29_rx_opt, monitor);
|
||||
|
||||
let mut telem_snapshot = telem_rx_opt
|
||||
.inner
|
||||
.as_ref()
|
||||
.map(|t| t.state().lock().clone())
|
||||
.unwrap_or_default();
|
||||
if telem_snapshot.packets_received == 0 {
|
||||
let g29_telem = shared_telem_state.lock();
|
||||
if g29_telem.packets_received > 0 {
|
||||
telem_snapshot = g29_telem.clone();
|
||||
}
|
||||
}
|
||||
|
||||
let (dvr_rec, dvr_secs) = {
|
||||
let mon = monitor.lock();
|
||||
@@ -1332,6 +1493,7 @@ fn run_desktop_fallback_loop(
|
||||
cfg.video_width,
|
||||
cfg.video_height,
|
||||
&telem_snapshot,
|
||||
&g29_snapshot,
|
||||
current_pose.pan_deg,
|
||||
current_pose.tilt_deg,
|
||||
current_pose.roll_deg,
|
||||
|
||||
@@ -0,0 +1,491 @@
|
||||
use crate::engine::EngineControlHandle;
|
||||
use crate::telemetry_osd::{TelemetryReceiver, TelemetryState};
|
||||
use anyhow::Result;
|
||||
use parking_lot::Mutex;
|
||||
use std::net::UdpSocket;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
const G29_TIMEOUT_MS: u64 = 1500;
|
||||
const TOAST_DURATION_MS: u64 = 1500;
|
||||
|
||||
/// État temps réel reçu depuis le volant G29 (RP2350 -> ESP32-C3 -> UDP)
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct G29State {
|
||||
pub connected: bool,
|
||||
pub failsafe: bool,
|
||||
pub armed: bool,
|
||||
pub gear: i8,
|
||||
pub throttle_pct: u8,
|
||||
pub brake_pct: u8,
|
||||
pub ffb_raw: u8,
|
||||
pub ffb_pct: u8,
|
||||
pub vib_pct: u8,
|
||||
pub packets_received: u64,
|
||||
pub last_packet: Option<Instant>,
|
||||
pub toast_text: String,
|
||||
pub toast_until: Option<Instant>,
|
||||
}
|
||||
|
||||
impl Default for G29State {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
connected: false,
|
||||
failsafe: false,
|
||||
armed: false,
|
||||
gear: 0,
|
||||
throttle_pct: 0,
|
||||
brake_pct: 0,
|
||||
ffb_raw: 140,
|
||||
ffb_pct: 55,
|
||||
vib_pct: 50,
|
||||
packets_received: 0,
|
||||
last_packet: None,
|
||||
toast_text: String::new(),
|
||||
toast_until: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl G29State {
|
||||
pub fn is_live(&self) -> bool {
|
||||
self.connected
|
||||
&& self
|
||||
.last_packet
|
||||
.map(|t| t.elapsed() <= Duration::from_millis(G29_TIMEOUT_MS))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn set_toast(&mut self, msg: impl Into<String>) {
|
||||
self.toast_text = msg.into();
|
||||
self.toast_until = Some(Instant::now() + Duration::from_millis(TOAST_DURATION_MS));
|
||||
}
|
||||
|
||||
pub fn active_toast(&self) -> Option<&str> {
|
||||
match self.toast_until {
|
||||
Some(until) if Instant::now() < until && !self.toast_text.is_empty() => {
|
||||
Some(&self.toast_text)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn gear_label(&self) -> &'static str {
|
||||
match self.gear {
|
||||
-1 => "R",
|
||||
0 => "N",
|
||||
1 => "1",
|
||||
2 => "2",
|
||||
3 => "3",
|
||||
_ => "?",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum G29ButtonEvent {
|
||||
Cross,
|
||||
Circle,
|
||||
Square,
|
||||
Triangle,
|
||||
Share,
|
||||
Options,
|
||||
Ps,
|
||||
L3,
|
||||
R3,
|
||||
DpadUp,
|
||||
DpadDown,
|
||||
DpadLeft,
|
||||
DpadRight,
|
||||
}
|
||||
|
||||
impl G29ButtonEvent {
|
||||
pub fn from_name(name: &str) -> Option<Self> {
|
||||
match name.trim() {
|
||||
"CROSS" => Some(Self::Cross),
|
||||
"CIRCLE" => Some(Self::Circle),
|
||||
"SQUARE" => Some(Self::Square),
|
||||
"TRIANGLE" => Some(Self::Triangle),
|
||||
"SHARE" => Some(Self::Share),
|
||||
"OPTIONS" => Some(Self::Options),
|
||||
"PS" => Some(Self::Ps),
|
||||
"L3" => Some(Self::L3),
|
||||
"R3" => Some(Self::R3),
|
||||
"DPAD_UP" => Some(Self::DpadUp),
|
||||
"DPAD_DOWN" => Some(Self::DpadDown),
|
||||
"DPAD_LEFT" => Some(Self::DpadLeft),
|
||||
"DPAD_RIGHT" => Some(Self::DpadRight),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Récepteur UDP non-bloquant pour la passerelle Wi-Fi G29
|
||||
pub struct G29BridgeReceiver {
|
||||
state: Arc<Mutex<G29State>>,
|
||||
stop_flag: Arc<AtomicBool>,
|
||||
worker: Option<thread::JoinHandle<()>>,
|
||||
}
|
||||
|
||||
impl G29BridgeReceiver {
|
||||
pub fn start(
|
||||
bind_ip: &str,
|
||||
port: u16,
|
||||
control: EngineControlHandle,
|
||||
telemetry: Option<Arc<Mutex<TelemetryState>>>,
|
||||
) -> Result<Self> {
|
||||
let addr = format!("{}:{}", bind_ip, port);
|
||||
let socket = UdpSocket::bind(&addr)?;
|
||||
socket.set_read_timeout(Some(Duration::from_millis(100)))?;
|
||||
log::info!("[G29 Bridge] En écoute UDP unifiée sur {}", addr);
|
||||
|
||||
let state = Arc::new(Mutex::new(G29State::default()));
|
||||
let state_clone = Arc::clone(&state);
|
||||
let stop_flag = Arc::new(AtomicBool::new(false));
|
||||
let stop_clone = Arc::clone(&stop_flag);
|
||||
|
||||
let worker = thread::Builder::new()
|
||||
.name("g29-udp-rx".into())
|
||||
.spawn(move || {
|
||||
let mut buf = [0u8; 512];
|
||||
while !stop_clone.load(Ordering::Acquire) {
|
||||
if let Ok((len, _src)) = socket.recv_from(&mut buf) {
|
||||
if let Ok(text) = std::str::from_utf8(&buf[..len]) {
|
||||
for line in text.lines() {
|
||||
Self::process_line(
|
||||
line,
|
||||
&state_clone,
|
||||
Some(&control),
|
||||
telemetry.as_ref(),
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let mut st = state_clone.lock();
|
||||
if st.connected && !st.is_live() {
|
||||
st.connected = false;
|
||||
log::warn!("[G29 Bridge] Perte de liaison avec le volant G29.");
|
||||
}
|
||||
}
|
||||
}
|
||||
log::info!("[G29 Bridge] Thread d'écoute UDP arrêté.");
|
||||
})?;
|
||||
|
||||
Ok(Self {
|
||||
state,
|
||||
stop_flag,
|
||||
worker: Some(worker),
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn send_command(target_ip: &str, target_port: u16, cmd: &str) -> Result<()> {
|
||||
let socket = UdpSocket::bind("0.0.0.0:0")?;
|
||||
let target = format!("{}:{}", target_ip.trim(), target_port);
|
||||
let payload = if cmd.ends_with('\n') {
|
||||
cmd.to_string()
|
||||
} else {
|
||||
format!("{}\n", cmd)
|
||||
};
|
||||
socket.send_to(payload.as_bytes(), target)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn state(&self) -> Arc<Mutex<G29State>> {
|
||||
Arc::clone(&self.state)
|
||||
}
|
||||
|
||||
pub fn process_line(
|
||||
raw_line: &str,
|
||||
state: &Arc<Mutex<G29State>>,
|
||||
control: Option<&EngineControlHandle>,
|
||||
telemetry: Option<&Arc<Mutex<TelemetryState>>>,
|
||||
) {
|
||||
let line = raw_line.trim();
|
||||
if let Some(rest) = line.strip_prefix("$G29,") {
|
||||
Self::parse_status_fields(rest, state);
|
||||
} else if let Some(rest) = line.strip_prefix("$G29_EVT,") {
|
||||
Self::parse_button_event(rest, state, control);
|
||||
} else if let Some(hex) = line.strip_prefix("$CRSF,") {
|
||||
if let Some(telem) = telemetry {
|
||||
Self::parse_crsf_hex(hex, telem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_crsf_hex(hex: &str, telemetry: &Arc<Mutex<TelemetryState>>) {
|
||||
let bytes = hex.trim().as_bytes();
|
||||
if bytes.len() < 8 || bytes.len() % 2 != 0 || bytes.len() > 128 {
|
||||
return;
|
||||
}
|
||||
let mut raw = [0u8; 64];
|
||||
let mut out_len = 0;
|
||||
for chunk in bytes.chunks_exact(2) {
|
||||
let Some(hi) = Self::hex_nibble(chunk[0]) else {
|
||||
return;
|
||||
};
|
||||
let Some(lo) = Self::hex_nibble(chunk[1]) else {
|
||||
return;
|
||||
};
|
||||
raw[out_len] = (hi << 4) | lo;
|
||||
out_len += 1;
|
||||
}
|
||||
TelemetryReceiver::parse_datagram(&raw[..out_len], telemetry);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn hex_nibble(b: u8) -> Option<u8> {
|
||||
match b {
|
||||
b'0'..=b'9' => Some(b - b'0'),
|
||||
b'a'..=b'f' => Some(b - b'a' + 10),
|
||||
b'A'..=b'F' => Some(b - b'A' + 10),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_status_fields(fields: &str, state: &Arc<Mutex<G29State>>) {
|
||||
let mut st = state.lock();
|
||||
let had_packets = st.packets_received > 0;
|
||||
let prev_ffb_pct = st.ffb_pct;
|
||||
let prev_vib_pct = st.vib_pct;
|
||||
|
||||
for pair in fields.split(',') {
|
||||
let Some((k, v)) = pair.split_once('=') else {
|
||||
continue;
|
||||
};
|
||||
match k.trim() {
|
||||
"ARM" => {
|
||||
if let Ok(val) = v.trim().parse::<u8>() {
|
||||
st.armed = val != 0;
|
||||
}
|
||||
}
|
||||
"GEAR" => {
|
||||
if let Ok(val) = v.trim().parse::<i8>() {
|
||||
st.gear = val.clamp(-1, 3);
|
||||
}
|
||||
}
|
||||
"THROT" => {
|
||||
if let Ok(val) = v.trim().parse::<u8>() {
|
||||
st.throttle_pct = val.min(100);
|
||||
}
|
||||
}
|
||||
"BRAKE" => {
|
||||
if let Ok(val) = v.trim().parse::<u8>() {
|
||||
st.brake_pct = val.min(100);
|
||||
}
|
||||
}
|
||||
"FFB" => {
|
||||
if let Ok(val) = v.trim().parse::<u8>() {
|
||||
st.ffb_raw = val;
|
||||
st.ffb_pct = ((val as u16 * 100) / 255) as u8;
|
||||
}
|
||||
}
|
||||
"VIB" => {
|
||||
if let Ok(val) = v.trim().parse::<u8>() {
|
||||
st.vib_pct = val.min(100);
|
||||
}
|
||||
}
|
||||
"FAIL" => {
|
||||
if let Ok(val) = v.trim().parse::<u8>() {
|
||||
st.failsafe = val != 0;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
if !st.connected {
|
||||
log::info!("[G29 Bridge] Volant G29 connecté en Wi-Fi UDP.");
|
||||
}
|
||||
st.connected = true;
|
||||
st.packets_received = st.packets_received.wrapping_add(1);
|
||||
st.last_packet = Some(Instant::now());
|
||||
|
||||
if had_packets && st.ffb_pct != prev_ffb_pct {
|
||||
let pct = st.ffb_pct;
|
||||
st.set_toast(format!("FFB {}%", pct));
|
||||
} else if had_packets && st.vib_pct != prev_vib_pct {
|
||||
let pct = st.vib_pct;
|
||||
st.set_toast(format!("VIB {}%", pct));
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_button_event(
|
||||
fields: &str,
|
||||
state: &Arc<Mutex<G29State>>,
|
||||
control: Option<&EngineControlHandle>,
|
||||
) {
|
||||
let Some((_, btn_name)) = fields.split_once("BTN=") else {
|
||||
return;
|
||||
};
|
||||
let Some(btn) = G29ButtonEvent::from_name(btn_name) else {
|
||||
return;
|
||||
};
|
||||
|
||||
log::info!("[G29 Bridge] Bouton volant reçu : {:?}", btn);
|
||||
|
||||
let toast = match btn {
|
||||
G29ButtonEvent::Cross | G29ButtonEvent::Ps | G29ButtonEvent::R3 => {
|
||||
if let Some(ctrl) = control {
|
||||
ctrl.request_recenter();
|
||||
}
|
||||
Some("TARE HT OK".to_string())
|
||||
}
|
||||
G29ButtonEvent::Share | G29ButtonEvent::Circle => {
|
||||
if let Some(ctrl) = control {
|
||||
let now_rec = ctrl.toggle_dvr();
|
||||
Some(if now_rec {
|
||||
"DVR REC".to_string()
|
||||
} else {
|
||||
"DVR STOP".to_string()
|
||||
})
|
||||
} else {
|
||||
Some("DVR TOGGLE".to_string())
|
||||
}
|
||||
}
|
||||
G29ButtonEvent::Triangle => {
|
||||
if let Some(ctrl) = control {
|
||||
let now_on = ctrl.toggle_telemetry();
|
||||
Some(if now_on {
|
||||
"OSD ON".to_string()
|
||||
} else {
|
||||
"OSD OFF".to_string()
|
||||
})
|
||||
} else {
|
||||
Some("OSD TOGGLE".to_string())
|
||||
}
|
||||
}
|
||||
G29ButtonEvent::Square => {
|
||||
if let Some(ctrl) = control {
|
||||
let mode_lbl = ctrl.cycle_projection_mode();
|
||||
Some(format!("PROJ: {}", mode_lbl))
|
||||
} else {
|
||||
Some("PROJ CYCLE".to_string())
|
||||
}
|
||||
}
|
||||
G29ButtonEvent::DpadUp => {
|
||||
if let Some(ctrl) = control {
|
||||
ctrl.adjust_head_trim(0.0, 1.0);
|
||||
}
|
||||
Some("TILT +1".to_string())
|
||||
}
|
||||
G29ButtonEvent::DpadDown => {
|
||||
if let Some(ctrl) = control {
|
||||
ctrl.adjust_head_trim(0.0, -1.0);
|
||||
}
|
||||
Some("TILT -1".to_string())
|
||||
}
|
||||
G29ButtonEvent::DpadLeft => {
|
||||
if let Some(ctrl) = control {
|
||||
ctrl.adjust_head_trim(-1.0, 0.0);
|
||||
}
|
||||
Some("PAN -1".to_string())
|
||||
}
|
||||
G29ButtonEvent::DpadRight => {
|
||||
if let Some(ctrl) = control {
|
||||
ctrl.adjust_head_trim(1.0, 0.0);
|
||||
}
|
||||
Some("PAN +1".to_string())
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for G29BridgeReceiver {
|
||||
fn drop(&mut self) {
|
||||
self.stop_flag.store(true, Ordering::Release);
|
||||
if let Some(handle) = self.worker.take() {
|
||||
let _ = handle.join();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_parse_g29_status_and_toast() {
|
||||
let state = Arc::new(Mutex::new(G29State::default()));
|
||||
G29BridgeReceiver::process_line(
|
||||
"$G29,ARM=1,GEAR=2,THROT=64,BRAKE=12,FFB=140,VIB=50,FAIL=0",
|
||||
&state,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
{
|
||||
let st = state.lock();
|
||||
assert!(st.connected);
|
||||
assert!(st.armed);
|
||||
assert_eq!(st.gear, 2);
|
||||
assert_eq!(st.gear_label(), "2");
|
||||
assert_eq!(st.throttle_pct, 64);
|
||||
assert_eq!(st.brake_pct, 12);
|
||||
assert_eq!(st.ffb_raw, 140);
|
||||
assert_eq!(st.vib_pct, 50);
|
||||
assert!(!st.failsafe);
|
||||
}
|
||||
|
||||
G29BridgeReceiver::process_line(
|
||||
"$G29,ARM=1,GEAR=-1,THROT=0,BRAKE=80,FFB=200,VIB=50,FAIL=0",
|
||||
&state,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
{
|
||||
let st = state.lock();
|
||||
assert_eq!(st.gear_label(), "R");
|
||||
assert_eq!(st.brake_pct, 80);
|
||||
assert_eq!(st.active_toast(), Some("FFB 78%"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_g29_button_event() {
|
||||
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.active_toast(), Some("TARE HT OK"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_crsf_telemetry_hex() {
|
||||
// Trame CRSF Battery Sensor (0x08) : 16.8V (168 = 0x00A8), 12.5A (125 = 0x007D), 1200 mAh, 75%
|
||||
let mut frame = [0u8; 12];
|
||||
frame[0] = 0xEA;
|
||||
frame[1] = 10;
|
||||
frame[2] = 0x08;
|
||||
frame[3] = 0x00;
|
||||
frame[4] = 0xA8; // 16.8V
|
||||
frame[5] = 0x00;
|
||||
frame[6] = 0x7D; // 12.5A
|
||||
frame[7] = 0x00;
|
||||
frame[8] = 0x04;
|
||||
frame[9] = 0xB0; // 1200 mAh
|
||||
frame[10] = 75; // 75%
|
||||
frame[11] = crate::nomad_elrs::NomadHeadTracker::crc8_dvb_s2(&frame[2..11]);
|
||||
|
||||
let hex: String = frame.iter().map(|b| format!("{:02X}", b)).collect();
|
||||
let line = format!("$CRSF,{}", hex);
|
||||
|
||||
let g29_state = Arc::new(Mutex::new(G29State::default()));
|
||||
let telem_state = Arc::new(Mutex::new(TelemetryState::default()));
|
||||
G29BridgeReceiver::process_line(&line, &g29_state, None, Some(&telem_state));
|
||||
|
||||
let ts = telem_state.lock();
|
||||
assert_eq!(ts.packets_received, 1);
|
||||
assert!((ts.battery_voltage_v - 16.8).abs() < 0.01);
|
||||
assert!((ts.battery_current_a - 12.5).abs() < 0.01);
|
||||
assert_eq!(ts.battery_remaining_pct, 75);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ 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;
|
||||
@@ -68,6 +69,7 @@ pub struct SteamFrameGpuiApp {
|
||||
xr_status: SubsystemStatus,
|
||||
nomad_status: SubsystemStatus,
|
||||
telem_status: SubsystemStatus,
|
||||
g29_status: SubsystemStatus,
|
||||
dvr_status: SubsystemStatus,
|
||||
dvr_recording: bool,
|
||||
dvr_elapsed_secs: u64,
|
||||
@@ -78,6 +80,7 @@ pub struct SteamFrameGpuiApp {
|
||||
video_frames_total: u64,
|
||||
latest_pose: HeadPoseSample,
|
||||
latest_telem: TelemetryState,
|
||||
latest_g29: G29State,
|
||||
log_entries: Vec<LogEntry>,
|
||||
log_err_count: usize,
|
||||
log_warn_count: usize,
|
||||
@@ -126,6 +129,7 @@ impl SteamFrameGpuiApp {
|
||||
xr_status: SubsystemStatus::Starting,
|
||||
nomad_status: SubsystemStatus::Disabled,
|
||||
telem_status: SubsystemStatus::Disabled,
|
||||
g29_status: SubsystemStatus::Disabled,
|
||||
dvr_status: SubsystemStatus::Stopped,
|
||||
dvr_recording: false,
|
||||
dvr_elapsed_secs: 0,
|
||||
@@ -136,6 +140,7 @@ impl SteamFrameGpuiApp {
|
||||
video_frames_total: 0,
|
||||
latest_pose: HeadPoseSample::default(),
|
||||
latest_telem: TelemetryState::default(),
|
||||
latest_g29: G29State::default(),
|
||||
log_entries: Vec::new(),
|
||||
log_err_count: 0,
|
||||
log_warn_count: 0,
|
||||
@@ -179,6 +184,10 @@ impl SteamFrameGpuiApp {
|
||||
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.dvr_recording != mon.dvr_recording
|
||||
|| self.dvr_elapsed_secs != mon.dvr_elapsed_secs
|
||||
|| self.dvr_status != mon.dvr_status
|
||||
@@ -201,6 +210,12 @@ impl SteamFrameGpuiApp {
|
||||
}
|
||||
self.latest_pose = mon.latest_head_pose;
|
||||
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
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
self.latest_g29 = mon.latest_g29.clone();
|
||||
|
||||
// Ne cloner et décoder la trame QUE si l'onglet Cockpit est actif !
|
||||
let frame_data: Option<(u32, u32, Vec<u8>)> = if self.active_tab == ActiveTab::Cockpit
|
||||
@@ -1219,6 +1234,18 @@ impl SteamFrameGpuiApp {
|
||||
.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",
|
||||
@@ -1328,6 +1355,15 @@ impl SteamFrameGpuiApp {
|
||||
.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)",
|
||||
@@ -2035,6 +2071,31 @@ impl SteamFrameGpuiApp {
|
||||
&format!("{:.1} m", self.latest_telem.altitude_m),
|
||||
&format!("Cap : {:.0}°", self.latest_telem.drone_heading_deg),
|
||||
COLOR_CYAN,
|
||||
))
|
||||
.child(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
|
||||
|
||||
@@ -2,6 +2,7 @@ mod config;
|
||||
mod dome_projection;
|
||||
mod dvr;
|
||||
mod engine;
|
||||
mod g29_bridge;
|
||||
mod gui;
|
||||
mod gui_gpui;
|
||||
mod logger;
|
||||
|
||||
+26
-1
@@ -19,11 +19,18 @@ pub enum NomadProtocol {
|
||||
Crsf,
|
||||
/// MAVLink v1 RC_CHANNELS_OVERRIDE (msgid 70) — compatible UDP Backpack /mavlink (port 14555)
|
||||
Mavlink,
|
||||
/// Pont unifié G29 / Radxa Zero 3W ($HT,<pan>,<tilt>,<roll>) — 100% filaire via usb0:14552
|
||||
G29Bridge,
|
||||
}
|
||||
|
||||
impl NomadProtocol {
|
||||
pub fn from_str(s: &str) -> Self {
|
||||
if s.eq_ignore_ascii_case("crsf") {
|
||||
if s.eq_ignore_ascii_case("g29")
|
||||
|| s.eq_ignore_ascii_case("g29_bridge")
|
||||
|| s.eq_ignore_ascii_case("radxa")
|
||||
{
|
||||
Self::G29Bridge
|
||||
} else if s.eq_ignore_ascii_case("crsf") {
|
||||
Self::Crsf
|
||||
} else if s.eq_ignore_ascii_case("mavlink") || s.eq_ignore_ascii_case("mav") {
|
||||
Self::Mavlink
|
||||
@@ -37,6 +44,7 @@ impl NomadProtocol {
|
||||
Self::Msp => "MSPv2 0x0383",
|
||||
Self::Crsf => "CRSF 0x16",
|
||||
Self::Mavlink => "MAVLink v1 (RC Override)",
|
||||
Self::G29Bridge => "G29 Hub ($HT)",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -208,6 +216,10 @@ impl NomadHeadTracker {
|
||||
self.mav_seq = self.mav_seq.wrapping_add(1);
|
||||
self.socket.send_to(&packet, self.target)
|
||||
}
|
||||
NomadProtocol::G29Bridge => {
|
||||
let msg = Self::encode_g29_ht(pan_crsf, tilt_crsf, roll_crsf);
|
||||
self.socket.send_to(msg.as_bytes(), self.target)
|
||||
}
|
||||
};
|
||||
|
||||
let last_send_ok = match send_res {
|
||||
@@ -260,6 +272,10 @@ impl NomadHeadTracker {
|
||||
(crsf_val.round() as u16).clamp(CRSF_CHANNEL_MIN, CRSF_CHANNEL_MAX)
|
||||
}
|
||||
|
||||
pub fn encode_g29_ht(pan: u16, tilt: u16, roll: u16) -> String {
|
||||
format!("$HT,{},{},{}\n", pan, tilt, roll)
|
||||
}
|
||||
|
||||
pub fn encode_mspv2_ptr(pan: u16, tilt: u16, roll: u16) -> [u8; 15] {
|
||||
let mut buf = [0u8; 15];
|
||||
buf[0] = b'$';
|
||||
@@ -474,4 +490,13 @@ mod tests {
|
||||
let ht = NomadHeadTracker::new("10.0.0.1", 14550, 90.0, 60.0, 45.0, NomadProtocol::Msp);
|
||||
assert!(ht.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_g29_bridge_ht_format() {
|
||||
assert_eq!(NomadProtocol::from_str("g29"), NomadProtocol::G29Bridge);
|
||||
assert_eq!(
|
||||
NomadHeadTracker::encode_g29_ht(992, 1200, 800),
|
||||
"$HT,992,1200,800\n"
|
||||
);
|
||||
}
|
||||
}
|
||||
+62
-1
@@ -1,3 +1,4 @@
|
||||
use crate::g29_bridge::G29State;
|
||||
use anyhow::Result;
|
||||
use parking_lot::Mutex;
|
||||
use std::fmt::Write as FmtWrite;
|
||||
@@ -88,6 +89,14 @@ pub struct TelemetryReceiver {
|
||||
|
||||
impl TelemetryReceiver {
|
||||
pub fn start(bind_ip: &str, port: u16) -> Result<Self> {
|
||||
Self::start_with_state(bind_ip, port, Arc::new(Mutex::new(TelemetryState::default())))
|
||||
}
|
||||
|
||||
pub fn start_with_state(
|
||||
bind_ip: &str,
|
||||
port: u16,
|
||||
state: Arc<Mutex<TelemetryState>>,
|
||||
) -> Result<Self> {
|
||||
let addr = format!("{}:{}", bind_ip, port);
|
||||
let socket = UdpSocket::bind(&addr).map_err(|e| {
|
||||
log::error!(
|
||||
@@ -103,7 +112,6 @@ impl TelemetryReceiver {
|
||||
addr
|
||||
);
|
||||
|
||||
let state = Arc::new(Mutex::new(TelemetryState::default()));
|
||||
let state_clone = Arc::clone(&state);
|
||||
let stop_flag = Arc::new(AtomicBool::new(false));
|
||||
let stop_clone = Arc::clone(&stop_flag);
|
||||
@@ -333,6 +341,7 @@ impl OsdOverlay {
|
||||
width: u32,
|
||||
height: u32,
|
||||
telem: &TelemetryState,
|
||||
g29: &G29State,
|
||||
head_pan_deg: f32,
|
||||
head_tilt_deg: f32,
|
||||
head_roll_deg: f32,
|
||||
@@ -469,6 +478,58 @@ impl OsdOverlay {
|
||||
scale,
|
||||
[240, 240, 240, 255],
|
||||
);
|
||||
|
||||
Self::draw_g29_hud(rgba, width, height, g29, scale, bottom_y);
|
||||
}
|
||||
|
||||
fn draw_g29_hud(
|
||||
rgba: &mut [u8],
|
||||
width: u32,
|
||||
height: u32,
|
||||
g29: &G29State,
|
||||
scale: u32,
|
||||
bottom_y: i32,
|
||||
) {
|
||||
if let Some(toast) = g29.active_toast() {
|
||||
let mut toast_buf = StackStr::<32>::new();
|
||||
let _ = write!(toast_buf, "[ {} ]", toast);
|
||||
let tx = (width as i32 / 2) - ((toast_buf.as_str().len() as i32 * 6 * scale as i32) / 2);
|
||||
let ty = 48 + 46 * scale as i32 / 2;
|
||||
Self::draw_text(rgba, width, height, tx, ty, toast_buf.as_str(), scale, [255, 230, 80, 255]);
|
||||
}
|
||||
|
||||
if g29.packets_received == 0 && !g29.connected {
|
||||
return;
|
||||
}
|
||||
|
||||
let gear_y = bottom_y - (12 * scale as i32);
|
||||
let gear_color = match g29.gear {
|
||||
-1 => [255, 70, 70, 255], // R : Rouge
|
||||
0 => [255, 165, 40, 255], // N : Orange
|
||||
1 => [80, 240, 255, 255], // 1 : Cyan
|
||||
2 => [90, 255, 120, 255], // 2 : Vert
|
||||
3 => [200, 110, 255, 255], // 3 : Violet
|
||||
_ => [220, 220, 220, 255],
|
||||
};
|
||||
|
||||
let mut gear_buf = StackStr::<12>::new();
|
||||
let _ = write!(gear_buf, "[{}]", g29.gear_label());
|
||||
Self::draw_text(rgba, width, height, 32, gear_y, gear_buf.as_str(), scale, gear_color);
|
||||
|
||||
let (arm_lbl, arm_color) = if !g29.is_live() || g29.failsafe {
|
||||
("G29 FAIL", [255, 65, 65, 255])
|
||||
} else if g29.armed {
|
||||
("ARMED", [90, 255, 120, 255])
|
||||
} else {
|
||||
("SAFE", [255, 180, 50, 255])
|
||||
};
|
||||
let arm_x = 32 + (4 * 6 * scale as i32);
|
||||
Self::draw_text(rgba, width, height, arm_x, gear_y, arm_lbl, scale, arm_color);
|
||||
|
||||
let mut pedal_buf = StackStr::<32>::new();
|
||||
let _ = write!(pedal_buf, "GAZ {:3}% FRN {:3}%", g29.throttle_pct, g29.brake_pct);
|
||||
let pedal_x = arm_x + ((arm_lbl.len() as i32 + 2) * 6 * scale as i32);
|
||||
Self::draw_text(rgba, width, height, pedal_x, gear_y, pedal_buf.as_str(), scale, [230, 235, 245, 255]);
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
|
||||
Reference in new issue
Block a user