mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
feat(perf,ux): GPU compute warp, dual-layer OpenXR OSD, HW decode, profiles & modular architecture (Lots 3 & 4)
This commit is contained in:
1 parent
d82a65d9e6
commit
4aa4fc06e7
27 files changed
+9678
-7045
No files matched your search
+336
-1
@@ -192,11 +192,280 @@ pub struct AppConfig {
|
||||
#[arg(long, default_value_t = false)]
|
||||
pub vr_only: bool,
|
||||
|
||||
/// Nombre de cellules LiPo (0 = auto-détection 2S..6S selon tension initiale, sinon 2..=6)
|
||||
#[arg(long, default_value_t = 0)]
|
||||
pub battery_cells: u8,
|
||||
|
||||
/// Seuil d'avertissement batterie par cellule en Volts (jaune)
|
||||
#[arg(long, default_value_t = 3.5)]
|
||||
pub battery_warn_cell_v: f32,
|
||||
|
||||
/// Seuil critique batterie par cellule en Volts (rouge + alerte haptique)
|
||||
#[arg(long, default_value_t = 3.3)]
|
||||
pub battery_crit_cell_v: f32,
|
||||
|
||||
/// Afficher les métriques de lien vidéo (FPS, Jitter, Drops) dans l'OSD VR
|
||||
#[arg(long, default_value_t = true)]
|
||||
pub osd_show_video_stats: bool,
|
||||
|
||||
/// Afficher les informations GPS / Mode de vol CRSF dans l'OSD VR
|
||||
#[arg(long, default_value_t = true)]
|
||||
pub osd_show_gps: bool,
|
||||
|
||||
/// Nom du profil véhicule actif (vide = personnalisé)
|
||||
#[arg(long, default_value = "")]
|
||||
pub active_profile: String,
|
||||
|
||||
/// Chemin du fichier journal d'erreurs et de diagnostic
|
||||
#[arg(long, default_value = "steamframe_fpv.log")]
|
||||
pub log_file: String,
|
||||
}
|
||||
|
||||
/// Profil véhicule regroupant vitesses CRSF, direction, optique VR, batterie et contrôleur.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct VehicleProfile {
|
||||
pub name: String,
|
||||
pub control_source: String,
|
||||
pub controller_expo: f32,
|
||||
pub controller_deadzone: f32,
|
||||
pub controller_invert_steering: bool,
|
||||
pub gaz_avant_min: u16,
|
||||
pub gear_1_max: u16,
|
||||
pub gear_2_max: u16,
|
||||
pub gear_3_max: u16,
|
||||
pub gaz_arriere_min: u16,
|
||||
pub gear_reverse_max: u16,
|
||||
pub projection_mode: String,
|
||||
pub camera_fov_deg: f32,
|
||||
pub lens_k1: f32,
|
||||
pub screen_distance_m: f32,
|
||||
pub battery_cells: u8,
|
||||
}
|
||||
|
||||
impl VehicleProfile {
|
||||
pub fn builtin_presets() -> Vec<Self> {
|
||||
vec![
|
||||
Self {
|
||||
name: "Crawler 3S".to_string(),
|
||||
control_source: "g29".to_string(),
|
||||
controller_expo: 0.35,
|
||||
controller_deadzone: 0.08,
|
||||
controller_invert_steering: false,
|
||||
gaz_avant_min: 1055,
|
||||
gear_1_max: 1090,
|
||||
gear_2_max: 1130,
|
||||
gear_3_max: 1180,
|
||||
gaz_arriere_min: 915,
|
||||
gear_reverse_max: 840,
|
||||
projection_mode: "dome".to_string(),
|
||||
camera_fov_deg: 140.0,
|
||||
lens_k1: -0.14,
|
||||
screen_distance_m: 1.6,
|
||||
battery_cells: 3,
|
||||
},
|
||||
Self {
|
||||
name: "Buggy 4S".to_string(),
|
||||
control_source: "steam".to_string(),
|
||||
controller_expo: 0.25,
|
||||
controller_deadzone: 0.06,
|
||||
controller_invert_steering: false,
|
||||
gaz_avant_min: 1065,
|
||||
gear_1_max: 1120,
|
||||
gear_2_max: 1200,
|
||||
gear_3_max: 1320,
|
||||
gaz_arriere_min: 905,
|
||||
gear_reverse_max: 780,
|
||||
projection_mode: "dome".to_string(),
|
||||
camera_fov_deg: 140.0,
|
||||
lens_k1: -0.14,
|
||||
screen_distance_m: 1.6,
|
||||
battery_cells: 4,
|
||||
},
|
||||
Self {
|
||||
name: "Aile FPV".to_string(),
|
||||
control_source: "steam".to_string(),
|
||||
controller_expo: 0.15,
|
||||
controller_deadzone: 0.05,
|
||||
controller_invert_steering: false,
|
||||
gaz_avant_min: 1065,
|
||||
gear_1_max: 1180,
|
||||
gear_2_max: 1350,
|
||||
gear_3_max: 1650,
|
||||
gaz_arriere_min: 905,
|
||||
gear_reverse_max: 800,
|
||||
projection_mode: "cylinder".to_string(),
|
||||
camera_fov_deg: 150.0,
|
||||
lens_k1: -0.10,
|
||||
screen_distance_m: 1.8,
|
||||
battery_cells: 0, // Auto 3S..6S
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
pub fn from_config(name: impl Into<String>, cfg: &AppConfig) -> Self {
|
||||
Self {
|
||||
name: name.into(),
|
||||
control_source: cfg.control_source.clone(),
|
||||
controller_expo: cfg.controller_expo,
|
||||
controller_deadzone: cfg.controller_deadzone,
|
||||
controller_invert_steering: cfg.controller_invert_steering,
|
||||
gaz_avant_min: cfg.gaz_avant_min,
|
||||
gear_1_max: cfg.gear_1_max,
|
||||
gear_2_max: cfg.gear_2_max,
|
||||
gear_3_max: cfg.gear_3_max,
|
||||
gaz_arriere_min: cfg.gaz_arriere_min,
|
||||
gear_reverse_max: cfg.gear_reverse_max,
|
||||
projection_mode: cfg.projection_mode.clone(),
|
||||
camera_fov_deg: cfg.camera_fov_deg,
|
||||
lens_k1: cfg.lens_k1,
|
||||
screen_distance_m: cfg.screen_distance_m,
|
||||
battery_cells: cfg.battery_cells,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn apply_to(&self, cfg: &mut AppConfig) {
|
||||
cfg.active_profile = self.name.clone();
|
||||
cfg.control_source = self.control_source.clone();
|
||||
cfg.controller_expo = self.controller_expo;
|
||||
cfg.controller_deadzone = self.controller_deadzone;
|
||||
cfg.controller_invert_steering = self.controller_invert_steering;
|
||||
cfg.gaz_avant_min = self.gaz_avant_min;
|
||||
cfg.gear_1_max = self.gear_1_max;
|
||||
cfg.gear_2_max = self.gear_2_max;
|
||||
cfg.gear_3_max = self.gear_3_max;
|
||||
cfg.gaz_arriere_min = self.gaz_arriere_min;
|
||||
cfg.gear_reverse_max = self.gear_reverse_max;
|
||||
cfg.projection_mode = self.projection_mode.clone();
|
||||
cfg.camera_fov_deg = self.camera_fov_deg;
|
||||
cfg.lens_k1 = self.lens_k1;
|
||||
cfg.screen_distance_m = self.screen_distance_m;
|
||||
cfg.battery_cells = self.battery_cells;
|
||||
}
|
||||
|
||||
pub fn profiles_dir() -> Option<PathBuf> {
|
||||
AppConfig::default_config_path()
|
||||
.and_then(|p| p.parent().map(|d| d.join("profiles")))
|
||||
}
|
||||
|
||||
pub fn sanitize_filename(name: &str) -> String {
|
||||
let s: String = name
|
||||
.chars()
|
||||
.map(|c| {
|
||||
if c.is_ascii_alphanumeric() || c == '-' || c == '_' {
|
||||
c.to_ascii_lowercase()
|
||||
} else {
|
||||
'_'
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let trimmed = s.trim_matches('_');
|
||||
if trimmed.is_empty() {
|
||||
"custom".to_string()
|
||||
} else {
|
||||
trimmed.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_toml_string(&self) -> String {
|
||||
format!(
|
||||
"name = \"{}\"\n\
|
||||
control_source = \"{}\"\n\
|
||||
controller_expo = {:.3}\n\
|
||||
controller_deadzone = {:.3}\n\
|
||||
controller_invert_steering = {}\n\
|
||||
gaz_avant_min = {}\n\
|
||||
gear_1_max = {}\n\
|
||||
gear_2_max = {}\n\
|
||||
gear_3_max = {}\n\
|
||||
gaz_arriere_min = {}\n\
|
||||
gear_reverse_max = {}\n\
|
||||
projection_mode = \"{}\"\n\
|
||||
camera_fov_deg = {:.2}\n\
|
||||
lens_k1 = {:.4}\n\
|
||||
screen_distance_m = {:.3}\n\
|
||||
battery_cells = {}\n",
|
||||
self.name.replace('"', "\\\""),
|
||||
self.control_source,
|
||||
self.controller_expo,
|
||||
self.controller_deadzone,
|
||||
self.controller_invert_steering,
|
||||
self.gaz_avant_min,
|
||||
self.gear_1_max,
|
||||
self.gear_2_max,
|
||||
self.gear_3_max,
|
||||
self.gaz_arriere_min,
|
||||
self.gear_reverse_max,
|
||||
self.projection_mode,
|
||||
self.camera_fov_deg,
|
||||
self.lens_k1,
|
||||
self.screen_distance_m,
|
||||
self.battery_cells,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn parse_toml(raw: &str) -> Option<Self> {
|
||||
let map = AppConfig::parse_toml_kv(raw);
|
||||
let name = map.get("name")?.clone();
|
||||
let mut base = Self::builtin_presets()[0].clone();
|
||||
base.name = name;
|
||||
if let Some(v) = map.get("control_source") { base.control_source = v.clone(); }
|
||||
if let Some(v) = map.get("controller_expo").and_then(|s| s.parse().ok()) { base.controller_expo = v; }
|
||||
if let Some(v) = map.get("controller_deadzone").and_then(|s| s.parse().ok()) { base.controller_deadzone = v; }
|
||||
if let Some(v) = map.get("controller_invert_steering").and_then(|s| s.parse().ok()) { base.controller_invert_steering = v; }
|
||||
if let Some(v) = map.get("gaz_avant_min").and_then(|s| s.parse().ok()) { base.gaz_avant_min = v; }
|
||||
if let Some(v) = map.get("gear_1_max").and_then(|s| s.parse().ok()) { base.gear_1_max = v; }
|
||||
if let Some(v) = map.get("gear_2_max").and_then(|s| s.parse().ok()) { base.gear_2_max = v; }
|
||||
if let Some(v) = map.get("gear_3_max").and_then(|s| s.parse().ok()) { base.gear_3_max = v; }
|
||||
if let Some(v) = map.get("gaz_arriere_min").and_then(|s| s.parse().ok()) { base.gaz_arriere_min = v; }
|
||||
if let Some(v) = map.get("gear_reverse_max").and_then(|s| s.parse().ok()) { base.gear_reverse_max = v; }
|
||||
if let Some(v) = map.get("projection_mode") { base.projection_mode = v.clone(); }
|
||||
if let Some(v) = map.get("camera_fov_deg").and_then(|s| s.parse().ok()) { base.camera_fov_deg = v; }
|
||||
if let Some(v) = map.get("lens_k1").and_then(|s| s.parse().ok()) { base.lens_k1 = v; }
|
||||
if let Some(v) = map.get("screen_distance_m").and_then(|s| s.parse().ok()) { base.screen_distance_m = v; }
|
||||
if let Some(v) = map.get("battery_cells").and_then(|s| s.parse().ok()) { base.battery_cells = v; }
|
||||
Some(base)
|
||||
}
|
||||
|
||||
pub fn save_to_disk(&self) -> Result<PathBuf> {
|
||||
let dir = Self::profiles_dir()
|
||||
.ok_or_else(|| anyhow::anyhow!("Impossible de déterminer le dossier des profils"))?;
|
||||
fs::create_dir_all(&dir)?;
|
||||
let path = dir.join(format!("{}.toml", Self::sanitize_filename(&self.name)));
|
||||
let content = self.to_toml_string();
|
||||
let tmp = path.with_extension("toml.tmp");
|
||||
fs::write(&tmp, content)?;
|
||||
fs::rename(&tmp, &path)?;
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
/// Retourne les profils intégrés fusionnés avec les profils personnalisés de `~/.config/steamframe-fpv/profiles/`.
|
||||
pub fn list_all() -> Vec<Self> {
|
||||
let mut profiles = Self::builtin_presets();
|
||||
if let Some(dir) = Self::profiles_dir() {
|
||||
if let Ok(entries) = fs::read_dir(dir) {
|
||||
for entry in entries.flatten() {
|
||||
let path = entry.path();
|
||||
if path.extension().and_then(|e| e.to_str()) == Some("toml") {
|
||||
if let Ok(raw) = fs::read_to_string(&path) {
|
||||
if let Some(parsed) = Self::parse_toml(&raw) {
|
||||
if let Some(existing) = profiles
|
||||
.iter_mut()
|
||||
.find(|p| p.name.eq_ignore_ascii_case(&parsed.name))
|
||||
{
|
||||
*existing = parsed;
|
||||
} else {
|
||||
profiles.push(parsed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
profiles
|
||||
}
|
||||
}
|
||||
|
||||
impl AppConfig {
|
||||
/// Retourne le chemin XDG du fichier de configuration persistant (`~/.config/steamframe-fpv/config.toml`).
|
||||
pub fn default_config_path() -> Option<PathBuf> {
|
||||
@@ -227,9 +496,27 @@ impl AppConfig {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Si --vrx-video-profile est fourni sans --video-width/--video-height explicites, aligner la résolution cible
|
||||
if matches.value_source("video_width") != Some(ValueSource::CommandLine)
|
||||
&& matches.value_source("video_height") != Some(ValueSource::CommandLine)
|
||||
&& matches.value_source("vrx_video_profile") == Some(ValueSource::CommandLine)
|
||||
{
|
||||
if let Some((w, h)) = Self::profile_dimensions(&cfg.vrx_video_profile) {
|
||||
cfg.video_width = w;
|
||||
cfg.video_height = h;
|
||||
}
|
||||
}
|
||||
cfg
|
||||
}
|
||||
|
||||
pub fn profile_dimensions(profile: &str) -> Option<(u32, u32)> {
|
||||
match profile.trim().to_ascii_lowercase().as_str() {
|
||||
"720p60" | "720p120" => Some((1280, 720)),
|
||||
"1080p60" | "1080p90" => Some((1920, 1080)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Sérialise les réglages pilote au format TOML propre et lisible.
|
||||
pub fn to_toml_string(&self) -> String {
|
||||
fn esc(s: &str) -> String {
|
||||
@@ -280,7 +567,13 @@ impl AppConfig {
|
||||
gear_reverse_max = {}\n\n\
|
||||
dvr_dir = \"{}\"\n\
|
||||
dvr_format = \"{}\"\n\
|
||||
dvr_mode = \"{}\"\n",
|
||||
dvr_mode = \"{}\"\n\n\
|
||||
battery_cells = {}\n\
|
||||
battery_warn_cell_v = {:.2}\n\
|
||||
battery_crit_cell_v = {:.2}\n\
|
||||
osd_show_video_stats = {}\n\
|
||||
osd_show_gps = {}\n\
|
||||
active_profile = \"{}\"\n",
|
||||
esc(&self.usb_video_mode),
|
||||
esc(&self.uvc_device),
|
||||
esc(&self.usb_bind_ip),
|
||||
@@ -324,6 +617,12 @@ impl AppConfig {
|
||||
esc(&self.dvr_dir),
|
||||
esc(&self.dvr_format),
|
||||
esc(&self.dvr_mode),
|
||||
self.battery_cells,
|
||||
self.battery_warn_cell_v,
|
||||
self.battery_crit_cell_v,
|
||||
self.osd_show_video_stats,
|
||||
self.osd_show_gps,
|
||||
esc(&self.active_profile),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -456,6 +755,13 @@ impl AppConfig {
|
||||
load_str!(dvr_format);
|
||||
load_str!(dvr_mode);
|
||||
|
||||
load_parse!(battery_cells);
|
||||
load_parse!(battery_warn_cell_v);
|
||||
load_parse!(battery_crit_cell_v);
|
||||
load_parse!(osd_show_video_stats);
|
||||
load_parse!(osd_show_gps);
|
||||
load_str!(active_profile);
|
||||
|
||||
// Sécurité bornes numériques
|
||||
self.video_width = self.video_width.clamp(320, 3840);
|
||||
self.video_height = self.video_height.clamp(240, 2160);
|
||||
@@ -463,6 +769,9 @@ impl AppConfig {
|
||||
self.lens_k1 = self.lens_k1.clamp(-0.50, 0.25);
|
||||
self.screen_distance_m = self.screen_distance_m.clamp(0.5, 5.0);
|
||||
self.controller_vibration = self.controller_vibration.min(100);
|
||||
self.battery_cells = self.battery_cells.min(6);
|
||||
self.battery_warn_cell_v = self.battery_warn_cell_v.clamp(3.0, 4.2);
|
||||
self.battery_crit_cell_v = self.battery_crit_cell_v.clamp(2.8, self.battery_warn_cell_v);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -500,4 +809,30 @@ mod tests {
|
||||
// L'argument CLI explicite doit garder priorité sur config.toml
|
||||
assert_eq!(loaded.wifi_channel, 149);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vehicle_profile_presets_and_apply_roundtrip() {
|
||||
let presets = VehicleProfile::builtin_presets();
|
||||
assert_eq!(presets.len(), 3);
|
||||
let buggy = presets
|
||||
.iter()
|
||||
.find(|p| p.name.contains("Buggy"))
|
||||
.expect("Preset Buggy 4S présent");
|
||||
assert_eq!(buggy.battery_cells, 4);
|
||||
|
||||
let mut cfg = AppConfig::parse_from(["steamframe-fpv"]);
|
||||
buggy.apply_to(&mut cfg);
|
||||
assert_eq!(cfg.active_profile, buggy.name);
|
||||
assert_eq!(cfg.battery_cells, 4);
|
||||
assert_eq!(cfg.gear_3_max, buggy.gear_3_max);
|
||||
assert!((cfg.lens_k1 - buggy.lens_k1).abs() < 0.001);
|
||||
|
||||
let extracted = VehicleProfile::from_config("Test Profile", &cfg);
|
||||
let toml_text = extracted.to_toml_string();
|
||||
let parsed = VehicleProfile::parse_toml(&toml_text).expect("TOML profil valide");
|
||||
assert_eq!(parsed.name, "Test Profile");
|
||||
assert_eq!(parsed.battery_cells, 4);
|
||||
assert_eq!(parsed.gear_3_max, buggy.gear_3_max);
|
||||
assert!((parsed.camera_fov_deg - buggy.camera_fov_deg).abs() < 0.01);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user