Glanceboard: configurable head-tilt angle, glance down to hide

- Head tilt angle setting (Glanceboard): sets the glasses' own head-up
  trigger through the stock settings message (g2_setting.proto
  DeviceReceiveInfoFromAPP.deviceReceiveHeadUpSetting), so detection stays
  on the glasses and nothing streams while the screen is off. The stored
  calibration is read back and compensated for, and the value is
  re-applied on every connect. "glasses" (the default) leaves the
  glasses' setting untouched.
- "Set to current head angle" measures the tilt from a ~1.2 s IMU burst
  and rounds it to the nearest 5 degrees.
- Glance down to hide: a head-tilt showing now stays up until the head comes back down
  (HEAD_DOWN, forwarded by Faceclaw/38) instead of a fixed timeout, with
  a 60 s safety cap. HEAD_DOWN goes only to the Glanceboard on Android
  and iOS, so it never counts as shell activity.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
BrendenandClaude Opus 5.5 committed 2026-11-06 08:58:33 -08:00
1 parent c896ce9ac8
commit cf74f34767
15 files changed
+536 -21

No files matched your search

+24
View File
@@ -20,6 +20,8 @@ import { shouldShowNotificationOnGlasses } from "../native/notification-sources"
import { watchNotificationListenerBinding } from "../native/notification-access";
import { openEvenAppSettings, readEvenAppNotificationState } from "../native/even-app-conflict";
import { defaultRingName, setGlassesRingLink } from "../native/ring-status";
import { applyGlanceAngle } from "./head-angle";
import { glanceAngleDegrees } from "../apps/glanceboard/glanceboard-settings";
import { getBooleanSetting, setBooleanSetting } from "../native/settings-store";
import { grayImageToPreviewSource } from "../native/gray-image-preview";
import { firmwareIncompatibilityMessage, hasCompatibleFirmware } from "./firmware-compat";
@@ -333,6 +335,7 @@ class DashboardController {
private evenHubResumePromise: Promise<boolean> | null = null;
/** Faceclaw's firmware at the required revision reported in; its extensions can be used. */
private customFirmwareConfirmed = false;
private lastGlanceAngleDegrees = glanceAngleDegrees();
private faceclawWakeLeaseState: boolean | null = null;
/** Ring connection mode the current session was started with (it applies per connection). */
private ringModeAtConnect: RingConnectionMode = "glasses";
@@ -484,6 +487,7 @@ class DashboardController {
this.applyAppLayoutsIfChanged();
this.syncAssistantBridgeIfChanged();
this.syncLockScreenSettingIfChanged();
this.applyGlanceAngleIfChanged();
// A Preview color or scaling change should show on the mirror at once,
// not at the next composited frame (cheap: floor-limited, dedup'd on
// the Java side).
@@ -1591,6 +1595,8 @@ class DashboardController {
if (mappedPhase === "connected") {
this.syncEvenHubScreenOffSetting();
this.ensureWearStateTracking();
// The session reapplies it on reconnects; restate it for a new session.
applyGlanceAngle();
this.maybeWakeAfterChargingReconnect();
} else if (mappedPhase !== "charging") {
this.cancelEvenHubSuspendTimer();
@@ -2386,6 +2392,16 @@ class DashboardController {
frameTimings.logFrame(frameId, `TS input handler start: ${event.kind} ${eventLabel(event.kind, event.eventType)}`);
let frameOwned = false;
try {
if (event.kind === "sys-event" && event.eventType === OsEventTypeList.HEAD_DOWN_EVENT) {
// Only the Glanceboard cares (it ends a head-tilt showing); never
// shell input, so it can't count as activity or wake anything.
const glanceEvent = this.glance.eventForGesture("head-down");
if (glanceEvent) {
await this.glance.handleEvent(glanceEvent, frameId);
frameOwned = true;
}
return;
}
const inputEvent = rawInputEventToInputEvent(event);
if (!acceptInput(inputEvent)) return;
// The gesture, plus which app is on screen and whether input goes to it,
@@ -2504,6 +2520,14 @@ class DashboardController {
}
}
/** Re-send the head-tilt angle when the setting changed (from either settings UI). */
private applyGlanceAngleIfChanged(): void {
const degrees = glanceAngleDegrees();
if (degrees === this.lastGlanceAngleDegrees) return;
this.lastGlanceAngleDegrees = degrees;
applyGlanceAngle();
}
/**
* The Glanceboard event a sleep-time input means, or null when the shell
* should see the input as usual. A display-wake carries the head-tilt
+7
View File
@@ -79,6 +79,12 @@ export const OsEventTypeList = {
HEAD_UP_EVENT: 12,
/** Faceclaw/18: R1 touch-down, before click/hold/slide recognition. */
RING_PRESS_EVENT: 14,
/**
* Faceclaw/38: the IMU head-down (the head back below the head-up
* threshold minus 20 degrees), forwarded while a page is up. Ends a
* head-tilt Glanceboard; nothing else uses it.
*/
HEAD_DOWN_EVENT: 15,
} as const;
export const OsEventTypeName: Record<number, string> = {
@@ -96,4 +102,5 @@ export const OsEventTypeName: Record<number, string> = {
11: "SHORT_THEN_LONG_PRESS_EVENT",
12: "HEAD_UP_EVENT",
14: "RING_PRESS_EVENT",
15: "HEAD_DOWN_EVENT",
};
+36 -9
View File
@@ -13,17 +13,33 @@
/** Fallback press timeout when the host supplies none; each further press restarts it. */
export const GLANCE_TIMEOUT_MS = 3000;
/**
* Safety cap for a head-tilt showing: the board normally stays up until the
* head comes back down (as the stock dashboard does), but a lost head-down
* event must not leave it on forever.
*/
export const GLANCE_TILT_MAX_MS = 60_000;
export type GlanceState = {
visible: boolean;
/** A long-press is holding the board up; the timer does not run meanwhile. */
holding: boolean;
/**
* A head-tilt is holding the board up: it stays until the firmware reports
* the head back down (or GLANCE_TILT_MAX_MS passes).
*/
tilted: boolean;
/** When the board hides on its own (epoch ms), or null while held / hidden. */
hideAtMs: number | null;
};
export type GlanceEvent =
/** Single tap or head-tilt wake: show, and (re)start the auto-hide timer. */
/** Single tap: show, and (re)start the auto-hide timer. */
| { type: "press" }
/** Head-tilt (IMU head-up): show until the head comes back down. */
| { type: "tilt" }
/** The IMU reported the head back down: ends a head-tilt showing. */
| { type: "head-down" }
/** Long-press: show and keep showing until the release. */
| { type: "hold" }
/** The long-press ended. */
@@ -33,7 +49,7 @@ export type GlanceEvent =
/** Double-tap (or any other wake of the regular UI): hide now. */
| { type: "dismiss" };
export const GLANCE_HIDDEN: GlanceState = Object.freeze({ visible: false, holding: false, hideAtMs: null });
export const GLANCE_HIDDEN: GlanceState = Object.freeze({ visible: false, holding: false, tilted: false, hideAtMs: null });
export function reduceGlance(
state: GlanceState,
@@ -43,14 +59,22 @@ export function reduceGlance(
): GlanceState {
switch (event.type) {
case "press":
// A tap during a hold changes nothing: the hold decides when it ends.
if (state.holding) return state;
return { visible: true, holding: false, hideAtMs: nowMs + timeoutMs };
// A tap during a hold or a head-tilt changes nothing: those decide when it ends.
if (state.holding || state.tilted) return state;
return { visible: true, holding: false, tilted: false, hideAtMs: nowMs + timeoutMs };
case "tilt":
return { visible: true, holding: state.holding, tilted: true, hideAtMs: state.holding ? null : nowMs + GLANCE_TILT_MAX_MS };
case "head-down":
// Only a head-tilt showing ends with the head; a tap's timer or a hold keeps running.
if (!state.tilted) return state;
return state.holding ? { ...state, tilted: false } : GLANCE_HIDDEN;
case "hold":
return { visible: true, holding: true, hideAtMs: null };
return { visible: true, holding: true, tilted: state.tilted, hideAtMs: null };
case "release":
// Releases delivered late or after a disabled hold gesture mean nothing here.
return state.holding ? GLANCE_HIDDEN : state;
if (!state.holding) return state;
// Head still up: the board stays, as if the tilt had just shown it.
return state.tilted ? { visible: true, holding: false, tilted: true, hideAtMs: nowMs + GLANCE_TILT_MAX_MS } : GLANCE_HIDDEN;
case "timeout":
if (!state.visible || state.holding || state.hideAtMs === null || nowMs < state.hideAtMs) return state;
return GLANCE_HIDDEN;
@@ -66,13 +90,16 @@ export function reduceGlance(
* already handles or ignores while asleep.
*/
export function glanceEventForGesture(
gesture: "click" | "double-click" | "long-press" | "short-then-long-press" | "long-press-release" | "head-tilt" | (string & {}),
gesture: "click" | "double-click" | "long-press" | "short-then-long-press" | "long-press-release" | "head-tilt" | "head-down" | (string & {}),
boardVisible: boolean,
): GlanceEvent | null {
switch (gesture) {
case "click":
case "head-tilt":
return { type: "press" };
case "head-tilt":
return { type: "tilt" };
case "head-down":
return boardVisible ? { type: "head-down" } : null;
case "long-press":
case "short-then-long-press":
return { type: "hold" };
+105
View File
@@ -0,0 +1,105 @@
import { addImuListener, setImuReportEnabled, type ImuReading } from "../native/imu";
import { getHeadUpStatus, setHeadUpTrigger, type HeadUpStatus } from "../native/glasses-controls";
import { glanceAngleDegrees, glanceAngleSetting, type GlanceAngle } from "../apps/glanceboard/glanceboard-settings";
// Same ImuReportPace code the accelerometer demo uses (not literal Hz).
const IMU_REPORT_PACE = 200;
/** How long to average once samples start arriving. */
const SAMPLE_WINDOW_MS = 1_200;
/** Give up when the glasses send nothing for this long. */
const FIRST_SAMPLE_TIMEOUT_MS = 3_000;
const MIN_SAMPLES = 3;
/** The setting's range; the firmware itself accepts 1..90. */
export const MIN_GLANCE_ANGLE = 5;
export const MAX_GLANCE_ANGLE = 60;
/** degrees/rounded are set on success; reason on failure. */
export type HeadAngleResult = { ok: boolean; degrees?: number; rounded?: number; reason?: string };
/**
* Measure how far the head is tilted up right now, from the glasses'
* accelerometer stream (the same IMU whose pitch the firmware compares with
* its head-up threshold).
*
* The temple's sensor axes are not documented, so this does not assume which
* axis points forward. When worn, gravity lies mostly along the sensor's
* vertical axis, and tilting the head up turns it toward the forward axis; the
* angle between gravity and the dominant axis is therefore the tilt, whichever
* axis that is and whichever sign it has. Head roll adds to it, so the wearer
* should keep the head level side to side. Past 45° the dominant axis swaps,
* which is why the setting stops at 60° and readings are clamped there.
*/
export async function measureHeadTilt(): Promise<HeadAngleResult> {
const samples: ImuReading[] = [];
let firstAt = 0;
const unsubscribe = addImuListener((reading) => {
// Glasses temples only (1 right, 3 left, 0 unspecified); the ring is 2.
if (reading.source === 2) return;
if (!Number.isFinite(reading.x) || !Number.isFinite(reading.y) || !Number.isFinite(reading.z)) return;
if (firstAt === 0) firstAt = Date.now();
samples.push(reading);
});
setImuReportEnabled(true, IMU_REPORT_PACE);
try {
const start = Date.now();
while (true) {
await delay(100);
const now = Date.now();
if (firstAt === 0 && now - start >= FIRST_SAMPLE_TIMEOUT_MS) break;
if (firstAt !== 0 && now - firstAt >= SAMPLE_WINDOW_MS) break;
}
} finally {
setImuReportEnabled(false, IMU_REPORT_PACE);
unsubscribe();
}
if (samples.length < MIN_SAMPLES) {
return { ok: false, reason: samples.length === 0 ? "no sensor data" : "too few samples" };
}
let x = 0, y = 0, z = 0;
for (const s of samples) {
x += s.x;
y += s.y;
z += s.z;
}
x /= samples.length;
y /= samples.length;
z /= samples.length;
const magnitude = Math.hypot(x, y, z);
if (!(magnitude > 1e-6)) return { ok: false, reason: "sensor reads zero" };
const dominant = Math.max(Math.abs(x), Math.abs(y), Math.abs(z));
const degrees = (Math.acos(Math.min(1, dominant / magnitude)) * 180) / Math.PI;
return { ok: true, degrees, rounded: roundGlanceAngle(degrees) };
}
/** Nearest multiple of 5, kept within the setting's range. */
export function roundGlanceAngle(degrees: number): number {
const rounded = Math.round(degrees / 5) * 5;
return Math.min(MAX_GLANCE_ANGLE, Math.max(MIN_GLANCE_ANGLE, rounded));
}
/**
* Measure, store the rounded angle in the Head tilt angle setting, and send
* it to the glasses. Returns a short status for the menu row.
*/
export async function setGlanceAngleFromHead(): Promise<string> {
const result = await measureHeadTilt();
if (!result.ok) return `Failed: ${result.reason}`;
glanceAngleSetting.set(String(result.rounded) as GlanceAngle);
const sent = applyGlanceAngle();
return sent ? `Set to ${result.rounded}°` : `Saved ${result.rounded}° (glasses offline)`;
}
/** Push the Head tilt angle setting to the session (on change and on each connect). */
export function applyGlanceAngle(): boolean {
return setHeadUpTrigger(glanceAngleDegrees());
}
/** The glasses' current head-up trigger (angle + calibration), or null when not read yet. */
export function glassesHeadUpTrigger(status: HeadUpStatus | null = getHeadUpStatus()): number | null {
if (!status || status.switch < 0) return null;
return status.switch === 1 ? status.angle + status.calibration : 0;
}
function delay(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}
+7
View File
@@ -961,6 +961,13 @@ export class IosPreviewController {
private handleRingEvent(input: RawInputEvent): void {
this.inputQueue = this.inputQueue.then(async () => {
if (this.state.phase !== 'connected') return
if (input.kind === 'sys-event' && input.eventType === OsEventTypeList.HEAD_DOWN_EVENT) {
// As on Android: only the Glanceboard uses it (it ends a head-tilt
// showing); it never reaches the shell or counts as activity.
const glanceEvent = this.glance.eventForGesture('head-down')
if (glanceEvent) await this.glance.handleEvent(glanceEvent, 0)
return
}
this.onActivity()
if (input.ringInput) this.state = { ...this.state, ring: true }
await this.receiveInput(rawInputEventToInputEvent(input),