refactor: add debug feature flag and cross-platform serial port filtering

This commit is contained in:
lenn
2026-06-09 14:27:30 +08:00
parent 8533747670
commit 821800beb1
3 changed files with 39 additions and 14 deletions

View File

@@ -327,12 +327,15 @@ where
}
}
}
#[cfg(feature = "devkit")]
{
let summary = vals.iter().copied().sum::<i32>();
let force = raw_to_g1(summary as u32);
push_devkit_frame(&app, vals.as_slice(), frame.dts_ms(), force);
}
// #[cfg(feature = "devkit")]
// {
// let summary = vals.iter().copied().sum::<i32>();
// #[cfg(feature = "debug")]
// let force = raw_to_g1(summary as u32);
// #[cfg(not(feature = "debug"))]
// let force = summary as f64;
// push_devkit_frame(&app, vals.as_slice(), frame.dts_ms(), force);
// }
pending_sub_frame = Some(PendingSubFrame {
frame: frame.clone(),
@@ -355,6 +358,11 @@ fn build_display_values(
spatial_force: Option<HudSpatialForce>,
) -> Option<Vec<i32>> {
let summary = values.iter().copied().sum::<i32>();
#[cfg(feature = "debug")]
{
let g1 = raw_to_g1(summary as u32);
println!("raw_to_g1 map: {g1}");
}
chart_state.record_spatial_force(spatial_force);
match ad_to_x(summary as f64) {
@@ -380,11 +388,12 @@ fn build_display_values(
const MIN_DISPLAY_FORCE: f64 = 0.1;
const MAX_DISPLAY_FORCE: f64 = 25.6;
const QUADRATIC_A: f64 = -375.2;
const QUADRATIC_B: f64 = 25880.0;
const QUADRATIC_C: f64 = 52150.0;
fn ad_to_x(ad: f64) -> Option<f64> {
const CUBIC_LIMIT: f64 = 6.57;
const QUADRATIC_A: f64 = -377.8;
const QUADRATIC_B: f64 = 26040.0;
const EPSILON: f64 = 0.000_001;
let cubic_min = ad_from_cubic_x(0.0);
@@ -429,7 +438,7 @@ fn ad_from_cubic_x(x: f64) -> f64 {
}
fn ad_from_quadratic_x(x: f64) -> f64 {
-377.8 * x.powi(2) + 26040.0 * x + 51120.0
QUADRATIC_A * x.powi(2) + QUADRATIC_B * x + QUADRATIC_C
}
#[cfg(feature = "devkit")]
@@ -484,14 +493,15 @@ fn infer_matrix_shape(len: usize) -> (u32, u32) {
(best.0 as u32, best.1 as u32)
}
#[cfg(feature = "devkit")]
#[cfg(feature = "debug")]
#[allow(dead_code)]
fn raw_to_g1(raw: u32) -> f64 {
const X: [u32; 12] = [
0, 84402, 117218, 140176, 159126, 175812, 191484, 208758, 224703, 252448, 302361, 352703,
0, 20829, 102371, 132956, 165568, 182033, 217263, 263098, 283747, 365120, 410556, 477190
];
const Y: [f64; 12] = [
0.0, 160.0, 260.0, 360.0, 460.0, 560.0, 660.0, 760.0, 860.0, 1060.0, 1560.0, 2060.0,
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0, 2557.0
];
let n = X.len();