Compare commits
2 Commits
waic-hand-
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d93a6694cf | ||
|
|
0d1296c482 |
108
src/app.rs
108
src/app.rs
@@ -3,26 +3,26 @@ use crate::connection::ConnectionManager;
|
|||||||
use crate::force::{ForceEstimatorState, HudSpatialForce};
|
use crate::force::{ForceEstimatorState, HudSpatialForce};
|
||||||
use crate::recording::Recorder;
|
use crate::recording::Recorder;
|
||||||
use crate::render::{ActiveMode, FingerMode, HandGatewayMode};
|
use crate::render::{ActiveMode, FingerMode, HandGatewayMode};
|
||||||
use crate::style::{ONE_DARK_PRO, apply_fonts, apply_theme, layout};
|
use crate::style::{self, ONE_DARK_PRO, apply_fonts, apply_theme, dim_text, layout};
|
||||||
use crate::ui::SerialMode;
|
use crate::ui::SerialMode;
|
||||||
use crate::{
|
use crate::{
|
||||||
matrix::{MATRIX_COLS, MATRIX_ROWS},
|
matrix::{MATRIX_COLS, MATRIX_ROWS, UNFOLDED_SENSOR_SEGMENT_COUNTS},
|
||||||
render::{
|
render::{
|
||||||
BackgroundRenderResources, PRESSURE_CELL_COUNT, PressureFrame, PressureSamples,
|
BackgroundRenderResources, PRESSURE_CELL_COUNT, PressureFrame, PressureSamples,
|
||||||
WgpuBackgroundCallback,
|
WgpuBackgroundCallback,
|
||||||
},
|
},
|
||||||
ui::{
|
ui::{
|
||||||
ConfigPanelState, ConnectPanelState, FloatingPanelState, MatrixConfigState,
|
ConfigPanelState, ConnectPanelState, FloatingPanelState, MatrixConfigState,
|
||||||
draw_config_panel, draw_export_panel, draw_hand_force_panels, draw_matrix_config_panel,
|
draw_config_panel, draw_export_panel, draw_hand_force_panels, draw_stats_panel,
|
||||||
draw_stats_panel, panel_restore_item,
|
panel_restore_item,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use eframe::{egui, egui_wgpu};
|
use eframe::{egui, egui_wgpu};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
const SUMMARY_POINTS_PER_SERIES: usize = 42;
|
const SUMMARY_POINTS_PER_SERIES: usize = 42;
|
||||||
const HAND_FORCE_PANEL_COUNT: usize = 7;
|
const HAND_FORCE_PANEL_COUNT: usize = UNFOLDED_SENSOR_SEGMENT_COUNTS.len();
|
||||||
const HAND_FORCE_SEGMENT_COUNTS: [usize; HAND_FORCE_PANEL_COUNT] = [84, 84, 84, 84, 84, 70, 44];
|
const HAND_FORCE_SEGMENT_COUNTS: [usize; HAND_FORCE_PANEL_COUNT] = UNFOLDED_SENSOR_SEGMENT_COUNTS;
|
||||||
|
|
||||||
pub struct EskinDesktopApp {
|
pub struct EskinDesktopApp {
|
||||||
connect_panel: FloatingPanelState,
|
connect_panel: FloatingPanelState,
|
||||||
@@ -159,15 +159,15 @@ impl EskinDesktopApp {
|
|||||||
let color = egui::Color32::from_rgb(255, 196, 54);
|
let color = egui::Color32::from_rgb(255, 196, 54);
|
||||||
let glow = egui::Color32::from_rgba_unmultiplied(255, 196, 54, 58);
|
let glow = egui::Color32::from_rgba_unmultiplied(255, 196, 54, 58);
|
||||||
|
|
||||||
painter.line_segment([center, end], egui::Stroke::new(9.0, glow));
|
painter.line_segment([center, end], egui::Stroke::new(9.0_f32, glow));
|
||||||
painter.line_segment([center, end], egui::Stroke::new(2.4, color));
|
painter.line_segment([center, end], egui::Stroke::new(2.4_f32, color));
|
||||||
painter.line_segment(
|
painter.line_segment(
|
||||||
[end, end - direction * 14.0 + side * 7.0],
|
[end, end - direction * 14.0 + side * 7.0],
|
||||||
egui::Stroke::new(2.4, color),
|
egui::Stroke::new(2.4_f32, color),
|
||||||
);
|
);
|
||||||
painter.line_segment(
|
painter.line_segment(
|
||||||
[end, end - direction * 14.0 - side * 7.0],
|
[end, end - direction * 14.0 - side * 7.0],
|
||||||
egui::Stroke::new(2.4, color),
|
egui::Stroke::new(2.4_f32, color),
|
||||||
);
|
);
|
||||||
painter.circle_filled(center, 4.2, color);
|
painter.circle_filled(center, 4.2, color);
|
||||||
}
|
}
|
||||||
@@ -218,6 +218,12 @@ impl EskinDesktopApp {
|
|||||||
|
|
||||||
fn update_pressure_matrix(&mut self) {
|
fn update_pressure_matrix(&mut self) {
|
||||||
if let Some(sample) = self.connection.take_latest_sample() {
|
if let Some(sample) = self.connection.take_latest_sample() {
|
||||||
|
if self.config_state.mode == SerialMode::Finger3D {
|
||||||
|
eprintln!(
|
||||||
|
"[3d-rawdata] rows={} cols={} values={:?}",
|
||||||
|
sample.rows, sample.cols, sample.matrix
|
||||||
|
);
|
||||||
|
}
|
||||||
normalize_pressure_sample(
|
normalize_pressure_sample(
|
||||||
&sample.matrix,
|
&sample.matrix,
|
||||||
sample.rows,
|
sample.rows,
|
||||||
@@ -244,10 +250,6 @@ impl EskinDesktopApp {
|
|||||||
if self.signal_history.len() > SUMMARY_POINTS_PER_SERIES {
|
if self.signal_history.len() > SUMMARY_POINTS_PER_SERIES {
|
||||||
self.signal_history.remove(0);
|
self.signal_history.remove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.config_state.mode == SerialMode::Hand {
|
|
||||||
update_hand_signal_histories(&mut self.hand_signal_histories, &sample.matrix);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,7 +267,7 @@ impl EskinDesktopApp {
|
|||||||
);
|
);
|
||||||
ui.painter().line_segment(
|
ui.painter().line_segment(
|
||||||
[title_bar_rect.left_bottom(), title_bar_rect.right_bottom()],
|
[title_bar_rect.left_bottom(), title_bar_rect.right_bottom()],
|
||||||
egui::Stroke::new(1.0, ONE_DARK_PRO.border),
|
egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Drag-to-move: double-click to maximize, drag to move
|
// Drag-to-move: double-click to maximize, drag to move
|
||||||
@@ -306,14 +308,14 @@ impl EskinDesktopApp {
|
|||||||
btn_close_center + egui::vec2(-3.0, -3.0),
|
btn_close_center + egui::vec2(-3.0, -3.0),
|
||||||
btn_close_center + egui::vec2(3.0, 3.0),
|
btn_close_center + egui::vec2(3.0, 3.0),
|
||||||
],
|
],
|
||||||
egui::Stroke::new(1.5, egui::Color32::from_rgb(80, 0, 0)),
|
egui::Stroke::new(1.5_f32, egui::Color32::from_rgb(80, 0, 0)),
|
||||||
);
|
);
|
||||||
ui.painter().line_segment(
|
ui.painter().line_segment(
|
||||||
[
|
[
|
||||||
btn_close_center + egui::vec2(3.0, -3.0),
|
btn_close_center + egui::vec2(3.0, -3.0),
|
||||||
btn_close_center + egui::vec2(-3.0, 3.0),
|
btn_close_center + egui::vec2(-3.0, 3.0),
|
||||||
],
|
],
|
||||||
egui::Stroke::new(1.5, egui::Color32::from_rgb(80, 0, 0)),
|
egui::Stroke::new(1.5_f32, egui::Color32::from_rgb(80, 0, 0)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if close_resp.clicked() {
|
if close_resp.clicked() {
|
||||||
@@ -332,7 +334,7 @@ impl EskinDesktopApp {
|
|||||||
btn_min_center + egui::vec2(-3.0, 0.0),
|
btn_min_center + egui::vec2(-3.0, 0.0),
|
||||||
btn_min_center + egui::vec2(3.0, 0.0),
|
btn_min_center + egui::vec2(3.0, 0.0),
|
||||||
],
|
],
|
||||||
egui::Stroke::new(1.5, egui::Color32::from_rgb(120, 80, 0)),
|
egui::Stroke::new(1.5_f32, egui::Color32::from_rgb(120, 80, 0)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if min_resp.clicked() {
|
if min_resp.clicked() {
|
||||||
@@ -351,7 +353,7 @@ impl EskinDesktopApp {
|
|||||||
ui.painter().rect_stroke(
|
ui.painter().rect_stroke(
|
||||||
egui::Rect::from_center_size(btn_max_center, egui::vec2(s * 2.0, s * 2.0)),
|
egui::Rect::from_center_size(btn_max_center, egui::vec2(s * 2.0, s * 2.0)),
|
||||||
egui::CornerRadius::same(1),
|
egui::CornerRadius::same(1),
|
||||||
egui::Stroke::new(1.5, egui::Color32::from_rgb(0, 80, 10)),
|
egui::Stroke::new(1.5_f32, egui::Color32::from_rgb(0, 80, 10)),
|
||||||
egui::StrokeKind::Outside,
|
egui::StrokeKind::Outside,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -362,7 +364,11 @@ impl EskinDesktopApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_floating_panels(&mut self, ctx: &egui::Context) {
|
fn draw_floating_panels(
|
||||||
|
&mut self,
|
||||||
|
ctx: &egui::Context,
|
||||||
|
stats: crate::serial_core::serial::SerialIoStats,
|
||||||
|
) {
|
||||||
// draw_scene_panel(ctx, &mut self.scene_panel);
|
// draw_scene_panel(ctx, &mut self.scene_panel);
|
||||||
// if self.config_state.mode == SerialMode::Hand && self.stats_panel.visible {
|
// if self.config_state.mode == SerialMode::Hand && self.stats_panel.visible {
|
||||||
// self.config_panel.visible = false;
|
// self.config_panel.visible = false;
|
||||||
@@ -376,6 +382,9 @@ impl EskinDesktopApp {
|
|||||||
&mut self.config_state,
|
&mut self.config_state,
|
||||||
&self.connection,
|
&self.connection,
|
||||||
&self.recorder,
|
&self.recorder,
|
||||||
|
stats,
|
||||||
|
100.0,
|
||||||
|
100.0,
|
||||||
) {
|
) {
|
||||||
self.switch_mode(next_mode);
|
self.switch_mode(next_mode);
|
||||||
}
|
}
|
||||||
@@ -388,6 +397,14 @@ impl EskinDesktopApp {
|
|||||||
self.latest_spatial_force,
|
self.latest_spatial_force,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
SerialMode::Finger3D => {
|
||||||
|
draw_stats_panel(
|
||||||
|
ctx,
|
||||||
|
&mut self.stats_panel,
|
||||||
|
&self.signal_history,
|
||||||
|
self.latest_spatial_force,
|
||||||
|
);
|
||||||
|
}
|
||||||
SerialMode::Hand => {
|
SerialMode::Hand => {
|
||||||
draw_hand_force_panels(ctx, self.stats_panel.visible, &self.hand_signal_histories);
|
draw_hand_force_panels(ctx, self.stats_panel.visible, &self.hand_signal_histories);
|
||||||
}
|
}
|
||||||
@@ -398,7 +415,7 @@ impl EskinDesktopApp {
|
|||||||
&self.recorder,
|
&self.recorder,
|
||||||
&mut self.export_path,
|
&mut self.export_path,
|
||||||
);
|
);
|
||||||
draw_matrix_config_panel(ctx, &mut self.matrix_config_panel, &mut self.matrix_config);
|
// draw_matrix_config_panel(ctx, &mut self.matrix_config_panel, &mut self.matrix_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_panel_context_menu(&mut self, ctx: &egui::Context) {
|
fn draw_panel_context_menu(&mut self, ctx: &egui::Context) {
|
||||||
@@ -491,6 +508,15 @@ impl EskinDesktopApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn switch_mode(&mut self, next: SerialMode) {
|
fn switch_mode(&mut self, next: SerialMode) {
|
||||||
|
if next == SerialMode::Finger3D {
|
||||||
|
// The 3D fingertip PCB sends one 12x9 TactileA frame (108 cells).
|
||||||
|
self.matrix_config = MatrixConfigState {
|
||||||
|
rows: 12,
|
||||||
|
cols: 9,
|
||||||
|
color_min: 0.0,
|
||||||
|
color_max: 7000.0,
|
||||||
|
};
|
||||||
|
}
|
||||||
self.connect_state.mode = next;
|
self.connect_state.mode = next;
|
||||||
self.config_state.mode = next;
|
self.config_state.mode = next;
|
||||||
self.config_state.baud_rate = next.baud_rate();
|
self.config_state.baud_rate = next.baud_rate();
|
||||||
@@ -511,8 +537,10 @@ impl EskinDesktopApp {
|
|||||||
range: 0..7000,
|
range: 0..7000,
|
||||||
dot: true,
|
dot: true,
|
||||||
}),
|
}),
|
||||||
SerialMode::Hand => ActiveMode::Hand(HandGatewayMode { range: 0..7000 }),
|
SerialMode::Finger3D | SerialMode::Hand => {
|
||||||
|
ActiveMode::Hand(HandGatewayMode { range: 0..7000 })
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -590,7 +618,7 @@ fn paint_split_viewport_shell(
|
|||||||
painter.rect_stroke(
|
painter.rect_stroke(
|
||||||
rect,
|
rect,
|
||||||
egui::CornerRadius::same(8),
|
egui::CornerRadius::same(8),
|
||||||
egui::Stroke::new(1.0, ONE_DARK_PRO.border_soft),
|
egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border_soft),
|
||||||
egui::StrokeKind::Outside,
|
egui::StrokeKind::Outside,
|
||||||
);
|
);
|
||||||
painter.line_segment(
|
painter.line_segment(
|
||||||
@@ -598,7 +626,7 @@ fn paint_split_viewport_shell(
|
|||||||
rect.left_top() + egui::vec2(12.0, 34.0),
|
rect.left_top() + egui::vec2(12.0, 34.0),
|
||||||
rect.right_top() + egui::vec2(-12.0, 34.0),
|
rect.right_top() + egui::vec2(-12.0, 34.0),
|
||||||
],
|
],
|
||||||
egui::Stroke::new(1.0, ONE_DARK_PRO.border_soft),
|
egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border_soft),
|
||||||
);
|
);
|
||||||
painter.text(
|
painter.text(
|
||||||
rect.left_top() + egui::vec2(14.0, 16.0),
|
rect.left_top() + egui::vec2(14.0, 16.0),
|
||||||
@@ -660,14 +688,44 @@ fn normalize_pressure_value(value: u32) -> [f32; 2] {
|
|||||||
[mapped, display_value]
|
[mapped, display_value]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw_config_bar_mode(ui: &mut egui::Ui, config: &mut ConfigPanelState) -> Option<SerialMode> {
|
||||||
|
let mut changed_to = None;
|
||||||
|
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.colored_label(dim_text(), "单面指尖");
|
||||||
|
if mode_button(ui, &mut config.mode, SerialMode::Finger, "单面指尖") {
|
||||||
|
changed_to = Some(SerialMode::Finger);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
changed_to
|
||||||
|
}
|
||||||
|
|
||||||
|
fn mode_button(
|
||||||
|
ui: &mut egui::Ui,
|
||||||
|
mode: &mut SerialMode,
|
||||||
|
value: SerialMode,
|
||||||
|
label: &'static str,
|
||||||
|
) -> bool {
|
||||||
|
let clicked = ui.add(style::mode_button(label, *mode == value)).clicked();
|
||||||
|
|
||||||
|
if clicked && *mode != value {
|
||||||
|
*mode = value;
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl eframe::App for EskinDesktopApp {
|
impl eframe::App for EskinDesktopApp {
|
||||||
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
|
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
|
||||||
let ctx = ui.ctx().clone();
|
let ctx = ui.ctx().clone();
|
||||||
|
let stats = self.connection.stats();
|
||||||
|
|
||||||
self.update_pressure_matrix();
|
self.update_pressure_matrix();
|
||||||
self.draw_workspace(ui);
|
self.draw_workspace(ui);
|
||||||
self.draw_title_bar(ui, frame);
|
self.draw_title_bar(ui, frame);
|
||||||
self.draw_floating_panels(&ctx);
|
self.draw_floating_panels(&ctx, stats);
|
||||||
self.draw_panel_context_menu(&ctx);
|
self.draw_panel_context_menu(&ctx);
|
||||||
|
|
||||||
// Keep repainting while the wgpu background is a realtime viewport.
|
// Keep repainting while the wgpu background is a realtime viewport.
|
||||||
|
|||||||
@@ -249,7 +249,11 @@ impl BreakoutGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn launch_ball(&mut self) {
|
fn launch_ball(&mut self) {
|
||||||
let direction = if self.level % 2 == 0 { -0.24 } else { 0.24 };
|
let direction = if self.level.is_multiple_of(2) {
|
||||||
|
-0.24
|
||||||
|
} else {
|
||||||
|
0.24
|
||||||
|
};
|
||||||
self.ball_pos = egui::pos2(self.paddle_x, PADDLE_Y - PADDLE_H - BALL_RADIUS);
|
self.ball_pos = egui::pos2(self.paddle_x, PADDLE_Y - PADDLE_H - BALL_RADIUS);
|
||||||
self.ball_vel = egui::vec2(direction, -1.0).normalized() * BALL_SPEED;
|
self.ball_vel = egui::vec2(direction, -1.0).normalized() * BALL_SPEED;
|
||||||
}
|
}
|
||||||
@@ -372,7 +376,7 @@ impl BreakoutGame {
|
|||||||
painter.rect_stroke(
|
painter.rect_stroke(
|
||||||
rect,
|
rect,
|
||||||
egui::CornerRadius::same(6),
|
egui::CornerRadius::same(6),
|
||||||
egui::Stroke::new(1.0, color_alpha(ONE_DARK_PRO.accent, 110)),
|
egui::Stroke::new(1.0_f32, color_alpha(ONE_DARK_PRO.accent, 110)),
|
||||||
egui::StrokeKind::Outside,
|
egui::StrokeKind::Outside,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -469,7 +473,7 @@ fn circle_hits_rect(center: egui::Pos2, radius: f32, rect: egui::Rect) -> bool {
|
|||||||
fn status_chip(ui: &mut egui::Ui, label: &'static str, value: impl ToString, color: egui::Color32) {
|
fn status_chip(ui: &mut egui::Ui, label: &'static str, value: impl ToString, color: egui::Color32) {
|
||||||
egui::Frame::new()
|
egui::Frame::new()
|
||||||
.fill(color_alpha(ONE_DARK_PRO.panel_deep, 190))
|
.fill(color_alpha(ONE_DARK_PRO.panel_deep, 190))
|
||||||
.stroke(egui::Stroke::new(1.0, color_alpha(color, 92)))
|
.stroke(egui::Stroke::new(1.0_f32, color_alpha(color, 92)))
|
||||||
.corner_radius(egui::CornerRadius::same(4))
|
.corner_radius(egui::CornerRadius::same(4))
|
||||||
.inner_margin(egui::Margin::symmetric(8, 4))
|
.inner_margin(egui::Margin::symmetric(8, 4))
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
@@ -514,7 +518,7 @@ fn paint_arena_grid(painter: &egui::Painter, rect: egui::Rect) {
|
|||||||
painter.rect_stroke(
|
painter.rect_stroke(
|
||||||
rect,
|
rect,
|
||||||
egui::CornerRadius::same(6),
|
egui::CornerRadius::same(6),
|
||||||
egui::Stroke::new(1.0, color_alpha(ONE_DARK_PRO.accent, 70)),
|
egui::Stroke::new(1.0_f32, color_alpha(ONE_DARK_PRO.accent, 70)),
|
||||||
egui::StrokeKind::Inside,
|
egui::StrokeKind::Inside,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -531,7 +535,7 @@ fn paint_brick(painter: &egui::Painter, arena: egui::Rect, brick: &Brick, index:
|
|||||||
painter.rect_stroke(
|
painter.rect_stroke(
|
||||||
rect.expand(4.0 * brick.flash),
|
rect.expand(4.0 * brick.flash),
|
||||||
egui::CornerRadius::same(4),
|
egui::CornerRadius::same(4),
|
||||||
egui::Stroke::new(1.4, color_alpha(ONE_DARK_PRO.accent_hot, alpha)),
|
egui::Stroke::new(1.4_f32, color_alpha(ONE_DARK_PRO.accent_hot, alpha)),
|
||||||
egui::StrokeKind::Outside,
|
egui::StrokeKind::Outside,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -564,7 +568,7 @@ fn paint_control_meter(painter: &egui::Painter, arena: egui::Rect, control: Brea
|
|||||||
painter.rect_stroke(
|
painter.rect_stroke(
|
||||||
meter,
|
meter,
|
||||||
egui::CornerRadius::same(4),
|
egui::CornerRadius::same(4),
|
||||||
egui::Stroke::new(1.0, color_alpha(ONE_DARK_PRO.border, 120)),
|
egui::Stroke::new(1.0_f32, color_alpha(ONE_DARK_PRO.border, 120)),
|
||||||
egui::StrokeKind::Outside,
|
egui::StrokeKind::Outside,
|
||||||
);
|
);
|
||||||
let center_x = meter.center().x;
|
let center_x = meter.center().x;
|
||||||
@@ -573,7 +577,7 @@ fn paint_control_meter(painter: &egui::Painter, arena: egui::Rect, control: Brea
|
|||||||
egui::pos2(center_x, meter.top()),
|
egui::pos2(center_x, meter.top()),
|
||||||
egui::pos2(center_x, meter.bottom()),
|
egui::pos2(center_x, meter.bottom()),
|
||||||
],
|
],
|
||||||
egui::Stroke::new(1.0, ONE_DARK_PRO.border_soft),
|
egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border_soft),
|
||||||
);
|
);
|
||||||
let marker_x = center_x + control.axis.clamp(-1.0, 1.0) * meter.width() * 0.45;
|
let marker_x = center_x + control.axis.clamp(-1.0, 1.0) * meter.width() * 0.45;
|
||||||
painter.circle_filled(
|
painter.circle_filled(
|
||||||
|
|||||||
@@ -179,6 +179,7 @@ impl Default for ConnectionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The blocking device loop that runs on a background thread.
|
/// The blocking device loop that runs on a background thread.
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn run_device_loop(
|
fn run_device_loop(
|
||||||
port_name: &str,
|
port_name: &str,
|
||||||
rows: u32,
|
rows: u32,
|
||||||
|
|||||||
@@ -1,5 +1,31 @@
|
|||||||
pub const MATRIX_ROWS: u32 = 12;
|
pub const MATRIX_ROWS: u32 = 12;
|
||||||
pub const MATRIX_COLS: u32 = 7;
|
pub const MATRIX_COLS: u32 = 7;
|
||||||
|
pub const UNFOLDED_L_CHANNEL_COUNT: usize = 8;
|
||||||
|
pub const UNFOLDED_H_CHANNEL_COUNT: usize = 13;
|
||||||
|
pub const UNFOLDED_SENSOR_COUNT: usize = UNFOLDED_L_CHANNEL_COUNT * UNFOLDED_H_CHANNEL_COUNT;
|
||||||
|
pub const UNFOLDED_SENSOR_SEGMENT_COUNTS: [usize; 10] = [8, 3, 5, 8, 10, 44, 3, 5, 8, 10];
|
||||||
|
|
||||||
|
pub const fn unfolded_lh_sample_index(l: usize, h: usize) -> usize {
|
||||||
|
debug_assert!(l < UNFOLDED_L_CHANNEL_COUNT);
|
||||||
|
debug_assert!(h < UNFOLDED_H_CHANNEL_COUNT);
|
||||||
|
h * UNFOLDED_L_CHANNEL_COUNT + l
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod adc_scan_tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn scan_changes_l_before_advancing_h() {
|
||||||
|
let first_h0_scan = (0..UNFOLDED_L_CHANNEL_COUNT)
|
||||||
|
.map(|l| unfolded_lh_sample_index(l, 0))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
assert_eq!(first_h0_scan, (0..8).collect::<Vec<_>>());
|
||||||
|
assert_eq!(unfolded_lh_sample_index(0, 1), 8);
|
||||||
|
assert_eq!(unfolded_lh_sample_index(7, 12), 103);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const BASE_MATRIX_SPAN: f32 = 24.0;
|
const BASE_MATRIX_SPAN: f32 = 24.0;
|
||||||
const MATRIX_SPAN_GROWTH: f32 = 0.6;
|
const MATRIX_SPAN_GROWTH: f32 = 0.6;
|
||||||
|
|||||||
@@ -145,11 +145,11 @@ impl Recorder {
|
|||||||
r.state == RecordingState::Recording || r.state == RecordingState::Paused,
|
r.state == RecordingState::Recording || r.state == RecordingState::Paused,
|
||||||
"nothing to stop"
|
"nothing to stop"
|
||||||
);
|
);
|
||||||
if r.state == RecordingState::Paused {
|
if r.state == RecordingState::Paused
|
||||||
if let Some(ps) = r.pause_start.take() {
|
&& let Some(ps) = r.pause_start.take()
|
||||||
|
{
|
||||||
r.paused_duration_ms += ps.elapsed().as_millis() as u64;
|
r.paused_duration_ms += ps.elapsed().as_millis() as u64;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
r.state = RecordingState::Idle;
|
r.state = RecordingState::Idle;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -317,16 +317,15 @@ impl Recorder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the start instant so duration_ms() reports the imported span
|
// Set the start instant so duration_ms() reports the imported span
|
||||||
if !r.frames.is_empty() {
|
if !r.frames.is_empty()
|
||||||
if let Some(last) = r.frames.last() {
|
&& let Some(last) = r.frames.last()
|
||||||
|
{
|
||||||
// Pretend the recording happened `last.timestamp_ms` ago
|
// Pretend the recording happened `last.timestamp_ms` ago
|
||||||
// so that elapsed_ms() would return that value.
|
// so that elapsed_ms() would return that value.
|
||||||
// We store a "fake" start by noting the offset.
|
// We store a "fake" start by noting the offset.
|
||||||
r.start =
|
r.start = Some(Instant::now() - std::time::Duration::from_millis(last.timestamp_ms));
|
||||||
Some(Instant::now() - std::time::Duration::from_millis(last.timestamp_ms));
|
|
||||||
r.paused_duration_ms = 0;
|
r.paused_duration_ms = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
528
src/render.rs
528
src/render.rs
@@ -1,5 +1,8 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
matrix::{MatrixLayout, build_view_projection, glyph_world_position},
|
matrix::{
|
||||||
|
MatrixLayout, UNFOLDED_SENSOR_COUNT, build_view_projection, glyph_world_position,
|
||||||
|
unfolded_lh_sample_index,
|
||||||
|
},
|
||||||
model::{AlphaMode, InstanceRaw, ModelVertex, Vertex},
|
model::{AlphaMode, InstanceRaw, ModelVertex, Vertex},
|
||||||
resources, texture,
|
resources, texture,
|
||||||
};
|
};
|
||||||
@@ -70,26 +73,96 @@ const HAND_TIP_MATRICES: [HandTipMatrix; 5] = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const HAND_PALM_CHIPS: [HandPalmChip; 2] = [
|
const UNFOLDED_CANVAS_SIZE: [f32; 2] = [850.0, 750.0];
|
||||||
|
const UNFOLDED_CELL_SPACING_PX: f32 = 42.0;
|
||||||
|
const UNFOLDED_SENSOR_CHIPS: [HandPalmChip; 10] = [
|
||||||
|
// Top cap: 2 rows x 4 columns.
|
||||||
HandPalmChip {
|
HandPalmChip {
|
||||||
center_px: [538.0, 608.0],
|
center_px: [425.0, 165.0],
|
||||||
size_px: [248.0, 82.0],
|
size_px: [176.0, 88.0],
|
||||||
angle_rad: 0.06,
|
angle_rad: 0.0,
|
||||||
rows: 5,
|
rows: 2,
|
||||||
cols: 14,
|
cols: 4,
|
||||||
|
sample_offset: 0,
|
||||||
|
},
|
||||||
|
// Left wing, authored from the outside towards the 11x4 center block.
|
||||||
|
HandPalmChip {
|
||||||
|
center_px: [140.0, 578.0],
|
||||||
|
size_px: [46.0, 132.0],
|
||||||
|
angle_rad: 0.0,
|
||||||
|
rows: 3,
|
||||||
|
cols: 1,
|
||||||
|
sample_offset: 8,
|
||||||
},
|
},
|
||||||
HandPalmChip {
|
HandPalmChip {
|
||||||
center_px: [606.0, 780.0],
|
center_px: [188.0, 534.0],
|
||||||
size_px: [72.0, 214.0],
|
size_px: [46.0, 220.0],
|
||||||
angle_rad: 0.05,
|
angle_rad: 0.0,
|
||||||
|
rows: 5,
|
||||||
|
cols: 1,
|
||||||
|
sample_offset: 11,
|
||||||
|
},
|
||||||
|
HandPalmChip {
|
||||||
|
center_px: [236.0, 468.0],
|
||||||
|
size_px: [46.0, 352.0],
|
||||||
|
angle_rad: 0.0,
|
||||||
|
rows: 8,
|
||||||
|
cols: 1,
|
||||||
|
sample_offset: 16,
|
||||||
|
},
|
||||||
|
HandPalmChip {
|
||||||
|
center_px: [284.0, 424.0],
|
||||||
|
size_px: [46.0, 440.0],
|
||||||
|
angle_rad: 0.0,
|
||||||
|
rows: 10,
|
||||||
|
cols: 1,
|
||||||
|
sample_offset: 24,
|
||||||
|
},
|
||||||
|
// Center spine: 11 rows x 4 columns.
|
||||||
|
HandPalmChip {
|
||||||
|
center_px: [425.0, 444.0],
|
||||||
|
size_px: [176.0, 484.0],
|
||||||
|
angle_rad: 0.0,
|
||||||
rows: 11,
|
rows: 11,
|
||||||
cols: 4,
|
cols: 4,
|
||||||
|
sample_offset: 34,
|
||||||
|
},
|
||||||
|
// Right wing mirrors the left wing. Data remains ordered 3, 5, 8, 10.
|
||||||
|
HandPalmChip {
|
||||||
|
center_px: [710.0, 578.0],
|
||||||
|
size_px: [46.0, 132.0],
|
||||||
|
angle_rad: 0.0,
|
||||||
|
rows: 3,
|
||||||
|
cols: 1,
|
||||||
|
sample_offset: 78,
|
||||||
|
},
|
||||||
|
HandPalmChip {
|
||||||
|
center_px: [662.0, 534.0],
|
||||||
|
size_px: [46.0, 220.0],
|
||||||
|
angle_rad: 0.0,
|
||||||
|
rows: 5,
|
||||||
|
cols: 1,
|
||||||
|
sample_offset: 81,
|
||||||
|
},
|
||||||
|
HandPalmChip {
|
||||||
|
center_px: [614.0, 468.0],
|
||||||
|
size_px: [46.0, 352.0],
|
||||||
|
angle_rad: 0.0,
|
||||||
|
rows: 8,
|
||||||
|
cols: 1,
|
||||||
|
sample_offset: 86,
|
||||||
|
},
|
||||||
|
HandPalmChip {
|
||||||
|
center_px: [566.0, 424.0],
|
||||||
|
size_px: [46.0, 440.0],
|
||||||
|
angle_rad: 0.0,
|
||||||
|
rows: 10,
|
||||||
|
cols: 1,
|
||||||
|
sample_offset: 94,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const HAND_FINGER_SENSOR_CELLS: usize = 12 * 7;
|
const HAND_FINGER_SENSOR_CELLS: usize = 12 * 7;
|
||||||
const HAND_PALM_HORIZONTAL_OFFSET: usize = HAND_FINGER_SENSOR_CELLS * 5;
|
|
||||||
const HAND_PALM_VERTICAL_OFFSET: usize = HAND_PALM_HORIZONTAL_OFFSET + 5 * 14;
|
|
||||||
|
|
||||||
// Each entry pins one miniature matrix to a fingertip in hand.png.
|
// Each entry pins one miniature matrix to a fingertip in hand.png.
|
||||||
// Coordinates are authored in source-image pixels so they are easy to tune by eye.
|
// Coordinates are authored in source-image pixels so they are easy to tune by eye.
|
||||||
@@ -100,14 +173,15 @@ struct HandTipMatrix {
|
|||||||
angle_rad: f32,
|
angle_rad: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Palm chips follow the hand layout: one horizontal 5x14 matrix and one vertical
|
// One block in the flat 270-degree sensor layout. Coordinates use a dedicated
|
||||||
// 11x4 matrix, rendered as dark inset chip tiles on the palm.
|
// 850x750 canvas so the unfolded shape stays prominent across window sizes.
|
||||||
struct HandPalmChip {
|
struct HandPalmChip {
|
||||||
center_px: [f32; 2],
|
center_px: [f32; 2],
|
||||||
size_px: [f32; 2],
|
size_px: [f32; 2],
|
||||||
angle_rad: f32,
|
angle_rad: f32,
|
||||||
rows: u32,
|
rows: u32,
|
||||||
cols: u32,
|
cols: u32,
|
||||||
|
sample_offset: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl egui_wgpu::CallbackTrait for WgpuBackgroundCallback {
|
impl egui_wgpu::CallbackTrait for WgpuBackgroundCallback {
|
||||||
@@ -156,7 +230,6 @@ pub struct BackgroundRenderResources {
|
|||||||
dot_pipeline: wgpu::RenderPipeline,
|
dot_pipeline: wgpu::RenderPipeline,
|
||||||
hand_membrane_pipeline: wgpu::RenderPipeline,
|
hand_membrane_pipeline: wgpu::RenderPipeline,
|
||||||
hand_dot_pipeline: wgpu::RenderPipeline,
|
hand_dot_pipeline: wgpu::RenderPipeline,
|
||||||
hand_palm_chip_pipeline: wgpu::RenderPipeline,
|
|
||||||
hand_palm_dot_pipeline: wgpu::RenderPipeline,
|
hand_palm_dot_pipeline: wgpu::RenderPipeline,
|
||||||
hand_image_bind_group: wgpu::BindGroup,
|
hand_image_bind_group: wgpu::BindGroup,
|
||||||
hand_image_texture: texture::Texture,
|
hand_image_texture: texture::Texture,
|
||||||
@@ -168,8 +241,6 @@ pub struct BackgroundRenderResources {
|
|||||||
hand_membrane_instances: Vec<GlyphInstance>,
|
hand_membrane_instances: Vec<GlyphInstance>,
|
||||||
hand_dot_instance_buffer: wgpu::Buffer,
|
hand_dot_instance_buffer: wgpu::Buffer,
|
||||||
hand_dot_instances: Vec<GlyphInstance>,
|
hand_dot_instances: Vec<GlyphInstance>,
|
||||||
hand_palm_chip_instance_buffer: wgpu::Buffer,
|
|
||||||
hand_palm_chip_instances: Vec<GlyphInstance>,
|
|
||||||
hand_palm_dot_instance_buffer: wgpu::Buffer,
|
hand_palm_dot_instance_buffer: wgpu::Buffer,
|
||||||
hand_palm_dot_instances: Vec<GlyphInstance>,
|
hand_palm_dot_instances: Vec<GlyphInstance>,
|
||||||
render_options: RenderOptions,
|
render_options: RenderOptions,
|
||||||
@@ -277,10 +348,7 @@ impl BackgroundRenderResources {
|
|||||||
build_view_projection(1.0, &layout),
|
build_view_projection(1.0, &layout),
|
||||||
surface_is_srgb,
|
surface_is_srgb,
|
||||||
render_options,
|
render_options,
|
||||||
[
|
UNFOLDED_CANVAS_SIZE,
|
||||||
hand_image_texture.width as f32,
|
|
||||||
hand_image_texture.height as f32,
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
let uniform_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
let uniform_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
label: Some("Pressure Matrix Uniform Buffer"),
|
label: Some("Pressure Matrix Uniform Buffer"),
|
||||||
@@ -497,8 +565,6 @@ impl BackgroundRenderResources {
|
|||||||
create_hand_membrane_pipeline(device, target_format, &shader, &pipeline_layout);
|
create_hand_membrane_pipeline(device, target_format, &shader, &pipeline_layout);
|
||||||
let hand_dot_pipeline =
|
let hand_dot_pipeline =
|
||||||
create_hand_dot_pipeline(device, target_format, &shader, &pipeline_layout);
|
create_hand_dot_pipeline(device, target_format, &shader, &pipeline_layout);
|
||||||
let hand_palm_chip_pipeline =
|
|
||||||
create_hand_palm_chip_pipeline(device, target_format, &shader, &pipeline_layout);
|
|
||||||
let hand_palm_dot_pipeline =
|
let hand_palm_dot_pipeline =
|
||||||
create_hand_palm_dot_pipeline(device, target_format, &shader, &pipeline_layout);
|
create_hand_palm_dot_pipeline(device, target_format, &shader, &pipeline_layout);
|
||||||
|
|
||||||
@@ -551,23 +617,8 @@ impl BackgroundRenderResources {
|
|||||||
contents: bytemuck::cast_slice(&hand_dot_instances),
|
contents: bytemuck::cast_slice(&hand_dot_instances),
|
||||||
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
|
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
|
||||||
});
|
});
|
||||||
let hand_palm_chip_instances = build_hand_palm_chip_instances(
|
let hand_palm_dot_instances =
|
||||||
hand_image_texture.width as f32,
|
build_hand_palm_dot_instances(rows, cols, &[[0.0, 0.0]; PRESSURE_CELL_COUNT]);
|
||||||
hand_image_texture.height as f32,
|
|
||||||
);
|
|
||||||
let hand_palm_chip_instance_buffer =
|
|
||||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
|
||||||
label: Some("Hand Palm Chip Instance Buffer"),
|
|
||||||
contents: bytemuck::cast_slice(&hand_palm_chip_instances),
|
|
||||||
usage: wgpu::BufferUsages::VERTEX,
|
|
||||||
});
|
|
||||||
let hand_palm_dot_instances = build_hand_palm_dot_instances(
|
|
||||||
rows,
|
|
||||||
cols,
|
|
||||||
hand_image_texture.width as f32,
|
|
||||||
hand_image_texture.height as f32,
|
|
||||||
&[[0.0, 0.0]; PRESSURE_CELL_COUNT],
|
|
||||||
);
|
|
||||||
let hand_palm_dot_instance_buffer =
|
let hand_palm_dot_instance_buffer =
|
||||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
label: Some("Hand Palm Chip Dot Instance Buffer"),
|
label: Some("Hand Palm Chip Dot Instance Buffer"),
|
||||||
@@ -589,7 +640,6 @@ impl BackgroundRenderResources {
|
|||||||
dot_pipeline,
|
dot_pipeline,
|
||||||
hand_membrane_pipeline,
|
hand_membrane_pipeline,
|
||||||
hand_dot_pipeline,
|
hand_dot_pipeline,
|
||||||
hand_palm_chip_pipeline,
|
|
||||||
hand_palm_dot_pipeline,
|
hand_palm_dot_pipeline,
|
||||||
hand_image_bind_group,
|
hand_image_bind_group,
|
||||||
hand_image_texture,
|
hand_image_texture,
|
||||||
@@ -600,8 +650,6 @@ impl BackgroundRenderResources {
|
|||||||
hand_membrane_instances,
|
hand_membrane_instances,
|
||||||
hand_dot_instance_buffer,
|
hand_dot_instance_buffer,
|
||||||
hand_dot_instances,
|
hand_dot_instances,
|
||||||
hand_palm_chip_instance_buffer,
|
|
||||||
hand_palm_chip_instances,
|
|
||||||
hand_palm_dot_instance_buffer,
|
hand_palm_dot_instance_buffer,
|
||||||
hand_palm_dot_instances,
|
hand_palm_dot_instances,
|
||||||
render_options,
|
render_options,
|
||||||
@@ -623,10 +671,7 @@ impl BackgroundRenderResources {
|
|||||||
build_view_projection(aspect, &self.layout),
|
build_view_projection(aspect, &self.layout),
|
||||||
self.surface_is_srgb,
|
self.surface_is_srgb,
|
||||||
self.render_options,
|
self.render_options,
|
||||||
[
|
UNFOLDED_CANVAS_SIZE,
|
||||||
self.hand_image_texture.width as f32,
|
|
||||||
self.hand_image_texture.height as f32,
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
queue.write_buffer(
|
queue.write_buffer(
|
||||||
&self.uniform_buffer,
|
&self.uniform_buffer,
|
||||||
@@ -653,8 +698,8 @@ impl BackgroundRenderResources {
|
|||||||
hand_pressure
|
hand_pressure
|
||||||
};
|
};
|
||||||
|
|
||||||
// Hand mode uses UV-anchored fingertip matrices over hand.png.
|
// Keep legacy fingertip buffers current while both hardware modes share
|
||||||
// Rebuild their instance positions here so pressure colors update every frame.
|
// the same renderer resources.
|
||||||
self.hand_dot_instances = build_hand_dot_instances(
|
self.hand_dot_instances = build_hand_dot_instances(
|
||||||
self.rows,
|
self.rows,
|
||||||
self.cols,
|
self.cols,
|
||||||
@@ -668,15 +713,9 @@ impl BackgroundRenderResources {
|
|||||||
bytemuck::cast_slice(&self.hand_dot_instances),
|
bytemuck::cast_slice(&self.hand_dot_instances),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Palm chips reuse the same live 12x7 pressure frame, but draw it as
|
// Rebuild the 104-cell unfolded layout with the latest gateway samples.
|
||||||
// embedded micro-pixels inside dark chip tiles.
|
self.hand_palm_dot_instances =
|
||||||
self.hand_palm_dot_instances = build_hand_palm_dot_instances(
|
build_hand_palm_dot_instances(self.rows, self.cols, hand_pressure);
|
||||||
self.rows,
|
|
||||||
self.cols,
|
|
||||||
self.hand_image_texture.width as f32,
|
|
||||||
self.hand_image_texture.height as f32,
|
|
||||||
hand_pressure,
|
|
||||||
);
|
|
||||||
queue.write_buffer(
|
queue.write_buffer(
|
||||||
&self.hand_palm_dot_instance_buffer,
|
&self.hand_palm_dot_instance_buffer,
|
||||||
0,
|
0,
|
||||||
@@ -692,12 +731,7 @@ impl BackgroundRenderResources {
|
|||||||
|
|
||||||
match active_mode {
|
match active_mode {
|
||||||
ActiveMode::Finger(mode) => self.paint_finger(render_pass, mode),
|
ActiveMode::Finger(mode) => self.paint_finger(render_pass, mode),
|
||||||
ActiveMode::Hand(mode) => {
|
ActiveMode::Hand(mode) => self.paint_hand(render_pass, mode),
|
||||||
render_pass.set_pipeline(&self.hand_image_pipeline);
|
|
||||||
render_pass.set_bind_group(1, &self.hand_image_bind_group, &[]);
|
|
||||||
render_pass.draw(0..6, 0..1);
|
|
||||||
self.paint_hand(render_pass, mode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -719,22 +753,7 @@ impl BackgroundRenderResources {
|
|||||||
fn paint_hand(&self, render_pass: &mut wgpu::RenderPass<'_>, mode: &HandGatewayMode) {
|
fn paint_hand(&self, render_pass: &mut wgpu::RenderPass<'_>, mode: &HandGatewayMode) {
|
||||||
let _range = mode.range.clone();
|
let _range = mode.range.clone();
|
||||||
|
|
||||||
// First draw the translucent sensor membranes, then draw live pressure beads on their grid.
|
// Match Finger mode: draw only the 104 independent pressure dots.
|
||||||
render_pass.set_pipeline(&self.hand_membrane_pipeline);
|
|
||||||
render_pass.set_vertex_buffer(0, self.glyph_vertex_buffer.slice(..));
|
|
||||||
render_pass.set_vertex_buffer(1, self.hand_membrane_instance_buffer.slice(..));
|
|
||||||
render_pass.draw(0..6, 0..self.hand_membrane_instances.len() as u32);
|
|
||||||
|
|
||||||
render_pass.set_pipeline(&self.hand_dot_pipeline);
|
|
||||||
render_pass.set_vertex_buffer(0, self.glyph_vertex_buffer.slice(..));
|
|
||||||
render_pass.set_vertex_buffer(1, self.hand_dot_instance_buffer.slice(..));
|
|
||||||
render_pass.draw(0..6, 0..self.hand_dot_instances.len() as u32);
|
|
||||||
|
|
||||||
render_pass.set_pipeline(&self.hand_palm_chip_pipeline);
|
|
||||||
render_pass.set_vertex_buffer(0, self.glyph_vertex_buffer.slice(..));
|
|
||||||
render_pass.set_vertex_buffer(1, self.hand_palm_chip_instance_buffer.slice(..));
|
|
||||||
render_pass.draw(0..6, 0..self.hand_palm_chip_instances.len() as u32);
|
|
||||||
|
|
||||||
render_pass.set_pipeline(&self.hand_palm_dot_pipeline);
|
render_pass.set_pipeline(&self.hand_palm_dot_pipeline);
|
||||||
render_pass.set_vertex_buffer(0, self.glyph_vertex_buffer.slice(..));
|
render_pass.set_vertex_buffer(0, self.glyph_vertex_buffer.slice(..));
|
||||||
render_pass.set_vertex_buffer(1, self.hand_palm_dot_instance_buffer.slice(..));
|
render_pass.set_vertex_buffer(1, self.hand_palm_dot_instance_buffer.slice(..));
|
||||||
@@ -1072,39 +1091,6 @@ fn create_hand_dot_pipeline(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_hand_palm_chip_pipeline(
|
|
||||||
device: &wgpu::Device,
|
|
||||||
target_format: &wgpu::TextureFormat,
|
|
||||||
shader: &wgpu::ShaderModule,
|
|
||||||
layout: &wgpu::PipelineLayout,
|
|
||||||
) -> wgpu::RenderPipeline {
|
|
||||||
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
|
||||||
label: Some("Hand Palm Embedded Chip Pipeline"),
|
|
||||||
layout: Some(layout),
|
|
||||||
vertex: wgpu::VertexState {
|
|
||||||
module: shader,
|
|
||||||
entry_point: Some("vs_hand_palm_chip"),
|
|
||||||
compilation_options: Default::default(),
|
|
||||||
buffers: &[GlyphVertex::desc(), GlyphInstance::desc()],
|
|
||||||
},
|
|
||||||
fragment: Some(wgpu::FragmentState {
|
|
||||||
module: shader,
|
|
||||||
entry_point: Some("fs_hand_palm_chip"),
|
|
||||||
compilation_options: Default::default(),
|
|
||||||
targets: &[Some(wgpu::ColorTargetState {
|
|
||||||
format: *target_format,
|
|
||||||
blend: Some(wgpu::BlendState::ALPHA_BLENDING),
|
|
||||||
write_mask: wgpu::ColorWrites::ALL,
|
|
||||||
})],
|
|
||||||
}),
|
|
||||||
primitive: wgpu::PrimitiveState::default(),
|
|
||||||
depth_stencil: None,
|
|
||||||
multisample: wgpu::MultisampleState::default(),
|
|
||||||
multiview_mask: None,
|
|
||||||
cache: None,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn create_hand_palm_dot_pipeline(
|
fn create_hand_palm_dot_pipeline(
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
target_format: &wgpu::TextureFormat,
|
target_format: &wgpu::TextureFormat,
|
||||||
@@ -1156,28 +1142,6 @@ fn build_hand_membrane_instances(image_width: f32, image_height: f32) -> Vec<Gly
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_hand_palm_chip_instances(image_width: f32, image_height: f32) -> Vec<GlyphInstance> {
|
|
||||||
HAND_PALM_CHIPS
|
|
||||||
.iter()
|
|
||||||
.map(|chip| {
|
|
||||||
let uv_x = chip.center_px[0] / image_width.max(1.0);
|
|
||||||
let uv_y = chip.center_px[1] / image_height.max(1.0);
|
|
||||||
|
|
||||||
GlyphInstance {
|
|
||||||
// Palm chip shaders read xy as hand.png UV.
|
|
||||||
world_position: [uv_x, uv_y, 0.0, 1.0],
|
|
||||||
// Store chip angle, source-image pixel size, and matrix shape for the shader grid.
|
|
||||||
style: [
|
|
||||||
chip.angle_rad,
|
|
||||||
chip.size_px[0],
|
|
||||||
chip.size_px[1],
|
|
||||||
(chip.rows * 100 + chip.cols) as f32,
|
|
||||||
],
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_hand_dot_instances(
|
fn build_hand_dot_instances(
|
||||||
rows: u32,
|
rows: u32,
|
||||||
cols: u32,
|
cols: u32,
|
||||||
@@ -1225,44 +1189,26 @@ fn build_hand_dot_instances(
|
|||||||
fn build_hand_palm_dot_instances(
|
fn build_hand_palm_dot_instances(
|
||||||
_rows: u32,
|
_rows: u32,
|
||||||
_cols: u32,
|
_cols: u32,
|
||||||
image_width: f32,
|
|
||||||
image_height: f32,
|
|
||||||
pressure: &[[f32; 2]],
|
pressure: &[[f32; 2]],
|
||||||
) -> Vec<GlyphInstance> {
|
) -> Vec<GlyphInstance> {
|
||||||
let chip_dot_count: usize = HAND_PALM_CHIPS
|
let chip_dot_count: usize = UNFOLDED_SENSOR_CHIPS
|
||||||
.iter()
|
.iter()
|
||||||
.map(|chip| (chip.rows * chip.cols) as usize)
|
.map(|chip| (chip.rows * chip.cols) as usize)
|
||||||
.sum();
|
.sum();
|
||||||
|
debug_assert_eq!(chip_dot_count, UNFOLDED_SENSOR_COUNT);
|
||||||
let mut instances = Vec::with_capacity(chip_dot_count);
|
let mut instances = Vec::with_capacity(chip_dot_count);
|
||||||
|
|
||||||
for (chip_index, chip) in HAND_PALM_CHIPS.into_iter().enumerate() {
|
for (chip_index, chip) in UNFOLDED_SENSOR_CHIPS.iter().enumerate() {
|
||||||
let cos = chip.angle_rad.cos();
|
|
||||||
let sin = chip.angle_rad.sin();
|
|
||||||
// Leave a bevel around the chip so the matrix reads as embedded pixels.
|
|
||||||
let active_size = [chip.size_px[0] * 0.72, chip.size_px[1] * 0.76];
|
|
||||||
|
|
||||||
for row in 0..chip.rows {
|
for row in 0..chip.rows {
|
||||||
for col in 0..chip.cols {
|
for col in 0..chip.cols {
|
||||||
let index = (row * chip.cols + col) as usize;
|
let index = unfolded_adc_sample_index(chip_index, row, col);
|
||||||
let offset = match chip_index {
|
let [normalized, display_value] = sample_pressure_at(pressure, index, index);
|
||||||
0 => HAND_PALM_HORIZONTAL_OFFSET,
|
let [x, y] = unfolded_cell_position(&chip, row, col);
|
||||||
_ => HAND_PALM_VERTICAL_OFFSET,
|
|
||||||
};
|
|
||||||
let [normalized, display_value] =
|
|
||||||
sample_pressure_at(pressure, offset + index, index);
|
|
||||||
|
|
||||||
let local_x =
|
|
||||||
(col as f32 - chip.cols as f32 / 2.0 + 0.5) / chip.cols as f32 * active_size[0];
|
|
||||||
let local_y =
|
|
||||||
(row as f32 - chip.rows as f32 / 2.0 + 0.5) / chip.rows as f32 * active_size[1];
|
|
||||||
|
|
||||||
let x = chip.center_px[0] + local_x * cos - local_y * sin;
|
|
||||||
let y = chip.center_px[1] + local_x * sin + local_y * cos;
|
|
||||||
|
|
||||||
instances.push(GlyphInstance {
|
instances.push(GlyphInstance {
|
||||||
world_position: [
|
world_position: [
|
||||||
x / image_width.max(1.0),
|
x / UNFOLDED_CANVAS_SIZE[0],
|
||||||
y / image_height.max(1.0),
|
y / UNFOLDED_CANVAS_SIZE[1],
|
||||||
0.0,
|
0.0,
|
||||||
1.0,
|
1.0,
|
||||||
],
|
],
|
||||||
@@ -1275,6 +1221,47 @@ fn build_hand_palm_dot_instances(
|
|||||||
instances
|
instances
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn unfolded_adc_sample_index(chip_index: usize, row: u32, col: u32) -> usize {
|
||||||
|
// Raw sample 0 is L0H0. The scan advances L first:
|
||||||
|
// L0H0, L1H0, …, L7H0, L0H1, …, L7H12.
|
||||||
|
// The PCB unfolds those channel pairs into the ten visual regions below.
|
||||||
|
let (l, h) = match chip_index {
|
||||||
|
0 => (5 - col, 12 - row), // top cap: L5…L2 × H12…H11
|
||||||
|
1 => (6, row), // left outer tip: L6 × H0…H2
|
||||||
|
2 => (7, folded_five_row_h(row)), // left folded wing
|
||||||
|
3 => (7, 10 - row), // left inner wing: L7 × H10…H3
|
||||||
|
4 => (6, 12 - row), // left inner spine: L6 × H12…H3
|
||||||
|
5 => (5 - col, 10 - row), // center: L5…L2 × H10…H0
|
||||||
|
6 => (1, row), // right outer tip: L1 × H0…H2
|
||||||
|
7 => (0, folded_five_row_h(row)), // right folded wing
|
||||||
|
8 => (0, 10 - row), // right inner wing: L0 × H10…H3
|
||||||
|
9 => (1, 12 - row), // right inner spine: L1 × H12…H3
|
||||||
|
_ => unreachable!("invalid unfolded PCB region"),
|
||||||
|
};
|
||||||
|
|
||||||
|
unfolded_lh_sample_index(l as usize, h as usize)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn folded_five_row_h(row: u32) -> u32 {
|
||||||
|
const PCB_H_ROUTE: [u32; 5] = [12, 11, 0, 1, 2];
|
||||||
|
PCB_H_ROUTE[row as usize]
|
||||||
|
}
|
||||||
|
fn unfolded_cell_position(chip: &HandPalmChip, row: u32, col: u32) -> [f32; 2] {
|
||||||
|
let cos = chip.angle_rad.cos();
|
||||||
|
let sin = chip.angle_rad.sin();
|
||||||
|
// Author every region on the same point grid. Using the last row as the
|
||||||
|
// vertical anchor keeps the stepped wing columns exactly bottom-aligned.
|
||||||
|
let bottom_center_y = chip.center_px[1] + chip.size_px[1] * 0.5 - 22.0;
|
||||||
|
let local_x = (col as f32 - chip.cols as f32 / 2.0 + 0.5) * UNFOLDED_CELL_SPACING_PX;
|
||||||
|
let y_from_bottom = (chip.rows.saturating_sub(row + 1)) as f32 * UNFOLDED_CELL_SPACING_PX;
|
||||||
|
let local_y = -y_from_bottom;
|
||||||
|
|
||||||
|
[
|
||||||
|
chip.center_px[0] + local_x * cos - local_y * sin,
|
||||||
|
bottom_center_y + local_x * sin + local_y * cos,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
fn sample_pressure_at(pressure: &[[f32; 2]], index: usize, fallback_index: usize) -> [f32; 2] {
|
fn sample_pressure_at(pressure: &[[f32; 2]], index: usize, fallback_index: usize) -> [f32; 2] {
|
||||||
pressure
|
pressure
|
||||||
.get(index)
|
.get(index)
|
||||||
@@ -1283,6 +1270,225 @@ fn sample_pressure_at(pressure: &[[f32; 2]], index: usize, fallback_index: usize
|
|||||||
.unwrap_or([0.0, 0.0])
|
.unwrap_or([0.0, 0.0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod unfolded_layout_tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::matrix::UNFOLDED_SENSOR_SEGMENT_COUNTS;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unfolded_layout_maps_every_lh_adc_channel_once() {
|
||||||
|
let mut seen = [false; UNFOLDED_SENSOR_COUNT];
|
||||||
|
|
||||||
|
for (chip_index, chip) in UNFOLDED_SENSOR_CHIPS.iter().enumerate() {
|
||||||
|
for row in 0..chip.rows {
|
||||||
|
for col in 0..chip.cols {
|
||||||
|
let index = unfolded_adc_sample_index(chip_index, row, col);
|
||||||
|
assert!(index < UNFOLDED_SENSOR_COUNT);
|
||||||
|
assert!(!seen[index], "duplicate ADC sample index {index}");
|
||||||
|
seen[index] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert!(seen.into_iter().all(|mapped| mapped));
|
||||||
|
assert_eq!(unfolded_lh_sample_index(0, 0), 0); // first raw sample
|
||||||
|
assert_eq!(unfolded_lh_sample_index(1, 0), 1); // L changes first
|
||||||
|
assert_eq!(unfolded_lh_sample_index(7, 0), 7);
|
||||||
|
assert_eq!(unfolded_lh_sample_index(0, 1), 8); // then H advances
|
||||||
|
assert_eq!(unfolded_adc_sample_index(7, 0, 0), 96); // L0H12
|
||||||
|
assert_eq!(unfolded_adc_sample_index(6, 0, 0), 1); // L1H0
|
||||||
|
assert_eq!(unfolded_lh_sample_index(7, 12), 103); // last rendered sample
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unfolded_layout_matches_annotated_adc_intersections() {
|
||||||
|
// Right folded/outer intersections: 1=L0H0, 2=L1H0,
|
||||||
|
// 9=L0H1, 10=L1H1, 17=L0H2, 18=L1H2.
|
||||||
|
assert_eq!(unfolded_adc_sample_index(7, 2, 0) + 1, 1);
|
||||||
|
assert_eq!(unfolded_adc_sample_index(6, 0, 0) + 1, 2);
|
||||||
|
assert_eq!(unfolded_adc_sample_index(7, 3, 0) + 1, 9);
|
||||||
|
assert_eq!(unfolded_adc_sample_index(6, 1, 0) + 1, 10);
|
||||||
|
assert_eq!(unfolded_adc_sample_index(7, 4, 0) + 1, 17);
|
||||||
|
assert_eq!(unfolded_adc_sample_index(6, 2, 0) + 1, 18);
|
||||||
|
|
||||||
|
// Right inner routes continue upward from H3.
|
||||||
|
assert_eq!(
|
||||||
|
(0..8)
|
||||||
|
.map(|row| unfolded_adc_sample_index(8, row, 0) + 1)
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
vec![81, 73, 65, 57, 49, 41, 33, 25]
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(0..10)
|
||||||
|
.map(|row| unfolded_adc_sample_index(9, row, 0) + 1)
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
vec![98, 90, 82, 74, 66, 58, 50, 42, 34, 26]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Left routes mirror the right side's PCB continuation.
|
||||||
|
assert_eq!(
|
||||||
|
(0..3)
|
||||||
|
.map(|row| unfolded_adc_sample_index(1, row, 0) + 1)
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
vec![7, 15, 23]
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(0..5)
|
||||||
|
.map(|row| unfolded_adc_sample_index(2, row, 0) + 1)
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
vec![104, 96, 8, 16, 24]
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(0..8)
|
||||||
|
.map(|row| unfolded_adc_sample_index(3, row, 0) + 1)
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
vec![88, 80, 72, 64, 56, 48, 40, 32]
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(0..10)
|
||||||
|
.map(|row| unfolded_adc_sample_index(4, row, 0) + 1)
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
vec![103, 95, 87, 79, 71, 63, 55, 47, 39, 31]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Center rows H0…H7, each ordered L5, L4, L3, L2.
|
||||||
|
for h in 0..=7 {
|
||||||
|
let row = 10 - h;
|
||||||
|
let expected = (2..=5)
|
||||||
|
.rev()
|
||||||
|
.map(|l| unfolded_lh_sample_index(l, h as usize) + 1)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
let rendered = (0..4)
|
||||||
|
.map(|col| unfolded_adc_sample_index(5, row, col) + 1)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
assert_eq!(rendered, expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn annotated_folded_points_share_the_same_physical_rows() {
|
||||||
|
let same_y = |left_chip: usize, left_row: u32, right_chip: usize, right_row: u32| {
|
||||||
|
let left = unfolded_cell_position(&UNFOLDED_SENSOR_CHIPS[left_chip], left_row, 0)[1];
|
||||||
|
let right = unfolded_cell_position(&UNFOLDED_SENSOR_CHIPS[right_chip], right_row, 0)[1];
|
||||||
|
assert!((left - right).abs() < 0.01);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Left outer pairs: 7/8, 15/16, 23/24.
|
||||||
|
for row in 0..3 {
|
||||||
|
same_y(1, row, 2, row + 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Right outer pairs: 2/1, 10/9, 18/17.
|
||||||
|
for row in 0..3 {
|
||||||
|
same_y(6, row, 7, row + 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inner continuations align by H despite belonging to different strips.
|
||||||
|
for row in 0..8 {
|
||||||
|
same_y(3, row, 4, row + 2);
|
||||||
|
same_y(8, row, 9, row + 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unfolded_layout_matches_requested_shapes() {
|
||||||
|
let shapes = UNFOLDED_SENSOR_CHIPS.map(|chip| (chip.rows, chip.cols));
|
||||||
|
let sample_counts = UNFOLDED_SENSOR_CHIPS.map(|chip| (chip.rows * chip.cols) as usize);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
shapes,
|
||||||
|
[
|
||||||
|
(2, 4),
|
||||||
|
(3, 1),
|
||||||
|
(5, 1),
|
||||||
|
(8, 1),
|
||||||
|
(10, 1),
|
||||||
|
(11, 4),
|
||||||
|
(3, 1),
|
||||||
|
(5, 1),
|
||||||
|
(8, 1),
|
||||||
|
(10, 1),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
assert_eq!(sample_counts, UNFOLDED_SENSOR_SEGMENT_COUNTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unfolded_wings_are_mirrored_around_center() {
|
||||||
|
let center_x = UNFOLDED_SENSOR_CHIPS[5].center_px[0];
|
||||||
|
|
||||||
|
for (left, right) in UNFOLDED_SENSOR_CHIPS[1..5]
|
||||||
|
.iter()
|
||||||
|
.zip(UNFOLDED_SENSOR_CHIPS[6..10].iter())
|
||||||
|
{
|
||||||
|
assert_eq!((left.rows, left.cols), (right.rows, right.cols));
|
||||||
|
assert_eq!(left.center_px[1], right.center_px[1]);
|
||||||
|
assert!(
|
||||||
|
((center_x - left.center_px[0]) - (right.center_px[0] - center_x)).abs() < 0.01
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unfolded_layout_fits_its_canvas() {
|
||||||
|
for chip in UNFOLDED_SENSOR_CHIPS {
|
||||||
|
let half_width = chip.size_px[0] * 0.5;
|
||||||
|
let half_height = chip.size_px[1] * 0.5;
|
||||||
|
|
||||||
|
assert!(chip.center_px[0] - half_width >= 0.0);
|
||||||
|
assert!(chip.center_px[0] + half_width <= UNFOLDED_CANVAS_SIZE[0]);
|
||||||
|
assert!(chip.center_px[1] - half_height >= 0.0);
|
||||||
|
assert!(chip.center_px[1] + half_height <= UNFOLDED_CANVAS_SIZE[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unfolded_wing_rows_share_one_bottom_baseline() {
|
||||||
|
let wing_indices = [1usize, 2, 3, 4, 6, 7, 8, 9];
|
||||||
|
let expected_y = unfolded_cell_position(
|
||||||
|
&UNFOLDED_SENSOR_CHIPS[wing_indices[0]],
|
||||||
|
UNFOLDED_SENSOR_CHIPS[wing_indices[0]].rows - 1,
|
||||||
|
0,
|
||||||
|
)[1];
|
||||||
|
|
||||||
|
for index in wing_indices {
|
||||||
|
let chip = &UNFOLDED_SENSOR_CHIPS[index];
|
||||||
|
let bottom_y = unfolded_cell_position(chip, chip.rows - 1, 0)[1];
|
||||||
|
assert!((bottom_y - expected_y).abs() < 0.01);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unfolded_wings_are_compact_with_more_space_at_center() {
|
||||||
|
let left_x = UNFOLDED_SENSOR_CHIPS[1..5]
|
||||||
|
.iter()
|
||||||
|
.map(|chip| chip.center_px[0])
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
let wing_gap = left_x[1] - left_x[0];
|
||||||
|
assert!((wing_gap - 48.0).abs() < 0.01);
|
||||||
|
assert!(
|
||||||
|
left_x
|
||||||
|
.windows(2)
|
||||||
|
.all(|pair| (pair[1] - pair[0] - wing_gap).abs() < 0.01)
|
||||||
|
);
|
||||||
|
|
||||||
|
let center_left_x = unfolded_cell_position(&UNFOLDED_SENSOR_CHIPS[5], 0, 0)[0];
|
||||||
|
let left_inner_x = unfolded_cell_position(&UNFOLDED_SENSOR_CHIPS[4], 0, 0)[0];
|
||||||
|
assert!(center_left_x - left_inner_x > wing_gap);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unfolded_top_block_sits_close_to_center_block() {
|
||||||
|
let top = &UNFOLDED_SENSOR_CHIPS[0];
|
||||||
|
let center = &UNFOLDED_SENSOR_CHIPS[5];
|
||||||
|
let top_bottom_y = unfolded_cell_position(top, top.rows - 1, 0)[1];
|
||||||
|
let center_top_y = unfolded_cell_position(center, 0, 0)[1];
|
||||||
|
|
||||||
|
assert!(center_top_y > top_bottom_y);
|
||||||
|
assert!(center_top_y - top_bottom_y < UNFOLDED_CELL_SPACING_PX * 2.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn build_glyph_instances(
|
fn build_glyph_instances(
|
||||||
rows: u32,
|
rows: u32,
|
||||||
cols: u32,
|
cols: u32,
|
||||||
|
|||||||
@@ -457,6 +457,7 @@ fn create_color_material(
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn create_material(
|
fn create_material(
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
texture_bind_group_layout: &wgpu::BindGroupLayout,
|
texture_bind_group_layout: &wgpu::BindGroupLayout,
|
||||||
@@ -702,6 +703,7 @@ fn append_gltf_node_meshes(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn append_gltf_primitive_mesh(
|
fn append_gltf_primitive_mesh(
|
||||||
mesh_name: &str,
|
mesh_name: &str,
|
||||||
primitive_index: usize,
|
primitive_index: usize,
|
||||||
@@ -969,7 +971,7 @@ fn rgba_from_chunks(
|
|||||||
read_component: fn(&[u8]) -> u8,
|
read_component: fn(&[u8]) -> u8,
|
||||||
) -> anyhow::Result<Vec<u8>> {
|
) -> anyhow::Result<Vec<u8>> {
|
||||||
let pixel_width = channels * component_width;
|
let pixel_width = channels * component_width;
|
||||||
if pixel_width == 0 || pixels.len() % pixel_width != 0 {
|
if pixel_width == 0 || !pixels.len().is_multiple_of(pixel_width) {
|
||||||
bail!("invalid glTF image byte length for {channels} channels");
|
bail!("invalid glTF image byte length for {channels} channels");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ impl HandGatewayCodec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_node_payload(data: &[u8]) -> Result<Vec<u16>, CodecError> {
|
pub fn parse_node_payload(data: &[u8]) -> Result<Vec<u16>, CodecError> {
|
||||||
if data.len() % 2 != 0 {
|
if !data.len().is_multiple_of(2) {
|
||||||
return Err(CodecError::InvalidLength);
|
return Err(CodecError::InvalidLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ impl TactileACodec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_data_frame(data: &[u8]) -> Result<Vec<i32>, CodecError> {
|
pub fn parse_data_frame(data: &[u8]) -> Result<Vec<i32>, CodecError> {
|
||||||
if data.len() % 2 != 0 {
|
if !data.len().is_multiple_of(2) {
|
||||||
return Err(CodecError::InvalidLength);
|
return Err(CodecError::InvalidLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ impl Codec<TactileAFrame> for TactileACodec {
|
|||||||
let need_check_data = self.buffer[0..14 + except_data_len].to_vec();
|
let need_check_data = self.buffer[0..14 + except_data_len].to_vec();
|
||||||
let payload = self.buffer[14..14 + except_data_len].to_vec();
|
let payload = self.buffer[14..14 + except_data_len].to_vec();
|
||||||
let crc8_itu_alg = crc::Crc::<u8>::new(&crc::CRC_8_I_432_1);
|
let crc8_itu_alg = crc::Crc::<u8>::new(&crc::CRC_8_I_432_1);
|
||||||
let checksum = crc8_itu_alg.checksum(&need_check_data.as_slice());
|
let checksum = crc8_itu_alg.checksum(need_check_data.as_slice());
|
||||||
if self.buffer[frame_length - 1] != checksum {
|
if self.buffer[frame_length - 1] != checksum {
|
||||||
log::debug!(
|
log::debug!(
|
||||||
"checksum mismatch: expected {:02X}, got {:02X}, frame_len={}",
|
"checksum mismatch: expected {:02X}, got {:02X}, frame_len={}",
|
||||||
@@ -188,3 +188,61 @@ impl Codec<TactileAFrame> for TactileACodec {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::serial_core::codec::Codec;
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
|
const FINGER_3D_ROWS: usize = 12;
|
||||||
|
const FINGER_3D_COLS: usize = 9;
|
||||||
|
const FINGER_3D_DATA_LEN: usize = FINGER_3D_ROWS * FINGER_3D_COLS * 2;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn finger_3d_request_asks_for_108_samples() {
|
||||||
|
let codec = TactileACodec::new(FINGER_3D_COLS, FINGER_3D_ROWS);
|
||||||
|
let frame = TactileACodec::build_req_frame(FINGER_3D_COLS, FINGER_3D_ROWS).unwrap();
|
||||||
|
let encoded = codec.encode(&frame).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
u16::from_le_bytes([encoded[11], encoded[12]]) as usize,
|
||||||
|
FINGER_3D_DATA_LEN
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn finger_3d_decode_accepts_108_samples_across_reads() {
|
||||||
|
let mut codec = TactileACodec::new(FINGER_3D_COLS, FINGER_3D_ROWS);
|
||||||
|
let payload = (0..FINGER_3D_ROWS * FINGER_3D_COLS)
|
||||||
|
.flat_map(|value| (value as u16).to_le_bytes())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
let mut response = Vec::new();
|
||||||
|
response.extend_from_slice(&[0xAA, 0x55]);
|
||||||
|
response.extend_from_slice(&9_u16.to_le_bytes());
|
||||||
|
response.extend_from_slice(&[0x34, 0x00, 0xFB]);
|
||||||
|
response.extend_from_slice(&7168_u32.to_le_bytes());
|
||||||
|
response.extend_from_slice(&(FINGER_3D_DATA_LEN as u16).to_le_bytes());
|
||||||
|
response.push(0);
|
||||||
|
response.extend_from_slice(&payload);
|
||||||
|
response.push(calc_crc8_itu(&response));
|
||||||
|
|
||||||
|
let split = response.len() / 2;
|
||||||
|
assert!(
|
||||||
|
codec
|
||||||
|
.decode(&response[..split], Instant::now())
|
||||||
|
.unwrap()
|
||||||
|
.is_empty()
|
||||||
|
);
|
||||||
|
let frames = codec.decode(&response[split..], Instant::now()).unwrap();
|
||||||
|
|
||||||
|
let TactileAFrame::Rep(rep) = &frames[0] else {
|
||||||
|
panic!("expected response frame");
|
||||||
|
};
|
||||||
|
assert_eq!(rep.payload.len(), FINGER_3D_DATA_LEN);
|
||||||
|
assert_eq!(
|
||||||
|
TactileACodec::parse_data_frame(&rep.payload).unwrap().len(),
|
||||||
|
108
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ impl PztProcessor {
|
|||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if n % 2 == 0 {
|
if n.is_multiple_of(2) {
|
||||||
(sorted[n / 2 - 1] + sorted[n / 2]) / 2.0
|
(sorted[n / 2 - 1] + sorted[n / 2]) / 2.0
|
||||||
} else {
|
} else {
|
||||||
sorted[n / 2]
|
sorted[n / 2]
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ pub enum SerialProtocol {
|
|||||||
|
|
||||||
/// Runs the serial polling loop on the calling (background) thread.
|
/// Runs the serial polling loop on the calling (background) thread.
|
||||||
/// Sends decoded pressure matrix data (Vec<i32>) to the output channel.
|
/// Sends decoded pressure matrix data (Vec<i32>) to the output channel.
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn run_serial_loop(
|
pub fn run_serial_loop(
|
||||||
port: &mut dyn ReadWrite,
|
port: &mut dyn ReadWrite,
|
||||||
rows: usize,
|
rows: usize,
|
||||||
@@ -73,12 +74,12 @@ fn run_tactile_a_loop(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send poll request
|
// Send poll request
|
||||||
if let Ok(req_bytes) = codec.encode(&req_frame) {
|
if let Ok(req_bytes) = codec.encode(&req_frame)
|
||||||
if port.write_all(&req_bytes).is_ok() {
|
&& port.write_all(&req_bytes).is_ok()
|
||||||
|
{
|
||||||
io_stats.tx_bytes += req_bytes.len() as u64;
|
io_stats.tx_bytes += req_bytes.len() as u64;
|
||||||
publish_stats(stats_tx, io_stats);
|
publish_stats(stats_tx, io_stats);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Read response with poll interval
|
// Read response with poll interval
|
||||||
let deadline = Instant::now() + poll_interval;
|
let deadline = Instant::now() + poll_interval;
|
||||||
@@ -93,8 +94,9 @@ fn run_tactile_a_loop(
|
|||||||
publish_stats(stats_tx, io_stats);
|
publish_stats(stats_tx, io_stats);
|
||||||
if let Ok(frames) = codec.decode(&buffer[..n], session_started_at) {
|
if let Ok(frames) = codec.decode(&buffer[..n], session_started_at) {
|
||||||
for frame in frames {
|
for frame in frames {
|
||||||
if let TactileAFrame::Rep(rep) = frame {
|
if let TactileAFrame::Rep(rep) = frame
|
||||||
if let Ok(vals) = TactileACodec::parse_data_frame(&rep.payload) {
|
&& let Ok(vals) = TactileACodec::parse_data_frame(&rep.payload)
|
||||||
|
{
|
||||||
if let Some(recorder) = recorder {
|
if let Some(recorder) = recorder {
|
||||||
let pressures: Vec<u32> =
|
let pressures: Vec<u32> =
|
||||||
vals.iter().map(|v| (*v).max(0) as u32).collect();
|
vals.iter().map(|v| (*v).max(0) as u32).collect();
|
||||||
@@ -105,7 +107,6 @@ fn run_tactile_a_loop(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
std::thread::sleep(Duration::from_millis(1));
|
std::thread::sleep(Duration::from_millis(1));
|
||||||
}
|
}
|
||||||
|
|||||||
51
src/style.rs
51
src/style.rs
@@ -61,6 +61,7 @@ pub const METRICS: DesignMetrics = DesignMetrics {
|
|||||||
|
|
||||||
pub mod layout {
|
pub mod layout {
|
||||||
pub const TITLE_BAR_HEIGHT: f32 = 36.0;
|
pub const TITLE_BAR_HEIGHT: f32 = 36.0;
|
||||||
|
pub const CONFIG_BAR_HEIGHT: f32 = 48.0;
|
||||||
pub const CENTER_PANEL_TOP: f32 = 48.0;
|
pub const CENTER_PANEL_TOP: f32 = 48.0;
|
||||||
pub const LEFT_X: f32 = 24.0;
|
pub const LEFT_X: f32 = 24.0;
|
||||||
pub const RIGHT_X: f32 = 1328.0;
|
pub const RIGHT_X: f32 = 1328.0;
|
||||||
@@ -76,7 +77,7 @@ pub fn apply_theme(ctx: &egui::Context, theme: &AppTheme) {
|
|||||||
visuals.override_text_color = Some(theme.text);
|
visuals.override_text_color = Some(theme.text);
|
||||||
visuals.panel_fill = theme.bg;
|
visuals.panel_fill = theme.bg;
|
||||||
visuals.window_fill = theme.panel;
|
visuals.window_fill = theme.panel;
|
||||||
visuals.window_stroke = egui::Stroke::new(1.0, theme.border);
|
visuals.window_stroke = egui::Stroke::new(1.0_f32, theme.border);
|
||||||
visuals.extreme_bg_color = theme.panel_deep;
|
visuals.extreme_bg_color = theme.panel_deep;
|
||||||
visuals.faint_bg_color = theme.panel_strong;
|
visuals.faint_bg_color = theme.panel_strong;
|
||||||
visuals.code_bg_color = theme.panel_deep;
|
visuals.code_bg_color = theme.panel_deep;
|
||||||
@@ -84,23 +85,23 @@ pub fn apply_theme(ctx: &egui::Context, theme: &AppTheme) {
|
|||||||
visuals.error_fg_color = ACCENT_RED;
|
visuals.error_fg_color = ACCENT_RED;
|
||||||
|
|
||||||
visuals.widgets.noninteractive.bg_fill = theme.panel_strong;
|
visuals.widgets.noninteractive.bg_fill = theme.panel_strong;
|
||||||
visuals.widgets.noninteractive.bg_stroke = egui::Stroke::new(1.0, theme.border_soft);
|
visuals.widgets.noninteractive.bg_stroke = egui::Stroke::new(1.0_f32, theme.border_soft);
|
||||||
visuals.widgets.noninteractive.fg_stroke = egui::Stroke::new(1.0, theme.text);
|
visuals.widgets.noninteractive.fg_stroke = egui::Stroke::new(1.0_f32, theme.text);
|
||||||
visuals.widgets.inactive.bg_fill = theme.panel_strong;
|
visuals.widgets.inactive.bg_fill = theme.panel_strong;
|
||||||
visuals.widgets.inactive.bg_stroke = egui::Stroke::new(1.0, theme.border_soft);
|
visuals.widgets.inactive.bg_stroke = egui::Stroke::new(1.0_f32, theme.border_soft);
|
||||||
visuals.widgets.inactive.fg_stroke = egui::Stroke::new(1.0, theme.text);
|
visuals.widgets.inactive.fg_stroke = egui::Stroke::new(1.0_f32, theme.text);
|
||||||
visuals.widgets.hovered.bg_fill = egui::Color32::from_rgb(44, 57, 70);
|
visuals.widgets.hovered.bg_fill = egui::Color32::from_rgb(44, 57, 70);
|
||||||
visuals.widgets.hovered.bg_stroke = egui::Stroke::new(1.0, theme.accent);
|
visuals.widgets.hovered.bg_stroke = egui::Stroke::new(1.0_f32, theme.accent);
|
||||||
visuals.widgets.hovered.fg_stroke = egui::Stroke::new(1.0, egui::Color32::WHITE);
|
visuals.widgets.hovered.fg_stroke = egui::Stroke::new(1.0_f32, egui::Color32::WHITE);
|
||||||
visuals.widgets.active.bg_fill = theme.accent;
|
visuals.widgets.active.bg_fill = theme.accent;
|
||||||
visuals.widgets.active.bg_stroke = egui::Stroke::new(1.0, theme.accent_hot);
|
visuals.widgets.active.bg_stroke = egui::Stroke::new(1.0_f32, theme.accent_hot);
|
||||||
visuals.widgets.active.fg_stroke = egui::Stroke::new(1.0, egui::Color32::WHITE);
|
visuals.widgets.active.fg_stroke = egui::Stroke::new(1.0_f32, egui::Color32::WHITE);
|
||||||
visuals.widgets.open.bg_fill = egui::Color32::from_rgb(39, 50, 62);
|
visuals.widgets.open.bg_fill = egui::Color32::from_rgb(39, 50, 62);
|
||||||
visuals.widgets.open.bg_stroke = egui::Stroke::new(1.0, theme.accent);
|
visuals.widgets.open.bg_stroke = egui::Stroke::new(1.0_f32, theme.accent);
|
||||||
visuals.widgets.open.fg_stroke = egui::Stroke::new(1.0, theme.text);
|
visuals.widgets.open.fg_stroke = egui::Stroke::new(1.0_f32, theme.text);
|
||||||
|
|
||||||
visuals.selection.bg_fill = egui::Color32::from_rgb(35, 123, 140);
|
visuals.selection.bg_fill = egui::Color32::from_rgb(35, 123, 140);
|
||||||
visuals.selection.stroke = egui::Stroke::new(1.0, egui::Color32::WHITE);
|
visuals.selection.stroke = egui::Stroke::new(1.0_f32, egui::Color32::WHITE);
|
||||||
visuals.hyperlink_color = theme.accent_hot;
|
visuals.hyperlink_color = theme.accent_hot;
|
||||||
ctx.set_visuals(visuals);
|
ctx.set_visuals(visuals);
|
||||||
|
|
||||||
@@ -126,8 +127,8 @@ pub fn apply_fonts(ctx: &egui::Context) {
|
|||||||
let mut fonts = egui::FontDefinitions::default();
|
let mut fonts = egui::FontDefinitions::default();
|
||||||
|
|
||||||
fonts.font_data.insert(
|
fonts.font_data.insert(
|
||||||
"Hack-Bold".to_owned(),
|
"MapleMono-NF-CN-Bold".to_owned(),
|
||||||
egui::FontData::from_static(include_bytes!("../static/Hack-Bold.ttf")).into(),
|
egui::FontData::from_static(include_bytes!("../static/MapleMono-NF-CN-Bold.ttf")).into(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let has_yahei = std::fs::read(r"C:\Windows\Fonts\msyh.ttc")
|
let has_yahei = std::fs::read(r"C:\Windows\Fonts\msyh.ttc")
|
||||||
@@ -144,7 +145,7 @@ pub fn apply_fonts(ctx: &egui::Context) {
|
|||||||
.families
|
.families
|
||||||
.entry(egui::FontFamily::Proportional)
|
.entry(egui::FontFamily::Proportional)
|
||||||
.or_default()
|
.or_default()
|
||||||
.insert(0, "Hack-Bold".to_owned());
|
.insert(0, "MapleMono-NF-CN-Bold".to_owned());
|
||||||
if has_yahei {
|
if has_yahei {
|
||||||
fonts
|
fonts
|
||||||
.families
|
.families
|
||||||
@@ -157,7 +158,7 @@ pub fn apply_fonts(ctx: &egui::Context) {
|
|||||||
.families
|
.families
|
||||||
.entry(egui::FontFamily::Monospace)
|
.entry(egui::FontFamily::Monospace)
|
||||||
.or_default()
|
.or_default()
|
||||||
.insert(0, "Hack-Bold".to_owned());
|
.insert(0, "MapleMono-NF-CN-Bold".to_owned());
|
||||||
if has_yahei {
|
if has_yahei {
|
||||||
fonts
|
fonts
|
||||||
.families
|
.families
|
||||||
@@ -173,7 +174,7 @@ pub fn panel_frame(ctx: &egui::Context) -> egui::Frame {
|
|||||||
let style = ctx.global_style();
|
let style = ctx.global_style();
|
||||||
egui::Frame::window(&style)
|
egui::Frame::window(&style)
|
||||||
.fill(ONE_DARK_PRO.panel)
|
.fill(ONE_DARK_PRO.panel)
|
||||||
.stroke(egui::Stroke::new(1.0, ONE_DARK_PRO.border))
|
.stroke(egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border))
|
||||||
.corner_radius(egui::CornerRadius::same(ONE_DARK_PRO.radius))
|
.corner_radius(egui::CornerRadius::same(ONE_DARK_PRO.radius))
|
||||||
.inner_margin(egui::Margin::same(METRICS.panel_padding))
|
.inner_margin(egui::Margin::same(METRICS.panel_padding))
|
||||||
.shadow(egui::epaint::Shadow {
|
.shadow(egui::epaint::Shadow {
|
||||||
@@ -197,7 +198,7 @@ pub fn center_panel_frame() -> egui::Frame {
|
|||||||
pub fn group_frame() -> egui::Frame {
|
pub fn group_frame() -> egui::Frame {
|
||||||
egui::Frame::new()
|
egui::Frame::new()
|
||||||
.fill(ONE_DARK_PRO.panel_deep)
|
.fill(ONE_DARK_PRO.panel_deep)
|
||||||
.stroke(egui::Stroke::new(1.0, ONE_DARK_PRO.border_soft))
|
.stroke(egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border_soft))
|
||||||
.corner_radius(egui::CornerRadius::same(4))
|
.corner_radius(egui::CornerRadius::same(4))
|
||||||
.inner_margin(egui::Margin::symmetric(
|
.inner_margin(egui::Margin::symmetric(
|
||||||
METRICS.group_padding_x,
|
METRICS.group_padding_x,
|
||||||
@@ -208,7 +209,7 @@ pub fn group_frame() -> egui::Frame {
|
|||||||
pub fn tag_button(label: impl Into<egui::WidgetText>) -> egui::Button<'static> {
|
pub fn tag_button(label: impl Into<egui::WidgetText>) -> egui::Button<'static> {
|
||||||
egui::Button::new(label)
|
egui::Button::new(label)
|
||||||
.fill(ONE_DARK_PRO.panel_strong)
|
.fill(ONE_DARK_PRO.panel_strong)
|
||||||
.stroke(egui::Stroke::new(1.0, ONE_DARK_PRO.border))
|
.stroke(egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border))
|
||||||
.corner_radius(egui::CornerRadius::same(4))
|
.corner_radius(egui::CornerRadius::same(4))
|
||||||
.min_size(egui::vec2(0.0, METRICS.button_height))
|
.min_size(egui::vec2(0.0, METRICS.button_height))
|
||||||
}
|
}
|
||||||
@@ -221,7 +222,7 @@ pub fn rich_tag_button(
|
|||||||
|
|
||||||
egui::Button::new(text)
|
egui::Button::new(text)
|
||||||
.fill(ONE_DARK_PRO.panel_strong)
|
.fill(ONE_DARK_PRO.panel_strong)
|
||||||
.stroke(egui::Stroke::new(1.0, ONE_DARK_PRO.border))
|
.stroke(egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border))
|
||||||
.corner_radius(egui::CornerRadius::same(4))
|
.corner_radius(egui::CornerRadius::same(4))
|
||||||
.min_size(egui::vec2(0.0, METRICS.button_height))
|
.min_size(egui::vec2(0.0, METRICS.button_height))
|
||||||
}
|
}
|
||||||
@@ -229,7 +230,7 @@ pub fn rich_tag_button(
|
|||||||
pub fn primary_button(label: impl Into<egui::WidgetText>) -> egui::Button<'static> {
|
pub fn primary_button(label: impl Into<egui::WidgetText>) -> egui::Button<'static> {
|
||||||
egui::Button::new(label)
|
egui::Button::new(label)
|
||||||
.fill(ONE_DARK_PRO.accent)
|
.fill(ONE_DARK_PRO.accent)
|
||||||
.stroke(egui::Stroke::new(1.0, ONE_DARK_PRO.accent_hot))
|
.stroke(egui::Stroke::new(1.0_f32, ONE_DARK_PRO.accent_hot))
|
||||||
.corner_radius(egui::CornerRadius::same(4))
|
.corner_radius(egui::CornerRadius::same(4))
|
||||||
.min_size(egui::vec2(112.0, METRICS.button_height))
|
.min_size(egui::vec2(112.0, METRICS.button_height))
|
||||||
}
|
}
|
||||||
@@ -238,7 +239,7 @@ pub fn danger_button(label: impl Into<egui::WidgetText>) -> egui::Button<'static
|
|||||||
egui::Button::new(label)
|
egui::Button::new(label)
|
||||||
.fill(ACCENT_RED)
|
.fill(ACCENT_RED)
|
||||||
.stroke(egui::Stroke::new(
|
.stroke(egui::Stroke::new(
|
||||||
1.0,
|
1.0_f32,
|
||||||
egui::Color32::from_rgb(255, 138, 126),
|
egui::Color32::from_rgb(255, 138, 126),
|
||||||
))
|
))
|
||||||
.corner_radius(egui::CornerRadius::same(4))
|
.corner_radius(egui::CornerRadius::same(4))
|
||||||
@@ -251,7 +252,7 @@ pub fn accent_button(
|
|||||||
) -> egui::Button<'static> {
|
) -> egui::Button<'static> {
|
||||||
egui::Button::new(label)
|
egui::Button::new(label)
|
||||||
.fill(fill)
|
.fill(fill)
|
||||||
.stroke(egui::Stroke::new(1.0, ONE_DARK_PRO.border))
|
.stroke(egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border))
|
||||||
.corner_radius(egui::CornerRadius::same(4))
|
.corner_radius(egui::CornerRadius::same(4))
|
||||||
.min_size(egui::vec2(0.0, METRICS.button_height))
|
.min_size(egui::vec2(0.0, METRICS.button_height))
|
||||||
}
|
}
|
||||||
@@ -270,7 +271,7 @@ pub fn mode_button(label: &'static str, selected: bool) -> egui::Button<'static>
|
|||||||
|
|
||||||
egui::Button::new(egui::RichText::new(label).color(egui::Color32::WHITE))
|
egui::Button::new(egui::RichText::new(label).color(egui::Color32::WHITE))
|
||||||
.fill(fill)
|
.fill(fill)
|
||||||
.stroke(egui::Stroke::new(1.0, stroke))
|
.stroke(egui::Stroke::new(1.0_f32, stroke))
|
||||||
.corner_radius(egui::CornerRadius::same(4))
|
.corner_radius(egui::CornerRadius::same(4))
|
||||||
.min_size(egui::vec2(96.0, METRICS.button_height))
|
.min_size(egui::vec2(96.0, METRICS.button_height))
|
||||||
}
|
}
|
||||||
@@ -278,7 +279,7 @@ pub fn mode_button(label: &'static str, selected: bool) -> egui::Button<'static>
|
|||||||
pub fn icon_button<'a>(icon: impl Into<egui::WidgetText>, size: egui::Vec2) -> egui::Button<'a> {
|
pub fn icon_button<'a>(icon: impl Into<egui::WidgetText>, size: egui::Vec2) -> egui::Button<'a> {
|
||||||
egui::Button::new(icon)
|
egui::Button::new(icon)
|
||||||
.fill(ONE_DARK_PRO.panel_strong)
|
.fill(ONE_DARK_PRO.panel_strong)
|
||||||
.stroke(egui::Stroke::new(1.0, ONE_DARK_PRO.border))
|
.stroke(egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border))
|
||||||
.corner_radius(egui::CornerRadius::same(4))
|
.corner_radius(egui::CornerRadius::same(4))
|
||||||
.min_size(size)
|
.min_size(size)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ impl Texture {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn from_rgba8_with_sampler(
|
pub fn from_rgba8_with_sampler(
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
queue: &wgpu::Queue,
|
queue: &wgpu::Queue,
|
||||||
|
|||||||
47
src/theme.rs
47
src/theme.rs
@@ -83,53 +83,6 @@ pub fn apply_theme(ctx: &egui::Context, theme: &AppTheme) {
|
|||||||
ctx.set_global_style(style);
|
ctx.set_global_style(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_fonts(ctx: &egui::Context) {
|
|
||||||
let mut fonts = egui::FontDefinitions::default();
|
|
||||||
|
|
||||||
fonts.font_data.insert(
|
|
||||||
"Hack-Bold".to_owned(),
|
|
||||||
egui::FontData::from_static(include_bytes!("../static/Hack-Bold.ttf")).into(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let has_yahei = std::fs::read(r"C:\Windows\Fonts\msyh.ttc")
|
|
||||||
.or_else(|_| std::fs::read(r"C:\Windows\Fonts\msyhbd.ttc"))
|
|
||||||
.map(|font_data| {
|
|
||||||
fonts.font_data.insert(
|
|
||||||
"Microsoft-YaHei".to_owned(),
|
|
||||||
egui::FontData::from_owned(font_data).into(),
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.is_ok();
|
|
||||||
|
|
||||||
fonts
|
|
||||||
.families
|
|
||||||
.entry(egui::FontFamily::Proportional)
|
|
||||||
.or_default()
|
|
||||||
.insert(0, "Hack-Bold".to_owned());
|
|
||||||
if has_yahei {
|
|
||||||
fonts
|
|
||||||
.families
|
|
||||||
.entry(egui::FontFamily::Proportional)
|
|
||||||
.or_default()
|
|
||||||
.push("Microsoft-YaHei".to_owned());
|
|
||||||
}
|
|
||||||
|
|
||||||
fonts
|
|
||||||
.families
|
|
||||||
.entry(egui::FontFamily::Monospace)
|
|
||||||
.or_default()
|
|
||||||
.insert(0, "Hack-Bold".to_owned());
|
|
||||||
if has_yahei {
|
|
||||||
fonts
|
|
||||||
.families
|
|
||||||
.entry(egui::FontFamily::Monospace)
|
|
||||||
.or_default()
|
|
||||||
.push("Microsoft-YaHei".to_owned());
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.set_fonts(fonts);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn panel_frame(ctx: &egui::Context) -> egui::Frame {
|
pub fn panel_frame(ctx: &egui::Context) -> egui::Frame {
|
||||||
let style = ctx.global_style();
|
let style = ctx.global_style();
|
||||||
egui::Frame::window(&style)
|
egui::Frame::window(&style)
|
||||||
|
|||||||
265
src/ui.rs
265
src/ui.rs
@@ -7,7 +7,9 @@ use crate::{
|
|||||||
serial_core::serial::{SerialIoStats, SerialProtocol},
|
serial_core::serial::{SerialIoStats, SerialProtocol},
|
||||||
style::{
|
style::{
|
||||||
self, ACCENT_BLUE, ACCENT_GREEN, ACCENT_ORANGE, ACCENT_RED, METRICS, ONE_DARK_PRO,
|
self, ACCENT_BLUE, ACCENT_GREEN, ACCENT_ORANGE, ACCENT_RED, METRICS, ONE_DARK_PRO,
|
||||||
dim_text, group_frame, layout, panel_frame, rich_tag_button, tag_button,
|
dim_text, group_frame,
|
||||||
|
layout::{self},
|
||||||
|
panel_frame, rich_tag_button, tag_button,
|
||||||
},
|
},
|
||||||
utils::serial_enum,
|
utils::serial_enum,
|
||||||
};
|
};
|
||||||
@@ -51,6 +53,7 @@ pub struct ConnectPanelState {
|
|||||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum SerialMode {
|
pub enum SerialMode {
|
||||||
Finger,
|
Finger,
|
||||||
|
Finger3D,
|
||||||
Hand,
|
Hand,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,16 +61,26 @@ impl SerialMode {
|
|||||||
pub fn baud_rate(self) -> u32 {
|
pub fn baud_rate(self) -> u32 {
|
||||||
match self {
|
match self {
|
||||||
SerialMode::Finger => 921_600,
|
SerialMode::Finger => 921_600,
|
||||||
SerialMode::Hand => 1_152_000,
|
SerialMode::Finger3D => 921_600,
|
||||||
|
SerialMode::Hand => 921_600,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn protocol(self) -> SerialProtocol {
|
pub fn protocol(self) -> SerialProtocol {
|
||||||
match self {
|
match self {
|
||||||
SerialMode::Finger => SerialProtocol::TactileA,
|
SerialMode::Finger => SerialProtocol::TactileA,
|
||||||
|
SerialMode::Finger3D => SerialProtocol::TactileA,
|
||||||
SerialMode::Hand => SerialProtocol::HandGateway,
|
SerialMode::Hand => SerialProtocol::HandGateway,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn matrix_shape(self) -> (u32, u32) {
|
||||||
|
match self {
|
||||||
|
SerialMode::Finger => (12, 7),
|
||||||
|
SerialMode::Finger3D => (12, 9),
|
||||||
|
SerialMode::Hand => (12, 7),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
@@ -101,7 +114,7 @@ impl Default for ConfigPanelState {
|
|||||||
let port = available_ports
|
let port = available_ports
|
||||||
.first()
|
.first()
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or_else(|| "COM3".to_owned());
|
.unwrap_or_else(|| "无可用串口".to_owned());
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
mode: SerialMode::Finger,
|
mode: SerialMode::Finger,
|
||||||
@@ -241,8 +254,8 @@ pub fn draw_connect_panel(
|
|||||||
|
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
draw_connect_port_row(ui, config);
|
draw_connect_port_row(ui, config);
|
||||||
ui.add_space(6.0);
|
// ui.add_space(8.0);
|
||||||
draw_connect_matrix_row(ui, config);
|
// draw_connect_matrix_row(ui, config);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -297,14 +310,13 @@ fn draw_connect_port_row(ui: &mut egui::Ui, config: &mut ConnectPanelState) {
|
|||||||
))
|
))
|
||||||
.on_hover_text("刷新串口")
|
.on_hover_text("刷新串口")
|
||||||
.clicked()
|
.clicked()
|
||||||
|
&& let Ok(ports) = serial_enum()
|
||||||
{
|
{
|
||||||
if let Ok(ports) = serial_enum() {
|
|
||||||
if !ports.contains(&config.selected_port) {
|
if !ports.contains(&config.selected_port) {
|
||||||
config.selected_port = ports.first().cloned().unwrap_or_default();
|
config.selected_port = ports.first().cloned().unwrap_or_default();
|
||||||
}
|
}
|
||||||
config.port = ports;
|
config.port = ports;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ui.add_space(METRICS.item_gap);
|
ui.add_space(METRICS.item_gap);
|
||||||
ui.label(style::field_label("频率"));
|
ui.label(style::field_label("频率"));
|
||||||
@@ -385,43 +397,94 @@ fn draw_connect_action_row(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn draw_config_panel(
|
pub fn draw_config_panel(
|
||||||
ctx: &egui::Context,
|
ctx: &egui::Context,
|
||||||
panel: &mut FloatingPanelState,
|
panel: &mut FloatingPanelState,
|
||||||
config: &mut ConfigPanelState,
|
config: &mut ConfigPanelState,
|
||||||
connection: &ConnectionManager,
|
connection: &ConnectionManager,
|
||||||
recorder: &Recorder,
|
recorder: &Recorder,
|
||||||
|
_state: SerialIoStats,
|
||||||
|
_sample_rate_hz: f32,
|
||||||
|
_render_rate_hz: f32,
|
||||||
) -> Option<SerialMode> {
|
) -> Option<SerialMode> {
|
||||||
let mut changed_mode = None;
|
let mut changed_mode = None;
|
||||||
let conn_state = connection.state();
|
let conn_state = connection.state();
|
||||||
let stats = connection.stats();
|
let screen = ctx.content_rect();
|
||||||
let panel_width = responsive_panel_width(ctx, 560.0, 340.0);
|
let bar_rect = egui::Rect::from_min_size(
|
||||||
|
screen.left_top() + egui::vec2(0.0, layout::TITLE_BAR_HEIGHT),
|
||||||
|
egui::vec2(screen.width(), layout::CONFIG_BAR_HEIGHT),
|
||||||
|
);
|
||||||
config.connected = matches!(
|
config.connected = matches!(
|
||||||
conn_state,
|
conn_state,
|
||||||
ConnectionState::Connected | ConnectionState::Streaming
|
ConnectionState::Connected | ConnectionState::Streaming
|
||||||
);
|
);
|
||||||
|
panel.visible = true;
|
||||||
|
|
||||||
draw_floating_panel(ctx, panel, "配置", "config_panel", 560.0, 340.0, |ui| {
|
egui::Area::new(egui::Id::new("config_panel_bar"))
|
||||||
ui.set_min_width(panel_width);
|
.fixed_pos(bar_rect.min)
|
||||||
ui.set_max_width(panel_width);
|
.order(egui::Order::Foreground)
|
||||||
|
.show(ctx, |ui| {
|
||||||
|
ui.set_min_size(bar_rect.size());
|
||||||
|
ui.set_max_size(bar_rect.size());
|
||||||
|
|
||||||
if let Some(mode) = draw_mode_row(ui, config) {
|
config_bar_frame().show(ui, |ui| {
|
||||||
|
ui.set_min_width(bar_rect.width());
|
||||||
|
ui.set_max_width(bar_rect.width());
|
||||||
|
ui.spacing_mut().item_spacing = egui::vec2(METRICS.item_gap, 6.0);
|
||||||
|
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.label(style::panel_title("配置面板"));
|
||||||
|
ui.add_space(12.0);
|
||||||
|
|
||||||
|
if let Some(mode) = draw_config_bar_mode(ui, config) {
|
||||||
changed_mode = Some(mode);
|
changed_mode = Some(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw_mode_row(ui, config);
|
ui.add_space(12.0);
|
||||||
ui.separator();
|
draw_config_bar_connection(ui, config, connection, recorder, conn_state);
|
||||||
draw_connection_row(ui, config, connection, recorder, conn_state);
|
|
||||||
ui.add_space(8.0);
|
// ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||||
// Legacy serial parameter grid is intentionally kept commented for future hardware:
|
// draw_conf
|
||||||
// draw_serial_grid(ui, config);
|
// })
|
||||||
// ui.add_space(8.0);
|
})
|
||||||
draw_mode_body(ui, config, conn_state, stats);
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// let stats = connection.stats();
|
||||||
|
// let panel_width = responsive_panel_width(ctx, 560.0, 340.0);
|
||||||
|
// config.connected = matches!(
|
||||||
|
// conn_state,
|
||||||
|
// ConnectionState::Connected | ConnectionState::Streaming
|
||||||
|
// );
|
||||||
|
|
||||||
|
// draw_floating_panel(ctx, panel, "配置", "config_panel", 560.0, 340.0, |ui| {
|
||||||
|
// ui.set_min_width(panel_width);
|
||||||
|
// ui.set_max_width(panel_width);
|
||||||
|
|
||||||
|
// if let Some(mode) = draw_mode_row(ui, config) {
|
||||||
|
// changed_mode = Some(mode);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // draw_mode_row(ui, config);
|
||||||
|
// ui.separator();
|
||||||
|
// draw_connection_row(ui, config, connection, recorder, conn_state);
|
||||||
|
// ui.add_space(8.0);
|
||||||
|
// // Legacy serial parameter grid is intentionally kept commented for future hardware:
|
||||||
|
// // draw_serial_grid(ui, config);
|
||||||
|
// // ui.add_space(8.0);
|
||||||
|
// draw_mode_body(ui, config, conn_state, stats);
|
||||||
|
// });
|
||||||
changed_mode
|
changed_mode
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_mode_row(ui: &mut egui::Ui, config: &mut ConfigPanelState) -> Option<SerialMode> {
|
fn config_bar_frame() -> egui::Frame {
|
||||||
|
egui::Frame::new()
|
||||||
|
.fill(ONE_DARK_PRO.panel_deep)
|
||||||
|
.inner_margin(egui::Margin::symmetric(8, 8))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw_config_bar_mode(ui: &mut egui::Ui, config: &mut ConfigPanelState) -> Option<SerialMode> {
|
||||||
let mut changed_to = None;
|
let mut changed_to = None;
|
||||||
ui.horizontal_wrapped(|ui| {
|
ui.horizontal_wrapped(|ui| {
|
||||||
ui.colored_label(dim_text(), "模式");
|
ui.colored_label(dim_text(), "模式");
|
||||||
@@ -430,11 +493,11 @@ fn draw_mode_row(ui: &mut egui::Ui, config: &mut ConfigPanelState) -> Option<Ser
|
|||||||
if mode_button(ui, &mut config.mode, SerialMode::Finger, "指尖模块") {
|
if mode_button(ui, &mut config.mode, SerialMode::Finger, "指尖模块") {
|
||||||
changed_to = Some(SerialMode::Finger)
|
changed_to = Some(SerialMode::Finger)
|
||||||
}
|
}
|
||||||
if mode_button(ui, &mut config.mode, SerialMode::Hand, "手掌模块") {
|
|
||||||
changed_to = Some(SerialMode::Hand)
|
|
||||||
}
|
|
||||||
// mode_button(ui, &mut config.mode, SerialMode::Model, "模型");
|
// mode_button(ui, &mut config.mode, SerialMode::Model, "模型");
|
||||||
|
|
||||||
|
if mode_button(ui, &mut config.mode, SerialMode::Finger3D, "3D指尖") {
|
||||||
|
changed_to = Some(SerialMode::Finger3D)
|
||||||
|
}
|
||||||
// Legacy reconnect controls. Current sensors run fixed 921600 baud without auto-reconnect UI.
|
// Legacy reconnect controls. Current sensors run fixed 921600 baud without auto-reconnect UI.
|
||||||
// ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
// ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||||
// ui.checkbox(&mut config.auto_reconnect, "自动");
|
// ui.checkbox(&mut config.auto_reconnect, "自动");
|
||||||
@@ -445,6 +508,87 @@ fn draw_mode_row(ui: &mut egui::Ui, config: &mut ConfigPanelState) -> Option<Ser
|
|||||||
changed_to
|
changed_to
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw_config_bar_connection(
|
||||||
|
ui: &mut egui::Ui,
|
||||||
|
config: &mut ConfigPanelState,
|
||||||
|
connection: &ConnectionManager,
|
||||||
|
recorder: &Recorder,
|
||||||
|
conn_state: ConnectionState,
|
||||||
|
) {
|
||||||
|
ui.colored_label(dim_text(), "端口");
|
||||||
|
egui::ComboBox::from_id_salt("config_bar_ports")
|
||||||
|
.selected_text("config_bar_ports")
|
||||||
|
.width(170.0)
|
||||||
|
.selected_text(if config.port.is_empty() {
|
||||||
|
"无可用串口".to_owned()
|
||||||
|
} else {
|
||||||
|
config.port.clone()
|
||||||
|
})
|
||||||
|
.show_ui(ui, |ui| {
|
||||||
|
for port in &config.available_ports {
|
||||||
|
ui.selectable_value(&mut config.port, port.clone(), port.as_str());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if ui
|
||||||
|
.add(style::icon_button(
|
||||||
|
egui::RichText::new("\u{f021}")
|
||||||
|
.color(ONE_DARK_PRO.text)
|
||||||
|
.size(16.0),
|
||||||
|
egui::vec2(30.0, METRICS.field_height),
|
||||||
|
))
|
||||||
|
.on_hover_text("刷新串口")
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
refresh_config_ports(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.add_space(4.0);
|
||||||
|
ui.colored_label(dim_text(), "波特率");
|
||||||
|
ui.label(style::value_text(config.baud_rate.to_string()));
|
||||||
|
|
||||||
|
ui.add_space(4.0);
|
||||||
|
ui.colored_label(dim_text(), "状态");
|
||||||
|
ui.colored_label(
|
||||||
|
connection_status_color(conn_state),
|
||||||
|
connection_status_text(conn_state),
|
||||||
|
);
|
||||||
|
|
||||||
|
ui.add_space(6.0);
|
||||||
|
|
||||||
|
let is_connected = matches!(
|
||||||
|
conn_state,
|
||||||
|
ConnectionState::Connected | ConnectionState::Streaming
|
||||||
|
);
|
||||||
|
|
||||||
|
let button_text = if is_connected { "\u{f127}" } else { "\u{f0c1}" };
|
||||||
|
if ui
|
||||||
|
.add_sized(
|
||||||
|
egui::vec2(88.0, METRICS.button_height),
|
||||||
|
if is_connected {
|
||||||
|
style::danger_button(button_text)
|
||||||
|
} else {
|
||||||
|
style::primary_button(button_text)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
if is_connected {
|
||||||
|
connection.disconnect();
|
||||||
|
} else if !config.port.is_empty() {
|
||||||
|
let (rows, cols) = config.mode.matrix_shape();
|
||||||
|
connection.connect(
|
||||||
|
&config.port,
|
||||||
|
rows,
|
||||||
|
cols,
|
||||||
|
config.mode.baud_rate(),
|
||||||
|
config.mode.protocol(),
|
||||||
|
recorder.clone(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn draw_connection_row(
|
fn draw_connection_row(
|
||||||
ui: &mut egui::Ui,
|
ui: &mut egui::Ui,
|
||||||
config: &mut ConfigPanelState,
|
config: &mut ConfigPanelState,
|
||||||
@@ -457,7 +601,7 @@ fn draw_connection_row(
|
|||||||
ui.horizontal_wrapped(|ui| {
|
ui.horizontal_wrapped(|ui| {
|
||||||
ui.label(style::field_label("端口"));
|
ui.label(style::field_label("端口"));
|
||||||
egui::ComboBox::from_id_salt("config_ports")
|
egui::ComboBox::from_id_salt("config_ports")
|
||||||
.width(ui.available_width().min(150.0).max(104.0))
|
.width(ui.available_width().clamp(104.0, 150.0))
|
||||||
.selected_text(if config.port.is_empty() {
|
.selected_text(if config.port.is_empty() {
|
||||||
"无可用串口".to_owned()
|
"无可用串口".to_owned()
|
||||||
} else {
|
} else {
|
||||||
@@ -504,10 +648,11 @@ fn draw_connection_row(
|
|||||||
if is_connected {
|
if is_connected {
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
} else if !config.port.is_empty() {
|
} else if !config.port.is_empty() {
|
||||||
|
let (rows, cols) = config.mode.matrix_shape();
|
||||||
connection.connect(
|
connection.connect(
|
||||||
&config.port,
|
&config.port,
|
||||||
12,
|
rows,
|
||||||
7,
|
cols,
|
||||||
config.mode.baud_rate(),
|
config.mode.baud_rate(),
|
||||||
config.mode.protocol(),
|
config.mode.protocol(),
|
||||||
recorder.clone(),
|
recorder.clone(),
|
||||||
@@ -625,6 +770,9 @@ fn draw_mode_body(
|
|||||||
// });
|
// });
|
||||||
draw_status_bytes_row(ui, conn_state, stats);
|
draw_status_bytes_row(ui, conn_state, stats);
|
||||||
}
|
}
|
||||||
|
SerialMode::Finger3D => {
|
||||||
|
draw_status_bytes_row(ui, conn_state, stats);
|
||||||
|
}
|
||||||
SerialMode::Hand => {
|
SerialMode::Hand => {
|
||||||
// Legacy manual-TX controls for older hand-module debugging:
|
// Legacy manual-TX controls for older hand-module debugging:
|
||||||
// ui.horizontal(|ui| {
|
// ui.horizontal(|ui| {
|
||||||
@@ -717,7 +865,7 @@ pub fn icon_button_sized<'a>(
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
.fill(ONE_DARK_PRO.panel_strong)
|
.fill(ONE_DARK_PRO.panel_strong)
|
||||||
.stroke(egui::Stroke::new(1.0, ONE_DARK_PRO.border))
|
.stroke(egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border))
|
||||||
.corner_radius(egui::CornerRadius::same(ONE_DARK_PRO.radius))
|
.corner_radius(egui::CornerRadius::same(ONE_DARK_PRO.radius))
|
||||||
.min_size(size);
|
.min_size(size);
|
||||||
|
|
||||||
@@ -836,14 +984,17 @@ const HAND_FORCE_PANEL_MAX_HEIGHT: f32 = 190.0;
|
|||||||
const HAND_FORCE_PANEL_GAP: f32 = 12.0;
|
const HAND_FORCE_PANEL_GAP: f32 = 12.0;
|
||||||
const HAND_FORCE_PANEL_SIDE_MARGIN: f32 = 24.0;
|
const HAND_FORCE_PANEL_SIDE_MARGIN: f32 = 24.0;
|
||||||
const HAND_FORCE_PANEL_VERTICAL_MARGIN: f32 = 28.0;
|
const HAND_FORCE_PANEL_VERTICAL_MARGIN: f32 = 28.0;
|
||||||
const HAND_FORCE_PANEL_TITLES: [(&str, &str); 7] = [
|
const HAND_FORCE_PANEL_TITLES: [(&str, &str); 10] = [
|
||||||
("T1", "拇指"),
|
("T", "顶部 2×4"),
|
||||||
("T2", "食指"),
|
("L3", "左侧 3×1"),
|
||||||
("T3", "中指"),
|
("L5", "左侧 5×1"),
|
||||||
("T4", "无名指"),
|
("L8", "左侧 8×1"),
|
||||||
("T5", "小指"),
|
("L10", "左侧 10×1"),
|
||||||
("P1", "掌心横区"),
|
("C", "中央 11×4"),
|
||||||
("P2", "掌心纵区"),
|
("R3", "右侧 3×1"),
|
||||||
|
("R5", "右侧 5×1"),
|
||||||
|
("R8", "右侧 8×1"),
|
||||||
|
("R10", "右侧 10×1"),
|
||||||
];
|
];
|
||||||
|
|
||||||
fn has_recent_resultant_force(values: &[f32]) -> bool {
|
fn has_recent_resultant_force(values: &[f32]) -> bool {
|
||||||
@@ -869,7 +1020,7 @@ pub fn draw_hand_force_panels(ctx: &egui::Context, visible: bool, histories: &[V
|
|||||||
.max(HAND_FORCE_PANEL_MIN_WIDTH.min(side_width));
|
.max(HAND_FORCE_PANEL_MIN_WIDTH.min(side_width));
|
||||||
let left_x = screen.left() + side_margin;
|
let left_x = screen.left() + side_margin;
|
||||||
let right_x = screen.right() - side_margin - panel_width;
|
let right_x = screen.right() - side_margin - panel_width;
|
||||||
let left_count = 4usize;
|
let left_count = 5usize;
|
||||||
let right_count = HAND_FORCE_PANEL_TITLES.len() - left_count;
|
let right_count = HAND_FORCE_PANEL_TITLES.len() - left_count;
|
||||||
let available_height =
|
let available_height =
|
||||||
(screen.height() - layout::TITLE_BAR_HEIGHT - vertical_margin * 2.0).max(0.0);
|
(screen.height() - layout::TITLE_BAR_HEIGHT - vertical_margin * 2.0).max(0.0);
|
||||||
@@ -885,9 +1036,8 @@ pub fn draw_hand_force_panels(ctx: &egui::Context, visible: bool, histories: &[V
|
|||||||
let left_top = (screen.center().y - left_height * 0.5).max(min_top);
|
let left_top = (screen.center().y - left_height * 0.5).max(min_top);
|
||||||
let right_top = (screen.center().y - right_height * 0.5).max(min_top);
|
let right_top = (screen.center().y - right_height * 0.5).max(min_top);
|
||||||
|
|
||||||
for index in 0..HAND_FORCE_PANEL_TITLES.len() {
|
for (index, &(code, title)) in HAND_FORCE_PANEL_TITLES.iter().enumerate() {
|
||||||
let history = histories.get(index).map(Vec::as_slice).unwrap_or(&[]);
|
let history = histories.get(index).map(Vec::as_slice).unwrap_or(&[]);
|
||||||
let (code, title) = HAND_FORCE_PANEL_TITLES[index];
|
|
||||||
let (target_x, target_y) = if index < left_count {
|
let (target_x, target_y) = if index < left_count {
|
||||||
(left_x, left_top + index as f32 * (panel_height + gap))
|
(left_x, left_top + index as f32 * (panel_height + gap))
|
||||||
} else {
|
} else {
|
||||||
@@ -911,6 +1061,7 @@ pub fn draw_hand_force_panels(ctx: &egui::Context, visible: bool, histories: &[V
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn draw_force_chart_area(
|
fn draw_force_chart_area(
|
||||||
ctx: &egui::Context,
|
ctx: &egui::Context,
|
||||||
id: egui::Id,
|
id: egui::Id,
|
||||||
@@ -987,7 +1138,7 @@ fn paint_resultant_force_chart(ui: &mut egui::Ui, values: &[f32], chart_height:
|
|||||||
painter.rect_stroke(
|
painter.rect_stroke(
|
||||||
rect,
|
rect,
|
||||||
radius,
|
radius,
|
||||||
egui::Stroke::new(1.0, color_alpha(ONE_DARK_PRO.accent, 95)),
|
egui::Stroke::new(1.0_f32, color_alpha(ONE_DARK_PRO.accent, 95)),
|
||||||
egui::StrokeKind::Outside,
|
egui::StrokeKind::Outside,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -1036,11 +1187,11 @@ fn paint_resultant_force_chart(ui: &mut egui::Ui, values: &[f32], chart_height:
|
|||||||
if points.len() >= 2 {
|
if points.len() >= 2 {
|
||||||
plot_painter.add(egui::Shape::line(
|
plot_painter.add(egui::Shape::line(
|
||||||
points.clone(),
|
points.clone(),
|
||||||
egui::Stroke::new(4.0, color_alpha(ONE_DARK_PRO.accent, 45)),
|
egui::Stroke::new(4.0_f32, color_alpha(ONE_DARK_PRO.accent, 45)),
|
||||||
));
|
));
|
||||||
plot_painter.add(egui::Shape::line(
|
plot_painter.add(egui::Shape::line(
|
||||||
points.clone(),
|
points.clone(),
|
||||||
egui::Stroke::new(1.7, ONE_DARK_PRO.accent),
|
egui::Stroke::new(1.7_f32, ONE_DARK_PRO.accent),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1050,7 +1201,7 @@ fn paint_resultant_force_chart(ui: &mut egui::Ui, values: &[f32], chart_height:
|
|||||||
last,
|
last,
|
||||||
5.0 + pulse * 12.0,
|
5.0 + pulse * 12.0,
|
||||||
egui::Stroke::new(
|
egui::Stroke::new(
|
||||||
1.0,
|
1.0_f32,
|
||||||
color_alpha(ACCENT_GREEN, ((1.0 - pulse) * 120.0) as u8),
|
color_alpha(ACCENT_GREEN, ((1.0 - pulse) * 120.0) as u8),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -1074,7 +1225,7 @@ fn paint_force_grid(
|
|||||||
egui::pos2(chart_rect.left(), y),
|
egui::pos2(chart_rect.left(), y),
|
||||||
egui::pos2(chart_rect.right(), y),
|
egui::pos2(chart_rect.right(), y),
|
||||||
],
|
],
|
||||||
egui::Stroke::new(1.0, color_alpha(ONE_DARK_PRO.border, 78)),
|
egui::Stroke::new(1.0_f32, color_alpha(ONE_DARK_PRO.border, 78)),
|
||||||
);
|
);
|
||||||
painter.text(
|
painter.text(
|
||||||
egui::pos2(rect.left() + 8.0, y),
|
egui::pos2(rect.left() + 8.0, y),
|
||||||
@@ -1092,7 +1243,7 @@ fn paint_force_grid(
|
|||||||
egui::pos2(x, chart_rect.top()),
|
egui::pos2(x, chart_rect.top()),
|
||||||
egui::pos2(x, chart_rect.bottom()),
|
egui::pos2(x, chart_rect.bottom()),
|
||||||
],
|
],
|
||||||
egui::Stroke::new(1.0, color_alpha(ONE_DARK_PRO.border_soft, 42)),
|
egui::Stroke::new(1.0_f32, color_alpha(ONE_DARK_PRO.border_soft, 42)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1201,8 +1352,7 @@ fn draw_floating_panel(
|
|||||||
window_rect = Some(response.response.rect);
|
window_rect = Some(response.response.rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
if hide_requested {
|
if hide_requested && let Some(rect) = window_rect {
|
||||||
if let Some(rect) = window_rect {
|
|
||||||
let screen = ctx.content_rect();
|
let screen = ctx.content_rect();
|
||||||
let tag_size = egui::vec2(86.0, 22.0);
|
let tag_size = egui::vec2(86.0, 22.0);
|
||||||
|
|
||||||
@@ -1219,7 +1369,6 @@ fn draw_floating_panel(
|
|||||||
|
|
||||||
panel.tag_pos = egui::pos2(x, y);
|
panel.tag_pos = egui::pos2(x, y);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
panel.visible = open && !hide_requested;
|
panel.visible = open && !hide_requested;
|
||||||
}
|
}
|
||||||
// else {
|
// else {
|
||||||
@@ -1401,11 +1550,11 @@ fn paint_integrated_handle(
|
|||||||
ui.painter().add(egui::Shape::convex_polygon(
|
ui.painter().add(egui::Shape::convex_polygon(
|
||||||
points.clone(),
|
points.clone(),
|
||||||
fill,
|
fill,
|
||||||
egui::Stroke::new(1.0, ONE_DARK_PRO.border),
|
egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border),
|
||||||
));
|
));
|
||||||
ui.painter().line_segment(
|
ui.painter().line_segment(
|
||||||
[points[2], points[3]],
|
[points[2], points[3]],
|
||||||
egui::Stroke::new(1.0, ONE_DARK_PRO.border_soft),
|
egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border_soft),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1426,14 +1575,14 @@ fn paint_integrated_handle(
|
|||||||
arrow_center + egui::vec2(-6.0, -2.0 * arrow),
|
arrow_center + egui::vec2(-6.0, -2.0 * arrow),
|
||||||
arrow_center + egui::vec2(0.0, 4.0 * arrow),
|
arrow_center + egui::vec2(0.0, 4.0 * arrow),
|
||||||
],
|
],
|
||||||
egui::Stroke::new(1.7, arrow_color),
|
egui::Stroke::new(1.7_f32, arrow_color),
|
||||||
);
|
);
|
||||||
ui.painter().line_segment(
|
ui.painter().line_segment(
|
||||||
[
|
[
|
||||||
arrow_center + egui::vec2(6.0, -2.0 * arrow),
|
arrow_center + egui::vec2(6.0, -2.0 * arrow),
|
||||||
arrow_center + egui::vec2(0.0, 4.0 * arrow),
|
arrow_center + egui::vec2(0.0, 4.0 * arrow),
|
||||||
],
|
],
|
||||||
egui::Stroke::new(1.7, arrow_color),
|
egui::Stroke::new(1.7_f32, arrow_color),
|
||||||
);
|
);
|
||||||
|
|
||||||
if !label.is_empty() {
|
if !label.is_empty() {
|
||||||
@@ -1459,8 +1608,8 @@ fn paint_integrated_center_panel(
|
|||||||
handle_on_bottom: bool,
|
handle_on_bottom: bool,
|
||||||
) {
|
) {
|
||||||
let painter = ui.painter();
|
let painter = ui.painter();
|
||||||
let stroke = egui::Stroke::new(1.0, ONE_DARK_PRO.border);
|
let stroke = egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border);
|
||||||
let accent_stroke = egui::Stroke::new(1.2, ONE_DARK_PRO.border_soft);
|
let accent_stroke = egui::Stroke::new(1.2_f32, ONE_DARK_PRO.border_soft);
|
||||||
let top = rect.top();
|
let top = rect.top();
|
||||||
let left = rect.left();
|
let left = rect.left();
|
||||||
let right = rect.right();
|
let right = rect.right();
|
||||||
@@ -1605,7 +1754,7 @@ pub fn draw_signal_chart(ui: &mut egui::Ui, values: &[f32], label: &str, color:
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
painter.add(egui::Shape::line(points, egui::Stroke::new(1.5, color)));
|
painter.add(egui::Shape::line(points, egui::Stroke::new(1.5_f32, color)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1666,11 +1815,9 @@ pub fn draw_recording_toolbar(ui: &mut egui::Ui, recorder: &Recorder, export_pat
|
|||||||
ui.add_space(4.0);
|
ui.add_space(4.0);
|
||||||
|
|
||||||
// Pause/Resume
|
// Pause/Resume
|
||||||
if is_recording {
|
if is_recording && ui.add(tag_button("⏸ 暂停")).clicked() {
|
||||||
if ui.add(tag_button("⏸ 暂停")).clicked() {
|
|
||||||
let _ = recorder.pause_recording();
|
let _ = recorder.pause_recording();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ui.add_space(8.0);
|
ui.add_space(8.0);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use anyhow;
|
|
||||||
use serialport::available_ports;
|
use serialport::available_ports;
|
||||||
|
|
||||||
pub fn serial_enum() -> anyhow::Result<Vec<String>> {
|
pub fn serial_enum() -> anyhow::Result<Vec<String>> {
|
||||||
|
|||||||
BIN
static/MapleMono-NF-CN-Bold.ttf
Normal file
BIN
static/MapleMono-NF-CN-Bold.ttf
Normal file
Binary file not shown.
BIN
static/MapleMono-NF-CN-Regular.ttf
Normal file
BIN
static/MapleMono-NF-CN-Regular.ttf
Normal file
Binary file not shown.
@@ -349,10 +349,8 @@ fn circle_alpha(local: vec2f, radius: f32, softness: f32) -> f32 {
|
|||||||
return 1.0 - smoothstep(radius, radius + softness, dist);
|
return 1.0 - smoothstep(radius, radius + softness, dist);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert a point authored in hand.png UV space into clip space.
|
// Convert a point authored in sensor-canvas UV space into aspect-fitted clip space.
|
||||||
// This mirrors fs_hand_image's aspect-fit math, so fingertip dots stay attached
|
fn sensor_canvas_uv_to_clip(image_uv: vec2f) -> vec2f {
|
||||||
// to the same image pixels when the app window changes shape.
|
|
||||||
fn hand_image_uv_to_clip(image_uv: vec2f) -> vec2f {
|
|
||||||
let viewport_aspect = u.viewport.x / max(u.viewport.y, 1.0);
|
let viewport_aspect = u.viewport.x / max(u.viewport.y, 1.0);
|
||||||
let image_aspect = u.image.x / max(u.image.y, 1.0);
|
let image_aspect = u.image.x / max(u.image.y, 1.0);
|
||||||
|
|
||||||
@@ -420,7 +418,7 @@ fn vs_hand_membrane(vertex: DotVertexInput, instance: DotInstanceInput) -> HandM
|
|||||||
let image_uv = (center_px + rotate_2d(local_px, angle)) / max(u.image.xy, vec2f(1.0, 1.0));
|
let image_uv = (center_px + rotate_2d(local_px, angle)) / max(u.image.xy, vec2f(1.0, 1.0));
|
||||||
|
|
||||||
var out: HandMembraneVertexOutput;
|
var out: HandMembraneVertexOutput;
|
||||||
out.clip_position = vec4f(hand_image_uv_to_clip(image_uv), 0.0, 1.0);
|
out.clip_position = vec4f(sensor_canvas_uv_to_clip(image_uv), 0.0, 1.0);
|
||||||
out.local = vertex.local;
|
out.local = vertex.local;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@@ -470,7 +468,7 @@ fn vs_hand_dot(vertex: DotVertexInput, instance: DotInstanceInput) -> DotVertexO
|
|||||||
let shaped = smoothstep(0.0, 1.0, intensity);
|
let shaped = smoothstep(0.0, 1.0, intensity);
|
||||||
|
|
||||||
// Hand instances store hand.png UV in world_position.xy instead of 3D world space.
|
// Hand instances store hand.png UV in world_position.xy instead of 3D world space.
|
||||||
let center = hand_image_uv_to_clip(instance.world_position.xy);
|
let center = sensor_canvas_uv_to_clip(instance.world_position.xy);
|
||||||
// Hand fingertip matrices are much smaller than the full Finger view.
|
// Hand fingertip matrices are much smaller than the full Finger view.
|
||||||
// Keep each bead below the local cell spacing so the 12x7 matrix remains visibly separated.
|
// Keep each bead below the local cell spacing so the 12x7 matrix remains visibly separated.
|
||||||
let pixel_size = u.glyph.x * mix(0.22, 0.34, shaped);
|
let pixel_size = u.glyph.x * mix(0.22, 0.34, shaped);
|
||||||
@@ -500,75 +498,14 @@ fn fs_hand_dot(in: DotVertexOutput) -> @location(0) vec4f {
|
|||||||
return output_color(color, max(core, halo));
|
return output_color(color, max(core, halo));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn chip_pixel_alpha(local: vec2f, half_size: f32, softness: f32) -> f32 {
|
|
||||||
let q = abs(local) - vec2f(half_size, half_size);
|
|
||||||
let dist = length(max(q, vec2f(0.0, 0.0))) + min(max(q.x, q.y), 0.0);
|
|
||||||
return 1.0 - smoothstep(0.0, softness, dist);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct HandPalmChipVertexOutput {
|
|
||||||
@builtin(position) clip_position: vec4f,
|
|
||||||
@location(0) local: vec2f,
|
|
||||||
@location(1) grid: vec2f,
|
|
||||||
}
|
|
||||||
|
|
||||||
@vertex
|
|
||||||
fn vs_hand_palm_chip(vertex: DotVertexInput, instance: DotInstanceInput) -> HandPalmChipVertexOutput {
|
|
||||||
let center_px = instance.world_position.xy * u.image.xy;
|
|
||||||
let size_px = instance.style.yz;
|
|
||||||
let angle = instance.style.x;
|
|
||||||
let packed_shape = instance.style.w;
|
|
||||||
let shape_rows = floor(packed_shape / 100.0);
|
|
||||||
let shape_cols = max(packed_shape - shape_rows * 100.0, 1.0);
|
|
||||||
let local_px = vertex.local * size_px * 0.5;
|
|
||||||
let image_uv = (center_px + rotate_2d(local_px, angle)) / max(u.image.xy, vec2f(1.0, 1.0));
|
|
||||||
|
|
||||||
var out: HandPalmChipVertexOutput;
|
|
||||||
out.clip_position = vec4f(hand_image_uv_to_clip(image_uv), 0.0, 1.0);
|
|
||||||
out.local = vertex.local;
|
|
||||||
out.grid = vec2f(shape_cols, max(shape_rows, 1.0));
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
@fragment
|
|
||||||
fn fs_hand_palm_chip(in: HandPalmChipVertexOutput) -> @location(0) vec4f {
|
|
||||||
// Dark rounded tile: this is the inset chip body sitting inside the palm surface.
|
|
||||||
let panel = rounded_rect_alpha(in.local, 0.10, 0.040);
|
|
||||||
let inset = rounded_rect_alpha(in.local * vec2f(1.10, 1.08), 0.08, 0.052);
|
|
||||||
let rim = clamp(panel - inset * 0.72, 0.0, 1.0);
|
|
||||||
|
|
||||||
// Inactive chip pixels use the chip's real hand layout:
|
|
||||||
// horizontal 14 columns x 5 rows, or vertical 4 columns x 11 rows.
|
|
||||||
let uv = clamp(in.local * 0.5 + vec2f(0.5, 0.5), vec2f(0.0, 0.0), vec2f(1.0, 1.0));
|
|
||||||
let cell = abs(fract(uv * in.grid) - vec2f(0.5, 0.5));
|
|
||||||
let micro_pixel = 1.0 - smoothstep(0.105, 0.178, length(cell * vec2f(1.04, 0.94)));
|
|
||||||
|
|
||||||
let top_bevel = smoothstep(-0.96, -0.18, -in.local.y) * 0.16;
|
|
||||||
let lower_shadow = smoothstep(0.20, 0.92, in.local.y) * 0.22;
|
|
||||||
let side_bevel = smoothstep(0.58, 0.96, abs(in.local.x)) * 0.12;
|
|
||||||
let scan = (0.5 + 0.5 * sin((uv.y * 36.0 + uv.x * 7.0) * 6.28318)) * 0.026;
|
|
||||||
|
|
||||||
let base = vec3f(0.004, 0.012, 0.018);
|
|
||||||
let glass = vec3f(0.012, 0.048, 0.064);
|
|
||||||
let pixel_color = vec3f(0.075, 0.300, 0.360);
|
|
||||||
let rim_color = vec3f(0.060, 0.560, 0.670);
|
|
||||||
let color = base * (0.92 - lower_shadow)
|
|
||||||
+ glass * (0.52 + top_bevel + side_bevel + scan)
|
|
||||||
+ pixel_color * micro_pixel * 0.70
|
|
||||||
+ rim_color * rim * 0.60;
|
|
||||||
|
|
||||||
let alpha = panel * (0.64 + micro_pixel * 0.18 + rim * 0.20);
|
|
||||||
return output_color(color, alpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
@vertex
|
@vertex
|
||||||
fn vs_hand_palm_dot(vertex: DotVertexInput, instance: DotInstanceInput) -> DotVertexOutput {
|
fn vs_hand_palm_dot(vertex: DotVertexInput, instance: DotInstanceInput) -> DotVertexOutput {
|
||||||
let intensity = saturate(instance.style.x);
|
let intensity = saturate(instance.style.x);
|
||||||
let shaped = smoothstep(0.0, 1.0, intensity);
|
let shaped = smoothstep(0.0, 1.0, intensity);
|
||||||
|
|
||||||
// Palm chip pixels are deliberately smaller than fingertip beads so they read as a chip matrix.
|
// Use the same on-screen point size as Finger mode.
|
||||||
let center = hand_image_uv_to_clip(instance.world_position.xy);
|
let center = sensor_canvas_uv_to_clip(instance.world_position.xy);
|
||||||
let pixel_size = u.glyph.x * mix(0.13, 0.25, shaped);
|
let pixel_size = u.glyph.x * mix(1.07, 2.23, shaped);
|
||||||
let ndc_offset = vertex.local * vec2f(pixel_size / u.viewport.x, pixel_size / u.viewport.y) * 2.0;
|
let ndc_offset = vertex.local * vec2f(pixel_size / u.viewport.x, pixel_size / u.viewport.y) * 2.0;
|
||||||
|
|
||||||
var out: DotVertexOutput;
|
var out: DotVertexOutput;
|
||||||
@@ -581,16 +518,11 @@ fn vs_hand_palm_dot(vertex: DotVertexInput, instance: DotInstanceInput) -> DotVe
|
|||||||
@fragment
|
@fragment
|
||||||
fn fs_hand_palm_dot(in: DotVertexOutput) -> @location(0) vec4f {
|
fn fs_hand_palm_dot(in: DotVertexOutput) -> @location(0) vec4f {
|
||||||
let intensity = saturate(in.intensity);
|
let intensity = saturate(in.intensity);
|
||||||
let pixel = chip_pixel_alpha(in.local, 0.52, 0.070);
|
let base_color = sample_range_color(intensity);
|
||||||
let glow = circle_alpha(in.local, 0.95, 0.22) * intensity * 0.36;
|
|
||||||
|
|
||||||
let cold = vec3f(0.070, 0.340, 0.360);
|
let alpha = circle_alpha(in.local, 0.46, 0.045);
|
||||||
let gradient = sample_range_color(intensity);
|
let color = base_color * mix(0.86, 1.06, intensity);
|
||||||
let color = mix(cold, gradient, smoothstep(0.0, 0.20, intensity))
|
|
||||||
* (0.58 + intensity * 1.04)
|
|
||||||
+ gradient * glow * 0.72;
|
|
||||||
|
|
||||||
let alpha = max(pixel * (0.20 + intensity * 0.76), glow);
|
|
||||||
return output_color(color, alpha);
|
return output_color(color, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user