diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index c86f43b..22d04b6 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -16,6 +16,7 @@ crate-type = ["staticlib", "cdylib", "rlib"] [features] default = ["multi-dim"] +debug = [] devkit = ["dep:tonic", "dep:prost", "dep:prost-types", "dep:async-stream", "dep:dirs"] multi-dim = ["dep:ndarray"] diff --git a/src-tauri/src/commands/serial.rs b/src-tauri/src/commands/serial.rs index c81f470..e6bebcd 100644 --- a/src-tauri/src/commands/serial.rs +++ b/src-tauri/src/commands/serial.rs @@ -122,8 +122,7 @@ pub fn serial_enum() -> Result, SerialError> { .into_iter() .filter_map(|p| { let name = p.port_name; - #[cfg(unix)] - if !name.contains("USB") { + if !should_include_serial_port(&name) { return None; } Some(name) @@ -133,6 +132,21 @@ pub fn serial_enum() -> Result, SerialError> { Ok(ports) } +#[cfg(target_os = "macos")] +fn should_include_serial_port(name: &str) -> bool { + name.to_ascii_lowercase().contains("usb") +} + +#[cfg(all(unix, not(target_os = "macos")))] +fn should_include_serial_port(name: &str) -> bool { + name.contains("USB") +} + +#[cfg(not(unix))] +fn should_include_serial_port(_name: &str) -> bool { + true +} + #[tauri::command] pub async fn serial_connect( app: AppHandle, diff --git a/src-tauri/src/serial_core/serial.rs b/src-tauri/src/serial_core/serial.rs index d78ab4f..acaa334 100644 --- a/src-tauri/src/serial_core/serial.rs +++ b/src-tauri/src/serial_core/serial.rs @@ -327,12 +327,15 @@ where } } } - #[cfg(feature = "devkit")] - { - let summary = vals.iter().copied().sum::(); - 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::(); + // #[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, ) -> Option> { let summary = values.iter().copied().sum::(); + #[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 { 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();