Compare commits
6 Commits
waic-hand
...
waic-hand-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4d0e65c02b | ||
|
|
ca6ca377df | ||
|
|
801a909c64 | ||
|
|
bf7907ce6f | ||
|
|
466bb5dec7 | ||
|
|
5af3c2862b |
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -1318,8 +1318,10 @@ dependencies = [
|
|||||||
"gltf",
|
"gltf",
|
||||||
"image",
|
"image",
|
||||||
"log",
|
"log",
|
||||||
|
"serde",
|
||||||
"serialport",
|
"serialport",
|
||||||
"tobj",
|
"tobj",
|
||||||
|
"toml",
|
||||||
"winresource",
|
"winresource",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -4001,9 +4003,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml"
|
name = "toml"
|
||||||
version = "1.1.2+spec-1.1.0"
|
version = "1.1.3+spec-1.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "81f3d15e84cbcd896376e6730314d59fb5a87f31e4b038454184435cd57defee"
|
checksum = "53c96ecdfa941c8fc4fcaed14f99ada8ebed502eef533015095a07e3301d4c3c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"serde_core",
|
"serde_core",
|
||||||
@@ -4046,9 +4048,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml_writer"
|
name = "toml_writer"
|
||||||
version = "1.1.1+spec-1.1.0"
|
version = "1.1.2+spec-1.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "756daf9b1013ebe47a8776667b466417e2d4c5679d441c26230efd9ef78692db"
|
checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing"
|
name = "tracing"
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ crc = "3.4.0"
|
|||||||
log = "0.4.29"
|
log = "0.4.29"
|
||||||
tobj = "4.0.4"
|
tobj = "4.0.4"
|
||||||
gltf = "1.4.1"
|
gltf = "1.4.1"
|
||||||
|
toml = "1.1.3"
|
||||||
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
|||||||
59
config.toml
Normal file
59
config.toml
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
[thumb]
|
||||||
|
"0.57" = 35694
|
||||||
|
"2.57" = 226640
|
||||||
|
"3.57" = 319868
|
||||||
|
"4.57" = 398021
|
||||||
|
"5.57" = 450448
|
||||||
|
"6.57" = 510506
|
||||||
|
"8.57" = 592075
|
||||||
|
"10.57" = 655760
|
||||||
|
"15.57" = 771671
|
||||||
|
"20.57" = 813967
|
||||||
|
|
||||||
|
[index]
|
||||||
|
"0.57" = 45490
|
||||||
|
"2.57" = 267579
|
||||||
|
"3.57" = 352066
|
||||||
|
"4.57" = 431681
|
||||||
|
"5.57" = 457605
|
||||||
|
"6.57" = 550875
|
||||||
|
"8.57" = 624327
|
||||||
|
"10.57" = 732735
|
||||||
|
"15.57" = 883397
|
||||||
|
"20.57" = 899338
|
||||||
|
|
||||||
|
[middle]
|
||||||
|
"0.57" = 51562
|
||||||
|
"2.57" = 252840
|
||||||
|
"3.57" = 326531
|
||||||
|
"4.57" = 386571
|
||||||
|
"5.57" = 415819
|
||||||
|
"6.57" = 514679
|
||||||
|
"8.57" = 631745
|
||||||
|
"10.57" = 678945
|
||||||
|
"15.57" = 810847
|
||||||
|
"20.57" = 900422
|
||||||
|
|
||||||
|
[ring]
|
||||||
|
"0.57" = 33213
|
||||||
|
"2.57" = 220611
|
||||||
|
"3.57" = 307383
|
||||||
|
"4.57" = 369637
|
||||||
|
"5.57" = 430462
|
||||||
|
"6.57" = 489659
|
||||||
|
"8.57" = 584789
|
||||||
|
"10.57" = 664960
|
||||||
|
"15.57" = 802749
|
||||||
|
"20.57" = 926907
|
||||||
|
|
||||||
|
[little]
|
||||||
|
"0.57" = 44291
|
||||||
|
"2.57" = 216657
|
||||||
|
"3.57" = 301950
|
||||||
|
"4.57" = 366186
|
||||||
|
"5.57" = 384791
|
||||||
|
"6.57" = 496521
|
||||||
|
"8.57" = 566189
|
||||||
|
"10.57" = 701459
|
||||||
|
"15.57" = 845608
|
||||||
|
"20.57" = 940796
|
||||||
275
scripts/extract_excel_data.py
Normal file
275
scripts/extract_excel_data.py
Normal file
@@ -0,0 +1,275 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
提取 展会数据-H版本.xlsx 中每一组数据并按指定格式输出。
|
||||||
|
|
||||||
|
数据组织:5 个数据组(1#、3#、7#、8#、10#),由空行分隔。
|
||||||
|
每组包含 10 行指标:
|
||||||
|
指标 / 1s 均值 / 240s 输出值 / 240s 均值 / 误差(%) /
|
||||||
|
精度 / b值平均值 / AD值增幅 / AD值漂移 / 增幅/漂移
|
||||||
|
每行有 12 个数值列(C~N),与 指标 行的 12 个挡位一一对应。
|
||||||
|
|
||||||
|
输出格式(示例):
|
||||||
|
1#, 115181, 365308, 485911, ...,
|
||||||
|
3#, 116825, 371568, 475160, ...,
|
||||||
|
|
||||||
|
用法:
|
||||||
|
python extract_excel_data.py [xlsx_path] [选项]
|
||||||
|
--row LABEL 只输出指定指标行(如 "1s 均值"),可多次指定
|
||||||
|
--skip-indicators V 跳过指定挡位(按 指标 行数值匹配),可多次指定
|
||||||
|
--with-title 在每行首部加上组编号(如 "1#, 115181, ...")
|
||||||
|
--raw 保留原始数值(不取整)
|
||||||
|
--annotate 在每行末尾附加 " // 组号 指标名" 注释
|
||||||
|
-o FILE 输出到文件(默认输出到标准输出)
|
||||||
|
"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import openpyxl
|
||||||
|
|
||||||
|
# 默认 Excel 文件路径
|
||||||
|
DEFAULT_XLSX = os.path.join(
|
||||||
|
os.path.dirname(os.path.abspath(__file__)),
|
||||||
|
"..",
|
||||||
|
"展会数据-H版本.xlsx",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def is_blank_row(row_values):
|
||||||
|
"""判断是否为空白行(全为 None 或空字符串)。"""
|
||||||
|
for v in row_values:
|
||||||
|
if v is None:
|
||||||
|
continue
|
||||||
|
if isinstance(v, str) and v.strip() == "":
|
||||||
|
continue
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def is_group_header(row_values):
|
||||||
|
"""判断是否为组标题行(A 列为类似 '1#' '3#' 的编号)。"""
|
||||||
|
first = row_values[0]
|
||||||
|
if first is None:
|
||||||
|
return False
|
||||||
|
return isinstance(first, str) and first.strip().endswith("#")
|
||||||
|
|
||||||
|
|
||||||
|
def extract_data_rows(ws):
|
||||||
|
"""
|
||||||
|
返回一个列表,每个元素是 (group_name, row_label, [12 个数值])。
|
||||||
|
group_name 为当前组编号;row_label 为 B 列标签;数值列表为 C~N 列。
|
||||||
|
"""
|
||||||
|
results = []
|
||||||
|
current_group = None
|
||||||
|
|
||||||
|
for row in ws.iter_rows(min_row=1, max_row=ws.max_row, values_only=True):
|
||||||
|
row = list(row[:14]) # 仅取前 14 列
|
||||||
|
if is_blank_row(row):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if is_group_header(row):
|
||||||
|
current_group = row[0]
|
||||||
|
label = row[1] if len(row) > 1 and row[1] is not None else "指标"
|
||||||
|
values = row[2:]
|
||||||
|
results.append((current_group, label, values))
|
||||||
|
continue
|
||||||
|
|
||||||
|
label = row[1] if len(row) > 1 and row[1] is not None else ""
|
||||||
|
values = row[2:]
|
||||||
|
if current_group is None:
|
||||||
|
continue
|
||||||
|
results.append((current_group, label, values))
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
def parse_skip_indicators(values):
|
||||||
|
"""
|
||||||
|
把命令行传入的 --skip-indicators 值解析为浮点数集合。
|
||||||
|
支持 "0.97" 或 "0.97,1.97" 形式。
|
||||||
|
"""
|
||||||
|
out = set()
|
||||||
|
if not values:
|
||||||
|
return out
|
||||||
|
for raw in values:
|
||||||
|
for token in str(raw).split(","):
|
||||||
|
token = token.strip()
|
||||||
|
if not token:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
out.add(float(token))
|
||||||
|
except ValueError:
|
||||||
|
print(f"警告:无法解析指标值 '{token}',已忽略。", file=sys.stderr)
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def indicators_match(a, b, tol=1e-9):
|
||||||
|
"""浮点数比较(容忍微小误差)。"""
|
||||||
|
if a is None or b is None:
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
return abs(float(a) - float(b)) < tol
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def format_value(v, raw=False):
|
||||||
|
"""
|
||||||
|
将单元格值格式化为字符串。
|
||||||
|
raw=False: 数值四舍五入到整数(匹配示例样式)。
|
||||||
|
raw=True : 保留原始数值。
|
||||||
|
"""
|
||||||
|
if v is None:
|
||||||
|
return "0"
|
||||||
|
if isinstance(v, bool):
|
||||||
|
return "1" if v else "0"
|
||||||
|
if isinstance(v, (int,)):
|
||||||
|
return str(v)
|
||||||
|
if isinstance(v, float):
|
||||||
|
if raw:
|
||||||
|
if v.is_integer():
|
||||||
|
return str(int(v))
|
||||||
|
return f"{v:g}" if abs(v) >= 1e-4 else repr(v)
|
||||||
|
return str(int(round(v)))
|
||||||
|
s = str(v).strip()
|
||||||
|
if s == "":
|
||||||
|
return "0"
|
||||||
|
try:
|
||||||
|
f = float(s)
|
||||||
|
if raw:
|
||||||
|
if f.is_integer():
|
||||||
|
return str(int(f))
|
||||||
|
return f"{f:g}"
|
||||||
|
return str(int(round(f)))
|
||||||
|
except ValueError:
|
||||||
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
def format_line(values, raw=False):
|
||||||
|
"""把数值列表格式化为 'v1, v2, ..., vn,' 形式。"""
|
||||||
|
return ", ".join(format_value(v, raw=raw) for v in values) + ","
|
||||||
|
|
||||||
|
|
||||||
|
def parse_args():
|
||||||
|
p = argparse.ArgumentParser(
|
||||||
|
description="提取展会数据 Excel 中的每一行数据。",
|
||||||
|
)
|
||||||
|
p.add_argument(
|
||||||
|
"xlsx",
|
||||||
|
nargs="?",
|
||||||
|
default=DEFAULT_XLSX,
|
||||||
|
help="Excel 文件路径(默认: 展会数据-H版本.xlsx)",
|
||||||
|
)
|
||||||
|
p.add_argument(
|
||||||
|
"--row",
|
||||||
|
action="append",
|
||||||
|
default=None,
|
||||||
|
metavar="LABEL",
|
||||||
|
help='只输出指定指标行(如 "1s 均值"),可多次指定。'
|
||||||
|
"未指定时输出全部行。",
|
||||||
|
)
|
||||||
|
p.add_argument(
|
||||||
|
"--skip-indicators",
|
||||||
|
action="append",
|
||||||
|
default=None,
|
||||||
|
metavar="V",
|
||||||
|
help="跳过指定挡位(按 指标 行数值匹配)。可多次指定,"
|
||||||
|
"也支持逗号分隔。例: --skip-indicators 0.97 --skip-indicators 1.97",
|
||||||
|
)
|
||||||
|
p.add_argument(
|
||||||
|
"--with-title",
|
||||||
|
action="store_true",
|
||||||
|
help="在每行首部加上组编号(如 \"1#, 115181, 365308, ...\")",
|
||||||
|
)
|
||||||
|
p.add_argument(
|
||||||
|
"--raw",
|
||||||
|
action="store_true",
|
||||||
|
help="保留原始数值(不取整)",
|
||||||
|
)
|
||||||
|
p.add_argument(
|
||||||
|
"--annotate",
|
||||||
|
action="store_true",
|
||||||
|
help="在每行末尾附加 // 组号 指标名 注释",
|
||||||
|
)
|
||||||
|
p.add_argument(
|
||||||
|
"-o",
|
||||||
|
"--output",
|
||||||
|
default=None,
|
||||||
|
help="输出文件路径(默认输出到标准输出)",
|
||||||
|
)
|
||||||
|
return p.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
args = parse_args()
|
||||||
|
xlsx_path = os.path.abspath(args.xlsx)
|
||||||
|
|
||||||
|
if not os.path.exists(xlsx_path):
|
||||||
|
print(f"错误:找不到文件 {xlsx_path}", file=sys.stderr)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
wb = openpyxl.load_workbook(xlsx_path, data_only=True)
|
||||||
|
ws = wb.active
|
||||||
|
|
||||||
|
rows = extract_data_rows(ws)
|
||||||
|
if not rows:
|
||||||
|
print("未找到任何数据。", file=sys.stderr)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
# ===== 列筛选(先做,依赖 指标 行) =====
|
||||||
|
skip_set = parse_skip_indicators(args.skip_indicators)
|
||||||
|
if skip_set:
|
||||||
|
filtered = []
|
||||||
|
current_indicators = None
|
||||||
|
for group, label, values in rows:
|
||||||
|
if label == "指标":
|
||||||
|
current_indicators = values
|
||||||
|
if current_indicators is None:
|
||||||
|
# 没有任何组提供 指标 行作对照,原样保留
|
||||||
|
filtered.append((group, label, values))
|
||||||
|
continue
|
||||||
|
kept = [
|
||||||
|
v for v, ind in zip(values, current_indicators)
|
||||||
|
if not any(indicators_match(ind, s) for s in skip_set)
|
||||||
|
]
|
||||||
|
filtered.append((group, label, kept))
|
||||||
|
rows = filtered
|
||||||
|
|
||||||
|
# ===== 行筛选(在列筛选之后) =====
|
||||||
|
if args.row:
|
||||||
|
wanted = {name.strip() for name in args.row}
|
||||||
|
rows = [(g, l, v) for (g, l, v) in rows if l in wanted]
|
||||||
|
if not rows:
|
||||||
|
print(
|
||||||
|
f"未找到匹配的行 {args.row}。可用行名请参考 Excel 文件 B 列。",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
out_lines = []
|
||||||
|
last_group = None
|
||||||
|
for group, label, values in rows:
|
||||||
|
if last_group is not None and group != last_group:
|
||||||
|
out_lines.append("") # 组之间插入空行
|
||||||
|
last_group = group
|
||||||
|
|
||||||
|
line = format_line(values, raw=args.raw)
|
||||||
|
if args.with_title:
|
||||||
|
line = f"{group}, {line}"
|
||||||
|
if args.annotate:
|
||||||
|
line = f"{line} // {group} {label}"
|
||||||
|
out_lines.append(line)
|
||||||
|
|
||||||
|
text = "\n".join(out_lines) + "\n"
|
||||||
|
if args.output:
|
||||||
|
with open(args.output, "w", encoding="utf-8") as f:
|
||||||
|
f.write(text)
|
||||||
|
print(f"已写入 {len(rows)} 行数据到 {args.output}", file=sys.stderr)
|
||||||
|
else:
|
||||||
|
sys.stdout.write(text)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(main())
|
||||||
541
src/app.rs
541
src/app.rs
@@ -1,4 +1,5 @@
|
|||||||
use crate::breakout::{BreakoutGame, control_from_matrix};
|
use crate::breakout::{BreakoutGame, control_from_matrix};
|
||||||
|
use crate::config::{HandForceConfig, try_load_hand_force_config};
|
||||||
use crate::connection::{ConnectionManager, ConnectionState};
|
use crate::connection::{ConnectionManager, ConnectionState};
|
||||||
use crate::force::{ForceEstimatorState, HAND_FINGERTIP_COUNT, HudSpatialForce};
|
use crate::force::{ForceEstimatorState, HAND_FINGERTIP_COUNT, HudSpatialForce};
|
||||||
use crate::recording::Recorder;
|
use crate::recording::Recorder;
|
||||||
@@ -17,6 +18,7 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
use eframe::{egui, egui_wgpu};
|
use eframe::{egui, egui_wgpu};
|
||||||
|
use std::collections::BTreeMap;
|
||||||
use std::{
|
use std::{
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
@@ -25,6 +27,7 @@ use std::{
|
|||||||
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 = 7;
|
||||||
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] = [84, 84, 84, 84, 84, 70, 44];
|
||||||
|
const HAND_FORCE_DISPLAY_THRESHOLD_N: f32 = 0.05;
|
||||||
const HAND_IMAGE_SIZE_PX: [f32; 2] = [971.0, 1117.0];
|
const HAND_IMAGE_SIZE_PX: [f32; 2] = [971.0, 1117.0];
|
||||||
const HAND_FINGERTIP_FORCE_ANCHORS_PX: [[f32; 2]; HAND_FINGERTIP_COUNT] = [
|
const HAND_FINGERTIP_FORCE_ANCHORS_PX: [[f32; 2]; HAND_FINGERTIP_COUNT] = [
|
||||||
[265.0, 495.0],
|
[265.0, 495.0],
|
||||||
@@ -62,12 +65,14 @@ pub struct EskinDesktopApp {
|
|||||||
latest_matrix_rows: u32,
|
latest_matrix_rows: u32,
|
||||||
latest_matrix_cols: u32,
|
latest_matrix_cols: u32,
|
||||||
last_sample_at: Option<Instant>,
|
last_sample_at: Option<Instant>,
|
||||||
|
last_color_debug_at: Option<Instant>,
|
||||||
breakout_visible: bool,
|
breakout_visible: bool,
|
||||||
breakout_game: BreakoutGame,
|
breakout_game: BreakoutGame,
|
||||||
live_rates: LiveRateMeters,
|
live_rates: LiveRateMeters,
|
||||||
context_menu_open: bool,
|
context_menu_open: bool,
|
||||||
context_menu_pos: egui::Pos2,
|
context_menu_pos: egui::Pos2,
|
||||||
active_mode: ActiveMode,
|
active_mode: ActiveMode,
|
||||||
|
hand_force_config: Option<HandForceConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LiveRateMeters {
|
struct LiveRateMeters {
|
||||||
@@ -135,6 +140,7 @@ impl EskinDesktopApp {
|
|||||||
MATRIX_COLS,
|
MATRIX_COLS,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
let hand_force_config = try_load_hand_force_config();
|
||||||
Self {
|
Self {
|
||||||
connect_panel: FloatingPanelState::new([0.0, 0.0], [layout::RIGHT_TAG_X, 48.0]),
|
connect_panel: FloatingPanelState::new([0.0, 0.0], [layout::RIGHT_TAG_X, 48.0]),
|
||||||
connect_state: ConnectPanelState::default(),
|
connect_state: ConnectPanelState::default(),
|
||||||
@@ -175,12 +181,14 @@ impl EskinDesktopApp {
|
|||||||
latest_matrix_rows: MATRIX_ROWS,
|
latest_matrix_rows: MATRIX_ROWS,
|
||||||
latest_matrix_cols: MATRIX_COLS,
|
latest_matrix_cols: MATRIX_COLS,
|
||||||
last_sample_at: None,
|
last_sample_at: None,
|
||||||
|
last_color_debug_at: None,
|
||||||
breakout_visible: false,
|
breakout_visible: false,
|
||||||
breakout_game: BreakoutGame::default(),
|
breakout_game: BreakoutGame::default(),
|
||||||
live_rates: LiveRateMeters::new(),
|
live_rates: LiveRateMeters::new(),
|
||||||
context_menu_open: false,
|
context_menu_open: false,
|
||||||
context_menu_pos: egui::pos2(24.0, 48.0),
|
context_menu_pos: egui::pos2(24.0, 48.0),
|
||||||
active_mode: ActiveMode::Hand(HandGatewayMode { range: 0..7000 }),
|
active_mode: ActiveMode::Hand(HandGatewayMode { range: 0..7000 }),
|
||||||
|
hand_force_config,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,7 +252,13 @@ impl EskinDesktopApp {
|
|||||||
|
|
||||||
fn analyze_spatial_force(&mut self, values: &[u32]) {
|
fn analyze_spatial_force(&mut self, values: &[u32]) {
|
||||||
if matches!(self.config_state.mode, SerialMode::Hand) {
|
if matches!(self.config_state.mode, SerialMode::Hand) {
|
||||||
self.latest_hand_spatial_forces = self.force_estimator.analyze_fingertips(values);
|
let enabled = std::array::from_fn(|tip_index| {
|
||||||
|
hand_segment_force(values, tip_index, self.hand_force_config.as_ref())
|
||||||
|
> HAND_FORCE_DISPLAY_THRESHOLD_N
|
||||||
|
});
|
||||||
|
self.latest_hand_spatial_forces = self
|
||||||
|
.force_estimator
|
||||||
|
.analyze_fingertips_masked(values, &enabled);
|
||||||
self.latest_spatial_force = self.strongest_hand_spatial_force();
|
self.latest_spatial_force = self.strongest_hand_spatial_force();
|
||||||
} else {
|
} else {
|
||||||
self.latest_spatial_force = self.force_estimator.analyze(values);
|
self.latest_spatial_force = self.force_estimator.analyze(values);
|
||||||
@@ -339,23 +353,20 @@ impl EskinDesktopApp {
|
|||||||
self.latest_raw_matrix.extend_from_slice(&sample.matrix);
|
self.latest_raw_matrix.extend_from_slice(&sample.matrix);
|
||||||
self.latest_matrix_rows = sample.rows;
|
self.latest_matrix_rows = sample.rows;
|
||||||
self.latest_matrix_cols = sample.cols;
|
self.latest_matrix_cols = sample.cols;
|
||||||
|
self.log_hand_color_mapping_debug(&sample.matrix);
|
||||||
|
|
||||||
self.analyze_spatial_force(&sample.matrix);
|
self.analyze_spatial_force(&sample.matrix);
|
||||||
|
|
||||||
// Keep JE-Skin's summary path separate from the optional spatial-force vector.
|
let force = update_hand_signal_histories(
|
||||||
let raw_total = sample
|
&mut self.hand_signal_histories,
|
||||||
.matrix
|
&sample.matrix,
|
||||||
.iter()
|
self.hand_force_config.as_ref(),
|
||||||
.fold(0_u64, |sum, value| sum + *value as u64)
|
)
|
||||||
.min(u32::MAX as u64) as u32;
|
.min(25.6);
|
||||||
let force = raw_to_g1(raw_total).min(25.6);
|
|
||||||
let force = if force <= 0.1 { 0.0 } else { force };
|
|
||||||
self.signal_history.push(force);
|
self.signal_history.push(force);
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
update_hand_signal_histories(&mut self.hand_signal_histories, &sample.matrix);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -587,6 +598,7 @@ impl EskinDesktopApp {
|
|||||||
self.pressure_matrix.fill([0.0, 0.0]);
|
self.pressure_matrix.fill([0.0, 0.0]);
|
||||||
self.hand_pressure.clear();
|
self.hand_pressure.clear();
|
||||||
self.last_sample_at = None;
|
self.last_sample_at = None;
|
||||||
|
self.last_color_debug_at = None;
|
||||||
self.force_estimator.reset();
|
self.force_estimator.reset();
|
||||||
self.latest_spatial_force = None;
|
self.latest_spatial_force = None;
|
||||||
self.latest_hand_spatial_forces = [None; HAND_FINGERTIP_COUNT];
|
self.latest_hand_spatial_forces = [None; HAND_FINGERTIP_COUNT];
|
||||||
@@ -606,6 +618,50 @@ impl EskinDesktopApp {
|
|||||||
SerialMode::Hand => ActiveMode::Hand(HandGatewayMode { range: 0..7000 }),
|
SerialMode::Hand => ActiveMode::Hand(HandGatewayMode { range: 0..7000 }),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn log_hand_color_mapping_debug(&mut self, raw: &[u32]) {
|
||||||
|
let now = Instant::now();
|
||||||
|
if self
|
||||||
|
.last_color_debug_at
|
||||||
|
.is_some_and(|last| now.duration_since(last) < Duration::from_secs(1))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.last_color_debug_at = Some(now);
|
||||||
|
|
||||||
|
let mut parts = Vec::with_capacity(HAND_FORCE_PANEL_COUNT);
|
||||||
|
let mut start = 0;
|
||||||
|
for (panel_index, (range, cell_count)) in HAND_SENSOR_PANEL_COLOR_RANGES
|
||||||
|
.iter()
|
||||||
|
.copied()
|
||||||
|
.zip(HAND_SENSOR_PANEL_CELL_COUNTS)
|
||||||
|
.enumerate()
|
||||||
|
{
|
||||||
|
let end = start + cell_count;
|
||||||
|
let peak = raw
|
||||||
|
.get(start..end)
|
||||||
|
.unwrap_or(&[])
|
||||||
|
.iter()
|
||||||
|
.copied()
|
||||||
|
.max()
|
||||||
|
.unwrap_or(0);
|
||||||
|
let cell_range = range.per_cell(cell_count);
|
||||||
|
let [intensity, _] = cell_range.normalize(peak);
|
||||||
|
parts.push(format!(
|
||||||
|
"{} raw_peak={} range_total_max={:.0} cell_range_max={:.0} intensity={:.3}",
|
||||||
|
match panel_index {
|
||||||
|
0..=4 => format!("F{}", panel_index + 1),
|
||||||
|
5 => "Palm-H".to_owned(),
|
||||||
|
_ => "Palm-V".to_owned(),
|
||||||
|
},
|
||||||
|
peak,
|
||||||
|
range.max,
|
||||||
|
cell_range.max,
|
||||||
|
intensity
|
||||||
|
));
|
||||||
|
start = end;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hand_image_pixel_to_screen(rect: egui::Rect, point_px: [f32; 2]) -> egui::Pos2 {
|
fn hand_image_pixel_to_screen(rect: egui::Rect, point_px: [f32; 2]) -> egui::Pos2 {
|
||||||
@@ -665,73 +721,116 @@ fn paint_spatial_force_arrow(
|
|||||||
fn update_hand_signal_histories(
|
fn update_hand_signal_histories(
|
||||||
histories: &mut [Vec<f32>; HAND_FORCE_PANEL_COUNT],
|
histories: &mut [Vec<f32>; HAND_FORCE_PANEL_COUNT],
|
||||||
raw_values: &[u32],
|
raw_values: &[u32],
|
||||||
) {
|
config: Option<&HandForceConfig>,
|
||||||
let mut offset = 0usize;
|
) -> f32 {
|
||||||
for (index, (history, sample_count)) in histories.iter_mut().zip(HAND_FORCE_SEGMENT_COUNTS).enumerate() {
|
let mut total_force = 0.0;
|
||||||
|
for (index, history) in histories.iter_mut().enumerate() {
|
||||||
|
let force = hand_segment_force(raw_values, index, config);
|
||||||
|
let force = if force <= HAND_FORCE_DISPLAY_THRESHOLD_N {
|
||||||
|
0.0
|
||||||
|
} else {
|
||||||
|
force
|
||||||
|
};
|
||||||
|
total_force += force;
|
||||||
|
history.push(force);
|
||||||
|
if history.len() > SUMMARY_POINTS_PER_SERIES {
|
||||||
|
history.remove(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
total_force
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hand_segment_force(raw_values: &[u32], index: usize, config: Option<&HandForceConfig>) -> f32 {
|
||||||
|
let offset: usize = HAND_FORCE_SEGMENT_COUNTS[..index.min(HAND_FORCE_PANEL_COUNT)]
|
||||||
|
.iter()
|
||||||
|
.sum();
|
||||||
|
let sample_count = HAND_FORCE_SEGMENT_COUNTS
|
||||||
|
.get(index)
|
||||||
|
.copied()
|
||||||
|
.unwrap_or_default();
|
||||||
let raw_total = raw_values
|
let raw_total = raw_values
|
||||||
.get(offset..offset + sample_count)
|
.get(offset..offset + sample_count)
|
||||||
.unwrap_or(&[])
|
.unwrap_or(&[])
|
||||||
.iter()
|
.iter()
|
||||||
.fold(0_u64, |sum, value| sum + *value as u64)
|
.fold(0_u64, |sum, value| sum + *value as u64)
|
||||||
.min(u32::MAX as u64) as u32;
|
.min(u32::MAX as u64) as u32;
|
||||||
let force = match index {
|
|
||||||
0 => raw_to_g1(raw_total).min(20.6),
|
raw_to_hand_segment_g(index, raw_total, config).min(20.6)
|
||||||
1 => raw_to_g2(raw_total).min(20.6),
|
}
|
||||||
2 => raw_to_g3(raw_total).min(20.6),
|
|
||||||
3 => raw_to_g4(raw_total).min(20.6),
|
fn raw_to_hand_segment_g(index: usize, raw: u32, config: Option<&HandForceConfig>) -> f32 {
|
||||||
4 => raw_to_g5(raw_total).min(20.6),
|
match index {
|
||||||
_ => raw_to_gd(raw_total).min(20.6),
|
0 => raw_to_g1(raw, config),
|
||||||
|
1 => raw_to_g2(raw, config),
|
||||||
|
2 => raw_to_g3(raw, config),
|
||||||
|
3 => raw_to_g4(raw, config),
|
||||||
|
4 => raw_to_g5(raw, config),
|
||||||
|
5 => raw_to_g6(raw),
|
||||||
|
6 => raw_to_g7(raw),
|
||||||
|
_ => raw_to_gd(raw),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_force_table(values: &BTreeMap<String, u32>) -> Vec<(u32, f32)> {
|
||||||
|
let mut table = values
|
||||||
|
.iter()
|
||||||
|
.filter_map(|(force_n, raw)| force_n.parse::<f32>().ok().map(|force| (*raw, force)))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
table.sort_by(|a, b| a.1.total_cmp(&b.1));
|
||||||
|
table.insert(0, (0, 0.0));
|
||||||
|
table
|
||||||
|
}
|
||||||
|
|
||||||
|
fn interpolate_force(raw: u32, table: &[(u32, f32)]) -> f32 {
|
||||||
|
let Some(&(first_raw, first_force)) = table.first() else {
|
||||||
|
return 0.0;
|
||||||
|
};
|
||||||
|
let Some(&(last_raw, last_force)) = table.last() else {
|
||||||
|
return 0.0;
|
||||||
};
|
};
|
||||||
// let force = raw_to_g1(raw_total).min(25.6);
|
|
||||||
let force = if force <= 0.1 { 0.0 } else { force };
|
|
||||||
|
|
||||||
history.push(force);
|
if raw <= first_raw {
|
||||||
if history.len() > SUMMARY_POINTS_PER_SERIES {
|
return first_force;
|
||||||
history.remove(0);
|
}
|
||||||
|
if raw >= last_raw {
|
||||||
|
return last_force;
|
||||||
}
|
}
|
||||||
|
|
||||||
offset += sample_count;
|
let right = table.partition_point(|(raw_point, _)| *raw_point <= raw);
|
||||||
|
let (raw_left, force_left) = table[right - 1];
|
||||||
|
let (raw_right, force_right) = table[right];
|
||||||
|
let ratio = (raw - raw_left) as f32 / (raw_right - raw_left).max(1) as f32;
|
||||||
|
force_left + ratio * (force_right - force_left)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn force_from_config_or_fallback(
|
||||||
|
raw: u32,
|
||||||
|
config_values: Option<&BTreeMap<String, u32>>,
|
||||||
|
fallback_raw: &[u32],
|
||||||
|
fallback_force_centi_n: &[f32],
|
||||||
|
) -> f32 {
|
||||||
|
if let Some(config_values) = config_values {
|
||||||
|
let table = to_force_table(config_values);
|
||||||
|
if table.len() >= 2 && table.windows(2).all(|pair| pair[0].0 <= pair[1].0) {
|
||||||
|
return interpolate_force(raw, &table);
|
||||||
|
}
|
||||||
|
log::warn!(
|
||||||
|
"Hand force config raw values are not monotonically increasing; using fallback table"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let fallback = fallback_raw
|
||||||
|
.iter()
|
||||||
|
.copied()
|
||||||
|
.zip(fallback_force_centi_n.iter().map(|force| force / 100.0))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
interpolate_force(raw, &fallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn raw_to_gd(raw: u32) -> f32 {
|
fn raw_to_gd(raw: u32) -> f32 {
|
||||||
const RAW: [u32; 12] = [
|
|
||||||
0, 21382, 108507, 123183, 147405, 171105, 192395, 250443, 231423, 350560, 396616, 429444,
|
|
||||||
];
|
|
||||||
const FORCE_CENTI_N: [f32; 12] = [
|
|
||||||
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0, 2557.0,
|
|
||||||
];
|
|
||||||
|
|
||||||
if raw <= RAW[0] {
|
|
||||||
return FORCE_CENTI_N[0] / 100.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if raw >= RAW[RAW.len() - 1] {
|
|
||||||
return FORCE_CENTI_N[FORCE_CENTI_N.len() - 1] / 100.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut left = 0usize;
|
|
||||||
let mut right = RAW.len() - 1;
|
|
||||||
while left + 1 < right {
|
|
||||||
let mid = (left + right) / 2;
|
|
||||||
if RAW[mid] <= raw {
|
|
||||||
left = mid;
|
|
||||||
} else {
|
|
||||||
right = mid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let raw_left = RAW[left] as f32;
|
|
||||||
let raw_right = RAW[right] as f32;
|
|
||||||
let span = (raw_right - raw_left).max(1.0);
|
|
||||||
let ratio = (raw as f32 - raw_left) / span;
|
|
||||||
|
|
||||||
(FORCE_CENTI_N[left] + ratio * (FORCE_CENTI_N[right] - FORCE_CENTI_N[left])) / 100.0
|
|
||||||
}
|
|
||||||
|
|
||||||
fn raw_to_g1(raw: u32) -> f32 {
|
|
||||||
const RAW: [u32; 11] = [
|
const RAW: [u32; 11] = [
|
||||||
0, 20239, 121454, 171532, 223968, 241467, 293500, 322744, 436294, 523275, 633083,
|
0, 486, 5310, 8130, 10005, 12883, 14700, 18141, 19877, 26270, 32648,
|
||||||
];
|
];
|
||||||
const FORCE_CENTI_N: [f32; 11] = [
|
const FORCE_CENTI_N: [f32; 11] = [
|
||||||
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0,
|
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0,
|
||||||
@@ -764,9 +863,64 @@ fn raw_to_g1(raw: u32) -> f32 {
|
|||||||
(FORCE_CENTI_N[left] + ratio * (FORCE_CENTI_N[right] - FORCE_CENTI_N[left])) / 100.0
|
(FORCE_CENTI_N[left] + ratio * (FORCE_CENTI_N[right] - FORCE_CENTI_N[left])) / 100.0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn raw_to_g2(raw: u32) -> f32 {
|
fn raw_to_g1(raw: u32, config: Option<&HandForceConfig>) -> f32 {
|
||||||
const RAW: [u32; 11] = [
|
const RAW: [u32; 11] = [
|
||||||
0, 5398, 52896, 86945, 122546, 145001, 165933, 220575, 241578, 350285, 449530,
|
0, 35694, 226640, 319868, 398021, 450448, 510506, 592075, 655760, 771671, 813967,
|
||||||
|
];
|
||||||
|
const FORCE_CENTI_N: [f32; 11] = [
|
||||||
|
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0,
|
||||||
|
];
|
||||||
|
|
||||||
|
force_from_config_or_fallback(raw, config.map(|cfg| &cfg.thumb), &RAW, &FORCE_CENTI_N)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn raw_to_g2(raw: u32, config: Option<&HandForceConfig>) -> f32 {
|
||||||
|
const RAW: [u32; 11] = [
|
||||||
|
0, 45490, 267579, 352066, 431681, 457605, 550875, 624327, 732735, 883397, 899338,
|
||||||
|
];
|
||||||
|
const FORCE_CENTI_N: [f32; 11] = [
|
||||||
|
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0,
|
||||||
|
];
|
||||||
|
|
||||||
|
force_from_config_or_fallback(raw, config.map(|cfg| &cfg.index), &RAW, &FORCE_CENTI_N)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn raw_to_g3(raw: u32, config: Option<&HandForceConfig>) -> f32 {
|
||||||
|
const RAW: [u32; 11] = [
|
||||||
|
0, 51562, 252840, 326531, 386571, 415819, 514679, 631745, 678945, 810847, 900422,
|
||||||
|
];
|
||||||
|
const FORCE_CENTI_N: [f32; 11] = [
|
||||||
|
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0,
|
||||||
|
];
|
||||||
|
|
||||||
|
force_from_config_or_fallback(raw, config.map(|cfg| &cfg.middle), &RAW, &FORCE_CENTI_N)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn raw_to_g4(raw: u32, config: Option<&HandForceConfig>) -> f32 {
|
||||||
|
const RAW: [u32; 11] = [
|
||||||
|
0, 33213, 220611, 307383, 369637, 430462, 489659, 584789, 664960, 802749, 926907,
|
||||||
|
];
|
||||||
|
const FORCE_CENTI_N: [f32; 11] = [
|
||||||
|
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0,
|
||||||
|
];
|
||||||
|
|
||||||
|
force_from_config_or_fallback(raw, config.map(|cfg| &cfg.ring), &RAW, &FORCE_CENTI_N)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn raw_to_g5(raw: u32, config: Option<&HandForceConfig>) -> f32 {
|
||||||
|
const RAW: [u32; 11] = [
|
||||||
|
0, 44291, 216657, 301950, 366186, 384791, 496521, 566189, 701459, 845608, 940796,
|
||||||
|
];
|
||||||
|
const FORCE_CENTI_N: [f32; 11] = [
|
||||||
|
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0,
|
||||||
|
];
|
||||||
|
|
||||||
|
force_from_config_or_fallback(raw, config.map(|cfg| &cfg.little), &RAW, &FORCE_CENTI_N)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn raw_to_g6(raw: u32) -> f32 {
|
||||||
|
const RAW: [u32; 11] = [
|
||||||
|
0, 0, 2532, 5122, 7256, 11525, 13544, 16044, 18504, 29778, 41845,
|
||||||
];
|
];
|
||||||
const FORCE_CENTI_N: [f32; 11] = [
|
const FORCE_CENTI_N: [f32; 11] = [
|
||||||
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0,
|
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0,
|
||||||
@@ -799,79 +953,9 @@ fn raw_to_g2(raw: u32) -> f32 {
|
|||||||
(FORCE_CENTI_N[left] + ratio * (FORCE_CENTI_N[right] - FORCE_CENTI_N[left])) / 100.0
|
(FORCE_CENTI_N[left] + ratio * (FORCE_CENTI_N[right] - FORCE_CENTI_N[left])) / 100.0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn raw_to_g3(raw: u32) -> f32 {
|
fn raw_to_g7(raw: u32) -> f32 {
|
||||||
const RAW: [u32; 11] = [
|
const RAW: [u32; 11] = [
|
||||||
0, 4920, 35945, 46499, 65566, 69613, 89971, 122321, 146384, 203426, 269474,
|
0, 233, 9000, 12067, 14311, 16297, 18113, 27918, 32559, 50861, 65857,
|
||||||
];
|
|
||||||
const FORCE_CENTI_N: [f32; 11] = [
|
|
||||||
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0,
|
|
||||||
];
|
|
||||||
|
|
||||||
if raw <= RAW[0] {
|
|
||||||
return FORCE_CENTI_N[0] / 100.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if raw >= RAW[RAW.len() - 1] {
|
|
||||||
return FORCE_CENTI_N[FORCE_CENTI_N.len() - 1] / 100.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut left = 0usize;
|
|
||||||
let mut right = RAW.len() - 1;
|
|
||||||
while left + 1 < right {
|
|
||||||
let mid = (left + right) / 2;
|
|
||||||
if RAW[mid] <= raw {
|
|
||||||
left = mid;
|
|
||||||
} else {
|
|
||||||
right = mid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let raw_left = RAW[left] as f32;
|
|
||||||
let raw_right = RAW[right] as f32;
|
|
||||||
let span = (raw_right - raw_left).max(1.0);
|
|
||||||
let ratio = (raw as f32 - raw_left) / span;
|
|
||||||
|
|
||||||
(FORCE_CENTI_N[left] + ratio * (FORCE_CENTI_N[right] - FORCE_CENTI_N[left])) / 100.0
|
|
||||||
}
|
|
||||||
|
|
||||||
fn raw_to_g4(raw: u32) -> f32 {
|
|
||||||
const RAW: [u32; 11] = [
|
|
||||||
0, 11346, 92229, 139822, 182282, 220004, 259898, 307303, 377922, 460755, 587834,
|
|
||||||
];
|
|
||||||
const FORCE_CENTI_N: [f32; 11] = [
|
|
||||||
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0,
|
|
||||||
];
|
|
||||||
|
|
||||||
if raw <= RAW[0] {
|
|
||||||
return FORCE_CENTI_N[0] / 100.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if raw >= RAW[RAW.len() - 1] {
|
|
||||||
return FORCE_CENTI_N[FORCE_CENTI_N.len() - 1] / 100.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut left = 0usize;
|
|
||||||
let mut right = RAW.len() - 1;
|
|
||||||
while left + 1 < right {
|
|
||||||
let mid = (left + right) / 2;
|
|
||||||
if RAW[mid] <= raw {
|
|
||||||
left = mid;
|
|
||||||
} else {
|
|
||||||
right = mid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let raw_left = RAW[left] as f32;
|
|
||||||
let raw_right = RAW[right] as f32;
|
|
||||||
let span = (raw_right - raw_left).max(1.0);
|
|
||||||
let ratio = (raw as f32 - raw_left) / span;
|
|
||||||
|
|
||||||
(FORCE_CENTI_N[left] + ratio * (FORCE_CENTI_N[right] - FORCE_CENTI_N[left])) / 100.0
|
|
||||||
}
|
|
||||||
|
|
||||||
fn raw_to_g5(raw: u32) -> f32 {
|
|
||||||
const RAW: [u32; 11] = [
|
|
||||||
0, 10081, 40910, 49944, 64291, 68299, 79282, 97767, 113567, 140520, 167132,
|
|
||||||
];
|
];
|
||||||
const FORCE_CENTI_N: [f32; 11] = [
|
const FORCE_CENTI_N: [f32; 11] = [
|
||||||
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0,
|
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0,
|
||||||
@@ -952,6 +1036,79 @@ fn split_viewport_body(rect: egui::Rect) -> egui::Rect {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
struct PressureColorRange {
|
||||||
|
min: f32,
|
||||||
|
max: f32,
|
||||||
|
gamma: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Controls the pressure-to-color response curve. Higher values reserve warmer
|
||||||
|
// colors for larger fractions of each panel's configured raw range.
|
||||||
|
const PRESSURE_COLOR_GAMMA: f32 = 1.5;
|
||||||
|
|
||||||
|
impl PressureColorRange {
|
||||||
|
const fn new(min: u32, max: u32) -> Self {
|
||||||
|
Self {
|
||||||
|
min: min as f32,
|
||||||
|
max: max as f32,
|
||||||
|
gamma: PRESSURE_COLOR_GAMMA,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn normalize(self, value: u32) -> [f32; 2] {
|
||||||
|
let raw = value as f32;
|
||||||
|
let span = (self.max - self.min).max(1.0);
|
||||||
|
let mapped = ((raw - self.min) / span).clamp(0.0, 1.0);
|
||||||
|
|
||||||
|
let intensity = if raw <= self.min + 4.0 {
|
||||||
|
0.0
|
||||||
|
} else {
|
||||||
|
mapped.powf(self.gamma)
|
||||||
|
};
|
||||||
|
|
||||||
|
let display_value = if raw <= self.min + 4.0 {
|
||||||
|
0.0
|
||||||
|
} else {
|
||||||
|
raw.round().min(9999.0)
|
||||||
|
};
|
||||||
|
|
||||||
|
[intensity, display_value]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn per_cell(self, cell_count: usize) -> Self {
|
||||||
|
let cells = cell_count.max(1) as f32;
|
||||||
|
Self {
|
||||||
|
min: self.min / cells,
|
||||||
|
max: self.max / cells,
|
||||||
|
gamma: self.gamma,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const DEFAULT_COLOR_RANGE: PressureColorRange = PressureColorRange::new(0, 7000);
|
||||||
|
|
||||||
|
const HAND_SENSOR_PANEL_COLOR_RANGES: [PressureColorRange; HAND_FORCE_PANEL_COUNT] = [
|
||||||
|
PressureColorRange::new(0, 813967),
|
||||||
|
PressureColorRange::new(0, 899338),
|
||||||
|
PressureColorRange::new(0, 900422),
|
||||||
|
PressureColorRange::new(0, 926907),
|
||||||
|
PressureColorRange::new(0, 940796),
|
||||||
|
PressureColorRange::new(0, 41845),
|
||||||
|
PressureColorRange::new(0, 65857),
|
||||||
|
];
|
||||||
|
|
||||||
|
const HAND_FINGER_SENSOR_CELLS: usize = 12 * 7;
|
||||||
|
const HAND_SENSOR_PANEL_CELL_COUNTS: [usize; HAND_FORCE_PANEL_COUNT] = [
|
||||||
|
HAND_FINGER_SENSOR_CELLS,
|
||||||
|
HAND_FINGER_SENSOR_CELLS,
|
||||||
|
HAND_FINGER_SENSOR_CELLS,
|
||||||
|
HAND_FINGER_SENSOR_CELLS,
|
||||||
|
HAND_FINGER_SENSOR_CELLS,
|
||||||
|
5 * 14,
|
||||||
|
11 * 4,
|
||||||
|
];
|
||||||
|
|
||||||
fn normalize_pressure_sample(raw: &[u32], rows: u32, cols: u32, normalized: &mut PressureFrame) {
|
fn normalize_pressure_sample(raw: &[u32], rows: u32, cols: u32, normalized: &mut PressureFrame) {
|
||||||
normalized.fill([0.0, 0.0]);
|
normalized.fill([0.0, 0.0]);
|
||||||
|
|
||||||
@@ -971,34 +1128,67 @@ fn normalize_pressure_sample(raw: &[u32], rows: u32, cols: u32, normalized: &mut
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn normalize_pressure_samples(raw: &[u32]) -> PressureSamples {
|
fn normalize_pressure_samples(raw: &[u32]) -> PressureSamples {
|
||||||
raw.iter().copied().map(normalize_pressure_value).collect()
|
raw.iter()
|
||||||
|
.copied()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(index, value)| {
|
||||||
|
hand_sensor_panel_for_index(index)
|
||||||
|
.map(|(range, cell_count)| range.per_cell(cell_count).normalize(value))
|
||||||
|
.unwrap_or_else(|| DEFAULT_COLOR_RANGE.normalize(value))
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hand_sensor_panel_for_index(index: usize) -> Option<(PressureColorRange, usize)> {
|
||||||
|
let mut start = 0;
|
||||||
|
|
||||||
|
for (range, cell_count) in HAND_SENSOR_PANEL_COLOR_RANGES
|
||||||
|
.iter()
|
||||||
|
.copied()
|
||||||
|
.zip(HAND_SENSOR_PANEL_CELL_COUNTS)
|
||||||
|
{
|
||||||
|
let end = start + cell_count;
|
||||||
|
if index < end {
|
||||||
|
return Some((range, cell_count));
|
||||||
|
}
|
||||||
|
start = end;
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn normalize_pressure_value(value: u32) -> [f32; 2] {
|
fn normalize_pressure_value(value: u32) -> [f32; 2] {
|
||||||
const RANGE_MIN: f32 = 0.0;
|
DEFAULT_COLOR_RANGE.normalize(value)
|
||||||
const RANGE_MAX: f32 = 7000.0;
|
|
||||||
const DISPLAY_GAMMA: f32 = 0.45;
|
|
||||||
|
|
||||||
let raw_value = value as f32;
|
|
||||||
let mapped = ((raw_value - RANGE_MIN) / (RANGE_MAX - RANGE_MIN)).clamp(0.0, 1.0);
|
|
||||||
let intensity = if raw_value <= RANGE_MIN + 4.0 {
|
|
||||||
0.0
|
|
||||||
} else {
|
|
||||||
mapped.powf(DISPLAY_GAMMA)
|
|
||||||
};
|
|
||||||
let display_value = if raw_value <= RANGE_MIN + 4.0 {
|
|
||||||
0.0
|
|
||||||
} else {
|
|
||||||
raw_value.round().min(9999.0)
|
|
||||||
};
|
|
||||||
|
|
||||||
[intensity, display_value]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn raw_to_g1_uses_loaded_thumb_config() {
|
||||||
|
let config: HandForceConfig = toml::from_str(
|
||||||
|
r#"
|
||||||
|
[thumb]
|
||||||
|
"0.57" = 10
|
||||||
|
"2.57" = 20
|
||||||
|
|
||||||
|
[index]
|
||||||
|
"0.57" = 1
|
||||||
|
[middle]
|
||||||
|
"0.57" = 1
|
||||||
|
[ring]
|
||||||
|
"0.57" = 1
|
||||||
|
[little]
|
||||||
|
"0.57" = 1
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.expect("test config should parse");
|
||||||
|
|
||||||
|
assert_eq!(raw_to_g1(20, Some(&config)), 2.57);
|
||||||
|
assert_ne!(raw_to_g1(20, None), 2.57);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pressure_normalization_makes_low_hand_values_visible() {
|
fn pressure_normalization_makes_low_hand_values_visible() {
|
||||||
let [zero_intensity, zero_label] = normalize_pressure_value(4);
|
let [zero_intensity, zero_label] = normalize_pressure_value(4);
|
||||||
@@ -1007,8 +1197,8 @@ mod tests {
|
|||||||
|
|
||||||
let [low_intensity, low_label] = normalize_pressure_value(100);
|
let [low_intensity, low_label] = normalize_pressure_value(100);
|
||||||
assert!(
|
assert!(
|
||||||
low_intensity > 0.10,
|
low_intensity > 0.0,
|
||||||
"low hand-gateway values should be visible in the wgpu dot matrix"
|
"low hand-gateway values should retain a non-zero response"
|
||||||
);
|
);
|
||||||
assert_eq!(low_label, 100.0);
|
assert_eq!(low_label, 100.0);
|
||||||
|
|
||||||
@@ -1016,6 +1206,41 @@ mod tests {
|
|||||||
assert_eq!(max_intensity, 1.0);
|
assert_eq!(max_intensity, 1.0);
|
||||||
assert_eq!(max_label, 7000.0);
|
assert_eq!(max_label, 7000.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pressure_normalization_applies_configured_gamma() {
|
||||||
|
let range = PressureColorRange::new(0, 10_000);
|
||||||
|
let [intensity, _] = range.normalize(8_000);
|
||||||
|
let expected = 0.8_f32.powf(PRESSURE_COLOR_GAMMA);
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
(intensity - expected).abs() < 0.002,
|
||||||
|
"the normalized response should follow the configured gamma"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn hand_panel_ranges_cover_both_palm_boards() {
|
||||||
|
let total_cells: usize = HAND_SENSOR_PANEL_CELL_COUNTS.iter().sum();
|
||||||
|
let mut raw = vec![0; total_cells];
|
||||||
|
let mut start = 0;
|
||||||
|
|
||||||
|
for (range, cell_count) in HAND_SENSOR_PANEL_COLOR_RANGES
|
||||||
|
.iter()
|
||||||
|
.copied()
|
||||||
|
.zip(HAND_SENSOR_PANEL_CELL_COUNTS)
|
||||||
|
{
|
||||||
|
raw[start] = (range.max / cell_count as f32).ceil() as u32;
|
||||||
|
start += cell_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
let normalized = normalize_pressure_samples(&raw);
|
||||||
|
let palm_horizontal_start = HAND_SENSOR_PANEL_CELL_COUNTS[..5].iter().sum::<usize>();
|
||||||
|
let palm_vertical_start = palm_horizontal_start + HAND_SENSOR_PANEL_CELL_COUNTS[5];
|
||||||
|
|
||||||
|
assert_eq!(normalized[palm_horizontal_start][0], 1.0);
|
||||||
|
assert_eq!(normalized[palm_vertical_start][0], 1.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl eframe::App for EskinDesktopApp {
|
impl eframe::App for EskinDesktopApp {
|
||||||
|
|||||||
70
src/config.rs
Normal file
70
src/config.rs
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
use serde::Deserialize;
|
||||||
|
use std::{
|
||||||
|
collections::BTreeMap,
|
||||||
|
fs,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct HandForceConfig {
|
||||||
|
pub thumb: BTreeMap<String, u32>,
|
||||||
|
pub index: BTreeMap<String, u32>,
|
||||||
|
pub middle: BTreeMap<String, u32>,
|
||||||
|
pub ring: BTreeMap<String, u32>,
|
||||||
|
pub little: BTreeMap<String, u32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn try_load_hand_force_config() -> Option<HandForceConfig> {
|
||||||
|
let path: PathBuf = std::env::current_exe().ok()?.parent()?.join("config.toml");
|
||||||
|
load_hand_force_config(&path)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_hand_force_config(path: &Path) -> Option<HandForceConfig> {
|
||||||
|
let content = fs::read_to_string(path).ok()?;
|
||||||
|
toml::from_str(&content).ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn loads_hand_force_config_toml() {
|
||||||
|
let path = std::env::temp_dir().join(format!(
|
||||||
|
"eskin-hand-force-config-{}-{}.toml",
|
||||||
|
std::process::id(),
|
||||||
|
SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.expect("system clock should be after Unix epoch")
|
||||||
|
.as_nanos()
|
||||||
|
));
|
||||||
|
fs::write(
|
||||||
|
&path,
|
||||||
|
r#"
|
||||||
|
[thumb]
|
||||||
|
"0.57" = 35694
|
||||||
|
"2.57" = 226640
|
||||||
|
|
||||||
|
[index]
|
||||||
|
"0.57" = 45490
|
||||||
|
|
||||||
|
[middle]
|
||||||
|
"0.57" = 51562
|
||||||
|
|
||||||
|
[ring]
|
||||||
|
"0.57" = 33213
|
||||||
|
|
||||||
|
[little]
|
||||||
|
"0.57" = 44291
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.expect("test config should be writable");
|
||||||
|
|
||||||
|
let config = load_hand_force_config(&path).expect("valid TOML should load");
|
||||||
|
fs::remove_file(&path).expect("test config should be removable");
|
||||||
|
|
||||||
|
assert_eq!(config.thumb["2.57"], 226640);
|
||||||
|
assert_eq!(config.index["0.57"], 45490);
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/force.rs
14
src/force.rs
@@ -2,7 +2,7 @@ use crate::serial_core::multi_dim_force::PztProcessor;
|
|||||||
|
|
||||||
pub const FINGER_SAMPLE_COUNT: usize = 84;
|
pub const FINGER_SAMPLE_COUNT: usize = 84;
|
||||||
pub const HAND_FINGERTIP_COUNT: usize = 5;
|
pub const HAND_FINGERTIP_COUNT: usize = 5;
|
||||||
const MIN_TANGENTIAL_MAGNITUDE: f32 = 0.02;
|
const MIN_TANGENTIAL_MAGNITUDE: f32 = 0.1;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct HudSpatialForce {
|
pub struct HudSpatialForce {
|
||||||
@@ -50,10 +50,22 @@ impl ForceEstimatorState {
|
|||||||
pub fn analyze_fingertips(
|
pub fn analyze_fingertips(
|
||||||
&mut self,
|
&mut self,
|
||||||
values: &[u32],
|
values: &[u32],
|
||||||
|
) -> [Option<HudSpatialForce>; HAND_FINGERTIP_COUNT] {
|
||||||
|
self.analyze_fingertips_masked(values, &[true; HAND_FINGERTIP_COUNT])
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn analyze_fingertips_masked(
|
||||||
|
&mut self,
|
||||||
|
values: &[u32],
|
||||||
|
enabled: &[bool; HAND_FINGERTIP_COUNT],
|
||||||
) -> [Option<HudSpatialForce>; HAND_FINGERTIP_COUNT] {
|
) -> [Option<HudSpatialForce>; HAND_FINGERTIP_COUNT] {
|
||||||
let mut forces = [None; HAND_FINGERTIP_COUNT];
|
let mut forces = [None; HAND_FINGERTIP_COUNT];
|
||||||
|
|
||||||
for (tip_index, processor) in self.fingertip_processors.iter_mut().enumerate() {
|
for (tip_index, processor) in self.fingertip_processors.iter_mut().enumerate() {
|
||||||
|
if !enabled[tip_index] {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let start = tip_index * FINGER_SAMPLE_COUNT;
|
let start = tip_index * FINGER_SAMPLE_COUNT;
|
||||||
let end = start + FINGER_SAMPLE_COUNT;
|
let end = start + FINGER_SAMPLE_COUNT;
|
||||||
let Some(segment) = values.get(start..end) else {
|
let Some(segment) = values.get(start..end) else {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
mod app;
|
mod app;
|
||||||
mod breakout;
|
mod breakout;
|
||||||
|
mod config;
|
||||||
mod connection;
|
mod connection;
|
||||||
mod force;
|
mod force;
|
||||||
mod matrix;
|
mod matrix;
|
||||||
|
|||||||
@@ -44,22 +44,22 @@ pub struct HandGatewayMode {
|
|||||||
|
|
||||||
const HAND_TIP_MATRICES: [HandTipMatrix; 5] = [
|
const HAND_TIP_MATRICES: [HandTipMatrix; 5] = [
|
||||||
HandTipMatrix {
|
HandTipMatrix {
|
||||||
center_px: [265.0, 495.0],
|
center_px: [263.5, 495.0],
|
||||||
size_px: [70.0, 120.0],
|
size_px: [70.0, 120.0],
|
||||||
angle_rad: -0.40,
|
angle_rad: -0.40,
|
||||||
},
|
},
|
||||||
HandTipMatrix {
|
HandTipMatrix {
|
||||||
center_px: [359.0, 260.0],
|
center_px: [362.0, 260.0],
|
||||||
size_px: [70.0, 120.0],
|
size_px: [70.0, 120.0],
|
||||||
angle_rad: -0.17,
|
angle_rad: -0.158,
|
||||||
},
|
},
|
||||||
HandTipMatrix {
|
HandTipMatrix {
|
||||||
center_px: [482.0, 228.0],
|
center_px: [480.5, 228.0],
|
||||||
size_px: [70.0, 120.0],
|
size_px: [70.0, 120.0],
|
||||||
angle_rad: -0.03,
|
angle_rad: -0.02,
|
||||||
},
|
},
|
||||||
HandTipMatrix {
|
HandTipMatrix {
|
||||||
center_px: [596.0, 265.0],
|
center_px: [594.0, 265.0],
|
||||||
size_px: [70.0, 120.0],
|
size_px: [70.0, 120.0],
|
||||||
angle_rad: 0.10,
|
angle_rad: 0.10,
|
||||||
},
|
},
|
||||||
@@ -532,12 +532,13 @@ impl BackgroundRenderResources {
|
|||||||
let hand_membrane_instances = build_hand_membrane_instances(
|
let hand_membrane_instances = build_hand_membrane_instances(
|
||||||
hand_image_texture.width as f32,
|
hand_image_texture.width as f32,
|
||||||
hand_image_texture.height as f32,
|
hand_image_texture.height as f32,
|
||||||
|
&[],
|
||||||
);
|
);
|
||||||
let hand_membrane_instance_buffer =
|
let hand_membrane_instance_buffer =
|
||||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
label: Some("Hand Fingertip Membrane Instance Buffer"),
|
label: Some("Hand Fingertip Membrane Instance Buffer"),
|
||||||
contents: bytemuck::cast_slice(&hand_membrane_instances),
|
contents: bytemuck::cast_slice(&hand_membrane_instances),
|
||||||
usage: wgpu::BufferUsages::VERTEX,
|
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
|
||||||
});
|
});
|
||||||
let hand_dot_instances = build_hand_dot_instances(
|
let hand_dot_instances = build_hand_dot_instances(
|
||||||
rows,
|
rows,
|
||||||
@@ -654,6 +655,17 @@ impl BackgroundRenderResources {
|
|||||||
hand_pressure
|
hand_pressure
|
||||||
};
|
};
|
||||||
|
|
||||||
|
self.hand_membrane_instances = build_hand_membrane_instances(
|
||||||
|
self.hand_image_texture.width as f32,
|
||||||
|
self.hand_image_texture.height as f32,
|
||||||
|
hand_pressure,
|
||||||
|
);
|
||||||
|
queue.write_buffer(
|
||||||
|
&self.hand_membrane_instance_buffer,
|
||||||
|
0,
|
||||||
|
bytemuck::cast_slice(&self.hand_membrane_instances),
|
||||||
|
);
|
||||||
|
|
||||||
// Hand mode uses UV-anchored fingertip matrices over hand.png.
|
// Hand mode uses UV-anchored fingertip matrices over hand.png.
|
||||||
// Rebuild their instance positions here so pressure colors update every frame.
|
// Rebuild their instance positions here so pressure colors update every frame.
|
||||||
self.hand_dot_instances = build_hand_dot_instances(
|
self.hand_dot_instances = build_hand_dot_instances(
|
||||||
@@ -1139,24 +1151,48 @@ fn create_hand_palm_dot_pipeline(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_hand_membrane_instances(image_width: f32, image_height: f32) -> Vec<GlyphInstance> {
|
fn build_hand_membrane_instances(
|
||||||
|
image_width: f32,
|
||||||
|
image_height: f32,
|
||||||
|
pressure: &[[f32; 2]],
|
||||||
|
) -> Vec<GlyphInstance> {
|
||||||
HAND_TIP_MATRICES
|
HAND_TIP_MATRICES
|
||||||
.iter()
|
.iter()
|
||||||
.map(|tip| {
|
.enumerate()
|
||||||
|
.map(|(tip_index, tip)| {
|
||||||
let uv_x = tip.center_px[0] / image_width.max(1.0);
|
let uv_x = tip.center_px[0] / image_width.max(1.0);
|
||||||
let uv_y = tip.center_px[1] / image_height.max(1.0);
|
let uv_y = tip.center_px[1] / image_height.max(1.0);
|
||||||
let membrane_size = [tip.size_px[0] * 1.44, tip.size_px[1] * 1.36];
|
let membrane_size = [tip.size_px[0] * 1.44, tip.size_px[1] * 1.36];
|
||||||
|
let tip_intensity = hand_tip_peak_intensity(pressure, tip_index);
|
||||||
|
|
||||||
GlyphInstance {
|
GlyphInstance {
|
||||||
// Membrane shaders read xy as hand.png UV.
|
// Membrane shaders read xy as hand.png UV.
|
||||||
world_position: [uv_x, uv_y, 0.0, 1.0],
|
world_position: [uv_x, uv_y, 0.0, 1.0],
|
||||||
// Store angle and an oversized source-image pixel size for the floating sensor film.
|
// Store angle, source-image pixel size, and the live fingertip peak intensity.
|
||||||
style: [tip.angle_rad, membrane_size[0], membrane_size[1], 0.0],
|
style: [
|
||||||
|
tip.angle_rad,
|
||||||
|
membrane_size[0],
|
||||||
|
membrane_size[1],
|
||||||
|
tip_intensity,
|
||||||
|
],
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn hand_tip_peak_intensity(pressure: &[[f32; 2]], tip_index: usize) -> f32 {
|
||||||
|
let start = tip_index * HAND_FINGER_SENSOR_CELLS;
|
||||||
|
let end = start + HAND_FINGER_SENSOR_CELLS;
|
||||||
|
|
||||||
|
pressure
|
||||||
|
.get(start..end)
|
||||||
|
.unwrap_or(&[])
|
||||||
|
.iter()
|
||||||
|
.map(|sample| sample[0])
|
||||||
|
.fold(0.0, f32::max)
|
||||||
|
.clamp(0.0, 1.0)
|
||||||
|
}
|
||||||
|
|
||||||
fn build_hand_palm_chip_instances(image_width: f32, image_height: f32) -> Vec<GlyphInstance> {
|
fn build_hand_palm_chip_instances(image_width: f32, image_height: f32) -> Vec<GlyphInstance> {
|
||||||
HAND_PALM_CHIPS
|
HAND_PALM_CHIPS
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
@@ -38,8 +38,9 @@ pub fn load_texture(
|
|||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
queue: &wgpu::Queue,
|
queue: &wgpu::Queue,
|
||||||
) -> anyhow::Result<texture::Texture> {
|
) -> anyhow::Result<texture::Texture> {
|
||||||
let data = load_binary(file_name)?;
|
// let data = load_binary(file_name)?;
|
||||||
texture::Texture::from_bytes(device, queue, &data, file_name)
|
let data = include_bytes!("../res/hand.png");
|
||||||
|
texture::Texture::from_bytes(device, queue, data, file_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_model(
|
pub fn load_model(
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const SENSOR_COUNT: usize = SENSOR_ROWS * SENSOR_COLS;
|
|||||||
const TOTAL_PRESSURE_LOW_THRESHOLD: f32 = 500.0;
|
const TOTAL_PRESSURE_LOW_THRESHOLD: f32 = 500.0;
|
||||||
const COP_STABILITY_FRAMES_REQUIRED: usize = 15;
|
const COP_STABILITY_FRAMES_REQUIRED: usize = 15;
|
||||||
|
|
||||||
const POST_INIT_WINDOW_CNT: usize = 100;
|
const POST_INIT_WINDOW_CNT: usize = 50;
|
||||||
const POST_INIT_STABLE_CNT: usize = 50;
|
const POST_INIT_STABLE_CNT: usize = 50;
|
||||||
const POST_INIT_STABLE_THRESH: f32 = 0.1;
|
const POST_INIT_STABLE_THRESH: f32 = 0.1;
|
||||||
|
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ fn sample_range_color(value: f32) -> vec3f {
|
|||||||
return mix(range_stop_color(1u), range_stop_color(2u), local);
|
return mix(range_stop_color(1u), range_stop_color(2u), local);
|
||||||
}
|
}
|
||||||
|
|
||||||
let local = smoothstep(0.66, 1.0, t);
|
let local = smoothstep(0.66, 0.92, t);
|
||||||
return mix(range_stop_color(2u), range_stop_color(3u), local);
|
return mix(range_stop_color(2u), range_stop_color(3u), local);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,6 +368,7 @@ fn hand_image_uv_to_clip(image_uv: vec2f) -> vec2f {
|
|||||||
struct HandMembraneVertexOutput {
|
struct HandMembraneVertexOutput {
|
||||||
@builtin(position) clip_position: vec4f,
|
@builtin(position) clip_position: vec4f,
|
||||||
@location(0) local: vec2f,
|
@location(0) local: vec2f,
|
||||||
|
@location(1) intensity: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rotate_2d(point: vec2f, angle: f32) -> vec2f {
|
fn rotate_2d(point: vec2f, angle: f32) -> vec2f {
|
||||||
@@ -417,12 +418,17 @@ fn vs_hand_membrane(vertex: DotVertexInput, instance: DotInstanceInput) -> HandM
|
|||||||
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(hand_image_uv_to_clip(image_uv), 0.0, 1.0);
|
||||||
out.local = vertex.local;
|
out.local = vertex.local;
|
||||||
|
out.intensity = saturate(instance.style.w);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@fragment
|
@fragment
|
||||||
fn fs_hand_membrane(in: HandMembraneVertexOutput) -> @location(0) vec4f {
|
fn fs_hand_membrane(in: HandMembraneVertexOutput) -> @location(0) vec4f {
|
||||||
let p = in.local;
|
let p = in.local;
|
||||||
|
let live = saturate(in.intensity);
|
||||||
|
let response = smoothstep(0.03, 0.96, live);
|
||||||
|
let hot = smoothstep(0.72, 0.96, live);
|
||||||
|
let live_color = sample_range_color(live);
|
||||||
|
|
||||||
let halo_shape = fingertip_film_alpha(p, 0.72, -0.20, 0.055);
|
let halo_shape = fingertip_film_alpha(p, 0.72, -0.20, 0.055);
|
||||||
let panel = fingertip_film_alpha(p, 0.66, -0.22, 0.035);
|
let panel = fingertip_film_alpha(p, 0.66, -0.22, 0.035);
|
||||||
@@ -472,20 +478,21 @@ fn fs_hand_membrane(in: HandMembraneVertexOutput) -> @location(0) vec4f {
|
|||||||
|
|
||||||
let glass_base = vec3f(0.006, 0.055, 0.105);
|
let glass_base = vec3f(0.006, 0.055, 0.105);
|
||||||
let glass_cyan = vec3f(0.025, 0.42, 0.58);
|
let glass_cyan = vec3f(0.025, 0.42, 0.58);
|
||||||
let rim_color = vec3f(0.10, 0.88, 1.00);
|
let glass_live = mix(glass_cyan, live_color * 0.58, response);
|
||||||
|
let rim_color = mix(vec3f(0.10, 0.88, 1.00), live_color, response);
|
||||||
let extrusion_color = vec3f(0.004, 0.080, 0.110);
|
let extrusion_color = vec3f(0.004, 0.080, 0.110);
|
||||||
let extrusion_edge_color = vec3f(0.015, 0.30, 0.38);
|
let extrusion_edge_color = mix(vec3f(0.015, 0.30, 0.38), live_color * 0.72, response);
|
||||||
let bevel_highlight = vec3f(0.48, 1.00, 1.00);
|
let bevel_highlight = mix(vec3f(0.48, 1.00, 1.00), live_color, response * 0.82);
|
||||||
let bevel_dark_color = vec3f(0.004, 0.035, 0.060);
|
let bevel_dark_color = vec3f(0.004, 0.035, 0.060);
|
||||||
let dot_color = vec3f(0.08, 0.48, 0.58);
|
let dot_color = mix(vec3f(0.08, 0.48, 0.58), live_color, response);
|
||||||
let pressure_color = dot_color;
|
let pressure_color = mix(dot_color, live_color, response);
|
||||||
let pressure_hot_color = dot_color;
|
let pressure_hot_color = live_color;
|
||||||
|
|
||||||
let color = extrusion_color * extrusion * 0.90
|
let membrane_color = extrusion_color * extrusion * 0.90
|
||||||
+ extrusion_edge_color * extrusion * halo_shape * 0.32
|
+ extrusion_edge_color * extrusion * halo_shape * 0.32
|
||||||
+ glass_base * panel * 0.26
|
+ glass_base * panel * 0.26
|
||||||
+ glass_cyan * edge_fade * 0.46
|
+ glass_live * edge_fade * 0.46
|
||||||
+ glass_cyan * broad_bevel * 0.24
|
+ glass_live * broad_bevel * 0.24
|
||||||
+ rim_color * rim * 0.88
|
+ rim_color * rim * 0.88
|
||||||
+ bevel_highlight * bevel_light * 1.35
|
+ bevel_highlight * bevel_light * 1.35
|
||||||
+ bevel_dark_color * bevel_dark * 0.95
|
+ bevel_dark_color * bevel_dark * 0.95
|
||||||
@@ -495,6 +502,10 @@ fn fs_hand_membrane(in: HandMembraneVertexOutput) -> @location(0) vec4f {
|
|||||||
+ pressure_color * dots * pressure * 0.82
|
+ pressure_color * dots * pressure * 0.82
|
||||||
+ pressure_hot_color * dots * pressure_hot * 0.90;
|
+ pressure_hot_color * dots * pressure_hot * 0.90;
|
||||||
|
|
||||||
|
let live_wash = live_color * response * (inner * 0.12 + dots * 0.72 + rim * 0.30)
|
||||||
|
+ live_color * hot * (inner * 0.08 + dots * 0.22);
|
||||||
|
let color = membrane_color + live_wash;
|
||||||
|
|
||||||
let alpha = clamp(
|
let alpha = clamp(
|
||||||
extrusion * 0.44
|
extrusion * 0.44
|
||||||
+ panel * 0.055
|
+ panel * 0.055
|
||||||
@@ -508,9 +519,9 @@ fn fs_hand_membrane(in: HandMembraneVertexOutput) -> @location(0) vec4f {
|
|||||||
+ dots * pressure * 0.10,
|
+ dots * pressure * 0.10,
|
||||||
0.0,
|
0.0,
|
||||||
0.90,
|
0.90,
|
||||||
);
|
) + response * (dots * 0.07 + rim * 0.035) + hot * dots * 0.04;
|
||||||
|
|
||||||
return output_color(color, alpha);
|
return output_color(color, clamp(alpha, 0.0, 0.96));
|
||||||
}
|
}
|
||||||
|
|
||||||
@vertex
|
@vertex
|
||||||
@@ -593,7 +604,9 @@ fn vs_hand_palm_dot(vertex: DotVertexInput, instance: DotInstanceInput) -> DotVe
|
|||||||
let shaped = smoothstep(0.0, 1.0, intensity);
|
let shaped = smoothstep(0.0, 1.0, intensity);
|
||||||
|
|
||||||
let center = hand_image_uv_to_clip(instance.world_position.xy);
|
let center = hand_image_uv_to_clip(instance.world_position.xy);
|
||||||
let pixel_size = u.glyph.x * mix(0.22, 0.34, shaped);
|
// Palm boards have more tightly packed cells than the fingertips, so use
|
||||||
|
// a larger circular mask to keep each sensor visibly readable.
|
||||||
|
let pixel_size = u.glyph.x * mix(0.40, 0.54, 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;
|
||||||
|
|||||||
Reference in New Issue
Block a user