Compare commits

21 changed files with 308 additions and 163 deletions

No files matched your search

@@ -249,6 +249,8 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre
fun enableWearDetectionAndRequestState() = core.enableWearDetectionAndRequestState()
fun configureHeadUpWake(enabled: Int, angle: Int) = core.configureHeadUpWake(enabled, angle)
fun startBandwidthBenchmark(messageSize: Int, windowSize: Int, durationMs: Int): Boolean =
core.startBandwidthBenchmark(messageSize, windowSize, durationMs)
+18 -1
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, 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,
@@ -296,6 +296,7 @@ class DashboardController {
private silentMode = false;
// Brightness value last pushed to the glasses; see pushBrightness.
private lastPushedBrightness: string | null = null;
private lastPushedHeadUp: string | null = null;
// Last battery level the glasses reported, kept across disconnects so a
// drop-off right after a low reading can be explained as a flat battery.
private lastHeadsetBattery: number | null = null;
@@ -476,6 +477,7 @@ class DashboardController {
// Apply a firmware-debug-flags toggle live while connected (Java dedups).
this.pushFirmwareDebugFlags();
this.pushBrightness();
this.pushHeadUpPreferences();
this.syncEvenHubScreenOffSetting();
// Display mode size first: a reflow repositions every surface too, so
// the band-position check after it then has nothing left to do.
@@ -1084,6 +1086,19 @@ class DashboardController {
});
}
private pushHeadUpPreferences(force = false): void {
if (!global.isAndroid || !this.communicator) return;
const { enabled, angle } = getHeadUpPreferences();
if (enabled < 0 && angle < 0) return;
const value = JSON.stringify({ enabled, angle });
if (!force && value === this.lastPushedHeadUp) return;
this.lastPushedHeadUp = value;
void this.communicator.configureHeadUpWake(enabled, angle).catch(error => {
this.lastPushedHeadUp = null;
this.appendLog(`head-up configuration failed: ${this.formatError(error)}`);
});
}
/** Save the occupied part of the composited screen as a 4-bit grayscale PNG. */
saveScreenshot(): string {
const path = this.display?.saveScreenshot(shell.screenshotCropRect()) ?? "";
@@ -1533,6 +1548,7 @@ class DashboardController {
// ahead of them. Mirrors ensurePreviewDisplay.
await communicator.configureCompositorScreen(G2_LENS_WIDTH, G2_LENS_HEIGHT);
await communicator.configureBrightness(getBrightnessPreferences());
this.pushHeadUpPreferences(true);
this.offState = communicator.onStateChange((state) => {
if (state.phase !== "connected") resetRingInputFilter();
if (isHaltedSessionPhase(state.phase)) {
@@ -1570,6 +1586,7 @@ class DashboardController {
// mode-7 control message once the dashboard container is warmed up.
this.pushFirmwareDebugFlags();
this.pushBrightness(true);
this.pushHeadUpPreferences(true);
this.handRingBackToGlassesIfNeeded();
}
if (mappedPhase !== "connected" && mappedPhase !== "charging") {
+5
View File
@@ -519,6 +519,11 @@ export class FaceclawCommunicatorBridge {
await this.enqueueJavaCall(() => this.communicator.enableWearDetectionAndRequestState());
}
/** -1 leaves a field unchanged. The native session retains explicit values across reconnects. */
async configureHeadUpWake(enabled: number, angle: number): Promise<void> {
await this.enqueueJavaCall(() => this.communicator.configureHeadUpWake(enabled, angle));
}
/** Whether the transport prelude has finished (each arm reports "connected" before it). */
isSessionReady(): boolean {
return Boolean(this.communicator.isSessionReady());
+32 -8
View File
@@ -555,6 +555,38 @@ export const brightnessSetting = new ConfigSettingEnum<BrightnessSetting>({
description: "Auto uses Faceclaw's ambient-light curve; numbers set a fixed level. 2 is the dimmest level.",
});
/** String storage distinguishes an untouched firmware preference from explicit ON/OFF. */
class HeadUpWakeSetting extends ConfigSettingBoolean {
get(): boolean { return getStringSetting(this.storageKey, "true") !== "false"; }
set(value: boolean): boolean { setStringSetting(this.storageKey, String(value)); return value; }
}
export const headUpWakeSetting = new HeadUpWakeSetting({
id: "head-up-wake", label: "Head-up wake", storageKey: "display.headUpWake", defaultValue: true,
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 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)))));
}
export const headUpAngleSetting = new ConfigSettingEnum({
id: "head-up-angle", label: "Head-up angle", storageKey: "display.headUpAngle", defaultValue: "30",
values: Array.from({ length: 61 }, (_, angle) => String(angle)),
normalize: normalizeHeadUpAngle,
formatValue: angle => `${angle}°`,
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. */
export function getHeadUpPreferences(): { enabled: number; angle: number } {
const enabled = getStringSetting("display.headUpWake", "");
const angle = getStringSetting("display.headUpAngle", "");
return { enabled: enabled === "true" ? 1 : enabled === "false" ? 0 : -1,
angle: angle === "" ? -1 : Number(normalizeHeadUpAngle(angle)) };
}
const AUTO_BRIGHTNESS_LEVELS = ["2", "5", "10", "20", "25", "30", "40", "50", "60", "70", "80", "90", "100"] as const;
export const autoBrightnessMinSetting = new ConfigSettingEnum({
id: "autoBrightnessMin", label: "Auto minimum", storageKey: "display.autoBrightnessMin",
@@ -601,14 +633,6 @@ export function getBrightnessPreferences() {
curve: autoBrightnessCurveSetting.getValidValue(), fadeMs: scaleAnimationDuration(SCREEN_FADE_MS, screenFadeSetting.get()) };
}
export const swapMenuGesturesSetting = new ConfigSettingBoolean({
id: "swap-menu-gestures",
label: "Long press for app menu",
storageKey: "input.swapMenuGestures",
defaultValue: false,
description: "Use long press for the app menu and tap then hold for the system menu. Apps using long press for a game action or voice capture keep their gestures. The app switcher keeps its system menu gestures.",
});
export const wakeToLastAppSetting = new ConfigSettingBoolean({
id: "wake-to-last-app",
label: "Wake into last app",
+3 -2
View File
@@ -49,6 +49,8 @@ import {
veniceWebSearchSetting,
batteryDisplayModeSetting,
brightnessSetting,
headUpWakeSetting,
headUpAngleSetting,
autoBrightnessMinSetting,
autoBrightnessMaxSetting,
autoBrightnessCurveSetting,
@@ -89,7 +91,6 @@ import {
voiceProviderSetting,
screenTimeoutSetting,
wakeToLastAppSetting,
swapMenuGesturesSetting,
wakeWordActionSetting,
watchCanUnlockSetting,
watchCrownClockwiseNextSetting,
@@ -119,6 +120,7 @@ function settingsSections(): SettingsSection[] {
// the dashboard controller when changed and on each connect.
enumSettingMenuItem(brightnessSetting),
autoBrightnessMenuItem(),
...(!global.isIOS ? [toggleSettingMenuItem(headUpWakeSetting), enumSettingMenuItem(headUpAngleSetting)] : []),
enumSettingMenuItem(screenTimeoutSetting, {
onChange: () => {
shell.noteUserActivity();
@@ -126,7 +128,6 @@ function settingsSections(): SettingsSection[] {
}),
toggleSettingMenuItem(lockScreenEnabledSetting),
toggleSettingMenuItem(wakeToLastAppSetting),
toggleSettingMenuItem(swapMenuGesturesSetting),
// A band (at one of five heights) / Tall / Full Screen; the
// dashboard controller moves or reflows windows on change.
enumSettingMenuItem(displayLayoutSetting),
+6 -17
View File
@@ -9,7 +9,6 @@ import {
directionalFallback,
type DirectionalInputEvent,
GESTURE_SHORT_THEN_LONG_PRESS,
GESTURE_LONG_PRESS,
gestureHints,
InputEvent,
type InputEventPayload,
@@ -53,7 +52,6 @@ import {
timeFormatSetting,
wakeWordActionSetting,
wakeToLastAppSetting,
swapMenuGesturesSetting,
windowBorderSetting,
} from "../dashboard-settings";
import { onAmbientCardsChanged } from "./ambient-cards";
@@ -1063,15 +1061,7 @@ class Shell {
return { shell: false, window: false };
}
// Remap menu intent only. Apps still receive the canonical context-menu
// event, while owned holds (games / voice) retain their raw input.
const menuWindow = this.foregroundWindow();
const swapMenus = this.focus === "window" && swapMenuGesturesSetting.get() &&
!menuWindow?.holdToTalk && !menuWindow?.claimsLongPress?.();
const systemMenuGesture = swapMenus ? "short-then-long-press" : "long-press";
const appMenuGesture = swapMenus ? "long-press" : "short-then-long-press";
// The resolved system gesture opens the shell's own menu
// Long-press is the shell's own gesture: it opens the system menu
// directly, never reaching the app — over the app's own context menu
// too (the window closes that on system-menu-opened), while an already
// open system menu just stays. Its later generic release is consumed
@@ -1079,7 +1069,7 @@ class Shell {
// app. The exception is a window that claims long-press for a move of
// its own: it gets the press forwarded, with the escape timer running
// so that holding the press long enough still opens the system menu.
if (event.type === systemMenuGesture) {
if (event.type === "long-press") {
if (this.activeVoiceLayer || !this.stack.isAtBase()) {
return { shell: true, window: false };
}
@@ -1101,11 +1091,11 @@ class Shell {
return { shell: true, window: true };
}
// The resolved app-menu gesture is delivered as tap-then-hold: it
// The 2.2.9 tap-then-hold gesture is the app's context-menu gesture: it
// goes to the foreground window (from the sidebar it focuses the window
// first), which answers with its own menu or asks for the system menu
// when it has none.
if (event.type === appMenuGesture) {
if (event.type === "short-then-long-press") {
const window = this.foregroundWindow();
if (window?.holdToTalk) {
this.openEscapeMenu();
@@ -1133,7 +1123,7 @@ class Shell {
window.onFocus?.(this.lastInput);
}
// The window owns frameId from here (render or explicit finish).
await window.handleInput(swapMenus ? { ...event, type: "short-then-long-press" } : event, frameId);
await window.handleInput(event, frameId);
return { shell: true, window: true };
}
if (event.type === "long-press-release") {
@@ -1990,8 +1980,7 @@ class Shell {
// when the app has one (otherwise it opens this very menu, not worth a
// hint).
const footer = foreground.hasAppMenu?.()
? (foreground.holdToTalk ? undefined : gestureHints([[this.focus === "window" && swapMenuGesturesSetting.get() && !foreground.claimsLongPress?.()
? GESTURE_LONG_PRESS : GESTURE_SHORT_THEN_LONG_PRESS, "app menu"]]))
? (foreground.holdToTalk ? undefined : gestureHints([[GESTURE_SHORT_THEN_LONG_PRESS, "app menu"]]))
: undefined;
const layer = new ShellOverlayMenuLayer(items, footer, () => this.yieldFocusToSidebar());
layer.selectItem(initialSelection);
+5 -7
View File
@@ -1,4 +1,3 @@
import { swapMenuGesturesSetting } from "./dashboard-settings";
import { GrayImage } from "../graphics/image";
import { singlePlane, type Plane } from "../graphics/plane";
import { GESTURE_LONG_PRESS, GESTURE_SHORT_THEN_LONG_PRESS, gestureHints, type InputEvent } from "./gestures";
@@ -7,9 +6,8 @@ import { CONTEXT_MENU_DIM, MenuLayer, type MenuItem, type MenuLayout } from "./m
import type { WorkerAppReply } from "./shell/worker-window";
/**
* The window context menu, opened by tap-then-hold by default: an app's own menu,
* holding its app-specific actions. The menu gesture preference can swap
* these bindings unless the app owns long-press. The shell's system menu
* The window context menu, opened by tap-then-hold: an app's own menu,
* holding its app-specific actions. The shell's system menu (long-press)
* carries the entries every window shares — Focus app switcher, Voice input,
* Close window — so an app with nothing of its own to offer has no menu of
* its own: tap-then-hold then opens the system menu in its place, so both
@@ -30,8 +28,8 @@ export const WINDOW_MENU_LAYOUT: MenuLayout = {
};
export class WindowMenuLayer extends MenuLayer {
constructor(title: string | null, items: MenuItem[], holdToTalk = false, claimsLongPress = false) {
super(title, items, (holdToTalk || (swapMenuGesturesSetting.get() && !claimsLongPress))
constructor(title: string | null, items: MenuItem[], holdToTalk = false) {
super(title, items, holdToTalk
? { ...WINDOW_MENU_LAYOUT, footer: gestureHints([[GESTURE_SHORT_THEN_LONG_PRESS, "system menu"]]) }
: WINDOW_MENU_LAYOUT);
}
@@ -125,7 +123,7 @@ export class WindowMenu {
handleInput: () => {},
};
const stack = new LayerStack(base, this.layerActions(), this.options.size, this.options.isFocused);
const layer = new WindowMenuLayer(title, items, false, this.options.claimsLongPress?.() ?? false);
const layer = new WindowMenuLayer(title, items);
if (selectedIndex !== undefined) layer.selectItem(selectedIndex);
stack.push(layer);
this.stack = stack;
+53
View File
@@ -0,0 +1,53 @@
# Head-up wake: software and hardware validation
The Android Display settings now contain “Head-up wake” and “Head-up angle”.
Glanceboard's “Show on head tilt” still only chooses which UI appears on wake.
Protocol reference: [OpenG2 Companion G2Protocol.swift](https://github.com/mmirman/open-g2-companion/blob/1400d1006ba045379a3ff34d0832add6fa10ced4/modules/ffs-ble/ios/G2Protocol.swift),
`setHeadUpSwitch` / `setHeadUpAngle`; dispatch to both lenses in
[`G2Central.swift`](https://github.com/mmirman/open-g2-companion/blob/1400d1006ba045379a3ff34d0832add6fa10ced4/modules/ffs-ble/ios/G2Central.swift).
Wire format uses Faceclaw's UI-settings sid 0x09, request flag, command 1, transaction
magic, device-receive-info field 3 / head-up field 4. Switch (field 1) and
angle (field 2) are sent in separate messages, including explicit zero values.
Angles are clamped to the reference's 0–60 degree range. No firmware patch,
firmware download or flash is needed by this implementation.
Untouched installations send neither field. The UI describes this inherited
state; its displayed ON/30 degree fallback is not a read-back of device state.
Changing just one control preserves the other device field. Explicit choices
are persisted in the existing settings store and resent on every connection.
The native session also retains them through transport reconnects and retries
after setting ACK timeouts. ACK reception confirms transport, not physical wake.
Software checks:
- `tests/head-up-wake.test.cjs`: persistence, untouched fields, angle bounds,
independence from Glanceboard, deduplication, reconnect and error recovery.
- `HeadUpProtocolTest`: byte-for-byte settings messages, including OFF and 0°.
- `GlassesSessionCoreTest`: both lenses, separate writes, pre-existing device
settings preserved, angle clamp and automatic transport reconnection.
Hardware validation: **pending**. Implementation was requested without device
access; protocol compatibility and physical effect on the target Faceclaw CFW
are not established by these software tests. The reference targets stock
2.2.6.10, while this repository normally uses newer Faceclaw firmware.
Source inspection of [Faceclaw's gesture forwarding](https://github.com/jimrandomh/g2flash/blob/845f665e0dfdcfd06b7d3a294388de6f17a5bd59/patches/gesture_fwd.c)
confirms that head-up/down forwarding while a page owns the screen checks the
stock `head_up_switch`. This supports using the existing setting rather than a
firmware patch, but does not establish the physical angle or wake behavior.
On the target glasses, record both lens firmware versions and test:
1. Leave preferences untouched and verify prior wake behavior remains unchanged.
2. Disable Head-up wake; sleep the display, raise the head repeatedly, and confirm
no wake. Check taps still wake normally.
3. Enable it and compare 0°, 30° and 60° trigger angles. Confirm other wake
gestures remain usable, including at the extreme values.
4. Reconnect Bluetooth, then restart the phone app; repeat ON/OFF and angle checks.
5. Toggle Glanceboard and “Show on head tilt” independently; disabled wake should
stay disabled, enabled wake should show the selected UI.
6. Check both lenses remain synchronized, including reconnecting only one arm.
Do not change firmware to run these checks without explicit permission.
-9
View File
@@ -1,9 +0,0 @@
# Configurable menu gestures
Settings > Display > Long press for app menu is off by default, preserving existing installations. When enabled with an app focused, long press opens its context menu and tap then hold opens the system menu. The preference uses the existing ConfigSettingBoolean/settings store and takes effect on subsequent input without restarting.
Windows claiming long press retain that input, their existing tap-then-hold app menu and the extended-hold system escape. Hold-to-talk windows retain voice capture and tap-then-hold for the system menu. The app switcher retains its existing bindings. Empty app menus continue to fall back to the system menu. The shell delivers the canonical tap-then-hold context-menu event to apps, so worker and EvenHub input contracts do not change. Menu gesture hints follow the preference and exceptions.
Software validation: TypeScript and changed-source lint; full JavaScript suite (1072 passed, 2 skipped on the independent branch). Routing tests cover both mappings, overlay switching, input metadata, dynamic hold ownership, switcher behavior and screen-off input. Persistence tests cover default, enabled and disabled values after store reload. App-menu hint tests cover owned holds and voice capture.
Hardware validation remains pending: test both bindings on the glasses/ring, app-specific holds, voice release, extended-hold escape, switching menus, app switcher, and restart. No firmware was flashed.
@@ -497,6 +497,23 @@ class BleProtocol {
)
}
/** Stock HeadUpSetting: switch and angle are separate oneof writes (field 4 of device info). */
@JvmStatic
fun buildSetHeadUpWake(magic: Int, enabled: Boolean): ByteArray = concat(
CollectionUtils.listOf(
encodeVarintField(1, 1), encodeVarintField(2, magic),
encodeMessageField(3, encodeMessageField(4, encodeVarintField(1, if (enabled) 1 else 0))),
)
)
@JvmStatic
fun buildSetHeadUpAngle(magic: Int, angle: Int): ByteArray = concat(
CollectionUtils.listOf(
encodeVarintField(1, 1), encodeVarintField(2, magic),
encodeMessageField(3, encodeMessageField(4, encodeVarintField(2, angle.coerceIn(0, 60)))),
)
)
/** Enable the firmware's wear detector (DeviceReceiveInfoFromAPP field 5). */
@JvmStatic
fun buildSetWearDetection(magic: Int, enabled: Boolean): ByteArray {
@@ -188,6 +188,17 @@ class MessageBuilder {
)
}
fun headUpControl(leftArm: Boolean, enabled: Boolean?, angle: Int): OutboundMessage {
val magic = magicPool.allocate()
return OutboundMessage(
"head-up-control", if (enabled == null) "head-up angle=$angle" else "head-up wake=$enabled",
BleProtocol.SID_UI_SETTING, BleProtocol.FLAG_REQUEST, magic,
if (enabled == null) BleProtocol.buildSetHeadUpAngle(magic, angle)
else BleProtocol.buildSetHeadUpWake(magic, enabled),
ACK_TIMEOUT_MS, -1, leftArm,
)
}
fun createLayout(): OutboundMessage {
var magic: Int = magicPool.allocate()
return OutboundMessage(
@@ -304,6 +304,8 @@ class GlassesSessionCore(
internal var brightnessSentLevel = -1
internal var brightnessAlsStartedAt = -2000L
internal var brightnessDemoPolling = false
internal var headUpPreferences: Pair<Int, Int>? = null
internal var headUpSent: Pair<Int, Int>? = null
internal var cfwCleanupDelivered = false
internal var lastCfwCleanupAckMagic = 0
@@ -920,6 +922,15 @@ class GlassesSessionCore(
interruptibleSleep.interrupt()
}
/** Explicit preferences only; -1 leaves the corresponding firmware field alone. */
fun configureHeadUpWake(enabled: Int, angle: Int) {
require(enabled in -1..1)
monitor.withLock {
headUpPreferences = Pair(enabled, if (angle < 0) -1 else angle.coerceIn(0, 60))
}
interruptibleSleep.interrupt()
}
/**
* Enable the stock wear detector, then ask CFW to emit its current cached
* state. The queue order matters: the query must run after the setting is
@@ -2232,6 +2243,7 @@ class GlassesSessionCore(
shutdownRequested = false
fixedLayoutCreated = false
clearAllMessagesLocked("session ready")
headUpSent = null
displayedFingerprint = ""
lastAckAtMs = now()
lastIncomingAtMs = lastAckAtMs
@@ -0,0 +1,22 @@
package com.faceclaw.app
/** Both arms receive separate stock settings messages; no CFW changes required. */
internal fun GlassesSessionCore.enqueueHeadUpPreferencesLocked() {
val desired = headUpPreferences ?: return
if (!sessionReady || shutdownRequested || chargingMode || headUpSent == desired
|| hasPendingOrInflightKindLocked("head-up-control")) return
for (leftArm in listOf(true, false)) {
// Set the angle before enabling wake. Omitted fields preserve device preferences.
if (desired.second >= 0) {
val message = messageBuilder.headUpControl(leftArm, null, desired.second)
message.onTimeout = MessageCallback { headUpSent = null; logLine("head-up angle ack timeout") }
pendingMessages.addLast(message)
}
if (desired.first >= 0) {
val message = messageBuilder.headUpControl(leftArm, desired.first == 1, -1)
message.onTimeout = MessageCallback { headUpSent = null; logLine("head-up wake ack timeout") }
pendingMessages.addLast(message)
}
}
headUpSent = desired
}
@@ -74,6 +74,7 @@ internal fun GlassesSessionCore.driveSession(): Long {
clearPendingMessagesLocked("after CFW cleanup")
return 250
}
enqueueHeadUpPreferencesLocked()
if (sessionReady
&& now - lastFaceclawFramebufferLeaseQueuedAtMs >= FACECLAW_WAKE_LEASE_RENEW_MS
&& !hasPendingOrInflightKindLocked("framebuffer-lease-control")) {
+1 -1
View File
@@ -266,7 +266,7 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
handleInput(event, ctx) { if (event.type === 'double-click') ctx.stack.pop(); }
}
const voiceDialogs = [];
const settings = { swapMenuGesturesSetting: { get: () => false }, wakeWordActionSetting: { get: () => wakeAction }, brightnessSetting: { get: () => 'auto' },
const settings = { wakeWordActionSetting: { get: () => wakeAction }, brightnessSetting: { get: () => 'auto' },
assistantSkipConfirmationSetting: { get: () => skipConfirmation } };
const { shell, rawInputEventToInputEvent } = load('app/ui/shell/shell.ts', {
'../../graphics/shell-scene': { encodeShellScene: () => new Uint8Array([0, 0]) },
-11
View File
@@ -59,14 +59,3 @@ test('curve drafts preview exactly while brightness keeps the previous valid sav
assert.equal(curve.validationError(), null);
assert.equal(api.getBrightnessPreferences().curve, '0:0,2:50,6:100');
});
test('menu gesture preference preserves defaults and survives restart in either state', () => {
const store = new Map();
let api = settingsFixture(store);
assert.equal(api.swapMenuGesturesSetting.get(), false);
api.swapMenuGesturesSetting.set(true);
api = settingsFixture(store);
assert.equal(api.swapMenuGesturesSetting.get(), true);
api.swapMenuGesturesSetting.set(false);
assert.equal(settingsFixture(store).swapMenuGesturesSetting.get(), false);
});
-1
View File
@@ -39,7 +39,6 @@ const menu = load('app/ui/menu.ts', {
function fixture(initial = '50', viewport = { x: 64, y: 124, width: 576, height: 260 }) {
let value = initial, writes = 0, closed = 0;
const settings = {
swapMenuGesturesSetting: { get: () => false },
brightnessSetting: { get: () => value, set: (next) => { value = next; writes++; } },
brightnessSettingToLevel: (value) => value === 'auto' ? null : Number(value),
};
+76
View File
@@ -0,0 +1,76 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
const source = file => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
function evaluate(code, globals) {
const context = { exports: {}, ...globals };
vm.runInNewContext(ts.transpileModule(code, {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText, context);
return context.exports;
}
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', '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(),
getStringSetting: (key, fallback) => values.get(key) ?? fallback,
setStringSetting: (key, value) => values.set(key, value),
});
}
test('head-up preferences preserve untouched device fields and persist each explicit choice separately', () => {
const values = new Map();
let prefs = settings(values);
assert.equal(prefs.getHeadUpPreferences().enabled, -1);
assert.equal(prefs.getHeadUpPreferences().angle, -1);
prefs.headUpWakeSetting.set(false);
prefs = settings(values);
assert.equal(prefs.headUpWakeSetting.get(), false);
assert.equal(prefs.getHeadUpPreferences().enabled, 0);
assert.equal(prefs.getHeadUpPreferences().angle, -1);
prefs.headUpAngleSetting.set('75');
prefs = settings(values);
assert.equal(prefs.headUpAngleSetting.get(), '60');
assert.equal(prefs.getHeadUpPreferences().enabled, 0);
assert.equal(prefs.getHeadUpPreferences().angle, 60);
for (const [input, expected] of [['-5', '0'], ['20.8', '21'], ['NaN', '30'], ['', '30']]) {
assert.equal(prefs.headUpAngleSetting.set(input), expected);
}
assert.equal(values.has('glanceboard.showOnHeadTilt'), false);
});
test('controller skips unset preferences, deduplicates changes and forces reconnect synchronization', async () => {
const file = ts.createSourceFile('controller.ts', source('app/g2/dashboard-controller.ts'), ts.ScriptTarget.Latest, true);
const controller = file.statements.find(node => ts.isClassDeclaration(node) && node.name.text === 'DashboardController');
const method = controller.members.find(node => node.name?.getText(file) === 'pushHeadUpPreferences').getText(file);
let prefs = { enabled: -1, angle: -1 };
const { Harness } = evaluate(`export class Harness { ${method} }`, {
global: { isAndroid: true }, getHeadUpPreferences: () => prefs,
});
const h = new Harness(), calls = [];
h.communicator = { configureHeadUpWake: async (...args) => calls.push(args) };
h.pushHeadUpPreferences(); assert.equal(calls.length, 0);
prefs = { enabled: 0, angle: 25 };
h.pushHeadUpPreferences(); h.pushHeadUpPreferences();
assert.deepEqual(calls, [[0, 25]]);
h.pushHeadUpPreferences(true); assert.equal(calls.length, 2);
prefs = { enabled: 1, angle: 40 }; h.pushHeadUpPreferences();
assert.deepEqual(calls.at(-1), [1, 40]);
let failures = 0;
h.communicator.configureHeadUpWake = async () => { throw new Error('offline'); };
h.appendLog = () => failures++;
h.formatError = error => error.message;
h.pushHeadUpPreferences(true);
await new Promise(resolve => setImmediate(resolve));
assert.equal(h.lastPushedHeadUp, null); assert.equal(failures, 1);
const connect = controller.members.find(node => node.name?.getText(file) === 'connect').getText(file);
assert.match(connect, /pushHeadUpPreferences\(true\)/);
});
@@ -316,6 +316,33 @@ private class Session {
}
class GlassesSessionCoreTest {
@Test fun headUpWritesOnlyExplicitFieldsToBothArmsAndResendsAfterReconnect() {
val s = Session()
try {
s.startAndAwaitLayout()
fun writes() = s.link.writes.filter { it.kind == "head-up-control" }
assertEquals(0, writes().size, "untouched firmware preferences must not be written")
s.core.configureHeadUpWake(0, 30)
assertTrue(waitUntil(5_000) { writes().size == 4 })
for (arm in listOf(LEFT, RIGHT)) {
val commands = writes().filter { it.address == arm }
assertContentEquals(BleProtocol.buildSetHeadUpAngle(commands[0].magic, 30), commands[0].pb)
assertContentEquals(BleProtocol.buildSetHeadUpWake(commands[1].magic, false), commands[1].pb)
}
s.core.handleTransportFailure("head-up reconnect test")
assertTrue(waitUntil(5_000) { !s.layoutCreated() })
s.platform.offsetMs += 10_000
s.core.interruptibleSleep.interrupt()
assertTrue(waitUntil(5_000) { s.layoutCreated() && writes().size == 8 }, s.host.logs().takeLast(10).toString())
s.core.configureHeadUpWake(-1, 100)
assertTrue(waitUntil(5_000) { writes().size == 10 })
assertTrue(writes().takeLast(2).all { it.label == "head-up angle=60" })
s.core.configureHeadUpWake(1, -1)
assertTrue(waitUntil(5_000) { writes().size == 12 })
assertTrue(writes().takeLast(2).all { it.label == "head-up wake=true" })
} finally { s.core.close() }
}
@Test fun brightnessConfigPrecedesFirstFrameAndSleepWakeFollowsComposites() {
val s = Session()
s.core.configureBrightness(false, 70, 2, 100, "0:0,1000:100", 280)
@@ -0,0 +1,17 @@
package com.faceclaw.app
import kotlin.test.Test
import kotlin.test.assertContentEquals
class HeadUpProtocolTest {
private fun bytes(hex: String) = hex.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
@Test fun separateSwitchAndAngleMessagesMatchReferenceWireFormat() {
// G2SettingPackage{1=1, 2=magic, 3={4=HeadUpSetting{1=switch | 2=angle}}}.
assertContentEquals(bytes("080110071a0422020800"), BleProtocol.buildSetHeadUpWake(7, false))
assertContentEquals(bytes("080110071a0422020801"), BleProtocol.buildSetHeadUpWake(7, true))
assertContentEquals(bytes("080110071a042202101e"), BleProtocol.buildSetHeadUpAngle(7, 30))
assertContentEquals(bytes("080110071a0422021000"), BleProtocol.buildSetHeadUpAngle(7, -10))
assertContentEquals(bytes("080110071a042202103c"), BleProtocol.buildSetHeadUpAngle(7, 100))
}
}
-106
View File
@@ -1,106 +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(swap = false, app = {}) {
const source = ts.createSourceFile('shell.ts', fs.readFileSync('app/ui/shell/shell.ts', 'utf8'), ts.ScriptTarget.Latest, true);
const cls = source.statements.find(n => ts.isClassDeclaration(n) && n.name.text === 'Shell');
const route = cls.members.find(n => n.name?.getText(source) === 'routeInput');
class Overlay {}
const context = { exports: {}, ShellOverlayMenuLayer: Overlay,
swapMenuGesturesSetting: { get: () => swap }, isWatchInput: () => false };
vm.runInNewContext(ts.transpileModule(`export class Shell { ${route.getText(source)} }`, {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText, context);
const s = new context.exports.Shell();
const delivered = [];
const window = { handleInput: async e => delivered.push(e), hasAppMenu: () => true, ...app };
let overlay = false, escapes = 0;
Object.assign(s, { focus: 'window', screenOn: true, lastInput: null,
foregroundWindow: () => window, cancelEscapeMenuTimer() {},
startEscapeMenuTimer() { escapes++; }, config: { requestShellRender() {} },
openEscapeMenu() { overlay = true; },
stack: { isAtBase: () => !overlay, popIfTop(fn) { if (overlay && fn(new Overlay())) { overlay = false; return true; } return false; } },
});
return { s, delivered, setSwap: value => { swap = value; }, overlay: () => overlay, escapes: () => escapes,
input: type => s.routeInput({ type, source: 'ring', timestampMs: 42 }, 17) };
}
for (const swap of [false, true]) {
test(`menu routing, overlay switching and metadata with inversion ${swap}`, async () => {
const h = fixture(swap);
const system = swap ? 'short-then-long-press' : 'long-press';
const app = swap ? 'long-press' : 'short-then-long-press';
await h.input(app);
assert.equal(h.delivered.at(-1).type, 'short-then-long-press');
assert.equal(h.delivered.at(-1).source, 'ring');
assert.equal(h.delivered.at(-1).timestampMs, 42);
await h.input(system);
assert.equal(h.overlay(), true);
await h.input(app);
assert.equal(h.overlay(), false);
assert.equal(h.delivered.length, 2);
});
for (const app of [{ claimsLongPress: () => true }, { holdToTalk: true }]) {
test(`owned long press remains intact with inversion ${swap}: ${JSON.stringify(Object.keys(app))}`, async () => {
const h = fixture(swap, app);
await h.input('long-press');
assert.equal(h.delivered[0].type, 'long-press');
assert.equal(h.escapes(), app.holdToTalk ? 0 : 1);
await h.input('short-then-long-press');
if (app.holdToTalk) assert.equal(h.overlay(), true);
else assert.equal(h.delivered[1].type, 'short-then-long-press');
});
}
}
test('gesture inversion never wakes a sleeping screen', async () => {
const h = fixture(true); h.s.screenOn = false;
await h.input('long-press'); await h.input('short-then-long-press');
assert.equal(h.delivered.length, 0); assert.equal(h.overlay(), false);
});
test('the switcher retains its existing gestures when inversion is enabled', async () => {
for (const type of ['long-press', 'short-then-long-press']) {
const snapshots = [];
for (const swap of [false, true]) {
const h = fixture(swap); h.s.focus = 'sidebar';
await h.input(type);
snapshots.push({ overlay: h.overlay(), delivered: h.delivered.map(e => e.type) });
}
assert.deepEqual(snapshots[0], snapshots[1]);
}
});
test('the setting applies immediately and follows changing app hold ownership', async () => {
let claims = false;
const h = fixture(false, { claimsLongPress: () => claims });
h.setSwap(true);
await h.input('long-press');
assert.equal(h.delivered.at(-1).type, 'short-then-long-press');
claims = true;
await h.input('long-press');
assert.equal(h.delivered.at(-1).type, 'long-press');
claims = false;
await h.input('long-press');
assert.equal(h.delivered.at(-1).type, 'short-then-long-press');
});
test('app menu hints reflect inversion, voice capture and owned holds', () => {
const source = ts.createSourceFile('window-menu.ts', fs.readFileSync('app/ui/window-menu.ts', 'utf8'), ts.ScriptTarget.Latest, true);
const cls = source.statements.find(n => ts.isClassDeclaration(n) && n.name.text === 'WindowMenuLayer');
let swap = false;
const context = { exports: {}, MenuLayer: class { constructor(_title, _items, layout) { this.layout = layout; } },
WINDOW_MENU_LAYOUT: { footer: 'long-press' }, GESTURE_SHORT_THEN_LONG_PRESS: 'tap-hold',
swapMenuGesturesSetting: { get: () => swap }, gestureHints: hints => hints[0][0] };
vm.runInNewContext(ts.transpileModule(cls.getText(source), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText, context);
const hint = (voice = false, claims = false) => new context.exports.WindowMenuLayer('App', [], voice, claims).layout.footer;
assert.equal(hint(), 'long-press');
swap = true;
assert.equal(hint(), 'tap-hold');
assert.equal(hint(false, true), 'long-press');
assert.equal(hint(true), 'tap-hold');
});