Files
faceclaw/app/native/glasses-controls.ts
BrendenandClaude Opus 5.5 b1ca8b8ca1 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>
2026-11-06 12:20:19 -08:00

66 lines
2.1 KiB
TypeScript

declare const com: any;
/**
* Head-up (look-up wake) trigger on the active glasses session
* (GlassesSessionCore.setHeadUpTrigger / getHeadUpStatus). Android only for
* now (headUpControlsAvailable): on iOS, or with no session, the setter does
* nothing and the getter returns null.
*/
/** Whether this platform can change the glasses' head-up setting at all. */
export function headUpControlsAvailable(): boolean {
return Boolean(global.isAndroid);
}
/** GlassesSessionCore.getHeadUpStatus. switch -1 = not read on this connection. */
export type HeadUpStatus = {
switch: number;
angle: number;
calibration: number;
/** The trigger Faceclaw is maintaining, or -1 when it leaves the glasses' own setting. */
desired: number;
readAgeMs: number;
/** The glasses' own switch and angle from before Faceclaw changed them (switch -1 = none held). */
originalSwitch: number;
originalAngle: number;
/** Those originals are being written back. */
restorePending: boolean;
};
function activeCommunicator(): any {
if (!global.isAndroid) return null;
try {
return com.faceclaw.app.FaceclawBleCommunicator.getActive();
} catch {
return null;
}
}
/**
* Ask the session to keep the head-up trigger at `degrees` (1..90); 0 stops
* managing it and writes back `original` (or what the session saved itself)
* if Faceclaw changed the glasses' values.
*/
export function setHeadUpTrigger(degrees: number, original: { switch: number; angle: number } | null = null): boolean {
const active = activeCommunicator();
if (!active) return false;
try {
active.setHeadUpTrigger(Math.round(degrees), original ? original.switch : -1, original ? Math.round(original.angle) : 0);
return true;
} catch (error) {
console.warn(`setHeadUpTrigger failed: ${error}`);
return false;
}
}
export function getHeadUpStatus(): HeadUpStatus | null {
const active = activeCommunicator();
if (!active) return null;
try {
return JSON.parse(String(active.getHeadUpStatus())) as HeadUpStatus;
} catch (error) {
console.warn(`getHeadUpStatus failed: ${error}`);
return null;
}
}