Compare commits
18 Commits
f30ebcf20b
...
waic-hand-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4d0e65c02b | ||
|
|
ca6ca377df | ||
|
|
801a909c64 | ||
|
|
bf7907ce6f | ||
|
|
466bb5dec7 | ||
|
|
5af3c2862b | ||
|
|
9fb4c0edf4 | ||
|
|
1e3cfdcf21 | ||
|
|
a04b903e96 | ||
|
|
c4bccc1747 | ||
|
|
5264f0c247 | ||
|
|
a999d9c064 | ||
|
|
71d314ac44 | ||
|
|
0a9fea0f0a | ||
|
|
da77f2f194 | ||
|
|
1ed729f8da | ||
|
|
444c20f233 | ||
|
|
d4f160af75 |
@@ -1,35 +0,0 @@
|
|||||||
{
|
|
||||||
"hooks": {
|
|
||||||
"pre-exec": [
|
|
||||||
{
|
|
||||||
"matcher": "",
|
|
||||||
"command": "scale gate pre-tool Bash --args-json \"$ARGS\" --session-id \"$SESSION_ID\""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"matcher": "edit|write",
|
|
||||||
"command": "scale gate pre-tool Edit --args-json \"$ARGS\" --session-id \"$SESSION_ID\""
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"post-exec": [
|
|
||||||
{
|
|
||||||
"matcher": "edit|write",
|
|
||||||
"command": "scale gate post-tool Edit --args-json \"$ARGS\" --exit-code \"$EXIT_CODE\" --session-id \"$SESSION_ID\""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"matcher": "",
|
|
||||||
"command": "scale gate post-tool Bash --args-json \"$ARGS\" --exit-code \"$EXIT_CODE\" --session-id \"$SESSION_ID\""
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"before-stop": [
|
|
||||||
{
|
|
||||||
"matcher": "",
|
|
||||||
"command": "scale gate before-stop --session-id \"$SESSION_ID\""
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"permissions": {
|
|
||||||
"allow": [
|
|
||||||
"scale:*"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
45
Cargo.lock
generated
45
Cargo.lock
generated
@@ -1304,7 +1304,7 @@ checksum = "dea2df4cf52843e0452895c455a1a2cfbb842a1e7329671acf418fdc53ed4c59"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "eskin-model-player"
|
name = "eskin-model-player"
|
||||||
version = "0.5.0"
|
version = "5.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
@@ -1318,8 +1318,11 @@ dependencies = [
|
|||||||
"gltf",
|
"gltf",
|
||||||
"image",
|
"image",
|
||||||
"log",
|
"log",
|
||||||
|
"serde",
|
||||||
"serialport",
|
"serialport",
|
||||||
"tobj",
|
"tobj",
|
||||||
|
"toml",
|
||||||
|
"winresource",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3645,6 +3648,15 @@ dependencies = [
|
|||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_spanned"
|
||||||
|
version = "1.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26"
|
||||||
|
dependencies = [
|
||||||
|
"serde_core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serialport"
|
name = "serialport"
|
||||||
version = "4.9.0"
|
version = "4.9.0"
|
||||||
@@ -3989,6 +4001,21 @@ dependencies = [
|
|||||||
"ahash",
|
"ahash",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml"
|
||||||
|
version = "1.1.3+spec-1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "53c96ecdfa941c8fc4fcaed14f99ada8ebed502eef533015095a07e3301d4c3c"
|
||||||
|
dependencies = [
|
||||||
|
"indexmap",
|
||||||
|
"serde_core",
|
||||||
|
"serde_spanned",
|
||||||
|
"toml_datetime",
|
||||||
|
"toml_parser",
|
||||||
|
"toml_writer",
|
||||||
|
"winnow",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml_datetime"
|
name = "toml_datetime"
|
||||||
version = "1.1.1+spec-1.1.0"
|
version = "1.1.1+spec-1.1.0"
|
||||||
@@ -4019,6 +4046,12 @@ dependencies = [
|
|||||||
"winnow",
|
"winnow",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml_writer"
|
||||||
|
version = "1.1.2+spec-1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing"
|
name = "tracing"
|
||||||
version = "0.1.44"
|
version = "0.1.44"
|
||||||
@@ -5017,6 +5050,16 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winresource"
|
||||||
|
version = "0.1.31"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0986a8b1d586b7d3e4fe3d9ea39fb451ae22869dcea4aa109d287a374d866087"
|
||||||
|
dependencies = [
|
||||||
|
"toml",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wit-bindgen"
|
name = "wit-bindgen"
|
||||||
version = "0.51.0"
|
version = "0.51.0"
|
||||||
|
|||||||
15
Cargo.toml
15
Cargo.toml
@@ -1,9 +1,14 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "eskin-model-player"
|
name = "eskin-model-player"
|
||||||
version = "0.5.0"
|
version = "5.0.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
authors = ["JOYSONQUIN"]
|
||||||
|
description = "Desktop pressure sensor visualization and playback application."
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|
||||||
|
[package.metadata.wix]
|
||||||
|
eula = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eframe = { version = "0.34.2", features = ["default", "wgpu", "__screenshot"] }
|
eframe = { version = "0.34.2", features = ["default", "wgpu", "__screenshot"] }
|
||||||
env_logger = { version = "0.11.10", features = ["auto-color", "humantime"] }
|
env_logger = { version = "0.11.10", features = ["auto-color", "humantime"] }
|
||||||
@@ -18,7 +23,15 @@ 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]
|
||||||
anyhow = "1.0.102"
|
anyhow = "1.0.102"
|
||||||
fs_extra = "1.3.0"
|
fs_extra = "1.3.0"
|
||||||
|
winresource = "0.1.31"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "ESkinPlayer"
|
||||||
|
path = "src/main.rs"
|
||||||
|
|||||||
8
build.rs
8
build.rs
@@ -27,6 +27,14 @@ fn main() -> Result<()> {
|
|||||||
copy_items(&items, &resource_dir, ©_options)?;
|
copy_items(&items, &resource_dir, ©_options)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") {
|
||||||
|
let mut resource = winresource::WindowsResource::new();
|
||||||
|
|
||||||
|
resource.set_icon("res/icon.ico");
|
||||||
|
|
||||||
|
resource.compile().expect("compile windows icon failed");
|
||||||
|
}
|
||||||
|
|
||||||
println!("cargo:rustc-env=RESOURCE_DIR={}", resource_dir.display());
|
println!("cargo:rustc-env=RESOURCE_DIR={}", resource_dir.display());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
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
|
||||||
1060
docs/cargo-wix-guide.md
Normal file
1060
docs/cargo-wix-guide.md
Normal file
File diff suppressed because it is too large
Load Diff
BIN
res/128x128@2x.png
Normal file
BIN
res/128x128@2x.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
BIN
res/hand.glb
Normal file
BIN
res/hand.glb
Normal file
Binary file not shown.
BIN
res/icon.ico
Normal file
BIN
res/icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 41 KiB |
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())
|
||||||
862
src/app.rs
862
src/app.rs
File diff suppressed because it is too large
Load Diff
@@ -20,6 +20,7 @@ enum BreakoutPhase {
|
|||||||
Idle,
|
Idle,
|
||||||
Running,
|
Running,
|
||||||
Paused,
|
Paused,
|
||||||
|
Won,
|
||||||
Over,
|
Over,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +47,6 @@ pub struct BreakoutGame {
|
|||||||
score: u32,
|
score: u32,
|
||||||
combo: u32,
|
combo: u32,
|
||||||
lives: u32,
|
lives: u32,
|
||||||
level: u32,
|
|
||||||
last_time: Option<f64>,
|
last_time: Option<f64>,
|
||||||
previous_pause_gesture: bool,
|
previous_pause_gesture: bool,
|
||||||
pause_locked_until: f64,
|
pause_locked_until: f64,
|
||||||
@@ -63,7 +63,6 @@ impl Default for BreakoutGame {
|
|||||||
score: 0,
|
score: 0,
|
||||||
combo: 0,
|
combo: 0,
|
||||||
lives: 3,
|
lives: 3,
|
||||||
level: 1,
|
|
||||||
last_time: None,
|
last_time: None,
|
||||||
previous_pause_gesture: false,
|
previous_pause_gesture: false,
|
||||||
pause_locked_until: 0.0,
|
pause_locked_until: 0.0,
|
||||||
@@ -150,7 +149,6 @@ impl BreakoutGame {
|
|||||||
status_chip(ui, "分数", self.score.to_string(), ACCENT_GREEN);
|
status_chip(ui, "分数", self.score.to_string(), ACCENT_GREEN);
|
||||||
status_chip(ui, "连击", self.combo.to_string(), ACCENT_ORANGE);
|
status_chip(ui, "连击", self.combo.to_string(), ACCENT_ORANGE);
|
||||||
status_chip(ui, "生命", self.lives.to_string(), ACCENT_RED);
|
status_chip(ui, "生命", self.lives.to_string(), ACCENT_RED);
|
||||||
status_chip(ui, "关卡", self.level.to_string(), ACCENT_BLUE);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.add_space(7.0);
|
ui.add_space(7.0);
|
||||||
@@ -191,12 +189,11 @@ impl BreakoutGame {
|
|||||||
self.score = 0;
|
self.score = 0;
|
||||||
self.combo = 0;
|
self.combo = 0;
|
||||||
self.lives = 3;
|
self.lives = 3;
|
||||||
self.level = 1;
|
|
||||||
self.rebuild_bricks();
|
self.rebuild_bricks();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start(&mut self) {
|
fn start(&mut self) {
|
||||||
if self.phase == BreakoutPhase::Over {
|
if self.phase == BreakoutPhase::Over || self.phase == BreakoutPhase::Won {
|
||||||
self.reset();
|
self.reset();
|
||||||
}
|
}
|
||||||
if self.phase != BreakoutPhase::Running {
|
if self.phase != BreakoutPhase::Running {
|
||||||
@@ -219,7 +216,10 @@ impl BreakoutGame {
|
|||||||
let threshold = pressure_pause_threshold();
|
let threshold = pressure_pause_threshold();
|
||||||
let active = top_force >= threshold;
|
let active = top_force >= threshold;
|
||||||
if active && !self.previous_pause_gesture && now >= self.pause_locked_until {
|
if active && !self.previous_pause_gesture && now >= self.pause_locked_until {
|
||||||
if self.phase == BreakoutPhase::Idle || self.phase == BreakoutPhase::Over {
|
if matches!(
|
||||||
|
self.phase,
|
||||||
|
BreakoutPhase::Idle | BreakoutPhase::Over | BreakoutPhase::Won
|
||||||
|
) {
|
||||||
self.start();
|
self.start();
|
||||||
} else {
|
} else {
|
||||||
self.toggle_pause();
|
self.toggle_pause();
|
||||||
@@ -249,7 +249,7 @@ 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 = 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;
|
||||||
}
|
}
|
||||||
@@ -324,9 +324,8 @@ impl BreakoutGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.bricks.iter().all(|brick| !brick.alive) {
|
if self.bricks.iter().all(|brick| !brick.alive) {
|
||||||
self.level += 1;
|
self.phase = BreakoutPhase::Won;
|
||||||
self.rebuild_bricks();
|
self.ball_vel = egui::Vec2::ZERO;
|
||||||
self.launch_ball();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,6 +357,7 @@ impl BreakoutGame {
|
|||||||
BreakoutPhase::Idle => "待机",
|
BreakoutPhase::Idle => "待机",
|
||||||
BreakoutPhase::Running => "运行",
|
BreakoutPhase::Running => "运行",
|
||||||
BreakoutPhase::Paused => "暂停",
|
BreakoutPhase::Paused => "暂停",
|
||||||
|
BreakoutPhase::Won => "过关",
|
||||||
BreakoutPhase::Over => "结束",
|
BreakoutPhase::Over => "结束",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -387,6 +387,7 @@ impl BreakoutGame {
|
|||||||
|
|
||||||
if self.phase == BreakoutPhase::Idle
|
if self.phase == BreakoutPhase::Idle
|
||||||
|| self.phase == BreakoutPhase::Paused
|
|| self.phase == BreakoutPhase::Paused
|
||||||
|
|| self.phase == BreakoutPhase::Won
|
||||||
|| self.phase == BreakoutPhase::Over
|
|| self.phase == BreakoutPhase::Over
|
||||||
{
|
{
|
||||||
paint_center_overlay(&painter, rect, self.phase);
|
paint_center_overlay(&painter, rect, self.phase);
|
||||||
@@ -403,6 +404,10 @@ pub fn control_from_matrix(raw: &[u32], rows: u32, cols: u32) -> BreakoutControl
|
|||||||
let cols = cols.max(1) as usize;
|
let cols = cols.max(1) as usize;
|
||||||
let sample_rows = rows.min(2);
|
let sample_rows = rows.min(2);
|
||||||
let sample_cols = cols.min(2);
|
let sample_cols = cols.min(2);
|
||||||
|
let top_gesture_rows = rows.min(1);
|
||||||
|
let top_gesture_cols = (cols / 3).clamp(1, cols);
|
||||||
|
let top_gesture_col_start = (cols - top_gesture_cols) / 2;
|
||||||
|
let top_gesture_col_end = top_gesture_col_start + top_gesture_cols;
|
||||||
let avg = |row_start: usize, row_end: usize, col_start: usize, col_end: usize| -> f32 {
|
let avg = |row_start: usize, row_end: usize, col_start: usize, col_end: usize| -> f32 {
|
||||||
let mut sum = 0.0;
|
let mut sum = 0.0;
|
||||||
let mut count = 0.0;
|
let mut count = 0.0;
|
||||||
@@ -430,7 +435,12 @@ pub fn control_from_matrix(raw: &[u32], rows: u32, cols: u32) -> BreakoutControl
|
|||||||
|
|
||||||
let left_force = tl + bl;
|
let left_force = tl + bl;
|
||||||
let right_force = tr + br;
|
let right_force = tr + br;
|
||||||
let top_force = tl + tr;
|
let top_force = avg(
|
||||||
|
0,
|
||||||
|
top_gesture_rows,
|
||||||
|
top_gesture_col_start,
|
||||||
|
top_gesture_col_end,
|
||||||
|
);
|
||||||
let span = 1200.0_f32.max((PRESSURE_RANGE_MAX - PRESSURE_RANGE_MIN) * 0.22);
|
let span = 1200.0_f32.max((PRESSURE_RANGE_MAX - PRESSURE_RANGE_MIN) * 0.22);
|
||||||
let raw_axis = ((right_force - left_force) / span).clamp(-1.0, 1.0);
|
let raw_axis = ((right_force - left_force) / span).clamp(-1.0, 1.0);
|
||||||
let axis = if raw_axis.abs() < 0.045 {
|
let axis = if raw_axis.abs() < 0.045 {
|
||||||
@@ -485,6 +495,7 @@ fn status_color(phase: BreakoutPhase) -> egui::Color32 {
|
|||||||
BreakoutPhase::Idle => ONE_DARK_PRO.text_dim,
|
BreakoutPhase::Idle => ONE_DARK_PRO.text_dim,
|
||||||
BreakoutPhase::Running => ACCENT_GREEN,
|
BreakoutPhase::Running => ACCENT_GREEN,
|
||||||
BreakoutPhase::Paused => ACCENT_ORANGE,
|
BreakoutPhase::Paused => ACCENT_ORANGE,
|
||||||
|
BreakoutPhase::Won => ACCENT_GREEN,
|
||||||
BreakoutPhase::Over => ACCENT_RED,
|
BreakoutPhase::Over => ACCENT_RED,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -607,6 +618,7 @@ fn paint_center_overlay(painter: &egui::Painter, rect: egui::Rect, phase: Breako
|
|||||||
let (title, detail) = match phase {
|
let (title, detail) = match phase {
|
||||||
BreakoutPhase::Idle => ("按压顶部或点击开始", "左右分区压力控制挡板"),
|
BreakoutPhase::Idle => ("按压顶部或点击开始", "左右分区压力控制挡板"),
|
||||||
BreakoutPhase::Paused => ("已暂停", "再次按压顶部、P 或点击暂停继续"),
|
BreakoutPhase::Paused => ("已暂停", "再次按压顶部、P 或点击暂停继续"),
|
||||||
|
BreakoutPhase::Won => ("恭喜过关", "按压顶部、点击或空格重新开始"),
|
||||||
BreakoutPhase::Over => ("游戏结束", "点击或空格重开"),
|
BreakoutPhase::Over => ("游戏结束", "点击或空格重开"),
|
||||||
BreakoutPhase::Running => ("", ""),
|
BreakoutPhase::Running => ("", ""),
|
||||||
};
|
};
|
||||||
|
|||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,10 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use crossbeam_channel::{self, Receiver, Sender, TryRecvError};
|
use crossbeam_channel::{self, Receiver, Sender, TryRecvError};
|
||||||
|
|
||||||
use crate::serial_core::serial::{SerialIoStats, SerialPortReadWrite, run_serial_loop};
|
use crate::recording::Recorder;
|
||||||
|
use crate::serial_core::serial::{
|
||||||
|
SerialIoStats, SerialPortReadWrite, SerialProtocol, run_serial_loop,
|
||||||
|
};
|
||||||
|
|
||||||
/// Connection state visible to the UI.
|
/// Connection state visible to the UI.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
@@ -28,6 +31,8 @@ struct Session {
|
|||||||
handle: JoinHandle<()>,
|
handle: JoinHandle<()>,
|
||||||
sample_rx: Receiver<Vec<i32>>,
|
sample_rx: Receiver<Vec<i32>>,
|
||||||
stats_rx: Receiver<SerialIoStats>,
|
stats_rx: Receiver<SerialIoStats>,
|
||||||
|
rows: u32,
|
||||||
|
cols: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Thread-safe connection manager that the UI and renderer can share.
|
/// Thread-safe connection manager that the UI and renderer can share.
|
||||||
@@ -72,7 +77,15 @@ impl ConnectionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Connect to the given serial port and start streaming in a background thread.
|
/// Connect to the given serial port and start streaming in a background thread.
|
||||||
pub fn connect(&self, port_name: &str, rows: u32, cols: u32) {
|
pub fn connect(
|
||||||
|
&self,
|
||||||
|
port_name: &str,
|
||||||
|
rows: u32,
|
||||||
|
cols: u32,
|
||||||
|
baud_rate: u32,
|
||||||
|
protocol: SerialProtocol,
|
||||||
|
recorder: Recorder,
|
||||||
|
) {
|
||||||
self.disconnect();
|
self.disconnect();
|
||||||
self.set_state(ConnectionState::Connecting);
|
self.set_state(ConnectionState::Connecting);
|
||||||
|
|
||||||
@@ -90,11 +103,14 @@ impl ConnectionManager {
|
|||||||
&port,
|
&port,
|
||||||
rows,
|
rows,
|
||||||
cols,
|
cols,
|
||||||
|
baud_rate,
|
||||||
|
protocol,
|
||||||
&state,
|
&state,
|
||||||
&cancel_rx,
|
&cancel_rx,
|
||||||
&sample_tx,
|
&sample_tx,
|
||||||
&stats_tx,
|
&stats_tx,
|
||||||
&latest_sample,
|
&latest_sample,
|
||||||
|
recorder,
|
||||||
);
|
);
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
eprintln!("[connection] device loop error: {e}");
|
eprintln!("[connection] device loop error: {e}");
|
||||||
@@ -107,6 +123,8 @@ impl ConnectionManager {
|
|||||||
handle,
|
handle,
|
||||||
sample_rx,
|
sample_rx,
|
||||||
stats_rx,
|
stats_rx,
|
||||||
|
rows,
|
||||||
|
cols,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,10 +153,12 @@ impl ConnectionManager {
|
|||||||
loop {
|
loop {
|
||||||
match session.sample_rx.try_recv() {
|
match session.sample_rx.try_recv() {
|
||||||
Ok(vals) => {
|
Ok(vals) => {
|
||||||
let rows = 12u32;
|
|
||||||
let cols = 7u32;
|
|
||||||
let matrix = vals.iter().map(|v| (*v).max(0) as u32).collect();
|
let matrix = vals.iter().map(|v| (*v).max(0) as u32).collect();
|
||||||
last = Some(PressureSample { matrix, rows, cols });
|
last = Some(PressureSample {
|
||||||
|
matrix,
|
||||||
|
rows: session.rows,
|
||||||
|
cols: session.cols,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Err(TryRecvError::Empty) => break,
|
Err(TryRecvError::Empty) => break,
|
||||||
Err(TryRecvError::Disconnected) => break,
|
Err(TryRecvError::Disconnected) => break,
|
||||||
@@ -163,14 +183,17 @@ fn run_device_loop(
|
|||||||
port_name: &str,
|
port_name: &str,
|
||||||
rows: u32,
|
rows: u32,
|
||||||
cols: u32,
|
cols: u32,
|
||||||
|
baud_rate: u32,
|
||||||
|
protocol: SerialProtocol,
|
||||||
state: &Arc<Mutex<ConnectionState>>,
|
state: &Arc<Mutex<ConnectionState>>,
|
||||||
cancel_rx: &Receiver<()>,
|
cancel_rx: &Receiver<()>,
|
||||||
sample_tx: &Sender<Vec<i32>>,
|
sample_tx: &Sender<Vec<i32>>,
|
||||||
stats_tx: &Sender<SerialIoStats>,
|
stats_tx: &Sender<SerialIoStats>,
|
||||||
latest_sample: &Arc<Mutex<Option<PressureSample>>>,
|
latest_sample: &Arc<Mutex<Option<PressureSample>>>,
|
||||||
|
recorder: Recorder,
|
||||||
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||||
let port = serialport::new(port_name, 921_600)
|
let port = serialport::new(port_name, baud_rate)
|
||||||
.timeout(Duration::from_millis(100))
|
.timeout(Duration::from_millis(1))
|
||||||
.open()?;
|
.open()?;
|
||||||
|
|
||||||
*state.lock().unwrap() = ConnectionState::Connected;
|
*state.lock().unwrap() = ConnectionState::Connected;
|
||||||
@@ -182,9 +205,11 @@ fn run_device_loop(
|
|||||||
&mut rw,
|
&mut rw,
|
||||||
rows as usize,
|
rows as usize,
|
||||||
cols as usize,
|
cols as usize,
|
||||||
|
protocol,
|
||||||
cancel_rx,
|
cancel_rx,
|
||||||
sample_tx,
|
sample_tx,
|
||||||
Some(stats_tx),
|
Some(stats_tx),
|
||||||
|
Some(&recorder),
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Ok(mut latest) = latest_sample.lock() {
|
if let Ok(mut latest) = latest_sample.lock() {
|
||||||
|
|||||||
98
src/force.rs
Normal file
98
src/force.rs
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
use crate::serial_core::multi_dim_force::PztProcessor;
|
||||||
|
|
||||||
|
pub const FINGER_SAMPLE_COUNT: usize = 84;
|
||||||
|
pub const HAND_FINGERTIP_COUNT: usize = 5;
|
||||||
|
const MIN_TANGENTIAL_MAGNITUDE: f32 = 0.1;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub struct HudSpatialForce {
|
||||||
|
pub angle_deg: f32,
|
||||||
|
pub magnitude: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ForceEstimatorState {
|
||||||
|
pzt_processor: PztProcessor,
|
||||||
|
fingertip_processors: [PztProcessor; HAND_FINGERTIP_COUNT],
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ForceEstimatorState {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
pzt_processor: PztProcessor::new(),
|
||||||
|
fingertip_processors: std::array::from_fn(|_| PztProcessor::new()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reset(&mut self) {
|
||||||
|
self.pzt_processor.reset_baseline();
|
||||||
|
self.fingertip_processors
|
||||||
|
.iter_mut()
|
||||||
|
.for_each(PztProcessor::reset_baseline);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn analyze(&mut self, values: &[u32]) -> Option<HudSpatialForce> {
|
||||||
|
if values.len() != FINGER_SAMPLE_COUNT {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let pzt_values = values.iter().map(|value| *value as f32).collect::<Vec<_>>();
|
||||||
|
|
||||||
|
self.pzt_processor
|
||||||
|
.get_pzt_analysis(&pzt_values)
|
||||||
|
.ok()
|
||||||
|
.filter(|analysis| analysis.magnitude > MIN_TANGENTIAL_MAGNITUDE)
|
||||||
|
.map(|analysis| HudSpatialForce {
|
||||||
|
angle_deg: analysis.angle_deg,
|
||||||
|
magnitude: analysis.magnitude,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn analyze_fingertips(
|
||||||
|
&mut self,
|
||||||
|
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] {
|
||||||
|
let mut forces = [None; HAND_FINGERTIP_COUNT];
|
||||||
|
|
||||||
|
for (tip_index, processor) in self.fingertip_processors.iter_mut().enumerate() {
|
||||||
|
if !enabled[tip_index] {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let start = tip_index * FINGER_SAMPLE_COUNT;
|
||||||
|
let end = start + FINGER_SAMPLE_COUNT;
|
||||||
|
let Some(segment) = values.get(start..end) else {
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
|
||||||
|
let pzt_values = segment
|
||||||
|
.iter()
|
||||||
|
.map(|value| *value as f32)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
forces[tip_index] = processor
|
||||||
|
.get_pzt_analysis(&pzt_values)
|
||||||
|
.ok()
|
||||||
|
.filter(|analysis| analysis.magnitude > MIN_TANGENTIAL_MAGNITUDE)
|
||||||
|
.map(|analysis| HudSpatialForce {
|
||||||
|
angle_deg: analysis.angle_deg,
|
||||||
|
magnitude: analysis.magnitude,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
forces
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ForceEstimatorState {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
#![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 matrix;
|
mod matrix;
|
||||||
mod model;
|
mod model;
|
||||||
mod recording;
|
mod recording;
|
||||||
@@ -17,12 +21,15 @@ use eframe::egui;
|
|||||||
fn main() -> eframe::Result<()> {
|
fn main() -> eframe::Result<()> {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
|
let window_icon = eframe::icon_data::from_png_bytes(include_bytes!("../res/128x128@2x.png"))
|
||||||
|
.expect("load window icon failed");
|
||||||
let options = eframe::NativeOptions {
|
let options = eframe::NativeOptions {
|
||||||
renderer: eframe::Renderer::Wgpu,
|
renderer: eframe::Renderer::Wgpu,
|
||||||
viewport: egui::ViewportBuilder::default()
|
viewport: egui::ViewportBuilder::default()
|
||||||
.with_inner_size([1920.0, 1080.0])
|
.with_inner_size([1920.0, 1080.0])
|
||||||
.with_min_inner_size([1280.0, 720.0])
|
.with_min_inner_size([1280.0, 720.0])
|
||||||
.with_decorations(false),
|
.with_decorations(false)
|
||||||
|
.with_icon(window_icon),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
190
src/render.rs
190
src/render.rs
@@ -13,11 +13,13 @@ use std::ops::Range;
|
|||||||
pub const PRESSURE_CELL_COUNT: usize =
|
pub const PRESSURE_CELL_COUNT: usize =
|
||||||
(crate::matrix::MATRIX_ROWS * crate::matrix::MATRIX_COLS) as usize;
|
(crate::matrix::MATRIX_ROWS * crate::matrix::MATRIX_COLS) as usize;
|
||||||
pub type PressureFrame = [[f32; 2]; PRESSURE_CELL_COUNT];
|
pub type PressureFrame = [[f32; 2]; PRESSURE_CELL_COUNT];
|
||||||
|
pub type PressureSamples = Vec<[f32; 2]>;
|
||||||
|
|
||||||
pub struct WgpuBackgroundCallback {
|
pub struct WgpuBackgroundCallback {
|
||||||
pub width: f32,
|
pub width: f32,
|
||||||
pub height: f32,
|
pub height: f32,
|
||||||
pub pressure: PressureFrame,
|
pub pressure: PressureFrame,
|
||||||
|
pub hand_pressure: PressureSamples,
|
||||||
pub active_mode: ActiveMode,
|
pub active_mode: ActiveMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,49 +44,54 @@ pub struct HandGatewayMode {
|
|||||||
|
|
||||||
const HAND_TIP_MATRICES: [HandTipMatrix; 5] = [
|
const HAND_TIP_MATRICES: [HandTipMatrix; 5] = [
|
||||||
HandTipMatrix {
|
HandTipMatrix {
|
||||||
center_px: [260.0, 490.0],
|
center_px: [263.5, 495.0],
|
||||||
size_px: [70.0, 120.0],
|
size_px: [70.0, 120.0],
|
||||||
angle_rad: -0.45,
|
angle_rad: -0.40,
|
||||||
},
|
},
|
||||||
HandTipMatrix {
|
HandTipMatrix {
|
||||||
center_px: [360.0, 255.0],
|
center_px: [362.0, 260.0],
|
||||||
size_px: [70.0, 120.0],
|
size_px: [70.0, 120.0],
|
||||||
angle_rad: -0.05,
|
angle_rad: -0.158,
|
||||||
},
|
},
|
||||||
HandTipMatrix {
|
HandTipMatrix {
|
||||||
center_px: [485.0, 225.0],
|
center_px: [480.5, 228.0],
|
||||||
size_px: [70.0, 120.0],
|
size_px: [70.0, 120.0],
|
||||||
angle_rad: 0.0,
|
angle_rad: -0.02,
|
||||||
},
|
},
|
||||||
HandTipMatrix {
|
HandTipMatrix {
|
||||||
center_px: [595.0, 260.0],
|
center_px: [594.0, 265.0],
|
||||||
size_px: [70.0, 120.0],
|
size_px: [70.0, 120.0],
|
||||||
angle_rad: 0.12,
|
angle_rad: 0.10,
|
||||||
},
|
},
|
||||||
HandTipMatrix {
|
HandTipMatrix {
|
||||||
center_px: [705.0, 385.0],
|
center_px: [693.0, 370.0],
|
||||||
size_px: [70.0, 120.0],
|
size_px: [70.0, 120.0],
|
||||||
angle_rad: 0.28,
|
angle_rad: 0.22,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const HAND_PALM_CHIPS: [HandPalmChip; 2] = [
|
const HAND_PALM_CHIPS: [HandPalmChip; 2] = [
|
||||||
HandPalmChip {
|
HandPalmChip {
|
||||||
center_px: [538.0, 608.0],
|
center_px: [530.0, 593.0],
|
||||||
size_px: [248.0, 82.0],
|
size_px: [258.0, 88.0],
|
||||||
angle_rad: 0.06,
|
angle_rad: 0.12,
|
||||||
rows: 5,
|
rows: 5,
|
||||||
cols: 14,
|
cols: 14,
|
||||||
},
|
},
|
||||||
HandPalmChip {
|
HandPalmChip {
|
||||||
center_px: [606.0, 780.0],
|
center_px: [610.0, 778.0],
|
||||||
size_px: [72.0, 214.0],
|
size_px: [82.0, 228.0],
|
||||||
angle_rad: 0.05,
|
angle_rad: 0.05,
|
||||||
rows: 11,
|
rows: 11,
|
||||||
cols: 4,
|
cols: 4,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
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;
|
||||||
|
const HAND_TIP_DOT_LOCAL_Y_OFFSET_PX: f32 = 14.0;
|
||||||
|
|
||||||
// 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.
|
||||||
// size_px keeps the same 7:12 aspect as the Finger-mode 7 columns x 12 rows matrix.
|
// size_px keeps the same 7:12 aspect as the Finger-mode 7 columns x 12 rows matrix.
|
||||||
@@ -114,7 +121,13 @@ impl egui_wgpu::CallbackTrait for WgpuBackgroundCallback {
|
|||||||
resources: &mut egui_wgpu::CallbackResources,
|
resources: &mut egui_wgpu::CallbackResources,
|
||||||
) -> Vec<wgpu::CommandBuffer> {
|
) -> Vec<wgpu::CommandBuffer> {
|
||||||
let resources: &mut BackgroundRenderResources = resources.get_mut().unwrap();
|
let resources: &mut BackgroundRenderResources = resources.get_mut().unwrap();
|
||||||
resources.prepare(queue, self.width, self.height, &self.pressure);
|
resources.prepare(
|
||||||
|
queue,
|
||||||
|
self.width,
|
||||||
|
self.height,
|
||||||
|
&self.pressure,
|
||||||
|
&self.hand_pressure,
|
||||||
|
);
|
||||||
Vec::new()
|
Vec::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -519,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,
|
||||||
@@ -596,7 +610,14 @@ impl BackgroundRenderResources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prepare(&mut self, queue: &wgpu::Queue, width: f32, height: f32, pressure: &PressureFrame) {
|
fn prepare(
|
||||||
|
&mut self,
|
||||||
|
queue: &wgpu::Queue,
|
||||||
|
width: f32,
|
||||||
|
height: f32,
|
||||||
|
pressure: &PressureFrame,
|
||||||
|
hand_pressure: &[[f32; 2]],
|
||||||
|
) {
|
||||||
let aspect = width / height.max(1.0);
|
let aspect = width / height.max(1.0);
|
||||||
self.uniform = MatrixUniform::new(
|
self.uniform = MatrixUniform::new(
|
||||||
width,
|
width,
|
||||||
@@ -628,14 +649,31 @@ impl BackgroundRenderResources {
|
|||||||
bytemuck::cast_slice(&self.glyph_instances),
|
bytemuck::cast_slice(&self.glyph_instances),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Hand mode uses five UV-anchored fingertip matrices over hand.png.
|
let hand_pressure = if hand_pressure.is_empty() {
|
||||||
|
pressure.as_slice()
|
||||||
|
} else {
|
||||||
|
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.
|
||||||
// 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(
|
||||||
self.rows,
|
self.rows,
|
||||||
self.cols,
|
self.cols,
|
||||||
self.hand_image_texture.width as f32,
|
self.hand_image_texture.width as f32,
|
||||||
self.hand_image_texture.height as f32,
|
self.hand_image_texture.height as f32,
|
||||||
pressure,
|
hand_pressure,
|
||||||
);
|
);
|
||||||
queue.write_buffer(
|
queue.write_buffer(
|
||||||
&self.hand_dot_instance_buffer,
|
&self.hand_dot_instance_buffer,
|
||||||
@@ -650,7 +688,7 @@ impl BackgroundRenderResources {
|
|||||||
self.cols,
|
self.cols,
|
||||||
self.hand_image_texture.width as f32,
|
self.hand_image_texture.width as f32,
|
||||||
self.hand_image_texture.height as f32,
|
self.hand_image_texture.height as f32,
|
||||||
pressure,
|
hand_pressure,
|
||||||
);
|
);
|
||||||
queue.write_buffer(
|
queue.write_buffer(
|
||||||
&self.hand_palm_dot_instance_buffer,
|
&self.hand_palm_dot_instance_buffer,
|
||||||
@@ -1113,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.62, tip.size_px[1] * 1.56];
|
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()
|
||||||
@@ -1158,23 +1220,27 @@ fn build_hand_dot_instances(
|
|||||||
cols: u32,
|
cols: u32,
|
||||||
image_width: f32,
|
image_width: f32,
|
||||||
image_height: f32,
|
image_height: f32,
|
||||||
pressure: &PressureFrame,
|
pressure: &[[f32; 2]],
|
||||||
) -> Vec<GlyphInstance> {
|
) -> Vec<GlyphInstance> {
|
||||||
let mut instances = Vec::with_capacity(HAND_TIP_MATRICES.len() * rows as usize * cols as usize);
|
let mut instances = Vec::with_capacity(HAND_TIP_MATRICES.len() * rows as usize * cols as usize);
|
||||||
|
|
||||||
for tip in HAND_TIP_MATRICES {
|
for (tip_index, tip) in HAND_TIP_MATRICES.into_iter().enumerate() {
|
||||||
let cos = tip.angle_rad.cos();
|
let cos = tip.angle_rad.cos();
|
||||||
let sin = tip.angle_rad.sin();
|
let sin = tip.angle_rad.sin();
|
||||||
|
|
||||||
for row in 0..rows {
|
for row in 0..rows {
|
||||||
for col in 0..cols {
|
for col in 0..cols {
|
||||||
let index = (row * cols + col) as usize;
|
let index = (row * cols + col) as usize;
|
||||||
let [normalized, display_value] =
|
let [normalized, display_value] = sample_pressure_at(
|
||||||
pressure.get(index).copied().unwrap_or([0.0, 0.0]);
|
pressure,
|
||||||
|
tip_index * HAND_FINGER_SENSOR_CELLS + index,
|
||||||
|
index,
|
||||||
|
);
|
||||||
|
|
||||||
// Lay out a rows x cols matrix in fingertip-local pixel space.
|
// Lay out a rows x cols matrix in fingertip-local pixel space.
|
||||||
let local_x = (col as f32 - cols as f32 / 2.0 + 0.5) / cols as f32 * tip.size_px[0];
|
let local_x = (col as f32 - cols as f32 / 2.0 + 0.5) / cols as f32 * tip.size_px[0];
|
||||||
let local_y = (row as f32 - rows as f32 / 2.0 + 0.5) / rows as f32 * tip.size_px[1];
|
let local_y = (row as f32 - rows as f32 / 2.0 + 0.5) / rows as f32 * tip.size_px[1]
|
||||||
|
+ HAND_TIP_DOT_LOCAL_Y_OFFSET_PX;
|
||||||
|
|
||||||
// Rotate the local matrix so it follows the direction of the finger.
|
// Rotate the local matrix so it follows the direction of the finger.
|
||||||
let x = tip.center_px[0] + local_x * cos - local_y * sin;
|
let x = tip.center_px[0] + local_x * cos - local_y * sin;
|
||||||
@@ -1195,11 +1261,11 @@ 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_width: f32,
|
||||||
image_height: f32,
|
image_height: f32,
|
||||||
pressure: &PressureFrame,
|
pressure: &[[f32; 2]],
|
||||||
) -> Vec<GlyphInstance> {
|
) -> Vec<GlyphInstance> {
|
||||||
let chip_dot_count: usize = HAND_PALM_CHIPS
|
let chip_dot_count: usize = HAND_PALM_CHIPS
|
||||||
.iter()
|
.iter()
|
||||||
@@ -1207,21 +1273,21 @@ fn build_hand_palm_dot_instances(
|
|||||||
.sum();
|
.sum();
|
||||||
let mut instances = Vec::with_capacity(chip_dot_count);
|
let mut instances = Vec::with_capacity(chip_dot_count);
|
||||||
|
|
||||||
for chip in HAND_PALM_CHIPS {
|
for (chip_index, chip) in HAND_PALM_CHIPS.into_iter().enumerate() {
|
||||||
let cos = chip.angle_rad.cos();
|
let cos = chip.angle_rad.cos();
|
||||||
let sin = chip.angle_rad.sin();
|
let sin = chip.angle_rad.sin();
|
||||||
// Leave a bevel around the chip so the matrix reads as embedded pixels.
|
// Palm films can float slightly beyond the hand artwork, similar to fingertip membranes.
|
||||||
let active_size = [chip.size_px[0] * 0.72, chip.size_px[1] * 0.76];
|
let active_size = [chip.size_px[0] * 0.86, chip.size_px[1] * 0.86];
|
||||||
|
|
||||||
for row in 0..chip.rows {
|
for row in 0..chip.rows {
|
||||||
for col in 0..chip.cols {
|
for col in 0..chip.cols {
|
||||||
// Current live data is still the device pressure frame. Sample it by
|
let offset = match chip_index {
|
||||||
// proportion so the palm's 5x14 and 11x4 layouts get coherent values.
|
0 => HAND_PALM_HORIZONTAL_OFFSET,
|
||||||
let source_row = resample_index(row, chip.rows, rows);
|
_ => HAND_PALM_VERTICAL_OFFSET,
|
||||||
let source_col = resample_index(col, chip.cols, cols);
|
};
|
||||||
let index = (source_row * cols + source_col) as usize;
|
let index = hand_palm_pressure_index(chip_index, row, col, chip.rows, chip.cols);
|
||||||
let [normalized, display_value] =
|
let [normalized, display_value] =
|
||||||
pressure.get(index).copied().unwrap_or([0.0, 0.0]);
|
sample_pressure_at(pressure, offset + index, index);
|
||||||
|
|
||||||
let local_x =
|
let local_x =
|
||||||
(col as f32 - chip.cols as f32 / 2.0 + 0.5) / chip.cols as f32 * active_size[0];
|
(col as f32 - chip.cols as f32 / 2.0 + 0.5) / chip.cols as f32 * active_size[0];
|
||||||
@@ -1247,13 +1313,20 @@ fn build_hand_palm_dot_instances(
|
|||||||
instances
|
instances
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resample_index(index: u32, source_count: u32, target_count: u32) -> u32 {
|
fn hand_palm_pressure_index(chip_index: usize, row: u32, col: u32, rows: u32, cols: u32) -> usize {
|
||||||
if source_count <= 1 || target_count <= 1 {
|
if chip_index == 0 {
|
||||||
return 0;
|
(col * rows + (rows - 1 - row)) as usize
|
||||||
|
} else {
|
||||||
|
(row * cols + col) as usize
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mapped = index as f32 / (source_count - 1) as f32 * (target_count - 1) as f32;
|
fn sample_pressure_at(pressure: &[[f32; 2]], index: usize, fallback_index: usize) -> [f32; 2] {
|
||||||
mapped.round().clamp(0.0, (target_count - 1) as f32) as u32
|
pressure
|
||||||
|
.get(index)
|
||||||
|
.or_else(|| pressure.get(fallback_index))
|
||||||
|
.copied()
|
||||||
|
.unwrap_or([0.0, 0.0])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_glyph_instances(
|
fn build_glyph_instances(
|
||||||
@@ -1379,3 +1452,24 @@ impl GlyphInstance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn hand_palm_horizontal_uses_column_major_pressure_order() {
|
||||||
|
assert_eq!(hand_palm_pressure_index(0, 0, 0, 5, 14), 4);
|
||||||
|
assert_eq!(hand_palm_pressure_index(0, 1, 0, 5, 14), 3);
|
||||||
|
assert_eq!(hand_palm_pressure_index(0, 0, 1, 5, 14), 9);
|
||||||
|
assert_eq!(hand_palm_pressure_index(0, 4, 13, 5, 14), 65);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn hand_palm_vertical_keeps_row_major_pressure_order() {
|
||||||
|
assert_eq!(hand_palm_pressure_index(1, 0, 0, 11, 4), 0);
|
||||||
|
assert_eq!(hand_palm_pressure_index(1, 0, 1, 11, 4), 1);
|
||||||
|
assert_eq!(hand_palm_pressure_index(1, 1, 0, 11, 4), 4);
|
||||||
|
assert_eq!(hand_palm_pressure_index(1, 10, 3, 11, 4), 43);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -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(
|
||||||
|
|||||||
404
src/serial_core/codecs/hand_gateway.rs
Normal file
404
src/serial_core/codecs/hand_gateway.rs
Normal file
@@ -0,0 +1,404 @@
|
|||||||
|
use crate::serial_core::codec::Codec;
|
||||||
|
use crate::serial_core::error::CodecError;
|
||||||
|
use crate::serial_core::utils::{calc_crc8_itu, elapsed_millis};
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
|
const FRAME_HEADER: [u8; 2] = [0x55, 0xAA];
|
||||||
|
const RESPONSE_DATA_CMD: u8 = 0x81;
|
||||||
|
const RESPONSE_DATA_LEGACY_FIXED_LENGTH: usize = 16;
|
||||||
|
const RESPONSE_DATA_LEGACY_PREFIX_LENGTH: usize = 19;
|
||||||
|
const RESPONSE_DATA_TEMP_FIXED_LENGTH: usize = 20;
|
||||||
|
const RESPONSE_DATA_TEMP_PREFIX_LENGTH: usize = 23;
|
||||||
|
const MIN_FRAME_LENGTH: usize = 7;
|
||||||
|
const DEFAULT_MAX_FRAME_LENGTH: usize = 64 * 1024;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
struct HandGatewayResponseLayout {
|
||||||
|
fixed_length: usize,
|
||||||
|
prefix_length: usize,
|
||||||
|
timestamp_len: usize,
|
||||||
|
config_offset: usize,
|
||||||
|
valid_config_offset: usize,
|
||||||
|
block_count_offset: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
const TEMP_RESPONSE_LAYOUT: HandGatewayResponseLayout = HandGatewayResponseLayout {
|
||||||
|
fixed_length: RESPONSE_DATA_TEMP_FIXED_LENGTH,
|
||||||
|
prefix_length: RESPONSE_DATA_TEMP_PREFIX_LENGTH,
|
||||||
|
timestamp_len: 8,
|
||||||
|
config_offset: 14,
|
||||||
|
valid_config_offset: 18,
|
||||||
|
block_count_offset: 22,
|
||||||
|
};
|
||||||
|
|
||||||
|
const LEGACY_RESPONSE_LAYOUT: HandGatewayResponseLayout = HandGatewayResponseLayout {
|
||||||
|
fixed_length: RESPONSE_DATA_LEGACY_FIXED_LENGTH,
|
||||||
|
prefix_length: RESPONSE_DATA_LEGACY_PREFIX_LENGTH,
|
||||||
|
timestamp_len: 4,
|
||||||
|
config_offset: 10,
|
||||||
|
valid_config_offset: 14,
|
||||||
|
block_count_offset: 18,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct HandGatewayNodeConfig {
|
||||||
|
pub config_mask: u32,
|
||||||
|
pub sample_count: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HandGatewayNodeConfig {
|
||||||
|
pub const fn new(config_mask: u32, sample_count: usize) -> Self {
|
||||||
|
Self {
|
||||||
|
config_mask,
|
||||||
|
sample_count,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn payload_len(&self, bytes_per_sample: usize) -> Option<usize> {
|
||||||
|
self.sample_count.checked_mul(bytes_per_sample)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct HandGatewayConfig {
|
||||||
|
pub protocol_version: u8,
|
||||||
|
pub bytes_per_sample: usize,
|
||||||
|
pub max_frame_length: usize,
|
||||||
|
pub nodes: Vec<HandGatewayNodeConfig>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HandGatewayConfig {
|
||||||
|
pub fn new(nodes: Vec<HandGatewayNodeConfig>) -> Self {
|
||||||
|
Self {
|
||||||
|
protocol_version: 0x01,
|
||||||
|
bytes_per_sample: 2,
|
||||||
|
max_frame_length: DEFAULT_MAX_FRAME_LENGTH,
|
||||||
|
nodes,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn validate(&self) -> Result<(), CodecError> {
|
||||||
|
if self.bytes_per_sample == 0 || self.max_frame_length < MIN_FRAME_LENGTH {
|
||||||
|
return Err(CodecError::InvalidLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut used_masks = 0u32;
|
||||||
|
for node in &self.nodes {
|
||||||
|
if node.config_mask == 0
|
||||||
|
|| node.config_mask.count_ones() != 1
|
||||||
|
|| used_masks & node.config_mask != 0
|
||||||
|
|| node.payload_len(self.bytes_per_sample).is_none()
|
||||||
|
{
|
||||||
|
return Err(CodecError::InvalidLength);
|
||||||
|
}
|
||||||
|
used_masks |= node.config_mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct HandGatewayFrameNode {
|
||||||
|
pub config_mask: u32,
|
||||||
|
pub valid: bool,
|
||||||
|
pub payload: Vec<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct HandGatewayDataRepFrame {
|
||||||
|
pub timestamp: u64,
|
||||||
|
pub config: u32,
|
||||||
|
pub valid_config: u32,
|
||||||
|
pub block_count: u8,
|
||||||
|
pub raw: Vec<u8>,
|
||||||
|
pub nodes: Vec<HandGatewayFrameNode>,
|
||||||
|
pub dts_ms: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub enum HandGatewayFrame {
|
||||||
|
DataRep(HandGatewayDataRepFrame),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct HandGatewayCodec {
|
||||||
|
buffer: Vec<u8>,
|
||||||
|
config: HandGatewayConfig,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HandGatewayCodec {
|
||||||
|
pub fn new(node_sample_counts: &[u16]) -> Self {
|
||||||
|
let nodes = node_sample_counts
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(index, &sample_count)| {
|
||||||
|
HandGatewayNodeConfig::new(
|
||||||
|
1u32.checked_shl(index as u32).unwrap_or(0),
|
||||||
|
sample_count as usize,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
buffer: Vec::new(),
|
||||||
|
config: HandGatewayConfig::new(nodes),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_node_payload(data: &[u8]) -> Result<Vec<u16>, CodecError> {
|
||||||
|
if data.len() % 2 != 0 {
|
||||||
|
return Err(CodecError::InvalidLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(data
|
||||||
|
.chunks_exact(2)
|
||||||
|
.map(|chunk| u16::from_le_bytes([chunk[0], chunk[1]]))
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn retain_possible_header_prefix(&mut self) {
|
||||||
|
if self.buffer.last() == Some(&FRAME_HEADER[0]) {
|
||||||
|
self.buffer.drain(..self.buffer.len() - 1);
|
||||||
|
} else {
|
||||||
|
self.buffer.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_data_response_with_layout(
|
||||||
|
&self,
|
||||||
|
frame: &[u8],
|
||||||
|
length: u16,
|
||||||
|
session_started_at: Instant,
|
||||||
|
layout: HandGatewayResponseLayout,
|
||||||
|
) -> Result<HandGatewayFrame, CodecError> {
|
||||||
|
let payload_len = usize::from(length)
|
||||||
|
.checked_sub(layout.fixed_length)
|
||||||
|
.ok_or(CodecError::InvalidLength)?;
|
||||||
|
let payload_end = layout
|
||||||
|
.prefix_length
|
||||||
|
.checked_add(payload_len)
|
||||||
|
.ok_or(CodecError::PayloadTooLarge)?;
|
||||||
|
|
||||||
|
if payload_end + 1 != frame.len() {
|
||||||
|
return Err(CodecError::InvalidLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
let version = frame[5];
|
||||||
|
if version != self.config.protocol_version {
|
||||||
|
return Err(CodecError::InvalidFrameType);
|
||||||
|
}
|
||||||
|
|
||||||
|
let timestamp = match layout.timestamp_len {
|
||||||
|
4 => u32::from_le_bytes(frame[6..10].try_into().unwrap()) as u64,
|
||||||
|
8 => u64::from_le_bytes(frame[6..14].try_into().unwrap()),
|
||||||
|
_ => return Err(CodecError::InvalidLength),
|
||||||
|
};
|
||||||
|
let config = u32::from_le_bytes(
|
||||||
|
frame[layout.config_offset..layout.config_offset + 4]
|
||||||
|
.try_into()
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
let valid_config = u32::from_le_bytes(
|
||||||
|
frame[layout.valid_config_offset..layout.valid_config_offset + 4]
|
||||||
|
.try_into()
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
let block_count = frame[layout.block_count_offset];
|
||||||
|
|
||||||
|
let active_nodes = self
|
||||||
|
.config
|
||||||
|
.nodes
|
||||||
|
.iter()
|
||||||
|
.filter(|node| config & node.config_mask != 0)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
if active_nodes.len() != usize::from(block_count) {
|
||||||
|
return Err(CodecError::InvalidLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
let expected_payload_len = active_nodes.iter().try_fold(0usize, |total, node| {
|
||||||
|
let node_len = node
|
||||||
|
.payload_len(self.config.bytes_per_sample)
|
||||||
|
.ok_or(CodecError::PayloadTooLarge)?;
|
||||||
|
total
|
||||||
|
.checked_add(node_len)
|
||||||
|
.ok_or(CodecError::PayloadTooLarge)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
if expected_payload_len != payload_len {
|
||||||
|
return Err(CodecError::InvalidLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut cursor = layout.prefix_length;
|
||||||
|
let mut nodes = Vec::with_capacity(active_nodes.len());
|
||||||
|
for node in active_nodes {
|
||||||
|
let node_len = node
|
||||||
|
.payload_len(self.config.bytes_per_sample)
|
||||||
|
.ok_or(CodecError::PayloadTooLarge)?;
|
||||||
|
let next = cursor + node_len;
|
||||||
|
nodes.push(HandGatewayFrameNode {
|
||||||
|
config_mask: node.config_mask,
|
||||||
|
valid: valid_config & node.config_mask != 0,
|
||||||
|
payload: frame[cursor..next].to_vec(),
|
||||||
|
});
|
||||||
|
cursor = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(HandGatewayFrame::DataRep(HandGatewayDataRepFrame {
|
||||||
|
timestamp,
|
||||||
|
config,
|
||||||
|
valid_config,
|
||||||
|
block_count,
|
||||||
|
raw: frame.to_vec(),
|
||||||
|
nodes,
|
||||||
|
dts_ms: elapsed_millis(session_started_at),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_data_response(
|
||||||
|
&self,
|
||||||
|
frame: &[u8],
|
||||||
|
length: u16,
|
||||||
|
session_started_at: Instant,
|
||||||
|
) -> Result<HandGatewayFrame, CodecError> {
|
||||||
|
self.parse_data_response_with_layout(
|
||||||
|
frame,
|
||||||
|
length,
|
||||||
|
session_started_at,
|
||||||
|
TEMP_RESPONSE_LAYOUT,
|
||||||
|
)
|
||||||
|
.or_else(|_| {
|
||||||
|
self.parse_data_response_with_layout(
|
||||||
|
frame,
|
||||||
|
length,
|
||||||
|
session_started_at,
|
||||||
|
LEGACY_RESPONSE_LAYOUT,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Codec<HandGatewayFrame> for HandGatewayCodec {
|
||||||
|
fn decode(
|
||||||
|
&mut self,
|
||||||
|
input: &[u8],
|
||||||
|
session_started_at: Instant,
|
||||||
|
) -> Result<Vec<HandGatewayFrame>, CodecError> {
|
||||||
|
self.config.validate()?;
|
||||||
|
self.buffer.extend_from_slice(input);
|
||||||
|
let mut frames = Vec::new();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let Some(header_pos) = self
|
||||||
|
.buffer
|
||||||
|
.windows(FRAME_HEADER.len())
|
||||||
|
.position(|window| window == FRAME_HEADER)
|
||||||
|
else {
|
||||||
|
self.retain_possible_header_prefix();
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
|
||||||
|
if header_pos > 0 {
|
||||||
|
self.buffer.drain(..header_pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.buffer.len() < 4 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
let length = u16::from_le_bytes([self.buffer[2], self.buffer[3]]);
|
||||||
|
let frame_len = usize::from(length)
|
||||||
|
.checked_add(4)
|
||||||
|
.ok_or(CodecError::PayloadTooLarge)?;
|
||||||
|
|
||||||
|
if frame_len < MIN_FRAME_LENGTH || frame_len > self.config.max_frame_length {
|
||||||
|
log::debug!("invalid hand gateway frame length: {frame_len}");
|
||||||
|
self.buffer.drain(..1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.buffer.len() < frame_len {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
let expected_checksum = calc_crc8_itu(&self.buffer[..frame_len - 1]);
|
||||||
|
let received_checksum = self.buffer[frame_len - 1];
|
||||||
|
if expected_checksum != received_checksum {
|
||||||
|
log::debug!(
|
||||||
|
"hand gateway checksum mismatch: expected {expected_checksum:02X}, got {received_checksum:02X}"
|
||||||
|
);
|
||||||
|
self.buffer.drain(..1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.buffer[4] == RESPONSE_DATA_CMD {
|
||||||
|
match self.parse_data_response(
|
||||||
|
&self.buffer[..frame_len],
|
||||||
|
length,
|
||||||
|
session_started_at,
|
||||||
|
) {
|
||||||
|
Ok(frame) => frames.push(frame),
|
||||||
|
Err(error) => log::debug!("invalid hand gateway data response: {error}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.buffer.drain(..frame_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(frames)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn encode(&self, frame: &HandGatewayFrame) -> Result<Vec<u8>, CodecError> {
|
||||||
|
let _ = frame;
|
||||||
|
Err(CodecError::InvalidFrameType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn data_response(config: u32, valid_config: u32, payload: &[u8]) -> Vec<u8> {
|
||||||
|
let block_count = config.count_ones() as u8;
|
||||||
|
let length = (RESPONSE_DATA_LEGACY_FIXED_LENGTH + payload.len()) as u16;
|
||||||
|
let mut frame = Vec::new();
|
||||||
|
frame.extend_from_slice(&FRAME_HEADER);
|
||||||
|
frame.extend_from_slice(&length.to_le_bytes());
|
||||||
|
frame.push(RESPONSE_DATA_CMD);
|
||||||
|
frame.push(0x01);
|
||||||
|
frame.extend_from_slice(&0x0102_0304u32.to_le_bytes());
|
||||||
|
frame.extend_from_slice(&config.to_le_bytes());
|
||||||
|
frame.extend_from_slice(&valid_config.to_le_bytes());
|
||||||
|
frame.push(block_count);
|
||||||
|
frame.extend_from_slice(payload);
|
||||||
|
let checksum = calc_crc8_itu(&frame);
|
||||||
|
frame.push(checksum);
|
||||||
|
frame
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn decodes_data_response_frame() {
|
||||||
|
let payload = [0x10, 0x00, 0x34, 0x12, 0x08, 0x00];
|
||||||
|
let bytes = data_response(0b11, 0b01, &payload);
|
||||||
|
let frames = HandGatewayCodec::new(&[2, 1])
|
||||||
|
.decode(&bytes, Instant::now())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(frames.len(), 1);
|
||||||
|
let HandGatewayFrame::DataRep(frame) = &frames[0];
|
||||||
|
assert_eq!(frame.timestamp, 0x0102_0304);
|
||||||
|
assert_eq!(frame.config, 0b11);
|
||||||
|
assert_eq!(frame.valid_config, 0b01);
|
||||||
|
assert_eq!(frame.block_count, 2);
|
||||||
|
assert_eq!(frame.raw, bytes);
|
||||||
|
assert_eq!(frame.nodes.len(), 2);
|
||||||
|
assert_eq!(
|
||||||
|
HandGatewayCodec::parse_node_payload(&frame.nodes[0].payload).unwrap(),
|
||||||
|
vec![16, 0x1234]
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
HandGatewayCodec::parse_node_payload(&frame.nodes[1].payload).unwrap(),
|
||||||
|
vec![8]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +1,2 @@
|
|||||||
|
pub mod hand_gateway;
|
||||||
pub mod tactile_a;
|
pub mod tactile_a;
|
||||||
|
|||||||
@@ -2,5 +2,6 @@ pub mod codec;
|
|||||||
pub mod codecs;
|
pub mod codecs;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod frame;
|
pub mod frame;
|
||||||
|
pub mod multi_dim_force;
|
||||||
pub mod serial;
|
pub mod serial;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|||||||
234
src/serial_core/multi_dim_force.rs
Normal file
234
src/serial_core/multi_dim_force.rs
Normal file
@@ -0,0 +1,234 @@
|
|||||||
|
const SENSOR_ROWS: usize = 12;
|
||||||
|
const SENSOR_COLS: usize = 7;
|
||||||
|
const SENSOR_COUNT: usize = SENSOR_ROWS * SENSOR_COLS;
|
||||||
|
|
||||||
|
const TOTAL_PRESSURE_LOW_THRESHOLD: f32 = 500.0;
|
||||||
|
const COP_STABILITY_FRAMES_REQUIRED: usize = 15;
|
||||||
|
|
||||||
|
const POST_INIT_WINDOW_CNT: usize = 50;
|
||||||
|
const POST_INIT_STABLE_CNT: usize = 50;
|
||||||
|
const POST_INIT_STABLE_THRESH: f32 = 0.1;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub struct PztSpatialAnalysis {
|
||||||
|
pub angle_deg: f32,
|
||||||
|
pub magnitude: f32,
|
||||||
|
pub planar_x: f32,
|
||||||
|
pub planar_y: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct PztProcessor {
|
||||||
|
first_frame: Option<Vec<f32>>,
|
||||||
|
|
||||||
|
first_contact_cop_x: Option<f32>,
|
||||||
|
first_contact_cop_y: Option<f32>,
|
||||||
|
contact_initialized: bool,
|
||||||
|
|
||||||
|
total_pressure_low_counter: usize,
|
||||||
|
|
||||||
|
cop_init_x_buf: Vec<f32>,
|
||||||
|
cop_init_y_buf: Vec<f32>,
|
||||||
|
|
||||||
|
post_init_frame_cnt: usize,
|
||||||
|
post_stable_cnt: usize,
|
||||||
|
post_refined_flag: bool,
|
||||||
|
post_cand_x: Option<f32>,
|
||||||
|
post_cand_y: Option<f32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PztProcessor {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
first_frame: None,
|
||||||
|
first_contact_cop_x: None,
|
||||||
|
first_contact_cop_y: None,
|
||||||
|
contact_initialized: false,
|
||||||
|
total_pressure_low_counter: 0,
|
||||||
|
cop_init_x_buf: Vec::with_capacity(COP_STABILITY_FRAMES_REQUIRED),
|
||||||
|
cop_init_y_buf: Vec::with_capacity(COP_STABILITY_FRAMES_REQUIRED),
|
||||||
|
post_init_frame_cnt: 0,
|
||||||
|
post_stable_cnt: 0,
|
||||||
|
post_refined_flag: false,
|
||||||
|
post_cand_x: None,
|
||||||
|
post_cand_y: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn subtract_baseline(&mut self, current_frame: &[f32]) -> Vec<f32> {
|
||||||
|
if self.first_frame.is_none() {
|
||||||
|
self.first_frame = Some(current_frame.to_vec());
|
||||||
|
}
|
||||||
|
|
||||||
|
let baseline = self.first_frame.as_ref().unwrap();
|
||||||
|
current_frame
|
||||||
|
.iter()
|
||||||
|
.zip(baseline.iter())
|
||||||
|
.map(|(current, baseline)| (current - baseline).max(0.0))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reset_cop_state(&mut self) {
|
||||||
|
self.first_contact_cop_x = None;
|
||||||
|
self.first_contact_cop_y = None;
|
||||||
|
self.contact_initialized = false;
|
||||||
|
self.total_pressure_low_counter = 0;
|
||||||
|
self.cop_init_x_buf.clear();
|
||||||
|
self.cop_init_y_buf.clear();
|
||||||
|
self.post_init_frame_cnt = 0;
|
||||||
|
self.post_stable_cnt = 0;
|
||||||
|
self.post_refined_flag = false;
|
||||||
|
self.post_cand_x = None;
|
||||||
|
self.post_cand_y = None;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn compute_median(sorted: &[f32]) -> f32 {
|
||||||
|
let n = sorted.len();
|
||||||
|
if n == 0 {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if n % 2 == 0 {
|
||||||
|
(sorted[n / 2 - 1] + sorted[n / 2]) / 2.0
|
||||||
|
} else {
|
||||||
|
sorted[n / 2]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn compute_pressure_direction(&mut self, frame: &[f32]) -> (f32, f32) {
|
||||||
|
let total_pressure = frame.iter().sum::<f32>();
|
||||||
|
if total_pressure < TOTAL_PRESSURE_LOW_THRESHOLD {
|
||||||
|
self.total_pressure_low_counter += 1;
|
||||||
|
} else {
|
||||||
|
self.total_pressure_low_counter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.total_pressure_low_counter >= COP_STABILITY_FRAMES_REQUIRED {
|
||||||
|
self.reset_cop_state();
|
||||||
|
return (0.0, 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if total_pressure == 0.0 {
|
||||||
|
return (0.0, 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut sum_x = 0.0;
|
||||||
|
let mut sum_y = 0.0;
|
||||||
|
for row in 0..SENSOR_ROWS {
|
||||||
|
for col in 0..SENSOR_COLS {
|
||||||
|
let value = frame[row * SENSOR_COLS + col];
|
||||||
|
sum_x += value * col as f32;
|
||||||
|
sum_y += value * row as f32;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let cop_x = sum_x / total_pressure;
|
||||||
|
let cop_y = sum_y / total_pressure;
|
||||||
|
|
||||||
|
if !self.contact_initialized {
|
||||||
|
self.cop_init_x_buf.push(cop_x);
|
||||||
|
self.cop_init_y_buf.push(cop_y);
|
||||||
|
|
||||||
|
if self.cop_init_x_buf.len() >= COP_STABILITY_FRAMES_REQUIRED {
|
||||||
|
let mut xs = self.cop_init_x_buf.clone();
|
||||||
|
xs.sort_by(|a, b| a.partial_cmp(b).unwrap());
|
||||||
|
let mut ys = self.cop_init_y_buf.clone();
|
||||||
|
ys.sort_by(|a, b| a.partial_cmp(b).unwrap());
|
||||||
|
|
||||||
|
self.first_contact_cop_x = Some(Self::compute_median(&xs));
|
||||||
|
self.first_contact_cop_y = Some(Self::compute_median(&ys));
|
||||||
|
self.contact_initialized = true;
|
||||||
|
self.cop_init_x_buf.clear();
|
||||||
|
self.cop_init_y_buf.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0.0, 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.post_init_frame_cnt += 1;
|
||||||
|
if !self.post_refined_flag && self.post_init_frame_cnt <= POST_INIT_WINDOW_CNT {
|
||||||
|
if let (Some(cx), Some(cy)) = (self.post_cand_x, self.post_cand_y) {
|
||||||
|
let dist = ((cop_x - cx).powi(2) + (cop_y - cy).powi(2)).sqrt();
|
||||||
|
if dist <= POST_INIT_STABLE_THRESH {
|
||||||
|
self.post_stable_cnt += 1;
|
||||||
|
} else {
|
||||||
|
self.post_cand_x = Some(cop_x);
|
||||||
|
self.post_cand_y = Some(cop_y);
|
||||||
|
self.post_stable_cnt = 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.post_cand_x = Some(cop_x);
|
||||||
|
self.post_cand_y = Some(cop_y);
|
||||||
|
self.post_stable_cnt = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.post_stable_cnt >= POST_INIT_STABLE_CNT {
|
||||||
|
self.first_contact_cop_x = self.post_cand_x;
|
||||||
|
self.first_contact_cop_y = self.post_cand_y;
|
||||||
|
self.post_refined_flag = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.post_refined_flag = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
let base_x = self.first_contact_cop_x.unwrap_or(cop_x);
|
||||||
|
let base_y = self.first_contact_cop_y.unwrap_or(cop_y);
|
||||||
|
let delta_x = cop_x - base_x;
|
||||||
|
let delta_y = base_y - cop_y;
|
||||||
|
(delta_x, delta_y)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn compute_vector_angle(x: f32, y: f32) -> (f32, f32) {
|
||||||
|
let epsilon = 1e-8f32;
|
||||||
|
let magnitude = (x * x + y * y).sqrt();
|
||||||
|
let mut angle = y.atan2(x + epsilon).to_degrees();
|
||||||
|
if angle < 0.0 {
|
||||||
|
angle += 360.0;
|
||||||
|
}
|
||||||
|
(angle, magnitude)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_pzt_analysis(
|
||||||
|
&mut self,
|
||||||
|
adc_data: &[f32],
|
||||||
|
) -> Result<PztSpatialAnalysis, &'static str> {
|
||||||
|
if adc_data.len() != SENSOR_COUNT {
|
||||||
|
return Err("ADC data length must be 84");
|
||||||
|
}
|
||||||
|
|
||||||
|
let baseline = self.subtract_baseline(adc_data);
|
||||||
|
let (dx, dy) = self.compute_pressure_direction(&baseline);
|
||||||
|
|
||||||
|
let planar_x = dx;
|
||||||
|
let planar_y = -dy;
|
||||||
|
let (angle_deg, magnitude) = Self::compute_vector_angle(planar_x, planar_y);
|
||||||
|
|
||||||
|
Ok(PztSpatialAnalysis {
|
||||||
|
angle_deg,
|
||||||
|
magnitude,
|
||||||
|
planar_x,
|
||||||
|
planar_y,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_pzt_angle(&mut self, adc_data: &[f32]) -> Result<f32, &'static str> {
|
||||||
|
Ok(self.get_pzt_analysis(adc_data)?.angle_deg)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reset_baseline(&mut self) {
|
||||||
|
self.first_frame = None;
|
||||||
|
self.reset_cop_state();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn idle_frame_returns_zero() {
|
||||||
|
let mut processor = PztProcessor::new();
|
||||||
|
let frame = [0.0f32; SENSOR_COUNT];
|
||||||
|
let analysis = processor.get_pzt_analysis(&frame).unwrap();
|
||||||
|
assert_eq!(analysis.magnitude, 0.0);
|
||||||
|
assert_eq!(analysis.angle_deg, 0.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,26 @@
|
|||||||
|
use crate::recording::Recorder;
|
||||||
use crate::serial_core::codec::Codec;
|
use crate::serial_core::codec::Codec;
|
||||||
|
use crate::serial_core::codecs::hand_gateway::{HandGatewayCodec, HandGatewayFrame};
|
||||||
use crate::serial_core::codecs::tactile_a::TactileACodec;
|
use crate::serial_core::codecs::tactile_a::TactileACodec;
|
||||||
use crate::serial_core::frame::TactileAFrame;
|
use crate::serial_core::frame::TactileAFrame;
|
||||||
use crossbeam_channel::{Receiver, Sender};
|
use crossbeam_channel::{Receiver, Sender};
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
const POLL_INTERVAL_MS: u64 = 10;
|
const POLL_INTERVAL_MS: u64 = 5;
|
||||||
|
const DEFAULT_HAND_GATEWAY_NODE_SAMPLE_COUNTS: &[u16] = &[84, 84, 84, 84, 84, 70, 44];
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct SerialIoStats {
|
pub struct SerialIoStats {
|
||||||
pub rx_bytes: u64,
|
pub rx_bytes: u64,
|
||||||
pub tx_bytes: u64,
|
pub tx_bytes: u64,
|
||||||
|
pub rx_frames: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum SerialProtocol {
|
||||||
|
TactileA,
|
||||||
|
HandGateway,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs the serial polling loop on the calling (background) thread.
|
/// Runs the serial polling loop on the calling (background) thread.
|
||||||
@@ -19,9 +29,30 @@ pub fn run_serial_loop(
|
|||||||
port: &mut dyn ReadWrite,
|
port: &mut dyn ReadWrite,
|
||||||
rows: usize,
|
rows: usize,
|
||||||
cols: usize,
|
cols: usize,
|
||||||
|
protocol: SerialProtocol,
|
||||||
cancel_rx: &Receiver<()>,
|
cancel_rx: &Receiver<()>,
|
||||||
sample_tx: &Sender<Vec<i32>>,
|
sample_tx: &Sender<Vec<i32>>,
|
||||||
stats_tx: Option<&Sender<SerialIoStats>>,
|
stats_tx: Option<&Sender<SerialIoStats>>,
|
||||||
|
recorder: Option<&Recorder>,
|
||||||
|
) {
|
||||||
|
match protocol {
|
||||||
|
SerialProtocol::TactileA => {
|
||||||
|
run_tactile_a_loop(port, rows, cols, cancel_rx, sample_tx, stats_tx, recorder)
|
||||||
|
}
|
||||||
|
SerialProtocol::HandGateway => {
|
||||||
|
run_hand_gateway_loop(port, cancel_rx, sample_tx, stats_tx, recorder)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_tactile_a_loop(
|
||||||
|
port: &mut dyn ReadWrite,
|
||||||
|
rows: usize,
|
||||||
|
cols: usize,
|
||||||
|
cancel_rx: &Receiver<()>,
|
||||||
|
sample_tx: &Sender<Vec<i32>>,
|
||||||
|
stats_tx: Option<&Sender<SerialIoStats>>,
|
||||||
|
recorder: Option<&Recorder>,
|
||||||
) {
|
) {
|
||||||
let session_started_at = Instant::now();
|
let session_started_at = Instant::now();
|
||||||
let mut codec = TactileACodec::new(cols, rows);
|
let mut codec = TactileACodec::new(cols, rows);
|
||||||
@@ -65,7 +96,14 @@ pub fn run_serial_loop(
|
|||||||
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) {
|
if let Ok(vals) = TactileACodec::parse_data_frame(&rep.payload) {
|
||||||
|
if let Some(recorder) = recorder {
|
||||||
|
let pressures: Vec<u32> =
|
||||||
|
vals.iter().map(|v| (*v).max(0) as u32).collect();
|
||||||
|
recorder.add_frame(&pressures);
|
||||||
|
}
|
||||||
let _ = sample_tx.try_send(vals);
|
let _ = sample_tx.try_send(vals);
|
||||||
|
io_stats.rx_frames += 1;
|
||||||
|
publish_stats(stats_tx, io_stats);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,6 +124,105 @@ pub fn run_serial_loop(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn run_hand_gateway_loop(
|
||||||
|
port: &mut dyn ReadWrite,
|
||||||
|
cancel_rx: &Receiver<()>,
|
||||||
|
sample_tx: &Sender<Vec<i32>>,
|
||||||
|
stats_tx: Option<&Sender<SerialIoStats>>,
|
||||||
|
recorder: Option<&Recorder>,
|
||||||
|
) {
|
||||||
|
let session_started_at = Instant::now();
|
||||||
|
let mut codec = HandGatewayCodec::new(DEFAULT_HAND_GATEWAY_NODE_SAMPLE_COUNTS);
|
||||||
|
let mut buffer = [0u8; 1024];
|
||||||
|
let poll_interval = Duration::from_millis(POLL_INTERVAL_MS);
|
||||||
|
let mut io_stats = SerialIoStats::default();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
if cancel_rx.try_recv().is_ok() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
let deadline = Instant::now() + poll_interval;
|
||||||
|
loop {
|
||||||
|
if Instant::now() >= deadline {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
match port.read(&mut buffer) {
|
||||||
|
Ok(n) if n > 0 => {
|
||||||
|
io_stats.rx_bytes += n as u64;
|
||||||
|
publish_stats(stats_tx, io_stats);
|
||||||
|
if let Ok(frames) = codec.decode(&buffer[..n], session_started_at) {
|
||||||
|
for frame in frames {
|
||||||
|
let HandGatewayFrame::DataRep(rep) = frame;
|
||||||
|
// println!(
|
||||||
|
// "[hand-packet-raw] bytes={} timestamp_us={} config=0x{:08X} valid_config=0x{:08X} block_count={} payload_bytes={} raw={}",
|
||||||
|
// rep.raw.len(),
|
||||||
|
// rep.timestamp,
|
||||||
|
// rep.config,
|
||||||
|
// rep.valid_config,
|
||||||
|
// rep.block_count,
|
||||||
|
// rep.nodes
|
||||||
|
// .iter()
|
||||||
|
// .map(|node| node.payload.len())
|
||||||
|
// .sum::<usize>(),
|
||||||
|
// format_hex_bytes(&rep.raw)
|
||||||
|
// );
|
||||||
|
let mut vals = Vec::new();
|
||||||
|
let mut parse_ok = true;
|
||||||
|
for node in &rep.nodes {
|
||||||
|
match HandGatewayCodec::parse_node_payload(&node.payload) {
|
||||||
|
Ok(node_values) => {
|
||||||
|
vals.extend(node_values.into_iter().map(|raw| {
|
||||||
|
let raw = raw as i32;
|
||||||
|
if raw < 15 { 0 } else { raw }
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
parse_ok = false;
|
||||||
|
eprintln!("[hand-packet-values] parse error: {err}");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if parse_ok {
|
||||||
|
// println!("[hand-packet-values] samples={}", vals.len());
|
||||||
|
if let Some(recorder) = recorder {
|
||||||
|
let pressures: Vec<u32> =
|
||||||
|
vals.iter().map(|v| (*v).max(0) as u32).collect();
|
||||||
|
recorder.add_frame(&pressures);
|
||||||
|
}
|
||||||
|
let _ = sample_tx.try_send(vals);
|
||||||
|
io_stats.rx_frames += 1;
|
||||||
|
publish_stats(stats_tx, io_stats);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(_) => {
|
||||||
|
std::thread::sleep(Duration::from_millis(1));
|
||||||
|
}
|
||||||
|
Err(ref e) if e.kind() == std::io::ErrorKind::TimedOut => {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("[serial] hand gateway read error: {e}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn format_hex_bytes(bytes: &[u8]) -> String {
|
||||||
|
bytes
|
||||||
|
.iter()
|
||||||
|
.map(|byte| format!("{byte:02X}"))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(" ")
|
||||||
|
}
|
||||||
|
|
||||||
fn publish_stats(stats_tx: Option<&Sender<SerialIoStats>>, stats: SerialIoStats) {
|
fn publish_stats(stats_tx: Option<&Sender<SerialIoStats>>, stats: SerialIoStats) {
|
||||||
if let Some(tx) = stats_tx {
|
if let Some(tx) = stats_tx {
|
||||||
let _ = tx.try_send(stats);
|
let _ = tx.try_send(stats);
|
||||||
|
|||||||
@@ -26,13 +26,17 @@ pub fn calc_crc8_itu(c: &[u8]) -> u8 {
|
|||||||
crc8_itu_alg.checksum(c)
|
crc8_itu_alg.checksum(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn calc_crc8_itu_xor55(c: &[u8]) -> u8 {
|
||||||
|
calc_crc8_itu(c) ^ 0x55
|
||||||
|
}
|
||||||
|
|
||||||
pub fn elapsed_millis(start_at: Instant) -> u64 {
|
pub fn elapsed_millis(start_at: Instant) -> u64 {
|
||||||
start_at.elapsed().as_millis() as u64
|
start_at.elapsed().as_millis() as u64
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::serial_core::utils::{calc_crc8_itu, calc_crc8_smbus};
|
use crate::serial_core::utils::{calc_crc8_itu, calc_crc8_itu_xor55, calc_crc8_smbus};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crc8_itu() {
|
fn test_crc8_itu() {
|
||||||
@@ -51,4 +55,10 @@ mod test {
|
|||||||
let checksum = calc_crc8_smbus(req_vec.as_slice());
|
let checksum = calc_crc8_smbus(req_vec.as_slice());
|
||||||
assert_eq!(checksum, 0x2F);
|
assert_eq!(checksum, 0x2F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_crc8_itu_xor55() {
|
||||||
|
let req_vec = vec![0x55, 0xAA, 0x07, 0x00, 0x01, 0x01, 0xFF, 0xFF, 0xFF, 0xFF];
|
||||||
|
assert_eq!(calc_crc8_itu_xor55(req_vec.as_slice()), 0xFD);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
18
src/style.rs
18
src/style.rs
@@ -1,4 +1,4 @@
|
|||||||
use eframe::egui;
|
use eframe::egui::{self, Color32};
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct AppTheme {
|
pub struct AppTheme {
|
||||||
@@ -29,7 +29,7 @@ pub struct DesignMetrics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub const ONE_DARK_PRO: AppTheme = AppTheme {
|
pub const ONE_DARK_PRO: AppTheme = AppTheme {
|
||||||
bg: egui::Color32::from_rgb(30, 40, 50),
|
bg: egui::Color32::BLACK,
|
||||||
panel: egui::Color32::from_rgb(22, 28, 35),
|
panel: egui::Color32::from_rgb(22, 28, 35),
|
||||||
panel_strong: egui::Color32::from_rgb(34, 43, 54),
|
panel_strong: egui::Color32::from_rgb(34, 43, 54),
|
||||||
panel_deep: egui::Color32::from_rgb(15, 20, 27),
|
panel_deep: egui::Color32::from_rgb(15, 20, 27),
|
||||||
@@ -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 = 38.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;
|
||||||
@@ -213,6 +214,19 @@ pub fn tag_button(label: impl Into<egui::WidgetText>) -> egui::Button<'static> {
|
|||||||
.min_size(egui::vec2(0.0, METRICS.button_height))
|
.min_size(egui::vec2(0.0, METRICS.button_height))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn rich_tag_button(
|
||||||
|
label: impl Into<String>,
|
||||||
|
color: impl Into<Color32>,
|
||||||
|
) -> egui::Button<'static> {
|
||||||
|
let text = egui::RichText::new(label.into()).color(color);
|
||||||
|
|
||||||
|
egui::Button::new(text)
|
||||||
|
.fill(ONE_DARK_PRO.panel_strong)
|
||||||
|
.stroke(egui::Stroke::new(1.0, ONE_DARK_PRO.border))
|
||||||
|
.corner_radius(egui::CornerRadius::same(4))
|
||||||
|
.min_size(egui::vec2(0.0, METRICS.button_height))
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ fn linear_to_srgb(linear: vec3f) -> vec3f {
|
|||||||
|
|
||||||
fn output_color(linear_rgb: vec3f, alpha: f32) -> vec4f {
|
fn output_color(linear_rgb: vec3f, alpha: f32) -> vec4f {
|
||||||
let clamped = clamp(linear_rgb, vec3f(0.0), vec3f(1.0));
|
let clamped = clamp(linear_rgb, vec3f(0.0), vec3f(1.0));
|
||||||
if (u.color.w > 0.5) {
|
if u.color.w > 0.5 {
|
||||||
return vec4f(clamped, alpha);
|
return vec4f(clamped, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,21 +91,20 @@ fn range_stop_color(index: u32) -> vec3f {
|
|||||||
fn sample_range_color(value: f32) -> vec3f {
|
fn sample_range_color(value: f32) -> vec3f {
|
||||||
let t = saturate(value);
|
let t = saturate(value);
|
||||||
|
|
||||||
if (t <= 0.33) {
|
if t <= 0.33 {
|
||||||
let local = smoothstep(0.0, 0.33, t);
|
let local = smoothstep(0.0, 0.33, t);
|
||||||
return mix(range_stop_color(0u), range_stop_color(1u), local);
|
return mix(range_stop_color(0u), range_stop_color(1u), local);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t <= 0.66) {
|
if t <= 0.66 {
|
||||||
let local = smoothstep(0.33, 0.66, t);
|
let local = smoothstep(0.33, 0.66, t);
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// background
|
// background
|
||||||
struct BackgroundVertexOutput {
|
struct BackgroundVertexOutput {
|
||||||
@builtin(position) clip_position: vec4f,
|
@builtin(position) clip_position: vec4f,
|
||||||
@@ -126,18 +125,9 @@ fn vs_background(@builtin(vertex_index) vertex_index: u32) -> BackgroundVertexOu
|
|||||||
|
|
||||||
@fragment
|
@fragment
|
||||||
fn fs_background(@builtin(position) frag_coord: vec4f) -> @location(0) vec4f {
|
fn fs_background(@builtin(position) frag_coord: vec4f) -> @location(0) vec4f {
|
||||||
let pixel = frag_coord.xy;
|
return output_color(vec3f(0.0, 0.0, 0.0), 1.0);
|
||||||
let viewport = u.viewport.xy;
|
|
||||||
let uv = pixel / max(viewport, vec2f(1.0, 1.0));
|
|
||||||
var color = mix(vec3f(0.018, 0.019, 0.022), vec3f(0.038, 0.040, 0.046), 1.0 - uv.y);
|
|
||||||
let vignette = smoothstep(0.18, 0.92, length((uv - vec2f(0.52, 0.48)) * vec2f(viewport.x / viewport.y, 1.0)));
|
|
||||||
color *= 1.0 - vignette * 0.22;
|
|
||||||
color += vec3f(0.010, 0.010, 0.012) * (1.0 - smoothstep(0.0, 0.85, abs(uv.y - 0.50)));
|
|
||||||
|
|
||||||
return output_color(color, 1.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// hand image background
|
// hand image background
|
||||||
struct HandImageVertexOutput {
|
struct HandImageVertexOutput {
|
||||||
@builtin(position) clip_position: vec4f,
|
@builtin(position) clip_position: vec4f,
|
||||||
@@ -175,7 +165,7 @@ fn fs_hand_image(in: HandImageVertexOutput) -> @location(0) vec4f {
|
|||||||
let image_aspect = u.image.x / max(u.image.y, 1.0);
|
let image_aspect = u.image.x / max(u.image.y, 1.0);
|
||||||
|
|
||||||
var uv = in.screen_uv;
|
var uv = in.screen_uv;
|
||||||
if (viewport_aspect > image_aspect) {
|
if viewport_aspect > image_aspect {
|
||||||
let image_width = image_aspect / viewport_aspect;
|
let image_width = image_aspect / viewport_aspect;
|
||||||
uv.x = (uv.x - (1.0 - image_width) * 0.5) / image_width;
|
uv.x = (uv.x - (1.0 - image_width) * 0.5) / image_width;
|
||||||
} else {
|
} else {
|
||||||
@@ -183,7 +173,7 @@ fn fs_hand_image(in: HandImageVertexOutput) -> @location(0) vec4f {
|
|||||||
uv.y = (uv.y - (1.0 - image_height) * 0.5) / image_height;
|
uv.y = (uv.y - (1.0 - image_height) * 0.5) / image_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) {
|
if uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0 {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +181,6 @@ fn fs_hand_image(in: HandImageVertexOutput) -> @location(0) vec4f {
|
|||||||
return output_color(color.rgb, color.a);
|
return output_color(color.rgb, color.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// glyph
|
// glyph
|
||||||
struct GlyphVertexInput {
|
struct GlyphVertexInput {
|
||||||
@location(0) local: vec2f,
|
@location(0) local: vec2f,
|
||||||
@@ -234,45 +223,45 @@ fn digit_segment_on(digit: u32, segment: u32) -> bool {
|
|||||||
|
|
||||||
fn seven_segment_digit_alpha(local: vec2f, digit: u32) -> f32 {
|
fn seven_segment_digit_alpha(local: vec2f, digit: u32) -> f32 {
|
||||||
var alpha = 0.0;
|
var alpha = 0.0;
|
||||||
if (digit_segment_on(digit, 0u)) {
|
if digit_segment_on(digit, 0u) {
|
||||||
alpha = max(alpha, rect_alpha(local, vec2f(0.0, 0.70), vec2f(0.38, 0.078)));
|
alpha = max(alpha, rect_alpha(local, vec2f(0.0, 0.70), vec2f(0.38, 0.078)));
|
||||||
}
|
}
|
||||||
if (digit_segment_on(digit, 1u)) {
|
if digit_segment_on(digit, 1u) {
|
||||||
alpha = max(alpha, rect_alpha(local, vec2f(0.39, 0.36), vec2f(0.078, 0.335)));
|
alpha = max(alpha, rect_alpha(local, vec2f(0.39, 0.36), vec2f(0.078, 0.335)));
|
||||||
}
|
}
|
||||||
if (digit_segment_on(digit, 2u)) {
|
if digit_segment_on(digit, 2u) {
|
||||||
alpha = max(alpha, rect_alpha(local, vec2f(0.39, -0.36), vec2f(0.078, 0.335)));
|
alpha = max(alpha, rect_alpha(local, vec2f(0.39, -0.36), vec2f(0.078, 0.335)));
|
||||||
}
|
}
|
||||||
if (digit_segment_on(digit, 3u)) {
|
if digit_segment_on(digit, 3u) {
|
||||||
alpha = max(alpha, rect_alpha(local, vec2f(0.0, -0.70), vec2f(0.38, 0.078)));
|
alpha = max(alpha, rect_alpha(local, vec2f(0.0, -0.70), vec2f(0.38, 0.078)));
|
||||||
}
|
}
|
||||||
if (digit_segment_on(digit, 4u)) {
|
if digit_segment_on(digit, 4u) {
|
||||||
alpha = max(alpha, rect_alpha(local, vec2f(-0.39, -0.36), vec2f(0.078, 0.335)));
|
alpha = max(alpha, rect_alpha(local, vec2f(-0.39, -0.36), vec2f(0.078, 0.335)));
|
||||||
}
|
}
|
||||||
if (digit_segment_on(digit, 5u)) {
|
if digit_segment_on(digit, 5u) {
|
||||||
alpha = max(alpha, rect_alpha(local, vec2f(-0.39, 0.36), vec2f(0.078, 0.335)));
|
alpha = max(alpha, rect_alpha(local, vec2f(-0.39, 0.36), vec2f(0.078, 0.335)));
|
||||||
}
|
}
|
||||||
if (digit_segment_on(digit, 6u)) {
|
if digit_segment_on(digit, 6u) {
|
||||||
alpha = max(alpha, rect_alpha(local, vec2f(0.0, 0.0), vec2f(0.35, 0.075)));
|
alpha = max(alpha, rect_alpha(local, vec2f(0.0, 0.0), vec2f(0.35, 0.075)));
|
||||||
}
|
}
|
||||||
return alpha;
|
return alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn digit_count(value: u32) -> u32 {
|
fn digit_count(value: u32) -> u32 {
|
||||||
if (value >= 1000u) {
|
if value >= 1000u {
|
||||||
return 4u;
|
return 4u;
|
||||||
}
|
}
|
||||||
if (value >= 100u) {
|
if value >= 100u {
|
||||||
return 3u;
|
return 3u;
|
||||||
}
|
}
|
||||||
if (value >= 10u) {
|
if value >= 10u {
|
||||||
return 2u;
|
return 2u;
|
||||||
}
|
}
|
||||||
return 1u;
|
return 1u;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn digit_at(value: u32, slot: u32, count: u32) -> u32 {
|
fn digit_at(value: u32, slot: u32, count: u32) -> u32 {
|
||||||
if (count == 4u) {
|
if count == 4u {
|
||||||
switch slot {
|
switch slot {
|
||||||
case 0u: { return (value / 1000u) % 10u; }
|
case 0u: { return (value / 1000u) % 10u; }
|
||||||
case 1u: { return (value / 100u) % 10u; }
|
case 1u: { return (value / 100u) % 10u; }
|
||||||
@@ -280,14 +269,14 @@ fn digit_at(value: u32, slot: u32, count: u32) -> u32 {
|
|||||||
default: { return value % 10u; }
|
default: { return value % 10u; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count == 3u) {
|
if count == 3u {
|
||||||
switch slot {
|
switch slot {
|
||||||
case 0u: { return (value / 100u) % 10u; }
|
case 0u: { return (value / 100u) % 10u; }
|
||||||
case 1u: { return (value / 10u) % 10u; }
|
case 1u: { return (value / 10u) % 10u; }
|
||||||
default: { return value % 10u; }
|
default: { return value % 10u; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count == 2u) {
|
if count == 2u {
|
||||||
return select(value % 10u, (value / 10u) % 10u, slot == 0u);
|
return select(value % 10u, (value / 10u) % 10u, slot == 0u);
|
||||||
}
|
}
|
||||||
return value % 10u;
|
return value % 10u;
|
||||||
@@ -302,7 +291,7 @@ fn number_alpha(local: vec2f, display_value: f32) -> f32 {
|
|||||||
var alpha = 0.0;
|
var alpha = 0.0;
|
||||||
|
|
||||||
for (var slot = 0u; slot < 4u; slot = slot + 1u) {
|
for (var slot = 0u; slot < 4u; slot = slot + 1u) {
|
||||||
if (slot < count) {
|
if slot < count {
|
||||||
let center_x = start_x + f32(slot) * slot_width;
|
let center_x = start_x + f32(slot) * slot_width;
|
||||||
let digit_local = vec2f((local.x - center_x) / (slot_width * 0.78), local.y / 0.92);
|
let digit_local = vec2f((local.x - center_x) / (slot_width * 0.78), local.y / 0.92);
|
||||||
let digit = digit_at(value, slot, count);
|
let digit = digit_at(value, slot, count);
|
||||||
@@ -343,8 +332,7 @@ struct DotVertexInput {
|
|||||||
|
|
||||||
struct DotInstanceInput {
|
struct DotInstanceInput {
|
||||||
@location(1) world_position: vec4f,
|
@location(1) world_position: vec4f,
|
||||||
@location(2) style: vec4f
|
@location(2) style: vec4f}
|
||||||
}
|
|
||||||
|
|
||||||
struct DotVertexOutput {
|
struct DotVertexOutput {
|
||||||
@builtin(position) clip_position: vec4f,
|
@builtin(position) clip_position: vec4f,
|
||||||
@@ -366,7 +354,7 @@ fn hand_image_uv_to_clip(image_uv: vec2f) -> vec2f {
|
|||||||
|
|
||||||
var screen_uv = image_uv;
|
var screen_uv = image_uv;
|
||||||
|
|
||||||
if (viewport_aspect > image_aspect) {
|
if viewport_aspect > image_aspect {
|
||||||
let image_width = image_aspect / viewport_aspect;
|
let image_width = image_aspect / viewport_aspect;
|
||||||
screen_uv.x = image_uv.x * image_width + (1.0 - image_width) * 0.5;
|
screen_uv.x = image_uv.x * image_width + (1.0 - image_width) * 0.5;
|
||||||
} else {
|
} else {
|
||||||
@@ -380,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 {
|
||||||
@@ -394,12 +383,15 @@ fn rounded_rect_alpha(local: vec2f, radius: f32, softness: f32) -> f32 {
|
|||||||
return 1.0 - smoothstep(0.0, softness, dist);
|
return 1.0 - smoothstep(0.0, softness, dist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn dot_matrix(uv: vec2f, grid: vec2f, dot_radius: f32, dot_softness: f32) -> f32 {
|
||||||
|
let cell = fract(uv * grid) - vec2f(0.5, 0.5);
|
||||||
|
return 1.0 - smoothstep(dot_radius, dot_radius + dot_softness, length(cell));
|
||||||
|
}
|
||||||
|
|
||||||
fn fingertip_film_alpha(
|
fn fingertip_film_alpha(
|
||||||
local: vec2f,
|
local: vec2f,
|
||||||
half_width: f32,
|
half_width: f32,
|
||||||
cap_center_y: f32,
|
cap_center_y: f32,
|
||||||
rear_edge_y: f32,
|
|
||||||
rear_bulge: f32,
|
|
||||||
softness: f32,
|
softness: f32,
|
||||||
) -> f32 {
|
) -> f32 {
|
||||||
// Top/front of the film is a closed round fingertip cap.
|
// Top/front of the film is a closed round fingertip cap.
|
||||||
@@ -407,14 +399,10 @@ fn fingertip_film_alpha(
|
|||||||
let cap = (1.0 - smoothstep(half_width, half_width + softness, cap_dist))
|
let cap = (1.0 - smoothstep(half_width, half_width + softness, cap_dist))
|
||||||
* (1.0 - smoothstep(cap_center_y - softness, cap_center_y + softness, local.y));
|
* (1.0 - smoothstep(cap_center_y - softness, cap_center_y + softness, local.y));
|
||||||
|
|
||||||
// The rear half keeps nearly parallel sides and ends with a shallow arc;
|
// The rear remains open; the carrier quad clips the membrane at its end.
|
||||||
// it deliberately does not converge back into another capsule end.
|
|
||||||
let x_norm = clamp(abs(local.x) / max(half_width, 0.001), 0.0, 1.0);
|
|
||||||
let rear_curve_y = rear_edge_y + rear_bulge * (1.0 - x_norm * x_norm);
|
|
||||||
let side = 1.0 - smoothstep(half_width, half_width + softness, abs(local.x));
|
let side = 1.0 - smoothstep(half_width, half_width + softness, abs(local.x));
|
||||||
let rear = 1.0 - smoothstep(rear_curve_y, rear_curve_y + softness, local.y);
|
|
||||||
let body_gate = smoothstep(cap_center_y - softness, cap_center_y + softness, local.y);
|
let body_gate = smoothstep(cap_center_y - softness, cap_center_y + softness, local.y);
|
||||||
let body = side * rear * body_gate;
|
let body = side * body_gate;
|
||||||
|
|
||||||
return max(cap, body);
|
return max(cap, body);
|
||||||
}
|
}
|
||||||
@@ -430,45 +418,110 @@ 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 {
|
||||||
// The film shape matches the fingertip: closed round front, parallel rear sides,
|
let p = in.local;
|
||||||
// and a shallow rear arc instead of a second capsule end.
|
let live = saturate(in.intensity);
|
||||||
let panel = fingertip_film_alpha(in.local, 0.66, -0.38, 0.72, 0.18, 0.045);
|
let response = smoothstep(0.03, 0.96, live);
|
||||||
let inner = fingertip_film_alpha(in.local, 0.54, -0.36, 0.64, 0.12, 0.060);
|
let hot = smoothstep(0.72, 0.96, live);
|
||||||
let border = clamp(panel - inner * 0.52, 0.0, 1.0);
|
let live_color = sample_range_color(live);
|
||||||
|
|
||||||
// Dense mesh: the live 12x7 pressure dots sit over this finer sensor lattice.
|
let halo_shape = fingertip_film_alpha(p, 0.72, -0.20, 0.055);
|
||||||
let uv = clamp(in.local * 0.5 + vec2f(0.5, 0.5), vec2f(0.0, 0.0), vec2f(1.0, 1.0));
|
let panel = fingertip_film_alpha(p, 0.66, -0.22, 0.035);
|
||||||
let grid = vec2f(18.0, 34.0);
|
let inner = fingertip_film_alpha(p, 0.58, -0.25, 0.045);
|
||||||
let cell = uv * grid - vec2f(0.5, 0.5);
|
let clear_inner = fingertip_film_alpha(p, 0.48, -0.24, 0.160);
|
||||||
let nearest = abs(fract(cell + vec2f(0.5, 0.5)) - vec2f(0.5, 0.5));
|
|
||||||
let grid_line = max(
|
let halo = clamp(halo_shape - panel, 0.0, 1.0);
|
||||||
1.0 - smoothstep(0.014, 0.038, nearest.x),
|
let rim = clamp(panel - inner, 0.0, 1.0);
|
||||||
1.0 - smoothstep(0.014, 0.038, nearest.y),
|
let edge_fade = pow(clamp(1.0 - clear_inner, 0.0, 1.0), 1.20) * panel;
|
||||||
|
|
||||||
|
// Strong pseudo extrusion / bevel.
|
||||||
|
let depth_offset = vec2f(0.045, 0.055);
|
||||||
|
let back_shape_1 = fingertip_film_alpha(p - depth_offset * 0.55, 0.66, -0.22, 0.045);
|
||||||
|
let back_shape_2 = fingertip_film_alpha(p - depth_offset, 0.66, -0.22, 0.060);
|
||||||
|
let extrusion = clamp(max(back_shape_1, back_shape_2) - panel, 0.0, 1.0);
|
||||||
|
|
||||||
|
let bevel_offset = vec2f(0.028, 0.034);
|
||||||
|
let shifted_down_right = fingertip_film_alpha(p - bevel_offset, 0.66, -0.22, 0.035);
|
||||||
|
let bevel_light = clamp(panel - shifted_down_right, 0.0, 1.0);
|
||||||
|
let shifted_up_left = fingertip_film_alpha(p + bevel_offset, 0.66, -0.22, 0.035);
|
||||||
|
let bevel_dark = clamp(panel - shifted_up_left, 0.0, 1.0);
|
||||||
|
|
||||||
|
let broad_bevel = edge_fade * clamp(0.58 - p.x * 0.20 - p.y * 0.18, 0.0, 1.0);
|
||||||
|
|
||||||
|
// Micro lattice.
|
||||||
|
let uv = clamp(
|
||||||
|
p * vec2f(0.52, 0.46) + vec2f(0.5, 0.46),
|
||||||
|
vec2f(0.0, 0.0),
|
||||||
|
vec2f(1.0, 1.0),
|
||||||
);
|
);
|
||||||
let joint = 1.0 - smoothstep(0.070, 0.150, length(nearest * vec2f(1.18, 1.0)));
|
|
||||||
let center_shadow = 1.0 - smoothstep(0.10, 0.76, length(in.local * vec2f(0.92, 0.66)));
|
|
||||||
|
|
||||||
let top_light = smoothstep(-0.52, 0.16, -in.local.y) * 0.20;
|
let grid = vec2f(18.0, 34.0);
|
||||||
let side_glow = smoothstep(0.30, 0.70, abs(in.local.x)) * 0.26;
|
let cell_uv = fract(uv * grid) - vec2f(0.5, 0.5);
|
||||||
let lift_shadow = smoothstep(0.48, 0.86, in.local.y) * (1.0 - smoothstep(0.50, 0.86, abs(in.local.x))) * 0.13;
|
let dot_dist = length(cell_uv * vec2f(1.0, 1.06));
|
||||||
let scan = (0.5 + 0.5 * sin((uv.y * 76.0 + uv.x * 9.0) * 6.28318)) * 0.030;
|
let dot_aa = max(fwidth(dot_dist) * 1.35, 0.006);
|
||||||
|
let dots = (1.0 - smoothstep(0.105 - dot_aa, 0.105 + dot_aa, dot_dist)) * inner;
|
||||||
|
|
||||||
let membrane_color = vec3f(0.006, 0.28, 0.38);
|
let sheen_axis = p.x * 0.88 + p.y * 0.22 + 0.16;
|
||||||
let line_color = vec3f(0.12, 0.72, 0.88);
|
let sheen = (1.0 - smoothstep(0.018, 0.105, abs(sheen_axis))) * panel;
|
||||||
let rim_color = vec3f(0.18, 0.98, 1.0);
|
let shell_sheen = sheen * (0.26 + edge_fade * 0.74);
|
||||||
let color = membrane_color * (0.68 + top_light + side_glow + scan)
|
|
||||||
+ line_color * (grid_line * 0.20 + joint * 0.42)
|
|
||||||
+ rim_color * (border * 0.92 + side_glow * 0.18)
|
|
||||||
- vec3f(0.0, 0.16, 0.24) * center_shadow * 0.30
|
|
||||||
- vec3f(0.0, 0.10, 0.16) * lift_shadow;
|
|
||||||
let alpha = panel * (0.24 + grid_line * 0.10 + joint * 0.23 + border * 0.42);
|
|
||||||
|
|
||||||
return output_color(color, alpha);
|
// Temporary synthetic pressure hotspot. Real hand pressure dots are drawn above this pass.
|
||||||
|
let pressure_center = vec2f(-0.08, -0.12);
|
||||||
|
let pressure_dist = length((p - pressure_center) * vec2f(1.0, 0.74));
|
||||||
|
let pressure = (1.0 - smoothstep(0.05, 0.36, pressure_dist)) * inner;
|
||||||
|
let pressure_hot = (1.0 - smoothstep(0.02, 0.13, pressure_dist)) * inner;
|
||||||
|
|
||||||
|
let glass_base = vec3f(0.006, 0.055, 0.105);
|
||||||
|
let glass_cyan = vec3f(0.025, 0.42, 0.58);
|
||||||
|
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_edge_color = mix(vec3f(0.015, 0.30, 0.38), live_color * 0.72, response);
|
||||||
|
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 dot_color = mix(vec3f(0.08, 0.48, 0.58), live_color, response);
|
||||||
|
let pressure_color = mix(dot_color, live_color, response);
|
||||||
|
let pressure_hot_color = live_color;
|
||||||
|
|
||||||
|
let membrane_color = extrusion_color * extrusion * 0.90
|
||||||
|
+ extrusion_edge_color * extrusion * halo_shape * 0.32
|
||||||
|
+ glass_base * panel * 0.26
|
||||||
|
+ glass_live * edge_fade * 0.46
|
||||||
|
+ glass_live * broad_bevel * 0.24
|
||||||
|
+ rim_color * rim * 0.88
|
||||||
|
+ bevel_highlight * bevel_light * 1.35
|
||||||
|
+ bevel_dark_color * bevel_dark * 0.95
|
||||||
|
+ bevel_highlight * shell_sheen * 0.28
|
||||||
|
+ rim_color * halo * 0.16
|
||||||
|
+ dot_color * dots * 0.68
|
||||||
|
+ pressure_color * dots * pressure * 0.82
|
||||||
|
+ 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(
|
||||||
|
extrusion * 0.44
|
||||||
|
+ panel * 0.055
|
||||||
|
+ edge_fade * 0.30
|
||||||
|
+ rim * 0.34
|
||||||
|
+ bevel_light * 0.34
|
||||||
|
+ bevel_dark * 0.20
|
||||||
|
+ shell_sheen * 0.09
|
||||||
|
+ halo * 0.045
|
||||||
|
+ dots * 0.09
|
||||||
|
+ dots * pressure * 0.10,
|
||||||
|
0.0,
|
||||||
|
0.90,
|
||||||
|
) + response * (dots * 0.07 + rim * 0.035) + hot * dots * 0.04;
|
||||||
|
|
||||||
|
return output_color(color, clamp(alpha, 0.0, 0.96));
|
||||||
}
|
}
|
||||||
|
|
||||||
@vertex
|
@vertex
|
||||||
@@ -497,13 +550,13 @@ fn fs_hand_dot(in: DotVertexOutput) -> @location(0) vec4f {
|
|||||||
|
|
||||||
// Use a compact bead so the response feels like it lives on the membrane mesh.
|
// Use a compact bead so the response feels like it lives on the membrane mesh.
|
||||||
let core = circle_alpha(in.local, 0.48, 0.07);
|
let core = circle_alpha(in.local, 0.48, 0.07);
|
||||||
let halo = circle_alpha(in.local, 0.74, 0.14) * 0.12;
|
let halo = circle_alpha(in.local, 0.74, 0.14) * (0.10 + intensity * 0.26);
|
||||||
|
|
||||||
// Keep the fingertip matrix visually close to JE-Skin's cyan model dots,
|
// Match Finger mode's pressure gradient so each hand region remains readable.
|
||||||
// while still letting pressure brighten the bead a little.
|
let idle = vec3f(0.060, 0.250, 0.320);
|
||||||
let cyan = vec3f(0.34, 0.86, 1.0);
|
let gradient = sample_range_color(intensity);
|
||||||
let hot = sample_range_color(intensity);
|
let color = mix(idle, gradient, smoothstep(0.0, 0.18, intensity))
|
||||||
let color = mix(cyan, hot, 0.22) * mix(0.82, 1.16, intensity);
|
* mix(0.78, 1.18, intensity);
|
||||||
|
|
||||||
return output_color(color, max(core, halo));
|
return output_color(color, max(core, halo));
|
||||||
}
|
}
|
||||||
@@ -540,33 +593,9 @@ fn vs_hand_palm_chip(vertex: DotVertexInput, instance: DotInstanceInput) -> Hand
|
|||||||
|
|
||||||
@fragment
|
@fragment
|
||||||
fn fs_hand_palm_chip(in: HandPalmChipVertexOutput) -> @location(0) vec4f {
|
fn fs_hand_palm_chip(in: HandPalmChipVertexOutput) -> @location(0) vec4f {
|
||||||
// Dark rounded tile: this is the inset chip body sitting inside the palm surface.
|
// The live palm-dot pass draws every chip cell, including the idle dots.
|
||||||
let panel = rounded_rect_alpha(in.local, 0.10, 0.040);
|
// Keeping this background pass transparent prevents a second offset dot grid.
|
||||||
let inset = rounded_rect_alpha(in.local * vec2f(1.10, 1.08), 0.08, 0.052);
|
return output_color(vec3f(0.0, 0.0, 0.0), 0.0);
|
||||||
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
|
||||||
@@ -574,9 +603,10 @@ fn vs_hand_palm_dot(vertex: DotVertexInput, instance: DotInstanceInput) -> DotVe
|
|||||||
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.
|
|
||||||
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.13, 0.25, 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;
|
||||||
@@ -589,17 +619,16 @@ 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 glow = circle_alpha(in.local, 0.95, 0.22) * intensity * 0.30;
|
|
||||||
|
|
||||||
let cold = vec3f(0.070, 0.340, 0.360);
|
let core = circle_alpha(in.local, 0.48, 0.07);
|
||||||
let active_color = mix(vec3f(0.110, 0.620, 0.420), vec3f(0.460, 1.000, 0.210), smoothstep(0.08, 1.0, intensity));
|
let halo = circle_alpha(in.local, 0.74, 0.14) * (0.10 + intensity * 0.26);
|
||||||
let color = mix(cold, active_color, smoothstep(0.02, 0.72, intensity))
|
|
||||||
* (0.54 + intensity * 1.10)
|
|
||||||
+ vec3f(0.28, 1.0, 0.36) * glow * 0.90;
|
|
||||||
|
|
||||||
let alpha = max(pixel * (0.20 + intensity * 0.76), glow);
|
let idle = vec3f(0.060, 0.250, 0.320);
|
||||||
return output_color(color, alpha);
|
let gradient = sample_range_color(intensity);
|
||||||
|
let color = mix(idle, gradient, smoothstep(0.0, 0.18, intensity))
|
||||||
|
* mix(0.78, 1.18, intensity);
|
||||||
|
|
||||||
|
return output_color(color, max(core, halo));
|
||||||
}
|
}
|
||||||
|
|
||||||
@vertex
|
@vertex
|
||||||
@@ -629,7 +658,6 @@ fn fs_dot(in: DotVertexOutput) -> @location(0) vec4f {
|
|||||||
return output_color(color, alpha);
|
return output_color(color, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// model
|
// model
|
||||||
struct ModelVertexInput {
|
struct ModelVertexInput {
|
||||||
@location(0) position: vec3f,
|
@location(0) position: vec3f,
|
||||||
@@ -748,11 +776,11 @@ fn aces_tonemap(x: vec3f) -> vec3f {
|
|||||||
|
|
||||||
fn material_normal(in: ModelVertexOutput, front_facing: bool) -> vec3f {
|
fn material_normal(in: ModelVertexOutput, front_facing: bool) -> vec3f {
|
||||||
var n = normalize(in.world_normal);
|
var n = normalize(in.world_normal);
|
||||||
if (!front_facing && material.flags.w > 0.5) {
|
if !front_facing && material.flags.w > 0.5 {
|
||||||
n = -n;
|
n = -n;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (material.flags.z < 0.5) {
|
if material.flags.z < 0.5 {
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -772,17 +800,17 @@ fn fs_model(in: ModelVertexOutput, @builtin(front_facing) front_facing: bool) ->
|
|||||||
let base_color = base_sample * material.base_color * in.color;
|
let base_color = base_sample * material.base_color * in.color;
|
||||||
let alpha_mode = material.emissive_alpha.w;
|
let alpha_mode = material.emissive_alpha.w;
|
||||||
var alpha = base_color.a;
|
var alpha = base_color.a;
|
||||||
if (alpha_mode < 0.5) {
|
if alpha_mode < 0.5 {
|
||||||
alpha = 1.0;
|
alpha = 1.0;
|
||||||
} else if (alpha_mode < 1.5) {
|
} else if alpha_mode < 1.5 {
|
||||||
if (alpha < material.flags.x) {
|
if alpha < material.flags.x {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
alpha = 1.0;
|
alpha = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let debug_mode = u32(u.render_options.x + 0.5);
|
let debug_mode = u32(u.render_options.x + 0.5);
|
||||||
if (debug_mode == 1u) {
|
if debug_mode == 1u {
|
||||||
return output_color(base_color.rgb, alpha);
|
return output_color(base_color.rgb, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -848,7 +876,7 @@ fn fs_model(in: ModelVertexOutput, @builtin(front_facing) front_facing: bool) ->
|
|||||||
let ambient_strength = 0.08;
|
let ambient_strength = 0.08;
|
||||||
// Temporary neutral linear ambient term until a real IBL/HDR environment is added.
|
// Temporary neutral linear ambient term until a real IBL/HDR environment is added.
|
||||||
var ambient = vec3f(0.0);
|
var ambient = vec3f(0.0);
|
||||||
if (u.render_options.y > 0.5) {
|
if u.render_options.y > 0.5 {
|
||||||
let ambient_diffuse = albedo * (1.0 - metallic) * ambient_color * ambient_strength;
|
let ambient_diffuse = albedo * (1.0 - metallic) * ambient_color * ambient_strength;
|
||||||
let ambient_specular = f_ambient * ambient_color * ambient_strength * (1.0 - roughness * 0.55);
|
let ambient_specular = f_ambient * ambient_color * ambient_strength * (1.0 - roughness * 0.55);
|
||||||
ambient = (ambient_diffuse + ambient_specular) * ao;
|
ambient = (ambient_diffuse + ambient_specular) * ao;
|
||||||
@@ -856,7 +884,7 @@ fn fs_model(in: ModelVertexOutput, @builtin(front_facing) front_facing: bool) ->
|
|||||||
|
|
||||||
let exposed_color = (ambient + key + fill + emissive) * max(u.render_options.w, 0.0);
|
let exposed_color = (ambient + key + fill + emissive) * max(u.render_options.w, 0.0);
|
||||||
var color = exposed_color;
|
var color = exposed_color;
|
||||||
if (u.render_options.z > 0.5) {
|
if u.render_options.z > 0.5 {
|
||||||
color = aces_tonemap(exposed_color);
|
color = aces_tonemap(exposed_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
254
wix/main.wxs
Normal file
254
wix/main.wxs
Normal file
@@ -0,0 +1,254 @@
|
|||||||
|
<?xml version='1.0' encoding='windows-1252'?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2017 Christopher R. Field.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
The "cargo wix" subcommand provides a variety of predefined variables available
|
||||||
|
for customization of this template. The values for each variable are set at
|
||||||
|
installer creation time. The following variables are available:
|
||||||
|
|
||||||
|
TargetTriple = The rustc target triple name.
|
||||||
|
TargetEnv = The rustc target environment. This is typically either
|
||||||
|
"msvc" or "gnu" depending on the toolchain downloaded and
|
||||||
|
installed.
|
||||||
|
TargetVendor = The rustc target vendor. This is typically "pc", but Rust
|
||||||
|
does support other vendors, like "uwp".
|
||||||
|
CargoTargetBinDir = The complete path to the directory containing the
|
||||||
|
binaries (exes) to include. The default would be
|
||||||
|
"target\release\". If an explicit rustc target triple is
|
||||||
|
used, i.e. cross-compiling, then the default path would
|
||||||
|
be "target\<CARGO_TARGET>\<CARGO_PROFILE>",
|
||||||
|
where "<CARGO_TARGET>" is replaced with the "CargoTarget"
|
||||||
|
variable value and "<CARGO_PROFILE>" is replaced with the
|
||||||
|
value from the "CargoProfile" variable. This can also
|
||||||
|
be overridden manually with the "target-bin-dir" flag.
|
||||||
|
CargoTargetDir = The path to the directory for the build artifacts, i.e.
|
||||||
|
"target".
|
||||||
|
CargoProfile = The cargo profile used to build the binaries
|
||||||
|
(usually "debug" or "release").
|
||||||
|
Version = The version for the installer. The default is the
|
||||||
|
"Major.Minor.Fix" semantic versioning number of the Rust
|
||||||
|
package.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Please do not remove these pre-processor If-Else blocks. These are used with
|
||||||
|
the `cargo wix` subcommand to automatically determine the installation
|
||||||
|
destination for 32-bit versus 64-bit installers. Removal of these lines will
|
||||||
|
cause installation errors.
|
||||||
|
-->
|
||||||
|
<?if $(sys.BUILDARCH) = x64 or $(sys.BUILDARCH) = arm64 ?>
|
||||||
|
<?define PlatformProgramFilesFolder = "ProgramFiles64Folder" ?>
|
||||||
|
<?else ?>
|
||||||
|
<?define PlatformProgramFilesFolder = "ProgramFilesFolder" ?>
|
||||||
|
<?endif ?>
|
||||||
|
|
||||||
|
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>
|
||||||
|
|
||||||
|
<Product
|
||||||
|
Id='*'
|
||||||
|
Name='eskin-model-player'
|
||||||
|
UpgradeCode='7CEF316B-BE23-4533-B4B2-87D06D2230B5'
|
||||||
|
Manufacturer='JOYSONQUIN'
|
||||||
|
Language='1033'
|
||||||
|
Codepage='1252'
|
||||||
|
Version='$(var.Version)'>
|
||||||
|
|
||||||
|
<Package Id='*'
|
||||||
|
Keywords='Installer'
|
||||||
|
Description='Desktop pressure sensor visualization and playback application.'
|
||||||
|
Manufacturer='JOYSONQUIN'
|
||||||
|
InstallerVersion='450'
|
||||||
|
Languages='1033'
|
||||||
|
Compressed='yes'
|
||||||
|
InstallScope='perUser'
|
||||||
|
InstallPrivileges='limited'
|
||||||
|
SummaryCodepage='1252'
|
||||||
|
/>
|
||||||
|
|
||||||
|
<MajorUpgrade
|
||||||
|
Schedule='afterInstallInitialize'
|
||||||
|
DowngradeErrorMessage='A newer version of [ProductName] is already installed. Setup will now exit.'/>
|
||||||
|
|
||||||
|
<Media Id='1' Cabinet='media1.cab' EmbedCab='yes' DiskPrompt='CD-ROM #1'/>
|
||||||
|
<Property Id='DiskPrompt' Value='eskin-model-player Installation'/>
|
||||||
|
|
||||||
|
<Directory Id='TARGETDIR' Name='SourceDir'>
|
||||||
|
<Directory Id='LocalAppDataFolder'>
|
||||||
|
<Directory Id='APPLICATIONFOLDER' Name='eskin-model-player'>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Enabling the license sidecar file in the installer is a four step process:
|
||||||
|
|
||||||
|
1. Uncomment the `Component` tag and its contents.
|
||||||
|
2. Change the value for the `Source` attribute in the `File` tag to a path
|
||||||
|
to the file that should be included as the license sidecar file. The path
|
||||||
|
can, and probably should be, relative to this file.
|
||||||
|
3. Change the value for the `Name` attribute in the `File` tag to the
|
||||||
|
desired name for the file when it is installed alongside the `bin` folder
|
||||||
|
in the installation directory. This can be omitted if the desired name is
|
||||||
|
the same as the file name.
|
||||||
|
4. Uncomment the `ComponentRef` tag with the Id attribute value of "License"
|
||||||
|
further down in this file.
|
||||||
|
-->
|
||||||
|
<!--
|
||||||
|
<Component Id='License' Guid='*'>
|
||||||
|
<File Id='LicenseFile' Name='ChangeMe' DiskId='1' Source='C:\Path\To\File' KeyPath='yes'/>
|
||||||
|
</Component>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<Directory Id='Bin' Name='bin'>
|
||||||
|
<Component Id='Path' Guid='FD230ABD-75B9-47D4-870B-CF2EA72B76BE'>
|
||||||
|
<RegistryValue
|
||||||
|
Root='HKCU'
|
||||||
|
Key='Software\JOYSONQUIN\eskin-model-player'
|
||||||
|
Name='PathComponent'
|
||||||
|
Type='integer'
|
||||||
|
Value='1'
|
||||||
|
KeyPath='yes'/>
|
||||||
|
<RemoveFolder Id='RemoveBinFolder' Directory='Bin' On='uninstall'/>
|
||||||
|
<RemoveFolder Id='RemoveApplicationFolder' Directory='APPLICATIONFOLDER' On='uninstall'/>
|
||||||
|
<Environment
|
||||||
|
Id='PATH'
|
||||||
|
Name='PATH'
|
||||||
|
Value='[Bin]'
|
||||||
|
Permanent='no'
|
||||||
|
Part='last'
|
||||||
|
Action='set'
|
||||||
|
System='no'/>
|
||||||
|
</Component>
|
||||||
|
<Component Id='binary0' Guid='302CAFB5-6951-426B-BC5A-988C351A2CF2'>
|
||||||
|
<RegistryValue
|
||||||
|
Root='HKCU'
|
||||||
|
Key='Software\JOYSONQUIN\eskin-model-player'
|
||||||
|
Name='BinaryComponent'
|
||||||
|
Type='integer'
|
||||||
|
Value='1'
|
||||||
|
KeyPath='yes'/>
|
||||||
|
<File
|
||||||
|
Id='exe0'
|
||||||
|
Name='ESkinPlayer.exe'
|
||||||
|
DiskId='1'
|
||||||
|
Source='$(var.CargoTargetBinDir)\ESkinPlayer.exe'/>
|
||||||
|
</Component>
|
||||||
|
</Directory>
|
||||||
|
</Directory>
|
||||||
|
</Directory>
|
||||||
|
</Directory>
|
||||||
|
|
||||||
|
<Feature
|
||||||
|
Id='Binaries'
|
||||||
|
Title='Application'
|
||||||
|
Description='Installs all binaries and the license.'
|
||||||
|
Level='1'
|
||||||
|
ConfigurableDirectory='APPLICATIONFOLDER'
|
||||||
|
AllowAdvertise='no'
|
||||||
|
Display='expand'
|
||||||
|
Absent='disallow'>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Uncomment the following `ComponentRef` tag to add the license
|
||||||
|
sidecar file to the installer.
|
||||||
|
-->
|
||||||
|
<!--<ComponentRef Id='License'/>-->
|
||||||
|
|
||||||
|
<ComponentRef Id='binary0'/>
|
||||||
|
|
||||||
|
<Feature
|
||||||
|
Id='Environment'
|
||||||
|
Title='PATH Environment Variable'
|
||||||
|
Description='Add the install location of the [ProductName] executable to the PATH system environment variable. This allows the [ProductName] executable to be called from any location.'
|
||||||
|
Level='1'
|
||||||
|
Absent='allow'>
|
||||||
|
<ComponentRef Id='Path'/>
|
||||||
|
</Feature>
|
||||||
|
</Feature>
|
||||||
|
|
||||||
|
<SetProperty Id='ARPINSTALLLOCATION' Value='[APPLICATIONFOLDER]' After='CostFinalize'/>
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Uncomment the following `Icon` and `Property` tags to change the product icon.
|
||||||
|
|
||||||
|
The product icon is the graphic that appears in the Add/Remove
|
||||||
|
Programs control panel for the application.
|
||||||
|
-->
|
||||||
|
<!--<Icon Id='ProductICO' SourceFile='wix\Product.ico'/>-->
|
||||||
|
<!--<Property Id='ARPPRODUCTICON' Value='ProductICO' />-->
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Adding a URL to Add/Remove Programs control panel listing for the
|
||||||
|
application is a two step process:
|
||||||
|
|
||||||
|
1. Uncomment the following `Property` tag with the "ARPHELPLINK" Id
|
||||||
|
attribute value.
|
||||||
|
2. Change the value for `Value` attribute of the following
|
||||||
|
`Property` tag to a valid URL.
|
||||||
|
-->
|
||||||
|
<!--<Property Id='ARPHELPLINK' Value='ChangeMe'/>-->
|
||||||
|
|
||||||
|
<UI>
|
||||||
|
<UIRef Id='WixUI_FeatureTree'/>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Enabling the EULA dialog in the installer is a three step process:
|
||||||
|
|
||||||
|
1. Comment out or remove the two `Publish` tags that follow the
|
||||||
|
`WixVariable` tag.
|
||||||
|
2. Uncomment the `<WixVariable Id='WixUILicenseRtf' Value='Path\to\Eula.rft'>` tag further down
|
||||||
|
3. Replace the `Value` attribute of the `WixVariable` tag with
|
||||||
|
the path to a RTF file that will be used as the EULA and
|
||||||
|
displayed in the license agreement dialog.
|
||||||
|
-->
|
||||||
|
<Publish Dialog='WelcomeDlg' Control='Next' Event='NewDialog' Value='CustomizeDlg' Order='99'>1</Publish>
|
||||||
|
<Publish Dialog='CustomizeDlg' Control='Back' Event='NewDialog' Value='WelcomeDlg' Order='99'>1</Publish>
|
||||||
|
|
||||||
|
</UI>
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Enabling the EULA dialog in the installer requires uncommenting
|
||||||
|
the following `WixUILicenseRTF` tag and changing the `Value`
|
||||||
|
attribute.
|
||||||
|
-->
|
||||||
|
<!-- <WixVariable Id='WixUILicenseRtf' Value='Relative\Path\to\Eula.rtf'/> -->
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Uncomment the next `WixVariable` tag to customize the installer's
|
||||||
|
Graphical User Interface (GUI) and add a custom banner image across
|
||||||
|
the top of each screen. See the WiX Toolset documentation for details
|
||||||
|
about customization.
|
||||||
|
|
||||||
|
The banner BMP dimensions are 493 x 58 pixels.
|
||||||
|
-->
|
||||||
|
<!--<WixVariable Id='WixUIBannerBmp' Value='wix\Banner.bmp'/>-->
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Uncomment the next `WixVariable` tag to customize the installer's
|
||||||
|
Graphical User Interface (GUI) and add a custom image to the first
|
||||||
|
dialog, or screen. See the WiX Toolset documentation for details about
|
||||||
|
customization.
|
||||||
|
|
||||||
|
The dialog BMP dimensions are 493 x 312 pixels.
|
||||||
|
-->
|
||||||
|
<!--<WixVariable Id='WixUIDialogBmp' Value='wix\Dialog.bmp'/>-->
|
||||||
|
|
||||||
|
</Product>
|
||||||
|
|
||||||
|
</Wix>
|
||||||
Reference in New Issue
Block a user