forked from Blendman974/faceclaw
Glanceboard: address review of head-tilt angle and glance down
- A verification read that still disagrees no longer requeues the writes at once (which looped while the firmware refused the value); the next regular poll retries. - "Glasses default" now writes back the glasses' own switch and angle, saved before Faceclaw first changed them (persisted across app restarts), and drops writes still queued. Disabling the Glanceboard does the same. - "Set to current head angle" takes two readings, head level then tilted up, and uses the angle between them, so it no longer depends on the sensor's axes or folds past 45°. A head that did not move is reported, not stored as 5°. The math is in head-tilt-math.ts, with tests. - A head-tilt that woke a suspended session, or a trigger under 25° (where a level gaze stays above the head-down threshold), hides after the tap duration instead of the 60 s cap. The setting's description explains it. - The angle rows are hidden on iOS, which cannot change the setting. - The capture row repaints while measuring, ignores repeat selects, and its status clears when the menu reopens or the angle changes; the angle is sent once, by the controller's settings listener. - Comments describing a head-tilt as a timed press are updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cf74f34767
commit
b1ca8b8ca1
15 files changed
+476
-128
No files matched your search
@@ -6,6 +6,7 @@ const {
|
||||
GLANCE_TIMEOUT_MS,
|
||||
GLANCE_TILT_MAX_MS,
|
||||
glanceEventForGesture,
|
||||
glanceTiltMaxMs,
|
||||
reduceGlance,
|
||||
} = require("../.test-build/app/g2/glance-state.js");
|
||||
|
||||
@@ -13,7 +14,7 @@ const T0 = 1_000_000;
|
||||
|
||||
test("a press shows the board and arms the auto-hide timer", () => {
|
||||
const shown = reduceGlance(GLANCE_HIDDEN, { type: "press" }, T0);
|
||||
assert.deepEqual(shown, { visible: true, holding: false, tilted: false, hideAtMs: T0 + GLANCE_TIMEOUT_MS });
|
||||
assert.deepEqual(shown, { visible: true, holding: false, tilted: false, tiltMaxMs: 0, hideAtMs: T0 + GLANCE_TIMEOUT_MS });
|
||||
// A timer firing early is ignored; on time it hides.
|
||||
assert.equal(reduceGlance(shown, { type: "timeout" }, T0 + GLANCE_TIMEOUT_MS - 1), shown);
|
||||
assert.deepEqual(reduceGlance(shown, { type: "timeout" }, T0 + GLANCE_TIMEOUT_MS), GLANCE_HIDDEN);
|
||||
@@ -28,7 +29,7 @@ test("a further press renews the timer from the new press", () => {
|
||||
|
||||
test("a hold shows the board without a timer and the release hides it", () => {
|
||||
const held = reduceGlance(GLANCE_HIDDEN, { type: "hold" }, T0);
|
||||
assert.deepEqual(held, { visible: true, holding: true, tilted: false, hideAtMs: null });
|
||||
assert.deepEqual(held, { visible: true, holding: true, tilted: false, tiltMaxMs: 0, hideAtMs: null });
|
||||
assert.equal(reduceGlance(held, { type: "timeout" }, T0 + 60_000), held);
|
||||
// A tap mid-hold neither hides nor starts a timer.
|
||||
assert.equal(reduceGlance(held, { type: "press" }, T0 + 500), held);
|
||||
@@ -71,7 +72,7 @@ test("the press timeout is the host's when supplied", () => {
|
||||
|
||||
test("a head-tilt shows the board until the head comes back down", () => {
|
||||
const up = reduceGlance(GLANCE_HIDDEN, { type: "tilt" }, T0);
|
||||
assert.deepEqual(up, { visible: true, holding: false, tilted: true, hideAtMs: T0 + GLANCE_TILT_MAX_MS });
|
||||
assert.deepEqual(up, { visible: true, holding: false, tilted: true, tiltMaxMs: GLANCE_TILT_MAX_MS, hideAtMs: T0 + GLANCE_TILT_MAX_MS });
|
||||
// The tap duration no longer applies, and taps change nothing.
|
||||
assert.equal(reduceGlance(up, { type: "timeout" }, T0 + GLANCE_TIMEOUT_MS), up);
|
||||
assert.equal(reduceGlance(up, { type: "press" }, T0 + 500), up);
|
||||
@@ -89,10 +90,27 @@ test("head-down leaves a tap's or a hold's showing alone", () => {
|
||||
|
||||
test("a hold and a head-tilt together: the board stays until both end", () => {
|
||||
const both = reduceGlance(reduceGlance(GLANCE_HIDDEN, { type: "tilt" }, T0), { type: "hold" }, T0 + 100);
|
||||
assert.deepEqual(both, { visible: true, holding: true, tilted: true, hideAtMs: null });
|
||||
assert.deepEqual(both, { visible: true, holding: true, tilted: true, tiltMaxMs: GLANCE_TILT_MAX_MS, hideAtMs: null });
|
||||
const released = reduceGlance(both, { type: "release" }, T0 + 200);
|
||||
assert.deepEqual(released, { visible: true, holding: false, tilted: true, hideAtMs: T0 + 200 + GLANCE_TILT_MAX_MS });
|
||||
assert.deepEqual(released, { visible: true, holding: false, tilted: true, tiltMaxMs: GLANCE_TILT_MAX_MS, hideAtMs: T0 + 200 + GLANCE_TILT_MAX_MS });
|
||||
const downWhileHeld = reduceGlance(both, { type: "head-down" }, T0 + 200);
|
||||
assert.deepEqual(downWhileHeld, { visible: true, holding: true, tilted: false, hideAtMs: null });
|
||||
assert.deepEqual(downWhileHeld, { visible: true, holding: true, tilted: false, tiltMaxMs: 0, hideAtMs: null });
|
||||
assert.deepEqual(reduceGlance(downWhileHeld, { type: "release" }, T0 + 300), GLANCE_HIDDEN);
|
||||
});
|
||||
|
||||
test("a tilt with a shorter cap keeps it, also across a hold", () => {
|
||||
const up = reduceGlance(GLANCE_HIDDEN, { type: "tilt", maxMs: 5000 }, T0);
|
||||
assert.equal(up.hideAtMs, T0 + 5000);
|
||||
assert.deepEqual(reduceGlance(up, { type: "timeout" }, T0 + 5000), GLANCE_HIDDEN);
|
||||
const held = reduceGlance(up, { type: "hold" }, T0 + 100);
|
||||
assert.equal(reduceGlance(held, { type: "release" }, T0 + 1000).hideAtMs, T0 + 1000 + 5000);
|
||||
});
|
||||
|
||||
test("the tilt cap falls back to the tap duration where the head-down is unlikely", () => {
|
||||
const tapTimeoutMs = 5000;
|
||||
assert.equal(glanceTiltMaxMs({ resumedSession: false, triggerDegrees: 30, tapTimeoutMs }), GLANCE_TILT_MAX_MS);
|
||||
assert.equal(glanceTiltMaxMs({ resumedSession: false, triggerDegrees: null, tapTimeoutMs }), GLANCE_TILT_MAX_MS);
|
||||
assert.equal(glanceTiltMaxMs({ resumedSession: true, triggerDegrees: 30, tapTimeoutMs }), tapTimeoutMs);
|
||||
assert.equal(glanceTiltMaxMs({ resumedSession: false, triggerDegrees: 20, tapTimeoutMs }), tapTimeoutMs);
|
||||
assert.equal(glanceTiltMaxMs({ resumedSession: false, triggerDegrees: 25, tapTimeoutMs }), GLANCE_TILT_MAX_MS);
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
const test = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
const {
|
||||
MAX_GLANCE_ANGLE,
|
||||
MIN_GLANCE_ANGLE,
|
||||
angleBetweenDegrees,
|
||||
glanceAngleForTilt,
|
||||
meanVector,
|
||||
roundGlanceAngle,
|
||||
} = require("../.test-build/app/g2/head-tilt-math.js");
|
||||
|
||||
const rad = (deg) => (deg * Math.PI) / 180;
|
||||
|
||||
/**
|
||||
* Gravity (m/s^2) after pitching the head by pitchDeg, in a sensor frame
|
||||
* mounted so that no axis lines up with the head: the level reading points
|
||||
* along an arbitrary direction, and the pitch rotates it about an arbitrary
|
||||
* axis perpendicular to that (Rodrigues' formula).
|
||||
*/
|
||||
function gravityPitched(pitchDeg) {
|
||||
const v = normalize({ x: 0.3, y: -0.9, z: 0.2 });
|
||||
const k0 = { x: 0.9, y: 0.4, z: 0.45 };
|
||||
const dot = k0.x * v.x + k0.y * v.y + k0.z * v.z;
|
||||
const k = normalize({ x: k0.x - dot * v.x, y: k0.y - dot * v.y, z: k0.z - dot * v.z });
|
||||
const c = Math.cos(rad(pitchDeg));
|
||||
const s = Math.sin(rad(pitchDeg));
|
||||
const cross = { x: k.y * v.z - k.z * v.y, y: k.z * v.x - k.x * v.z, z: k.x * v.y - k.y * v.x };
|
||||
return { x: 9.8 * (v.x * c + cross.x * s), y: 9.8 * (v.y * c + cross.y * s), z: 9.8 * (v.z * c + cross.z * s) };
|
||||
}
|
||||
|
||||
function normalize(v) {
|
||||
const m = Math.hypot(v.x, v.y, v.z);
|
||||
return { x: v.x / m, y: v.y / m, z: v.z / m };
|
||||
}
|
||||
|
||||
test("the tilt between two readings does not depend on the sensor's axes, past 45° too", () => {
|
||||
const level = gravityPitched(0);
|
||||
for (const pitch of [5, 20, 30, 45, 50, 60, 75]) {
|
||||
assert.ok(Math.abs(angleBetweenDegrees(level, gravityPitched(pitch)) - pitch) < 1e-6, `pitch ${pitch}`);
|
||||
}
|
||||
// From a non-zero level reading the difference is what counts.
|
||||
assert.ok(Math.abs(angleBetweenDegrees(gravityPitched(-10), gravityPitched(40)) - 50) < 1e-6);
|
||||
assert.ok(Math.abs(angleBetweenDegrees(level, level)) < 1e-6);
|
||||
});
|
||||
|
||||
test("meanVector averages and rejects empty or zero input", () => {
|
||||
assert.deepEqual(meanVector([{ x: 1, y: 2, z: 3 }, { x: 3, y: 2, z: 1 }]), { x: 2, y: 2, z: 2 });
|
||||
assert.equal(meanVector([]), null);
|
||||
assert.equal(meanVector([{ x: 0, y: 0, z: 0 }]), null);
|
||||
});
|
||||
|
||||
test("roundGlanceAngle rounds to 5° within the setting's range", () => {
|
||||
assert.equal(roundGlanceAngle(27.4), 25);
|
||||
assert.equal(roundGlanceAngle(27.5), 30);
|
||||
assert.equal(roundGlanceAngle(1), MIN_GLANCE_ANGLE);
|
||||
assert.equal(roundGlanceAngle(80), MAX_GLANCE_ANGLE);
|
||||
});
|
||||
|
||||
test("glanceAngleForTilt reports a head that did not move or went too far instead of clamping", () => {
|
||||
assert.deepEqual(glanceAngleForTilt(31), { ok: true, rounded: 30 });
|
||||
assert.deepEqual(glanceAngleForTilt(52), { ok: true, rounded: 50 });
|
||||
assert.deepEqual(glanceAngleForTilt(3), { ok: true, rounded: 5 });
|
||||
assert.equal(glanceAngleForTilt(0.5).ok, false);
|
||||
assert.equal(glanceAngleForTilt(65).ok, false);
|
||||
assert.equal(glanceAngleForTilt(NaN).ok, false);
|
||||
});
|
||||
@@ -36,6 +36,7 @@
|
||||
"../app/g2/glasses-artwork.ts",
|
||||
"../app/g2/glasses-display-state.ts",
|
||||
"../app/g2/glance-state.ts",
|
||||
"../app/g2/head-tilt-math.ts",
|
||||
"../app/ui/shell/notification-modal-queue.ts",
|
||||
"../app/ui/shell/notification-popup-delay.ts",
|
||||
"../app/apps/glanceboard/layout.ts",
|
||||
|
||||
Reference in new issue
Block a user