mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe87e75fc2
|
||
|
|
f029e3ce91
|
||
|
|
5929259d84
|
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)
|
||||
|
||||
|
||||
@@ -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,
|
||||
@@ -121,7 +121,6 @@ export type DashboardSnapshot = {
|
||||
* glasses, and this says which harmless thing is actually going on.
|
||||
*/
|
||||
displayPreviewMessage: string;
|
||||
silentModeFeedback: string;
|
||||
activeTextSettingId: string | null;
|
||||
activeTextEditorTitle: string;
|
||||
activeTextSettingTitle: string;
|
||||
@@ -295,11 +294,9 @@ class DashboardController {
|
||||
/** The screen area displayPreview shows (Preview scaling), or null for the whole panel. */
|
||||
private displayPreviewCrop: ScreenRect | null = null;
|
||||
private silentMode = false;
|
||||
private silentModeFeedback = "";
|
||||
private silentModeFeedbackGeneration = 0;
|
||||
private silentModeFeedbackTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
// 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;
|
||||
@@ -480,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.
|
||||
@@ -1088,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()) ?? "";
|
||||
@@ -1146,7 +1157,6 @@ class DashboardController {
|
||||
status: this.status,
|
||||
displayPreview: this.displayPreview,
|
||||
displayPreviewMessage: this.displayPreviewMessage(),
|
||||
silentModeFeedback: this.silentModeFeedback,
|
||||
activeTextSettingId: primaryTextSetting?.id ?? null,
|
||||
activeTextEditorTitle: this.activeTextEditorTitle,
|
||||
activeTextSettingTitle: primaryTextSetting?.editorTitle ?? "",
|
||||
@@ -1186,43 +1196,6 @@ class DashboardController {
|
||||
* charging and silent mode both make the display unavailable while BLE stays
|
||||
* up, and a battery that just ran out simply stops answering.
|
||||
*/
|
||||
private handleSilentMode(silent: boolean): void {
|
||||
if (this.silentMode === silent) return;
|
||||
this.silentMode = silent;
|
||||
const generation = ++this.silentModeFeedbackGeneration;
|
||||
if (this.silentModeFeedbackTimer !== null) clearTimeout(this.silentModeFeedbackTimer);
|
||||
this.silentModeFeedbackTimer = null;
|
||||
this.silentModeFeedback = silent
|
||||
? "Silent mode enabled — hold both touchpads to exit"
|
||||
: "Silent mode disabled";
|
||||
if (!silent) {
|
||||
void this.showSilentModeExit(generation).catch(error => {
|
||||
this.appendLog(`silent-mode exit feedback failed: ${this.formatError(error)}`);
|
||||
});
|
||||
this.silentModeFeedbackTimer = setTimeout(() => {
|
||||
this.silentModeFeedbackTimer = null;
|
||||
this.silentModeFeedback = "";
|
||||
this.emit();
|
||||
}, 5000);
|
||||
}
|
||||
this.emit();
|
||||
}
|
||||
|
||||
private async showSilentModeExit(generation: number): Promise<void> {
|
||||
if (this.phase !== "connected" || this.silentMode || this.glassesLocked) return;
|
||||
// The firmware powered the lenses down, and Faceclaw may have gone to
|
||||
// sleep/suspended EvenHub meanwhile. Reusing the ordinary wake barrier is
|
||||
// essential: rendering an alert into the retained surface alone is invisible.
|
||||
this.cancelEvenHubSuspendTimer();
|
||||
shell.wake("sidebar");
|
||||
const ready = await this.ensureEvenHubSessionActive();
|
||||
if (!ready || generation !== this.silentModeFeedbackGeneration || this.silentMode ||
|
||||
this.phase !== "connected" || this.glassesLocked) return;
|
||||
shell.showAlert("Silent mode disabled");
|
||||
shell.foregroundWindow()?.requestRender();
|
||||
this.requestShellRender();
|
||||
}
|
||||
|
||||
private displayPreviewMessage(): string {
|
||||
if (this.phase === "charging") {
|
||||
return chargingPreviewMessage(this.glassesDisplayState());
|
||||
@@ -1575,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)) {
|
||||
@@ -1612,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") {
|
||||
@@ -1646,7 +1621,9 @@ class DashboardController {
|
||||
});
|
||||
});
|
||||
this.offSilentMode = communicator.onSilentMode((silent) => {
|
||||
this.handleSilentMode(silent);
|
||||
if (this.silentMode === silent) return;
|
||||
this.silentMode = silent;
|
||||
this.emit();
|
||||
});
|
||||
this.offWearState = communicator.onWearState((wearing) => {
|
||||
this.handleWearState(wearing);
|
||||
@@ -3024,10 +3001,6 @@ class DashboardController {
|
||||
// Kept across "connecting": silent mode blocks app launches, so it can
|
||||
// itself cause the reconnect churn, and Java re-reports it either way.
|
||||
this.silentMode = false;
|
||||
this.silentModeFeedbackGeneration++;
|
||||
if (this.silentModeFeedbackTimer !== null) clearTimeout(this.silentModeFeedbackTimer);
|
||||
this.silentModeFeedbackTimer = null;
|
||||
this.silentModeFeedback = "";
|
||||
}
|
||||
this.emit();
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -74,9 +74,6 @@
|
||||
class="ble-bandwidth-indicator"
|
||||
horizontalAlignment="center"
|
||||
verticalAlignment="bottom" />
|
||||
<Label text="{{ silentModeFeedback }}" visibility="{{ silentModeFeedbackVisibility }}"
|
||||
textWrap="true" horizontalAlignment="center" verticalAlignment="top"
|
||||
margin="12" padding="12" backgroundColor="#333333" color="white" borderRadius="8" />
|
||||
<ScrollView
|
||||
class="warnings-modal"
|
||||
visibility="{{ warningsModalVisibility }}"
|
||||
|
||||
@@ -37,7 +37,6 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
private _status = "Disconnected.";
|
||||
private _displayPreview: ImageSource | null = null;
|
||||
private _displayPreviewMessage = "";
|
||||
private _silentModeFeedback = "";
|
||||
private _layoutOrientation: LayoutOrientation = this.readLayoutOrientation();
|
||||
private _landscapePreviewWidth = 0;
|
||||
private _landscapePreviewHeight = 0;
|
||||
@@ -91,7 +90,6 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
this.previewMode = snapshot.previewMode;
|
||||
this.displayPreview = snapshot.displayPreview;
|
||||
this.displayPreviewMessage = snapshot.displayPreviewMessage;
|
||||
this.silentModeFeedback = snapshot.silentModeFeedback ?? "";
|
||||
this.phase = snapshot.phase;
|
||||
this.batteryLine = formatBatteryLine(
|
||||
snapshot.batteries,
|
||||
@@ -218,17 +216,6 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
get silentModeFeedback(): string { return this._silentModeFeedback; }
|
||||
set silentModeFeedback(value: string) {
|
||||
if (this._silentModeFeedback === value) return;
|
||||
this._silentModeFeedback = value;
|
||||
this.notifyPropertyChange("silentModeFeedback", value);
|
||||
this.notifyPropertyChange("silentModeFeedbackVisibility", this.silentModeFeedbackVisibility);
|
||||
}
|
||||
get silentModeFeedbackVisibility(): "visible" | "collapse" {
|
||||
return this._silentModeFeedback ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get hasDisplayPreview(): boolean {
|
||||
return this._displayPreview !== null;
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -49,6 +49,8 @@ import {
|
||||
veniceWebSearchSetting,
|
||||
batteryDisplayModeSetting,
|
||||
brightnessSetting,
|
||||
headUpWakeSetting,
|
||||
headUpAngleSetting,
|
||||
autoBrightnessMinSetting,
|
||||
autoBrightnessMaxSetting,
|
||||
autoBrightnessCurveSetting,
|
||||
@@ -118,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();
|
||||
|
||||
@@ -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.
|
||||
@@ -1,11 +0,0 @@
|
||||
# Silent-mode feedback
|
||||
|
||||
The firmware blanks the lenses and stops ordinary input while silent mode is active. App code cannot display an activation popup on lenses that the firmware has switched off. The phone now shows a persistent enabled banner with the exit gesture, and a five-second disabled banner on exit. On exit, unlocked glasses wake through the normal screen/EvenHub barrier before the alert popup is rendered. This also handles the shell falling asleep during a long silent period. Locked glasses keep the phone feedback without being woken. A generation check suppresses stale notices after re-entry or disconnect. Duplicate state reports do not repeat feedback, stale timers are cancelled, and disconnect clears the notice.
|
||||
|
||||
Silent-off firmware pushes are not reliable. The existing fallback read used the five-minute battery cadence. While silent mode is known to be on, settings are now polled every two seconds when the session is ready and the message queues are idle. Normal battery cadence and shutdown guards are retained. This bounds ordinary missing-push recovery without assuming a touch gesture always means silent mode ended.
|
||||
|
||||
Independent JavaScript suite: 1065 passed, 2 skipped. TypeScript and changed-source lint passed. Controller tests cover enabled/disabled notices, duplicates, timer cancellation, disconnect and sleeping-display recovery, locked displays, wake-barrier failure and stale async completion. A Kotlin session test checks the two-second silent cadence, normal cadence and shutdown guard. Kotlin compilation and hardware checks are tracked with the combined integration validation.
|
||||
|
||||
Hardware validation remains pending: both transitions via the temple gesture, missing exit push, phone background/foreground, lenses that are awake/asleep/locked, reconnect and charging. No firmware was flashed.
|
||||
|
||||
Follow-up after device-log inspection: both silent transitions arrived, but the exit could occur after the normal idle timeout. Exit now cancels pending suspension, wakes the shell, awaits the existing EvenHub/screen wake barrier and only then shows the notice. It resets idle activity through the ordinary wake path. Re-entry, disconnect, locking or a failed resume suppress stale asynchronous notices. Activation still turns the lenses off in firmware; phone feedback does not claim a lens-side activation popup.
|
||||
@@ -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 {
|
||||
|
||||
-2
@@ -37,8 +37,6 @@ class ConnectionOptions {
|
||||
const val HEARTBEAT_FAILURE_DEADLINE_MS = 10_000
|
||||
const val HEARTBEAT_READY_MS = 4_000
|
||||
const val HEARTBEAT_URGENT_MS = 6_000
|
||||
// Silent-off pushes are not reliable; promptly re-read the state while silent.
|
||||
const val SILENT_MODE_POLL_MS = 2_000
|
||||
const val BATTERY_REFRESH_INTERVAL_MS = 5 * 60_000
|
||||
const val BATTERY_INPUT_QUIET_MS = 5_000
|
||||
// Poll cadence while in charging mode; also bounds how quickly we notice
|
||||
|
||||
+11
@@ -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(
|
||||
|
||||
+12
@@ -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
|
||||
|
||||
+22
@@ -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
|
||||
}
|
||||
+3
-3
@@ -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")) {
|
||||
@@ -1041,9 +1042,8 @@ internal fun GlassesSessionCore.shouldPollBatteryLocked(now: Long): Boolean {
|
||||
&& sessionReady
|
||||
&& pendingMessages.isEmpty()
|
||||
&& inFlightMessages.isEmpty()
|
||||
&& (silentMode == 1 || now - lastConnectionOrInputAtMs >= ConnectionOptions.BATTERY_INPUT_QUIET_MS)
|
||||
&& (lastBatteryRefreshAtMs == 0L || now - lastBatteryRefreshAtMs >=
|
||||
if (silentMode == 1) ConnectionOptions.SILENT_MODE_POLL_MS else ConnectionOptions.BATTERY_REFRESH_INTERVAL_MS)
|
||||
&& now - lastConnectionOrInputAtMs >= ConnectionOptions.BATTERY_INPUT_QUIET_MS
|
||||
&& (lastBatteryRefreshAtMs == 0L || now - lastBatteryRefreshAtMs >= ConnectionOptions.BATTERY_REFRESH_INTERVAL_MS)
|
||||
}
|
||||
|
||||
internal fun GlassesSessionCore.createBatteryQueryMessageLocked(): OutboundMessage {
|
||||
|
||||
@@ -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,22 +316,31 @@ private class Session {
|
||||
}
|
||||
|
||||
class GlassesSessionCoreTest {
|
||||
@Test fun silentModePollsPromptlyWithoutChangingNormalBatteryCadence() {
|
||||
@Test fun headUpWritesOnlyExplicitFieldsToBothArmsAndResendsAfterReconnect() {
|
||||
val s = Session()
|
||||
val core = s.core
|
||||
core.monitor.withLock {
|
||||
core.sessionReady = true
|
||||
core.silentMode = 1
|
||||
core.lastBatteryRefreshAtMs = 8_000L
|
||||
core.lastConnectionOrInputAtMs = 10_000L
|
||||
assertFalse(core.shouldPollBatteryLocked(9_999L))
|
||||
assertTrue(core.shouldPollBatteryLocked(10_000L))
|
||||
core.silentMode = 0
|
||||
assertFalse(core.shouldPollBatteryLocked(10_000L))
|
||||
assertTrue(core.shouldPollBatteryLocked(308_000L))
|
||||
core.shutdownRequested = true
|
||||
assertFalse(core.shouldPollBatteryLocked(608_000L))
|
||||
}
|
||||
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() {
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
@@ -1,67 +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 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 methods = cls.members.filter(n => ['handleSilentMode', 'showSilentModeExit', 'setPhase'].includes(n.name?.getText(source)));
|
||||
const alerts = [], timers = new Map(); let next = 0, on = true, wakes = 0;
|
||||
const context = { exports: {}, setTimeout: fn => { timers.set(++next, fn); return next; }, clearTimeout: id => timers.delete(id),
|
||||
updateGlassesPresence() {}, shell: { isScreenOn: () => on, wake: () => { on = true; wakes++; }, showAlert: text => alerts.push(text),
|
||||
foregroundWindow: () => ({ requestRender() {} }), setBatteryLevels() {}, getBatteryLevels: () => ({}) } };
|
||||
vm.runInNewContext(ts.transpileModule(`export class Controller { ${methods.map(n => n.getText(source)).join('\n')} }`, {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
||||
}).outputText, context);
|
||||
const c = new context.exports.Controller();
|
||||
Object.assign(c, { silentMode: false, silentModeFeedback: '', silentModeFeedbackTimer: null, silentModeFeedbackGeneration: 0, phase: 'connected', emit() {},
|
||||
cancelEvenHubSuspendTimer() {}, ensureEvenHubSessionActive: async () => true, requestShellRender() {},
|
||||
appendLog() {}, formatError: error => String(error) });
|
||||
return { c, alerts, timers, wakes: () => wakes, dark: () => { on = false; }, expire() { const callbacks = [...timers.values()]; timers.clear(); callbacks.forEach(fn => fn()); } };
|
||||
}
|
||||
test('silent activation remains visible on phone; exit waits for the display wake barrier', async () => {
|
||||
const h = fixture(); h.c.handleSilentMode(false);
|
||||
assert.equal(h.c.silentModeFeedback, '');
|
||||
h.c.handleSilentMode(true);
|
||||
assert.match(h.c.silentModeFeedback, /enabled/); assert.equal(h.timers.size, 0); assert.equal(h.alerts.length, 0);
|
||||
h.c.handleSilentMode(false);
|
||||
assert.equal(h.c.silentModeFeedback, 'Silent mode disabled');
|
||||
await new Promise(setImmediate);
|
||||
assert.deepEqual(h.alerts, ['Silent mode disabled']);
|
||||
h.expire(); assert.equal(h.c.silentModeFeedback, '');
|
||||
});
|
||||
test('repeated state reports do not duplicate feedback; an old timer cannot clear a new activation', async () => {
|
||||
const h = fixture(); h.c.handleSilentMode(true); h.c.handleSilentMode(false);
|
||||
h.c.handleSilentMode(false); await new Promise(setImmediate); assert.equal(h.alerts.length, 1);
|
||||
h.c.handleSilentMode(true); h.expire();
|
||||
assert.match(h.c.silentModeFeedback, /enabled/);
|
||||
});
|
||||
test('silent exit wakes a sleeping display before showing feedback but leaves locked glasses alone', async () => {
|
||||
for (const locked of [false, true]) {
|
||||
const h = fixture(); h.c.glassesLocked = locked; h.dark();
|
||||
h.c.handleSilentMode(true); h.c.handleSilentMode(false); await new Promise(setImmediate);
|
||||
assert.equal(h.wakes(), locked ? 0 : 1);
|
||||
assert.equal(h.alerts.length, locked ? 0 : 1);
|
||||
assert.equal(h.c.silentModeFeedback, 'Silent mode disabled');
|
||||
}
|
||||
});
|
||||
test('an unavailable session, re-entry into silence or disconnect suppresses a stale exit popup', async () => {
|
||||
for (const state of ['not-ready', 'silent', 'disconnected']) {
|
||||
const h = fixture(); let finish;
|
||||
h.c.ensureEvenHubSessionActive = () => new Promise(resolve => { finish = resolve; });
|
||||
h.c.handleSilentMode(true); h.c.handleSilentMode(false);
|
||||
assert.equal(h.alerts.length, 0);
|
||||
if (state === 'silent') h.c.handleSilentMode(true);
|
||||
if (state === 'disconnected') h.c.setPhase('disconnected');
|
||||
finish(state !== 'not-ready'); await new Promise(setImmediate);
|
||||
assert.equal(h.alerts.length, 0);
|
||||
}
|
||||
});
|
||||
|
||||
test('disconnect clears feedback and any pending timer without announcing a silent exit', () => {
|
||||
const h = fixture(); h.c.handleSilentMode(true); h.c.handleSilentMode(false);
|
||||
h.c.setPhase('disconnected');
|
||||
assert.equal(h.c.silentModeFeedback, ''); assert.equal(h.timers.size, 0);
|
||||
h.expire(); assert.equal(h.c.silentModeFeedback, '');
|
||||
});
|
||||
Reference in new issue
Block a user