Revert "feat: add shared tilt-down hide and current-angle measurement"
Secret scan / gitleaks (pull_request) Canceled after 0s
Tests / test (pull_request) Canceled after 0s
Tests / test-kotlin (pull_request) Canceled after 0s
Tests / stats-server (pull_request) Canceled after 0s
Tests / evenhub-extensions (pull_request) Canceled after 0s

This reverts commit f029e3ce91.
This commit is contained in:
Blendman974 committed 2026-11-06 22:20:24 +01:00
1 parent f029e3ce91
commit fe87e75fc2
21 files changed
+24 -356

No files matched your search

@@ -250,9 +250,6 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre
fun enableWearDetectionAndRequestState() = core.enableWearDetectionAndRequestState()
fun configureHeadUpWake(enabled: Int, angle: Int) = core.configureHeadUpWake(enabled, angle)
fun beginHeadAngleMeasurement(): Boolean = core.beginHeadAngleMeasurement()
fun endHeadAngleMeasurement() = core.endHeadAngleMeasurement()
fun getHeadUpCalibration(): Double = core.getHeadUpCalibration()
fun startBandwidthBenchmark(messageSize: Int, windowSize: Int, durationMs: Int): Boolean =
core.startBandwidthBenchmark(messageSize, windowSize, durationMs)
+1 -8
View File
@@ -78,7 +78,7 @@ import { loadPersistedOpenApps, savePersistedOpenApps } from "../ui/shell/open-a
import { appViewportRect, isOnSwitcherEdge, sidebarStripVisible, type ScreenRect, type WindowHeightMode } from "../ui/shell/geometry";
import { type ContinuousCaptureOptions, type LayerActions, type TextSettingsEditToggle, type TranscriptionChoice } from "../ui/layers";
import { type KeyboardInputSession } from "../ui/shell/keyboard-input";
import { appSwitcherPositionSetting, statusBarPositionSetting, statusBarVisibilitySetting, windowBorderSetting, assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, getBrightnessPreferences, getHeadUpPreferences, headDownHideSetting, displayLayoutSetting, navigateDisplayLayoutSetting, terminalDisplayLayoutSetting, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, whisperServerApiKeySetting, whisperServerLanguageSetting, whisperServerModelSetting, whisperServerUrlSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, previewColorSetting, ringConnectionModeSetting, type RingConnectionMode, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
import { appSwitcherPositionSetting, statusBarPositionSetting, statusBarVisibilitySetting, windowBorderSetting, assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, getBrightnessPreferences, getHeadUpPreferences, displayLayoutSetting, navigateDisplayLayoutSetting, terminalDisplayLayoutSetting, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, whisperServerApiKeySetting, whisperServerLanguageSetting, whisperServerModelSetting, whisperServerUrlSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, previewColorSetting, ringConnectionModeSetting, type RingConnectionMode, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
import { isIgnoringBatteryOptimizations, requestIgnoreBatteryOptimizations } from "../native/battery-optimization";
import {
getInstalledEvenHubAppById,
@@ -2403,13 +2403,6 @@ 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) {
if (headDownHideSetting.get()) {
this.glance.dismiss();
if (shell.isScreenOn()) shell.sleep();
}
return;
}
const inputEvent = rawInputEventToInputEvent(event);
if (!acceptInput(inputEvent)) return;
// The gesture, plus which app is on screen and whether input goes to it,
-2
View File
@@ -77,7 +77,6 @@ export const OsEventTypeList = {
* this eventType; the glance host treats it as a press.
*/
HEAD_UP_EVENT: 12,
HEAD_DOWN_EVENT: 15,
/** Faceclaw/18: R1 touch-down, before click/hold/slide recognition. */
RING_PRESS_EVENT: 14,
} as const;
@@ -96,6 +95,5 @@ export const OsEventTypeName: Record<number, string> = {
10: "RING_LONG_PRESS_RELEASE_EVENT",
11: "SHORT_THEN_LONG_PRESS_EVENT",
12: "HEAD_UP_EVENT",
15: "HEAD_DOWN_EVENT",
14: "RING_PRESS_EVENT",
};
+1 -2
View File
@@ -1,4 +1,3 @@
import { headDownHideSetting } from "../ui/dashboard-settings";
/**
* Shows the Glanceboard while the shell sleeps. The board is not a window:
* it lives on its own full-screen opaque compositor surface above the shell
@@ -93,7 +92,7 @@ export class GlanceHost {
if (gesture === "click" && !provider.showOnTap()) return null;
if ((gesture === "long-press" || gesture === "short-then-long-press") && !provider.showOnLongPress()) return null;
if (gesture === "head-tilt" && !provider.showOnHeadTilt()) return null;
return glanceEventForGesture(gesture, this.isVisible(), headDownHideSetting.get());
return glanceEventForGesture(gesture, this.isVisible());
}
/**
+3 -11
View File
@@ -12,13 +12,11 @@
/** Fallback press timeout when the host supplies none; each further press restarts it. */
export const GLANCE_TIMEOUT_MS = 3000;
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;
tilted?: boolean;
/** When the board hides on its own (epoch ms), or null while held / hidden. */
hideAtMs: number | null;
};
@@ -26,7 +24,6 @@ export type GlanceState = {
export type GlanceEvent =
/** Single tap or head-tilt wake: show, and (re)start the auto-hide timer. */
| { type: "press" }
| { type: "tilt" }
/** Long-press: show and keep showing until the release. */
| { type: "hold" }
/** The long-press ended. */
@@ -47,15 +44,12 @@ export function reduceGlance(
switch (event.type) {
case "press":
// A tap during a hold changes nothing: the hold decides when it ends.
if (state.holding || state.tilted) return state;
if (state.holding) return state;
return { visible: true, holding: false, hideAtMs: nowMs + timeoutMs };
case "tilt":
return { visible: true, holding: state.holding, tilted: true, hideAtMs: state.holding ? null : nowMs + GLANCE_TILT_MAX_MS };
case "hold":
return { visible: true, holding: true, ...(state.tilted ? { tilted: true } : {}), hideAtMs: null };
return { visible: true, holding: true, hideAtMs: null };
case "release":
// Releases delivered late or after a disabled hold gesture mean nothing here.
if (state.holding && state.tilted) return { visible: true, holding: false, tilted: true, hideAtMs: nowMs + GLANCE_TILT_MAX_MS };
return state.holding ? GLANCE_HIDDEN : state;
case "timeout":
if (!state.visible || state.holding || state.hideAtMs === null || nowMs < state.hideAtMs) return state;
@@ -74,13 +68,11 @@ export function reduceGlance(
export function glanceEventForGesture(
gesture: "click" | "double-click" | "long-press" | "short-then-long-press" | "long-press-release" | "head-tilt" | (string & {}),
boardVisible: boolean,
tiltDownToHide = false,
): GlanceEvent | null {
switch (gesture) {
case "click":
return { type: "press" };
case "head-tilt":
return { type: tiltDownToHide ? "tilt" : "press" };
return { type: "press" };
case "long-press":
case "short-then-long-press":
return { type: "hold" };
-86
View File
@@ -1,86 +0,0 @@
import { headUpAngleSetting } from "../ui/dashboard-settings";
import type { ImuReading } from "../native/imu-types";
declare const com: any;
/** Experimental inclination estimate inspired by https://github.com/jimrandomh/faceclaw/pull/64; not a calibrated sensor-axis pitch. */
export function estimateHeadInclination(samples: ImuReading[]): number | null {
if (samples.length < 3) return null;
const mean = samples.reduce((v, s) => [v[0]! + s.x, v[1]! + s.y, v[2]! + s.z], [0, 0, 0]).map(v => v / samples.length);
const magnitude = Math.hypot(...mean);
if (!Number.isFinite(magnitude) || magnitude < 1e-6) return null;
// Reject motion instead of persisting a passing acceleration as an angle.
for (const s of samples) {
const length = Math.hypot(s.x, s.y, s.z);
const dot = (s.x * mean[0]! + s.y * mean[1]! + s.z * mean[2]!) / (length * magnitude);
if (!Number.isFinite(dot) || Math.acos(Math.max(-1, Math.min(1, dot))) * 180 / Math.PI > 5) return null;
}
return Math.acos(Math.min(1, Math.max(...mean.map(Math.abs)) / magnitude)) * 180 / Math.PI;
}
export type HeadAngleDevice = {
beginHeadAngleMeasurement(): boolean;
endHeadAngleMeasurement(): void;
getHeadUpCalibration(): number;
subscribe(listener: (reading: ImuReading) => void): () => void;
};
let measuring = false;
export async function setAngleFromCurrentHead(device: HeadAngleDevice | null = androidDevice()): Promise<string> {
if (measuring) return "Measurement already running";
if (!device) return "Connect the glasses first";
measuring = true;
let release = () => {};
let lease = false;
try {
if (!device.beginHeadAngleMeasurement()) return "Glasses unavailable or measurement busy";
lease = true;
const samples: ImuReading[] = [];
await new Promise<void>((resolve, reject) => {
let source: number | null = null;
let sampleTimer: ReturnType<typeof setTimeout> | null = null;
const timeout = setTimeout(resolve, 4200);
const finish = () => { clearTimeout(timeout); if (sampleTimer !== null) clearTimeout(sampleTimer); resolve(); };
try {
const unsubscribe = device.subscribe(reading => {
if (![0, 1, 3].includes(reading.source) || ![reading.x, reading.y, reading.z].every(Number.isFinite)) return;
if (source === null) { source = reading.source; sampleTimer = setTimeout(finish, 1200); }
if (source === reading.source && samples.length < 200) samples.push(reading);
});
release = () => { clearTimeout(timeout); if (sampleTimer !== null) clearTimeout(sampleTimer); unsubscribe(); };
} catch (error) { clearTimeout(timeout); if (sampleTimer !== null) clearTimeout(sampleTimer); reject(error); }
});
const degrees = estimateHeadInclination(samples);
if (degrees === null) return "No stable sensor data; keep still and retry";
const calibration = device.getHeadUpCalibration();
if (!Number.isFinite(calibration)) return "Glasses calibration not received; retry";
// Preserve the existing raw-angle preference and firmware calibration, rather
// than changing the meaning of saved angles for existing installations.
const offset = Math.round((degrees - calibration) / 5) * 5;
if (offset < 0 || offset > 60) return "Measured angle is outside the supported range";
headUpAngleSetting.set(String(offset));
return `Saved estimated head-up angle: ${offset}°`;
} catch { return "Measurement failed; try again"; }
finally {
try { release(); } catch { /* Disconnected communicator. */ }
try { if (lease) device.endHeadAngleMeasurement(); } catch { /* Disconnected communicator. */ }
measuring = false;
}
}
function androidDevice(): HeadAngleDevice | null {
if (!global.isAndroid) return null;
let active: any;
try { active = com.faceclaw.app.FaceclawBleCommunicator.getActive(); } catch { return null; }
if (!active) return null;
return {
beginHeadAngleMeasurement: () => Boolean(active.beginHeadAngleMeasurement()),
endHeadAngleMeasurement: () => active.endHeadAngleMeasurement(),
getHeadUpCalibration: () => Number(active.getHeadUpCalibration()),
subscribe(listener) {
const proxy = new com.faceclaw.app.FaceclawImuListener({ onImuData: (x: number, y: number, z: number, source: number) =>
listener({ x: Number(x), y: Number(y), z: Number(z), source: Number(source) }) });
active.addImuListener(proxy);
return () => active.removeImuListener(proxy);
},
};
}
+1 -8
View File
@@ -53,7 +53,7 @@ import { onAnySettingChanged,
previewColorSetting, lockScreenEnabledSetting, getBrightnessPreferences, getStringSettingById,
nightscoutSiteUrlSetting, nightscoutApiTokenSetting, voiceProviderSetting, elevenLabsApiKeySetting,
openAiApiKeySetting, sonioxApiKeySetting, whisperServerApiKeySetting, whisperServerLanguageSetting,
headDownHideSetting, whisperServerModelSetting, whisperServerUrlSetting, ringConnectionModeSetting, saveTranscribeAudioSetting } from '../ui/dashboard-settings'
whisperServerModelSetting, whisperServerUrlSetting, ringConnectionModeSetting, saveTranscribeAudioSetting } from '../ui/dashboard-settings'
import { transcriptionKey, type VoiceProviderSelection } from '../native/cloud-stt-provider'
import type { PhoneGesture } from '../phone-ui/phone-gestures'
import { claimGlassesOnboardingAutoLaunch, ONBOARDING_APP_ID } from '../apps/onboarding/onboarding-progress'
@@ -1007,13 +1007,6 @@ 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) {
if (headDownHideSetting.get()) {
this.glance.dismiss()
if (shell.isScreenOn()) shell.sleep()
}
return
}
this.onActivity()
if (input.ringInput) this.state = { ...this.state, ring: true }
await this.receiveInput(rawInputEventToInputEvent(input),
+1 -6
View File
@@ -566,11 +566,6 @@ export const headUpWakeSetting = new HeadUpWakeSetting({
description: "Enable waking the glasses when you look up. Until changed, the glasses keep their current setting. Glanceboard's Show on head tilt chooses what appears after waking.",
});
export const headDownHideSetting = new ConfigSettingBoolean({
id: "head-down-hide", label: "Tilt down to hide", storageKey: "display.headDownHide", defaultValue: false,
description: "Lowering your head hides the display, including Glanceboard. A board shown by head tilt stays until you lower your head, with a 60-second safety timeout. Requires firmware forwarding HEAD_DOWN (Faceclaw/38).",
});
export function normalizeHeadUpAngle(value: string | null | undefined): string {
if (value == null || value.trim() === "" || !Number.isFinite(Number(value))) return "30";
return String(Math.max(0, Math.min(60, Math.round(Number(value)))));
@@ -581,7 +576,7 @@ export const headUpAngleSetting = new ConfigSettingEnum({
values: Array.from({ length: 61 }, (_, angle) => String(angle)),
normalize: normalizeHeadUpAngle,
formatValue: angle => `${angle}°`,
description: "Firmware head-up angle, 0–60 degrees, added to the glasses’ stored calibration. Until changed, the glasses keep their current angle. Requires validation on your Faceclaw firmware.",
description: "Look-up trigger angle, 0–60 degrees. Until changed, the glasses keep their current angle. Requires validation on your Faceclaw firmware.",
});
/** -1 means leave that firmware field unchanged; no writes on an untouched installation. */
+1 -12
View File
@@ -1,4 +1,3 @@
import { setAngleFromCurrentHead } from "../../g2/head-angle";
import { remoteInputMenuItem } from "./remote-input-menu";
import { knownFolders } from "@nativescript/core";
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
@@ -52,7 +51,6 @@ import {
brightnessSetting,
headUpWakeSetting,
headUpAngleSetting,
headDownHideSetting,
autoBrightnessMinSetting,
autoBrightnessMaxSetting,
autoBrightnessCurveSetting,
@@ -122,16 +120,7 @@ function settingsSections(): SettingsSection[] {
// the dashboard controller when changed and on each connect.
enumSettingMenuItem(brightnessSetting),
autoBrightnessMenuItem(),
...(!global.isIOS ? [toggleSettingMenuItem(headUpWakeSetting), enumSettingMenuItem(headUpAngleSetting), {
label: "Set to current head angle",
description: "Experimental estimate inspired by PR #64. Keep still, without tilting sideways, at a moderate head-up angle (under 45°). Adjust manually if needed.",
onSelect: async (ctx: LayerContext) => {
shell.showAlert("Measuring head angle — keep still");
const result = await setAngleFromCurrentHead();
shell.showAlert(result);
ctx.actions.requestRender();
},
}, toggleSettingMenuItem(headDownHideSetting)] : []),
...(!global.isIOS ? [toggleSettingMenuItem(headUpWakeSetting), enumSettingMenuItem(headUpAngleSetting)] : []),
enumSettingMenuItem(screenTimeoutSetting, {
onChange: () => {
shell.noteUserActivity();
-14
View File
@@ -51,17 +51,3 @@ On the target glasses, record both lens firmware versions and test:
6. Check both lenses remain synchronized, including reconnecting only one arm.
Do not change firmware to run these checks without explicit permission.
## Shared tilt-down hide and current-angle estimate
Inspired by [Faceclaw PR #64](https://github.com/jimrandomh/faceclaw/pull/64), Display settings now include one Tilt down to hide toggle (off by default), used by both the regular glasses UI and Glanceboard. HEAD_DOWN is forwarded by the existing firmware (event 15, Faceclaw/38), consumed before input filtering/activity tracking, and never wakes the screen. With the option enabled it dismisses Glanceboard and sleeps the regular UI, including after a manual wake. The action is an explicit sleep gesture, like manually turning the display off. With the option disabled, it is ignored, preserving prior behavior.
A Glanceboard shown by head-up uses a 60-second safety limit when Tilt down to hide is enabled; otherwise the existing tap timeout is retained. Show on head tilt still selects what appears on wake. There are no separate Glanceboard angle/hide preferences. iOS consumes the shared HEAD_DOWN event so it cannot become spurious input; current-angle measurement remains Android-only.
Set to current head angle performs a short experimental IMU measurement, then stores the result in the existing shared Head-up angle preference. It reads the glasses' restored calibration (settings request field 9) and subtracts it before saving the raw firmware angle. Existing raw-angle preferences and untouched fields keep their original meaning. A temporary native IMU lease restores the latest application request, including changes made during measurement. Sampling uses one temple only; ring readings, non-finite/zero vectors, unstable samples and unsupported offsets are rejected. Failures leave the saved angle unchanged. Existing synchronization sends the result to both lenses and restores it on reconnect.
Important measurement limitation: PR #64's dominant-axis inclination estimate is approximate, includes side tilt, and cannot disambiguate a dominant-axis swap beyond 45 degrees. The menu explicitly marks it experimental and asks for a moderate angle below 45 degrees with the head level sideways. It does not claim hardware-calibrated pitch; the manual 0–60 degree control remains available. Firmware calibration is not rewritten. Do not rely on software tests alone for physical angle accuracy.
Additional software coverage: shared preference persistence; controller routing with the display awake/asleep and the option on/off; Glanceboard safety timeout; measurement success/failure, concurrent calls, missing/moving sensors, ring exclusion and cleanup; calibration protocol zero/signed/missing fields; native IMU lease restoration; native HEAD_DOWN forwarding without user activity.
Extended independent validation: 1070 JavaScript tests passed, 2 skipped; 272 Kotlin Android host tests passed; TypeScript and changed-source lint passed. Physical wake, hide and angle accuracy remain unverified on glasses.
@@ -514,13 +514,6 @@ class BleProtocol {
)
)
/** Settings read: restored calibration is signed, proto3 omits a zero value. */
@JvmStatic
fun parseHeadUpCalibration(pb: ByteArray): Int? {
val request = readFieldBytes(stripTrailingCrc(pb), 4) ?: return null
return readVarintFieldValue(request, 9, 0)
}
/** Enable the firmware's wear detector (DeviceReceiveInfoFromAPP field 5). */
@JvmStatic
fun buildSetWearDetection(magic: Int, enabled: Boolean): ByteArray {
@@ -306,10 +306,6 @@ class GlassesSessionCore(
internal var brightnessDemoPolling = false
internal var headUpPreferences: Pair<Int, Int>? = null
internal var headUpSent: Pair<Int, Int>? = null
internal var headAngleMeasuring = false
internal var imuRequestedEnabled = false
internal var imuRequestedPace = 200
internal var headUpCalibration: Int? = null
internal var cfwCleanupDelivered = false
internal var lastCfwCleanupAckMagic = 0
@@ -861,50 +857,19 @@ class GlassesSessionCore(
*/
fun setImuReportEnabled(enable: Boolean, reportFrq: Int) {
monitor.withLock {
imuRequestedEnabled = enable
imuRequestedPace = reportFrq
queueSharedImuLocked()
if (!running || !sessionReady) {
logLine("skip IMU " + (if (enable) "enable" else "disable") + "; session not ready")
return
}
clearMessagesOfKindLocked("imu-control")
val message = messageBuilder.enableOrDisableImu(enable, reportFrq)
message.onTimeout = MessageCallback { logLine("IMU control ack timeout") }
pendingMessages.addFirst(message)
logLine("queue IMU " + (if (enable) "enable freq=$reportFrq" else "disable"))
}
interruptibleSleep.interrupt()
}
private fun queueSharedImuLocked() {
if (!running || !sessionReady) return
val enabled = imuRequestedEnabled || headAngleMeasuring
val pace = if (headAngleMeasuring) {
if (imuRequestedEnabled) minOf(imuRequestedPace, 200) else 200
} else imuRequestedPace
clearMessagesOfKindLocked("imu-control")
val message = messageBuilder.enableOrDisableImu(enabled, pace)
message.onTimeout = MessageCallback { logLine("IMU control ack timeout") }
pendingMessages.addFirst(message)
}
/** Temporary IMU lease; application requests made meanwhile are restored on release. */
fun beginHeadAngleMeasurement(): Boolean {
val started = monitor.withLock {
if (!running || !sessionReady || shutdownRequested || chargingMode || headAngleMeasuring) return@withLock false
headAngleMeasuring = true
headUpCalibration = null
queueSharedImuLocked()
pendingMessages.addFirst(createBatteryQueryMessageLocked())
true
}
if (started) interruptibleSleep.interrupt()
return started
}
fun endHeadAngleMeasurement() {
monitor.withLock {
if (!headAngleMeasuring) return
headAngleMeasuring = false
queueSharedImuLocked()
}
interruptibleSleep.interrupt()
}
fun getHeadUpCalibration(): Double = monitor.withLock { headUpCalibration?.toDouble() ?: Double.NaN }
/**
* Enable/disable the stock compass through CFW image-handler mode 10. The
* desired state is retained across reconnects; headings arrive through
@@ -2027,16 +1992,18 @@ class GlassesSessionCore(
} else if (decoded != null
&& "sys-event" == decoded.kind
&& decoded.eventType == BleProtocol.EVENT_HEAD_DOWN) {
// A lifecycle gesture, never ordinary user activity. TS consumes
// it before the shell's activity/wake handling.
logLine("head-down forwarded by CFW")
// Faceclaw/38 also forwards the head coming back down. Nothing
// uses it yet; as an unknown input it would count as activity
// and keep the screen awake, so drop it here.
logLine("head-down forwarded by CFW (ignored)")
decoded = null
}
event = decoded
if (decoded != null) {
// Pure IMU samples arrive continuously; don't let them count
// as user input (which would starve battery polling).
val pureImuSample = "sys-event" == decoded.kind
&& (decoded.eventType == BleProtocol.EVENT_IMU_DATA_REPORT || decoded.eventType == BleProtocol.EVENT_HEAD_DOWN)
&& decoded.eventType == BleProtocol.EVENT_IMU_DATA_REPORT
if (!pureImuSample) {
lastConnectionOrInputAtMs = lastIncomingAtMs
if (decoded.eventSource == BleProtocol.EVENT_SOURCE_RING) {
@@ -2277,8 +2244,6 @@ class GlassesSessionCore(
fixedLayoutCreated = false
clearAllMessagesLocked("session ready")
headUpSent = null
headUpCalibration = null
headAngleMeasuring = false
displayedFingerprint = ""
lastAckAtMs = now()
lastIncomingAtMs = lastAckAtMs
@@ -1054,7 +1054,6 @@ internal fun GlassesSessionCore.createBatteryQueryMessageLocked(): OutboundMessa
ringBattery = if (ring == null) -1 else ring.battery
ringCharging = if (ring == null) -1 else ring.charging
if (ringBattery >= 0) releaseRingFromGlassesLocked("glasses report the ring connected")
headUpCalibration = BleProtocol.parseHeadUpCalibration(message.ackPayload)
val snapshot = BleProtocol.parseSettingsBattery(message.ackPayload)
if (snapshot != null) {
headsetBattery = snapshot.battery
@@ -40,7 +40,6 @@ function settingsEnv(initialUrl = '', initialModel = 'openai-compatible') {
},
});
const load = loader({ global: { isIOS: false, isAndroid: true } }, {
'../../g2/head-angle': { setAngleFromCurrentHead: async () => 'test' },
'./remote-input-menu': { remoteInputMenuItem: () => ({ label: 'Remote input' }) },
'@nativescript/core': { knownFolders: {} },
'../../graphics/ui-fonts': { getDefaultSmallFont: () => ({}) },
-11
View File
@@ -65,14 +65,3 @@ test("the press timeout is the host's when supplied", () => {
assert.equal(reduceGlance(shown, { type: "timeout" }, T0 + GLANCE_TIMEOUT_MS), shown);
assert.deepEqual(reduceGlance(shown, { type: "timeout" }, T0 + 10_000), GLANCE_HIDDEN);
});
test('shared tilt-down option holds a tilted board up to the safety cap; legacy defaults keep the timer', () => {
const { GLANCE_TILT_MAX_MS } = require('../.test-build/app/g2/glance-state.js');
assert.deepEqual(glanceEventForGesture('head-tilt', false), { type: 'press' });
assert.deepEqual(glanceEventForGesture('head-tilt', false, true), { type: 'tilt' });
const state = reduceGlance(GLANCE_HIDDEN, { type: 'tilt' }, 1000);
assert.equal(state.hideAtMs, 1000 + GLANCE_TILT_MAX_MS);
assert.equal(reduceGlance(state, { type: 'timeout' }, 2000), state);
assert.deepEqual(reduceGlance(state, { type: 'dismiss' }, 2000), GLANCE_HIDDEN);
assert.deepEqual(reduceGlance(state, { type: 'timeout' }, state.hideAtMs), GLANCE_HIDDEN);
});
-52
View File
@@ -1,52 +0,0 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const vm = require('node:vm');
const ts = require('typescript');
function fixture() {
const timers = new Map(), saved = []; let id = 0, listener, ended = 0, released = 0;
const context = { exports: {}, global: { isAndroid: false },
require: () => ({ headUpAngleSetting: { set: value => saved.push(value) } }),
setTimeout(fn, ms) { timers.set(++id, { fn, ms }); return id; }, clearTimeout: id => timers.delete(id) };
vm.runInNewContext(ts.transpileModule(fs.readFileSync('app/g2/head-angle.ts', 'utf8'), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText, context);
const device = { beginHeadAngleMeasurement: () => true, endHeadAngleMeasurement: () => ended++, getHeadUpCalibration: () => 10,
subscribe(fn) { listener = fn; return () => released++; } };
const sample = (degrees, source = 1) => {
const r = degrees * Math.PI / 180;
listener({ x: Math.sin(r), y: 0, z: Math.cos(r), source });
};
return { api: context.exports, device, saved, sample, ended: () => ended, released: () => released,
tick(ms) { for (const [key, timer] of [...timers]) if (timer.ms === ms) { timers.delete(key); timer.fn(); } } };
}
test('short measurement compensates firmware calibration, persists one shared angle and releases resources', async () => {
const h = fixture(); const pending = h.api.setAngleFromCurrentHead(h.device);
h.sample(30); h.sample(30); h.sample(30); h.tick(1200);
assert.match(await pending, /Saved.*20°/);
assert.deepEqual(h.saved, ['20']); assert.equal(h.ended(), 1); assert.equal(h.released(), 1);
});
test('no data, motion, unknown calibration and unsupported offsets leave the old angle unchanged', async () => {
for (const kind of ['none', 'motion', 'unknown', 'range']) {
const h = fixture();
if (kind === 'unknown') h.device.getHeadUpCalibration = () => NaN;
if (kind === 'range') h.device.getHeadUpCalibration = () => 70;
const pending = h.api.setAngleFromCurrentHead(h.device);
if (kind !== 'none') { h.sample(30); h.sample(kind === 'motion' ? 0 : 30); h.sample(30); h.tick(1200); }
else h.tick(4200);
assert.doesNotMatch(await pending, /Saved/); assert.equal(h.saved.length, 0);
assert.equal(h.ended(), 1); assert.equal(h.released(), 1);
}
});
test('ring readings never calibrate the glasses; concurrent measurements are rejected', async () => {
const h = fixture(); const pending = h.api.setAngleFromCurrentHead(h.device);
assert.match(await h.api.setAngleFromCurrentHead(h.device), /already running/);
h.sample(30, 2); h.sample(30, 2); h.sample(30, 2); h.tick(4200);
assert.doesNotMatch(await pending, /Saved/); assert.equal(h.saved.length, 0);
});
test('failure to subscribe releases the IMU lease and allows a later attempt', async () => {
const h = fixture(); h.device.subscribe = () => { throw new Error('offline'); };
assert.match(await h.api.setAngleFromCurrentHead(h.device), /failed/);
assert.equal(h.ended(), 1);
assert.match(await h.api.setAngleFromCurrentHead(null), /Connect/);
});
-23
View File
@@ -1,23 +0,0 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const vm = require('node:vm');
const ts = require('typescript');
test('head-down hides both displays under one option and is never treated as input or wake', async () => {
const source = ts.createSourceFile('controller.ts', fs.readFileSync('app/g2/dashboard-controller.ts', 'utf8'), ts.ScriptTarget.Latest, true);
const cls = source.statements.find(n => ts.isClassDeclaration(n) && n.name?.text === 'DashboardController');
const method = cls.members.find(n => n.name?.getText(source) === 'handleInputEvent').getText(source);
for (const enabled of [false, true]) for (const awake of [false, true]) {
let dismissed = 0, slept = 0, finished = 0;
const context = { exports: {}, OsEventTypeList: { HEAD_DOWN_EVENT: 15 }, headDownHideSetting: { get: () => enabled },
shell: { isScreenOn: () => awake, sleep: () => slept++ }, eventLabel: () => '',
frameTimings: { logFrame() {}, finishFrame() { finished++; } },
rawInputEventToInputEvent() { throw new Error('head-down entered the regular input path'); } };
vm.runInNewContext(ts.transpileModule(`export class Controller { ${method} }`, {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText, context);
const c = new context.exports.Controller(); c.glance = { dismiss: () => dismissed++ };
await c.handleInputEvent({ kind: 'sys-event', eventType: 15, frameId: 42 });
assert.equal(dismissed, enabled ? 1 : 0); assert.equal(slept, enabled && awake ? 1 : 0); assert.equal(finished, 1);
}
});
+1 -14
View File
@@ -15,14 +15,12 @@ function evaluate(code, globals) {
function settings(values = new Map()) {
const file = ts.createSourceFile('settings.ts', source('app/ui/dashboard-settings.ts'), ts.ScriptTarget.Latest, true);
const names = new Set(['ConfigSetting', 'ConfigSettingBoolean', 'ConfigSettingEnum', 'HeadUpWakeSetting',
'headUpWakeSetting', 'headDownHideSetting', 'normalizeHeadUpAngle', 'headUpAngleSetting', 'getHeadUpPreferences']);
'headUpWakeSetting', 'normalizeHeadUpAngle', 'headUpAngleSetting', 'getHeadUpPreferences']);
const code = file.statements.filter(node => names.has(node.name?.text) ||
(ts.isVariableStatement(node) && node.declarationList.declarations.some(d => names.has(d.name.getText(file)))))
.map(node => node.getText(file)).join('\n');
return evaluate(code, {
fixedChoiceSettings: new Map(),
getBooleanSetting: (key, fallback) => values.get(key) ?? fallback,
setBooleanSetting: (key, value) => values.set(key, value),
getStringSetting: (key, fallback) => values.get(key) ?? fallback,
setStringSetting: (key, value) => values.set(key, value),
});
@@ -76,14 +74,3 @@ test('controller skips unset preferences, deduplicates changes and forces reconn
const connect = controller.members.find(node => node.name?.getText(file) === 'connect').getText(file);
assert.match(connect, /pushHeadUpPreferences\(true\)/);
});
test('one shared tilt-down preference defaults off and survives restart independently of head-up', () => {
const values = new Map(); let prefs = settings(values);
assert.equal(prefs.headDownHideSetting.get(), false);
prefs.headDownHideSetting.set(true); prefs = settings(values);
assert.equal(prefs.headDownHideSetting.get(), true);
assert.equal(prefs.getHeadUpPreferences().enabled, -1);
assert.equal(prefs.getHeadUpPreferences().angle, -1);
assert.equal(values.has('glanceboard.headDownHide'), false);
});
-1
View File
@@ -34,7 +34,6 @@ function fixture() {
setTimeout: (fn, ms) => { tasks.set(++nextTask, { fn, at: now + ms }); return nextTask; },
clearTimeout: id => tasks.delete(id), setInterval: () => ++nextTask, clearInterval() {} };
const { GlanceHost } = load('app/g2/glance-host.ts', {
'../ui/dashboard-settings': { headDownHideSetting: { get: () => false } },
'../graphics/image': images, '../graphics/plane': planes,
'../graphics/glyph-wire': { prepareFrameDraws: () => null }, '../native/frame-timings': timings,
'../ui/shell/geometry': { minWindowTop: () => 48 },
@@ -316,41 +316,6 @@ private class Session {
}
class GlassesSessionCoreTest {
@Test fun headDownIsForwardedWithoutCountingAsUserActivity() {
val s = Session()
try {
s.startAndAwaitLayout()
s.core.monitor.withLock { s.core.lastConnectionOrInputAtMs = 1L }
val pb = hex("6a061a04080f1001") // deviceEvent{sysEvent{type=HEAD_DOWN, source=right arm}}
s.core.onNotification(RIGHT, BleProtocol.NOTIFY_CHAR_UUID,
BleProtocol.framePb(pb, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_NOTIFY, 77)[0])
assertTrue(waitUntil(1_000) { s.listener.events.contains("sys-event:15") })
assertEquals(1L, s.core.monitor.withLock { s.core.lastConnectionOrInputAtMs })
} finally { s.core.close() }
}
@Test fun angleMeasurementRestoresLatestApplicationImuRequest() {
val s = Session()
val core = s.core
core.running = true
core.sessionReady = true
try {
core.setImuReportEnabled(true, 100)
assertTrue(core.beginHeadAngleMeasurement())
assertFalse(core.beginHeadAngleMeasurement())
core.setImuReportEnabled(false, 200)
assertEquals("IMU enable", core.pendingMessages.first { it.kind == "imu-control" }.label)
core.endHeadAngleMeasurement()
assertEquals("IMU disable", core.pendingMessages.first { it.kind == "imu-control" }.label)
assertTrue(core.beginHeadAngleMeasurement())
core.setImuReportEnabled(true, 100)
core.endHeadAngleMeasurement()
assertEquals("IMU enable", core.pendingMessages.first { it.kind == "imu-control" }.label)
assertEquals(100, core.imuRequestedPace)
} finally { core.running = false }
}
@Test fun headUpWritesOnlyExplicitFieldsToBothArmsAndResendsAfterReconnect() {
val s = Session()
try {
@@ -1,18 +1,9 @@
package com.faceclaw.app
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull
import kotlin.test.assertContentEquals
class HeadUpProtocolTest {
@Test fun calibrationReadHandlesOmittedZeroSignedValuesAndMissingSettings() {
assertEquals(0, BleProtocol.parseHeadUpCalibration(bytes("22000000")))
assertEquals(12, BleProtocol.parseHeadUpCalibration(bytes("2202480c0000")))
assertEquals(-12, BleProtocol.parseHeadUpCalibration(bytes("220648f4ffffff0f0000")))
assertNull(BleProtocol.parseHeadUpCalibration(bytes("08010000")))
}
private fun bytes(hex: String) = hex.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
@Test fun separateSwitchAndAngleMessagesMatchReferenceWireFormat() {