feat: integrate tangential force HUD

This commit is contained in:
lenn
2026-05-20 08:33:20 +08:00
parent 59e9203363
commit 6187976b6b
8 changed files with 1058 additions and 82 deletions

View File

@@ -13,6 +13,7 @@ pub struct HudPacket {
pub panels: Vec<HudSignalPanel>,
pub summary: HudSummary,
pub pressure_matrix: Option<Vec<f32>>,
pub spatial_force: Option<HudSpatialForce>,
}
#[derive(serde::Serialize, Clone)]
@@ -74,6 +75,14 @@ pub struct HudSignalIcon {
pub tone: HudTone,
}
#[derive(serde::Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct HudSpatialForce {
pub angle_deg: f32,
pub magnitude: f32,
pub confidence: f32,
}
struct HudPanelUpdate {
source_id: String,
values: Vec<f32>,
@@ -89,6 +98,7 @@ pub struct HudChartState {
order: Vec<String>,
summary_points: Vec<f32>,
pressure_matrix: Option<Vec<f32>>,
spatial_force: Option<HudSpatialForce>,
last_frame_seen: Option<Instant>,
}
@@ -99,6 +109,7 @@ impl HudChartState {
order: Vec::new(),
summary_points: Vec::new(),
pressure_matrix: None,
spatial_force: None,
last_frame_seen: None,
}
}
@@ -115,6 +126,10 @@ impl HudChartState {
self.pressure_matrix = Some(values.iter().map(|value| *value as f32).collect());
}
pub fn record_spatial_force(&mut self, spatial_force: Option<HudSpatialForce>) {
self.spatial_force = spatial_force;
}
pub fn apply_frame(&mut self, frame: &TestFrame, decoded_values: Option<&[i32]>) -> HudPacket {
let now = Instant::now();
self.last_frame_seen = Some(now);
@@ -130,9 +145,15 @@ impl HudChartState {
pub fn prune_stale(&mut self) -> Option<HudPacket> {
let before = self.panels.len();
let summary_points_before = self.summary_points.len();
let had_pressure_matrix = self.pressure_matrix.is_some();
let had_spatial_force = self.spatial_force.is_some();
self.prune_stale_at(Instant::now());
if before == self.panels.len() && summary_points_before == self.summary_points.len() {
if before == self.panels.len()
&& summary_points_before == self.summary_points.len()
&& had_pressure_matrix == self.pressure_matrix.is_some()
&& had_spatial_force == self.spatial_force.is_some()
{
return None;
}
@@ -187,6 +208,7 @@ impl HudChartState {
if summary_stale {
self.summary_points.clear();
self.pressure_matrix = None;
self.spatial_force = None;
self.last_frame_seen = None;
}
}
@@ -205,6 +227,7 @@ impl HudChartState {
panels,
summary: build_summary(&self.summary_points),
pressure_matrix: self.pressure_matrix.clone(),
spatial_force: self.spatial_force.clone(),
}
}