forked from Blendman974/faceclaw
Merge main into ios-port and update the iOS CFW transport
This commit is contained in:
commit
e8e144f3f2
156 files changed
+10528
-1679
No files matched your search
@@ -2,10 +2,10 @@ import { concat, rle4 } from './ble-protocol'
|
||||
|
||||
/** Android BleImageOptimizer's mode-3 changed rectangle. Coordinates are in
|
||||
* units of 4 columns / 2 rows; pixels are top-down packed 4bpp, high nibble first.
|
||||
* null means identical, incomparable, or a full-screen box: use dedup/mode 6.
|
||||
* null means identical, incomparable, or a full-screen box: use dedup/mode 6. Compression belongs to the CFW transport.
|
||||
*/
|
||||
export function buildBoundingBoxPayload(previous: Uint8Array | null, next: Uint8Array,
|
||||
width: number, height: number, frameId: number, deflate: (data: Uint8Array) => Uint8Array): Uint8Array | null {
|
||||
width: number, height: number, frameId: number): Uint8Array | null {
|
||||
if (!Number.isInteger(width) || !Number.isInteger(height) || width <= 0 || height <= 0 ||
|
||||
width % 4 || height % 2 || width / 4 > 255 || height / 2 > 255 ||
|
||||
!previous || previous.length !== width * height / 2 || next.length !== previous.length) return null
|
||||
@@ -30,5 +30,20 @@ export function buildBoundingBoxPayload(previous: Uint8Array | null, next: Uint8
|
||||
region.set(next.subarray(start, start + regionStride), y * regionStride)
|
||||
}
|
||||
return concat(new Uint8Array([3, left / 4, top / 2, boxWidth / 4, boxHeight / 2,
|
||||
frameId & 255, (frameId >>> 8) & 255]), deflate(rle4(region)))
|
||||
frameId & 255, (frameId >>> 8) & 255]), rle4(region))
|
||||
}
|
||||
|
||||
/** Full repaint as independent 64-row mode-3 bands when RLE exceeds uint16. */
|
||||
export function buildFullFrameBands(packed: Uint8Array, width: number, height: number, firstId: number): Uint8Array[] {
|
||||
if (width <= 0 || width > 640 || width % 4 || height <= 0 || height > 480 || height % 2 || packed.length !== width * height / 2)
|
||||
throw new Error('Invalid framebuffer dimensions')
|
||||
const bands: Uint8Array[] = []
|
||||
let id = firstId
|
||||
for (let top = 0; top < height; top += 64) {
|
||||
const rows = Math.min(64, height - top)
|
||||
bands.push(concat(new Uint8Array([3, 0, top / 2, width / 4, rows / 2, id & 255, id >>> 8]),
|
||||
rle4(packed.subarray(top * width / 2, (top + rows) * width / 2))))
|
||||
id = id >= 0xfffe ? 1 : id + 1
|
||||
}
|
||||
return bands
|
||||
}
|
||||
@@ -3,7 +3,7 @@ export const G2_WRITE = '00002760-08c2-11e1-9073-0e8ac72e5401'
|
||||
export const G2_NOTIFY = '00002760-08c2-11e1-9073-0e8ac72e5402'
|
||||
export const G2_RENDER_NOTIFY = '00002760-08c2-11e1-9073-0e8ac72e6402'
|
||||
export const RING_NOTIFY = ['bae80011-4f05-4503-8e65-3af1f7329d1f', 'bae80013-4f05-4503-8e65-3af1f7329d1f']
|
||||
export const SID = { auth: 0x80, launch: 1, hub: 0xe0, settings: 9 } as const
|
||||
export const SID = { auth: 0x80, launch: 1, hub: 0xe0, settings: 9, cfw: 0xf0 } as const
|
||||
export function concat(...parts: Uint8Array[]): Uint8Array {
|
||||
const output = new Uint8Array(parts.reduce((n, p) => n + p.length, 0))
|
||||
let offset = 0; for (const part of parts) { output.set(part, offset); offset += part.length }; return output
|
||||
@@ -28,13 +28,7 @@ export const framebufferLease = (acquire: boolean) => concat(integer(1, 1), inte
|
||||
export function createLayout(magic: number): Uint8Array {
|
||||
const geometry = concat(integer(1, 0), integer(2, 0), integer(3, 576), integer(4, 288))
|
||||
const text = concat(geometry, integer(9, 1), string(10, 'dashboard'), integer(11, 1), string(12, ' '))
|
||||
const image = concat(geometry, integer(5, 10), string(6, 'img00'))
|
||||
return wrap(0, magic, 3, concat(integer(1, 2), bytes(3, text), bytes(4, image), integer(5, 10000)))
|
||||
}
|
||||
export function imageFragment(magic: number, payload: Uint8Array, offset: number, size = 3800): Uint8Array {
|
||||
const fragment = payload.subarray(offset, offset + size)
|
||||
return wrap(3, magic, 5, concat(integer(1, 10), string(2, 'img00'), integer(3, 10), integer(4, payload.length),
|
||||
integer(5, 0), integer(6, Math.floor(offset / size)), integer(7, fragment.length), bytes(8, fragment)))
|
||||
return wrap(0, magic, 3, concat(integer(1, 1), bytes(3, text), integer(5, 10000)))
|
||||
}
|
||||
export function crc16(data: Uint8Array): number {
|
||||
let crc = 0xffff
|
||||
@@ -55,7 +49,7 @@ export function frameMessage(payload: Uint8Array, sid: number, flag: number, seq
|
||||
return concat(new Uint8Array([0xaa, 0x21, sequence & 255, chunk.length, count, i + 1, sid, flag]), chunk)
|
||||
})
|
||||
}
|
||||
export type ProtocolMessage = { sid: number; flag: number; payload: Uint8Array; command: number; magic: number }
|
||||
export type ProtocolMessage = { sid: number; flag: number; payload: Uint8Array; command: number; magic: number; packet?: Uint8Array }
|
||||
/** Handles split/coalesced envelopes and reassembles each link/sequence separately. */
|
||||
export class MessageReceiver {
|
||||
private streams = new Map<string, Uint8Array>()
|
||||
@@ -70,7 +64,12 @@ export class MessageReceiver {
|
||||
const length = stream[3], count = stream[4], index = stream[5]
|
||||
if (stream.length < length + 8) break
|
||||
const sid = stream[6], flag = stream[7], key = `${link}:${stream[2]}:${sid}:${flag}`
|
||||
const packet = stream.slice(0, length + 8)
|
||||
const chunk = stream.slice(8, 8 + length); stream = stream.subarray(length + 8)
|
||||
if (sid === SID.cfw) {
|
||||
output.push({ sid, flag, payload: chunk, command: -1, magic: -1, packet })
|
||||
continue
|
||||
}
|
||||
if (!count || !index || index > count) { this.messages.delete(key); continue }
|
||||
if (index === 1) this.messages.set(key, { chunks: [], total: count, seen: now, size: 0 })
|
||||
const message = this.messages.get(key)
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { concat, crc16, SID } from './ble-protocol'
|
||||
|
||||
declare const require: (name: string) => any
|
||||
export const CFW_MAX_MESSAGE = 65535
|
||||
export type CfwAck = { nack: boolean; streamId: number; messageId: number; lens: number; size: number; checksum: number }
|
||||
const u16 = (data: Uint8Array, offset: number) => data[offset] | (data[offset + 1] << 8)
|
||||
|
||||
/** Matches Android CfwTransport. maxWrite is the ATT value limit (MTU - 3). */
|
||||
export class CfwTransport {
|
||||
private compressor: any
|
||||
private resetPending = true
|
||||
private lenses = 0
|
||||
reset(): void { this.compressor = null; this.resetPending = true; this.lenses = 0 }
|
||||
encode(message: Uint8Array, streamId: number, lenses: number, maxWrite: number): Uint8Array[] {
|
||||
if (message.length > CFW_MAX_MESSAGE || !Number.isInteger(streamId) || streamId < 0 || streamId > 255 ||
|
||||
![1, 2, 3].includes(lenses) || !Number.isInteger(maxWrite) || maxWrite < 20 || maxWrite > 514)
|
||||
throw new Error('Invalid CFW stream parameters')
|
||||
if (this.lenses !== lenses) this.reset()
|
||||
if (!this.compressor) this.compressor = new (require('pako').Deflate)()
|
||||
const chunks: Uint8Array[] = []
|
||||
// SYNC_FLUSH emits this record while retaining history for the next one.
|
||||
this.compressor.onData = (chunk: Uint8Array) => chunks.push(chunk.slice())
|
||||
if (!this.compressor.push(message, 2)) throw new Error(this.compressor.msg || 'CFW compression failed')
|
||||
let body = concat(...chunks), flags = lenses | 4 | (this.resetPending ? 8 : 0)
|
||||
if (!body.length) flags &= ~4
|
||||
if (body.length > CFW_MAX_MESSAGE) {
|
||||
this.reset(); body = message; flags = lenses | 8
|
||||
} else { this.resetPending = false; this.lenses = lenses }
|
||||
const checksum = crc16(message)
|
||||
const record = concat(new Uint8Array([flags, body.length & 255, body.length >>> 8, checksum & 255, checksum >>> 8]), body)
|
||||
const capacity = Math.min(252, maxWrite - 11), packets: Uint8Array[] = []
|
||||
for (let offset = 0, index = 0; offset < record.length; offset += capacity, index++) {
|
||||
const body = concat(new Uint8Array([lenses | (offset === 0 ? 0x80 : 0) |
|
||||
(offset + capacity >= record.length ? 0x40 : 0)]), record.subarray(offset, offset + capacity))
|
||||
const crc = crc16(body)
|
||||
packets.push(concat(new Uint8Array([0xaa, 0x21, (streamId + index) & 255, body.length + 2, 1, 1, SID.cfw, 0]),
|
||||
body, new Uint8Array([crc & 255, crc >>> 8])))
|
||||
}
|
||||
return packets
|
||||
}
|
||||
}
|
||||
|
||||
/** Validate the entire primary + redundant-ACK packet before applying any ACK. */
|
||||
export function parseCfwAcks(packet: Uint8Array): CfwAck[] | null {
|
||||
const n = packet.length
|
||||
if (n < 19 || n > 40 || (n - 19) % 7 || packet[0] !== 0xaa || packet[1] !== 0x12 ||
|
||||
packet[3] !== n - 8 || packet[4] !== 1 || packet[5] !== 1 || packet[6] !== SID.cfw || packet[7] !== 0 ||
|
||||
![1, 3].includes(packet[8]) || ![1, 2].includes(packet[12]) || (packet[8] === 3 && n !== 19) ||
|
||||
crc16(packet.subarray(8, -2)) !== u16(packet, n - 2)) return null
|
||||
const acks = [{ nack: packet[8] === 3, streamId: packet[9], messageId: u16(packet, 10),
|
||||
lens: packet[12], size: u16(packet, 13), checksum: u16(packet, 15) }]
|
||||
for (let offset = 17; offset < n - 2; offset += 7)
|
||||
acks.push({ nack: false, streamId: packet[offset], messageId: u16(packet, offset + 1), lens: packet[12],
|
||||
size: u16(packet, offset + 3), checksum: u16(packet, offset + 5) })
|
||||
return acks
|
||||
}
|
||||
+109
-38
@@ -16,7 +16,7 @@ import { ALL_NOTIFICATIONS, onAndroidNotificationPosted, readActiveNotifications
|
||||
import { shouldShowNotificationOnGlasses } from "../native/notification-sources";
|
||||
import { openEvenAppSettings, readEvenAppNotificationState } from "../native/even-app-conflict";
|
||||
import { grayImageToPreviewSource } from "../native/gray-image-preview";
|
||||
import { firmwareIncompatibilityMessage } from "./firmware-compat";
|
||||
import { firmwareIncompatibilityMessage, hasCompatibleFirmware } from "./firmware-compat";
|
||||
import { hasExtractedEvenHubFonts } from "./firmware-builder";
|
||||
import { resumeAutoReconnect, suppressAutoReconnect } from "./reconnect-policy";
|
||||
import { WearRemote, type WearRemoteInputKind } from "./wear-remote";
|
||||
@@ -43,6 +43,8 @@ const MIRROR_TOUCH_GESTURES: Record<Exclude<MirrorTouchKind, "tap">, WearRemoteI
|
||||
"swipe-right": "swipe-right",
|
||||
};
|
||||
import { findSoundEffect, playSoundEffect } from "../ui/sound-effects";
|
||||
import { GlanceHost } from "./glance-host";
|
||||
import { type GlanceEvent } from "./glance-state";
|
||||
import { isWelcomeSoundPending, setWelcomeSoundPending } from "../phone-ui/onboarding-state";
|
||||
import { beginRenderPass, endRenderPass } from "../util/render-freshness";
|
||||
import { voiceControlBridge } from "../native/voice-control";
|
||||
@@ -52,6 +54,7 @@ import { prepareFrameDraws } from "../graphics/glyph-wire";
|
||||
import { getDefaultMediumFont } from "../graphics/ui-fonts";
|
||||
import { wrapText } from "../graphics/textwrap";
|
||||
import { rawInputEventToInputEvent, shell, type ShellInputOutcome } from "../ui/shell/shell";
|
||||
import { type InputEvent } from "../ui/gestures";
|
||||
import { registerSystemTools } from "../assistant/system-tools";
|
||||
import { updateGlassesPresence } from "./glasses-presence";
|
||||
import { timerEngine } from "../apps/timer/timer-engine";
|
||||
@@ -252,10 +255,30 @@ class DashboardController {
|
||||
private screenTimeoutTimer: ReturnType<typeof setInterval> | null = null;
|
||||
private evenHubSuspendTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
private evenHubSessionSuspended = false;
|
||||
/**
|
||||
* The Glanceboard: the alternate sleep-time display, on its own surface
|
||||
* above the shell. Fed sleep-time input from handleInputEvent; it uses the
|
||||
* same wake barrier as the shell and hands the compositor back to the
|
||||
* screen-off path when it hides.
|
||||
*/
|
||||
private readonly glance = new GlanceHost({
|
||||
getDisplay: () => this.display,
|
||||
getProvider: () => ALL_APPS.find((app) => app.glanceboard)?.glanceboard ?? null,
|
||||
canShow: () => (this.phase === "connected" || this.isPreviewDisplayActive()) && !this.glassesLocked,
|
||||
ensureSessionActive: (frameId) => this.ensureEvenHubSessionActive(frameId),
|
||||
onHiddenWhileAsleep: () => {
|
||||
if (!shell.isScreenOn()) this.handleScreenStateChanged(false);
|
||||
},
|
||||
onVisibilityChanged: () => {
|
||||
this.schedulePreviewUpdate();
|
||||
this.emit();
|
||||
},
|
||||
appendLog: (message) => this.appendLog(message),
|
||||
});
|
||||
private evenHubResumePromise: Promise<boolean> | null = null;
|
||||
private faceclawWakeLeaseSupported = false;
|
||||
/** Faceclaw's firmware at the required revision reported in; its extensions can be used. */
|
||||
private customFirmwareConfirmed = false;
|
||||
private faceclawWakeLeaseState: boolean | null = null;
|
||||
private wearNotifySupported = false;
|
||||
private glassesWorn: boolean | null = null;
|
||||
private phoneLocked = false;
|
||||
private glassesLocked = false;
|
||||
@@ -319,7 +342,7 @@ class DashboardController {
|
||||
toggle?: TextSettingsEditToggle,
|
||||
) => this.startTextSettingsEdit(settings, title, onFinish, toggle),
|
||||
endTextSettingEdit: () => this.endTextSettingEdit(),
|
||||
startVoiceCapture: () => this.startVoiceCapture(),
|
||||
startVoiceCapture: (endpointing = false) => this.startVoiceCapture(endpointing),
|
||||
stopVoiceCapture: () => this.stopVoiceCapture(),
|
||||
startContinuousVoiceCapture: () => this.startContinuousVoiceCapture(),
|
||||
stopContinuousVoiceCapture: () => this.stopContinuousVoiceCapture(),
|
||||
@@ -359,6 +382,8 @@ class DashboardController {
|
||||
this.emit();
|
||||
},
|
||||
onScreenStateChanged: (on) => {
|
||||
// Any wake of the regular UI replaces a showing Glanceboard.
|
||||
if (on) this.glance.dismiss();
|
||||
this.handleScreenStateChanged(on);
|
||||
if (on) this.requestShellRender();
|
||||
this.emit();
|
||||
@@ -631,7 +656,7 @@ class DashboardController {
|
||||
const communicator = this.communicator;
|
||||
if (
|
||||
!lockScreenEnabledSetting.get() ||
|
||||
!this.wearNotifySupported ||
|
||||
!this.customFirmwareConfirmed ||
|
||||
this.phase !== "connected" ||
|
||||
!communicator
|
||||
) {
|
||||
@@ -736,7 +761,7 @@ class DashboardController {
|
||||
// foreground app when Faceclaw handles the glasses wakeword. Without the
|
||||
// latter, Even AI displaces EvenHub before our first wake frame can ACK.
|
||||
return (
|
||||
this.faceclawWakeLeaseSupported &&
|
||||
this.customFirmwareConfirmed &&
|
||||
(suspendEvenHubWhenScreenOffSetting.get() || wakeWordActionSetting.get() !== "off")
|
||||
);
|
||||
}
|
||||
@@ -788,6 +813,7 @@ class DashboardController {
|
||||
if (
|
||||
!suspendEvenHubWhenScreenOffSetting.get() ||
|
||||
shell.isScreenOn() ||
|
||||
this.glance.isVisible() ||
|
||||
this.phase !== "connected" ||
|
||||
!this.communicator ||
|
||||
this.evenHubSessionSuspended
|
||||
@@ -801,9 +827,11 @@ class DashboardController {
|
||||
if (
|
||||
!suspendEvenHubWhenScreenOffSetting.get() ||
|
||||
shell.isScreenOn() ||
|
||||
this.glance.isVisible() ||
|
||||
this.phase !== "connected" ||
|
||||
this.communicator !== communicator
|
||||
) {
|
||||
// A showing Glanceboard re-arms this when it hides.
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -816,7 +844,7 @@ class DashboardController {
|
||||
}
|
||||
|
||||
void (async () => {
|
||||
if (this.faceclawWakeLeaseSupported) {
|
||||
if (this.customFirmwareConfirmed) {
|
||||
// Refresh immediately before teardown so the first suspended wake
|
||||
// cannot race an old lease's expiry.
|
||||
const leaseReady = await this.syncFaceclawWakeLease(communicator, true);
|
||||
@@ -829,6 +857,7 @@ class DashboardController {
|
||||
if (
|
||||
!suspendEvenHubWhenScreenOffSetting.get() ||
|
||||
shell.isScreenOn() ||
|
||||
this.glance.isVisible() ||
|
||||
this.phase !== "connected" ||
|
||||
this.communicator !== communicator
|
||||
) {
|
||||
@@ -1250,6 +1279,7 @@ class DashboardController {
|
||||
const target = this.previewTarget;
|
||||
if (!target) return;
|
||||
this.previewTarget = null;
|
||||
this.glance.reset();
|
||||
target.release();
|
||||
this.clearDashboardTimer();
|
||||
this.appendLog("Preview-only display released.");
|
||||
@@ -1291,10 +1321,10 @@ class DashboardController {
|
||||
);
|
||||
|
||||
let communicator: FaceclawCommunicatorBridge | null = null;
|
||||
this.faceclawWakeLeaseSupported = false;
|
||||
this.customFirmwareConfirmed = false;
|
||||
this.faceclawWakeLeaseState = null;
|
||||
this.wearNotifySupported = false;
|
||||
this.lockSurfaceConfigured = false;
|
||||
this.glance.reset();
|
||||
this.evenHubResumePromise = null;
|
||||
this.connectRunning = true;
|
||||
|
||||
@@ -1390,9 +1420,14 @@ class DashboardController {
|
||||
// especially while the glasses remain reachable in their case.
|
||||
const hasBatteryLevel = Number.isInteger(state.battery) && state.battery >= 0 && state.battery <= 100;
|
||||
if (hasBatteryLevel) this.lastHeadsetBattery = state.battery;
|
||||
const ringBattery = state.ringBattery;
|
||||
const hasRingBattery = typeof ringBattery === "number" && Number.isInteger(ringBattery)
|
||||
&& ringBattery >= 0 && ringBattery <= 100;
|
||||
shell.setBatteryLevels({
|
||||
headset: hasBatteryLevel ? state.battery : this.lastHeadsetBattery,
|
||||
headsetCharging: state.chargingStatus > 0,
|
||||
ring: hasRingBattery ? ringBattery : null,
|
||||
ringCharging: hasRingBattery ? state.ringChargingStatus === 1 : null,
|
||||
});
|
||||
updateGlassesPresence({ charging: state.chargingStatus > 0 || this.phase === "charging" });
|
||||
if ((this.phase === "connected" || this.phase === "charging") && this.communicator) {
|
||||
@@ -1436,26 +1471,18 @@ class DashboardController {
|
||||
this.offFirmwareInfo = communicator.onFirmwareInfo((info) => {
|
||||
this.appendLog(
|
||||
`firmware: L=${info.leftVersion || "?"} R=${info.rightVersion || "?"}` +
|
||||
(info.capabilities ? ` caps="${info.capabilities}"` : " (no CFW capability string)"),
|
||||
(info.extension ? ` ext="${info.extension}"` : " (no firmware extension string)"),
|
||||
);
|
||||
const warning = firmwareIncompatibilityMessage(info) ?? "";
|
||||
const wakeLeaseSupported = info.capabilities
|
||||
.trim()
|
||||
.split(/\s+/)
|
||||
.includes("wakelease");
|
||||
const wearNotifySupported = info.capabilities
|
||||
.trim()
|
||||
.split(/\s+/)
|
||||
.includes("wearnotify");
|
||||
if (wakeLeaseSupported !== this.faceclawWakeLeaseSupported) {
|
||||
this.faceclawWakeLeaseSupported = wakeLeaseSupported;
|
||||
// The firmware contract is all-or-nothing: a compatible revision has
|
||||
// every extension (wake lease, wear notifications, ...) we use.
|
||||
const customFirmwareConfirmed = !warning && hasCompatibleFirmware(info);
|
||||
if (customFirmwareConfirmed !== this.customFirmwareConfirmed) {
|
||||
this.customFirmwareConfirmed = customFirmwareConfirmed;
|
||||
this.faceclawWakeLeaseState = null;
|
||||
void this.syncFaceclawWakeLease().catch((error) => {
|
||||
this.appendLog(`wake takeover lease sync failed: ${this.formatError(error)}`);
|
||||
});
|
||||
}
|
||||
if (wearNotifySupported !== this.wearNotifySupported) {
|
||||
this.wearNotifySupported = wearNotifySupported;
|
||||
this.ensureWearStateTracking();
|
||||
}
|
||||
if (warning !== this.firmwareWarningMessage) {
|
||||
@@ -1553,8 +1580,8 @@ class DashboardController {
|
||||
}
|
||||
this.communicator = null;
|
||||
this.lockSurfaceConfigured = false;
|
||||
this.wearNotifySupported = false;
|
||||
this.faceclawWakeLeaseSupported = false;
|
||||
this.glance.reset();
|
||||
this.customFirmwareConfirmed = false;
|
||||
this.faceclawWakeLeaseState = null;
|
||||
this.evenHubResumePromise = null;
|
||||
this.clearDashboardTimer();
|
||||
@@ -1688,6 +1715,7 @@ class DashboardController {
|
||||
const communicator = this.communicator;
|
||||
this.communicator = null;
|
||||
this.lockSurfaceConfigured = false;
|
||||
this.glance.reset();
|
||||
this.evenHubSessionSuspended = false;
|
||||
this.evenHubResumePromise = null;
|
||||
|
||||
@@ -1746,9 +1774,8 @@ class DashboardController {
|
||||
await communicator?.close().catch(() => {});
|
||||
} finally {
|
||||
stopForegroundNotification();
|
||||
this.faceclawWakeLeaseSupported = false;
|
||||
this.customFirmwareConfirmed = false;
|
||||
this.faceclawWakeLeaseState = null;
|
||||
this.wearNotifySupported = false;
|
||||
this.setPhase("disconnected");
|
||||
this.setStatus("Disconnected.");
|
||||
this.appendLog("Disconnected from the glasses.");
|
||||
@@ -1762,14 +1789,14 @@ class DashboardController {
|
||||
* finger-down/finger-up (the watch) hold for as long as the user does.
|
||||
*/
|
||||
async injectSyntheticRingInput(kind: WearRemoteInputKind, origin: SyntheticInputOrigin = "ring"): Promise<void> {
|
||||
// Match the ring while the display is dark: only a double-click wakes it,
|
||||
// and that wake is handled by Shell.receiveInput. This check also protects
|
||||
// against a watch acting on a stale state snapshot.
|
||||
// Match the ring while the display is dark: a double-click wakes it
|
||||
// (handled by Shell.receiveInput) and a tap or hold shows the
|
||||
// Glanceboard; scrolls and the menu gesture mean nothing. This check also
|
||||
// protects against a watch acting on a stale state snapshot.
|
||||
if (
|
||||
origin === "watch" &&
|
||||
!shell.isScreenOn() &&
|
||||
kind !== "double-click" &&
|
||||
kind !== "long-press-release"
|
||||
(kind === "scroll-up" || kind === "scroll-down" || kind === "short-then-long-press")
|
||||
) {
|
||||
this.appendLog(`${kind} (watch scheme) ignored while display is off`);
|
||||
return;
|
||||
@@ -1800,7 +1827,12 @@ class DashboardController {
|
||||
return;
|
||||
}
|
||||
if (!shell.isScreenOn()) {
|
||||
// Asleep, the mirror offers the sleep gestures: double-tap wakes, a
|
||||
// tap shows the Glanceboard for its timeout. The mirror's hold has no
|
||||
// real release (the synthetic long-press releases at once, which would
|
||||
// only flash the board), so it counts as a tap here too.
|
||||
if (kind === "double-tap") await this.injectSyntheticRingInput("double-click", "watch");
|
||||
else if (kind === "tap" || kind === "long-press") await this.injectSyntheticRingInput("click", "watch");
|
||||
return;
|
||||
}
|
||||
if (kind !== "tap") {
|
||||
@@ -1874,12 +1906,15 @@ class DashboardController {
|
||||
* push-to-talk and the Transcribe app. Android mic permission is the consent
|
||||
* gate even though the audio source is the G2 mic over BLE.
|
||||
*/
|
||||
private startVoiceCapture(endpointing = false): void {
|
||||
this.beginVoiceCapture("ptt", endpointing);
|
||||
private pttCaptureGeneration = 0;
|
||||
|
||||
private startVoiceCapture(endpointing = false): Promise<void> {
|
||||
return this.beginVoiceCapture("ptt", endpointing);
|
||||
}
|
||||
|
||||
private stopVoiceCapture(): void {
|
||||
voiceControlBridge.stopPushToTalk();
|
||||
private stopVoiceCapture(): Promise<void> | void {
|
||||
++this.pttCaptureGeneration;
|
||||
return voiceControlBridge.stopPushToTalk();
|
||||
}
|
||||
|
||||
private startContinuousVoiceCapture(): void {
|
||||
@@ -1944,7 +1979,8 @@ class DashboardController {
|
||||
return granted;
|
||||
}
|
||||
|
||||
private beginVoiceCapture(kind: "ptt" | "continuous", endpointing = false): void {
|
||||
private async beginVoiceCapture(kind: "ptt" | "continuous", endpointing = false): Promise<void> {
|
||||
const pttGeneration = kind === "ptt" ? ++this.pttCaptureGeneration : 0;
|
||||
// Preview mode captures from the phone mic (voiceCaptureOptions with a
|
||||
// null communicator); otherwise a live glasses session must be the source.
|
||||
const previewCapture = this.isPreviewDisplayActive();
|
||||
@@ -1952,8 +1988,12 @@ class DashboardController {
|
||||
return;
|
||||
}
|
||||
const communicator = this.communicator;
|
||||
void ensureVoicePermissions()
|
||||
// The system prompt appears on the phone; tell the glasses dialog so it
|
||||
// sends the user there rather than claiming to listen.
|
||||
if (!hasMicrophonePermission()) voiceControlBridge.reportPermissionPrompt();
|
||||
await ensureVoicePermissions()
|
||||
.then(() => {
|
||||
if (kind === "ptt" && pttGeneration !== this.pttCaptureGeneration) return;
|
||||
if (previewCapture) {
|
||||
if (!this.isPreviewDisplayActive()) return;
|
||||
} else if (this.phase !== "connected" || this.communicator !== communicator) {
|
||||
@@ -1968,6 +2008,7 @@ class DashboardController {
|
||||
})
|
||||
.catch((error) => {
|
||||
this.appendLog(`voice permission failed: ${this.formatError(error)}`);
|
||||
if (!hasMicrophonePermission()) voiceControlBridge.reportPermissionDenied();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2057,6 +2098,20 @@ class DashboardController {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!shell.isScreenOn()) {
|
||||
// Sleep-time gestures belong to the Glanceboard: a tap or a hold
|
||||
// shows it (the shell would ignore them), and a double-tap while it
|
||||
// is up dismisses it and falls through to the normal wake below.
|
||||
const glanceEvent = this.glanceEventFor(inputEvent, event);
|
||||
if (glanceEvent?.type === "dismiss") {
|
||||
this.glance.dismiss();
|
||||
} else if (glanceEvent) {
|
||||
frameTimings.annotateFrame(frameId, `glanceboard ${glanceEvent.type}`);
|
||||
await this.glance.handleEvent(glanceEvent, frameId);
|
||||
frameOwned = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
const wakewordShouldWake =
|
||||
event.kind === "even-ai" &&
|
||||
event.eventType === EvenAIStatus.EVEN_AI_WAKE_UP &&
|
||||
@@ -2130,6 +2185,19 @@ class DashboardController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The Glanceboard event a sleep-time input means, or null when the shell
|
||||
* should see the input as usual. A display-wake carries the head-tilt
|
||||
* gesture (HEAD_UP_EVENT) as a press; the double-tap display-wake stays the
|
||||
* regular UI's wake.
|
||||
*/
|
||||
private glanceEventFor(inputEvent: InputEvent, event: RawInputEvent): GlanceEvent | null {
|
||||
if (inputEvent.type === "display-wake") {
|
||||
return event.eventType === OsEventTypeList.HEAD_UP_EVENT ? this.glance.eventForGesture("head-tilt") : null;
|
||||
}
|
||||
return this.glance.eventForGesture(inputEvent.type);
|
||||
}
|
||||
|
||||
/** Launch or focus an in-process singleton app (notifications, debug tests). */
|
||||
private async launchInProcessApp(
|
||||
windowId: string,
|
||||
@@ -2527,6 +2595,9 @@ class DashboardController {
|
||||
private setPhase(phase: ConnectionPhase): void {
|
||||
if (this.phase === phase) return;
|
||||
this.phase = phase;
|
||||
if (phase !== "connected" && phase !== "charging") {
|
||||
shell.setBatteryLevels({ ring: null, ringCharging: null });
|
||||
}
|
||||
// "charging" is a live BLE link with the glasses in their case.
|
||||
updateGlassesPresence({
|
||||
connected: phase === "connected" || phase === "charging",
|
||||
|
||||
@@ -71,6 +71,12 @@ export const OsEventTypeList = {
|
||||
RING_LONG_PRESS_RELEASE_EVENT: 10,
|
||||
/** CFW extension: the 2.2.9 tap-then-hold Menu gesture. */
|
||||
SHORT_THEN_LONG_PRESS_EVENT: 11,
|
||||
/**
|
||||
* CFW extension (head-tilt wake branch): the IMU head-up gesture, forwarded
|
||||
* while the display sleeps. Reaches the phone as a display-wake carrying
|
||||
* this eventType; the glance host treats it as a press.
|
||||
*/
|
||||
HEAD_UP_EVENT: 12,
|
||||
} as const;
|
||||
|
||||
export const OsEventTypeName: Record<number, string> = {
|
||||
@@ -86,4 +92,5 @@ export const OsEventTypeName: Record<number, string> = {
|
||||
9: "RING_LONG_PRESS_EVENT",
|
||||
10: "RING_LONG_PRESS_RELEASE_EVENT",
|
||||
11: "SHORT_THEN_LONG_PRESS_EVENT",
|
||||
12: "HEAD_UP_EVENT",
|
||||
};
|
||||
+146
-68
@@ -1,20 +1,79 @@
|
||||
/**
|
||||
* Compatibility check for the glasses firmware. Faceclaw requires the custom
|
||||
* firmware: version >= 2.2.4.34 with the required direct-framebuffer and wear
|
||||
* notification tokens in the CFW capability string. Stock firmware sends no
|
||||
* capability string at all.
|
||||
* Compatibility check for the glasses firmware. Faceclaw requires its own
|
||||
* custom firmware at a specific revision.
|
||||
*
|
||||
* The firmware identifies itself through one extra string in the sid-0x09
|
||||
* settings READ response (protobuf field 100, the "firmware extension" slot):
|
||||
*
|
||||
* "Faceclaw/<n>" -- Faceclaw's custom firmware, revision <n>. The revision
|
||||
* goes up whenever the firmware contract changes and is
|
||||
* not kept in sync with Faceclaw app versions.
|
||||
* "EVENCFW/..." -- older Faceclaw firmware, from before revisions existed
|
||||
* (it advertised feature tokens instead). Always outdated.
|
||||
* (empty) -- stock firmware; it never sends the field.
|
||||
* anything else -- custom firmware from a different source.
|
||||
*
|
||||
* Because an exact revision is required, nothing else in the app gates on the
|
||||
* extension string: once the firmware is compatible, every feature it provides
|
||||
* is assumed present.
|
||||
*/
|
||||
|
||||
import { type FirmwareInfo } from "../native/faceclaw-communicator";
|
||||
export type FirmwareInfo = {
|
||||
leftVersion: string;
|
||||
rightVersion: string;
|
||||
/** Raw contents of the firmware-extension slot ("" on stock firmware). */
|
||||
extension: string;
|
||||
};
|
||||
|
||||
const MIN_FIRMWARE_VERSION = [2, 2, 4, 34];
|
||||
const REQUIRED_FIRMWARE_EXTENSIONS = ["img640", "fbguard", "wearnotify"] as const;
|
||||
/** The Faceclaw firmware revision this build of the app needs. */
|
||||
export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 13;
|
||||
|
||||
const FACECLAW_PREFIX = "Faceclaw/";
|
||||
const LEGACY_PREFIX = "EVENCFW";
|
||||
|
||||
// The stock firmware release Faceclaw's custom image is built from. Stock at or
|
||||
// below this can be flashed with our patched image; a newer stock version is
|
||||
// unrecognized (its layout may differ from what our patch set targets).
|
||||
export const FLASHABLE_STOCK_VERSION = [2, 2, 9, 22];
|
||||
export const FLASHABLE_STOCK_VERSION_TEXT = FLASHABLE_STOCK_VERSION.join(".");
|
||||
export const BASE_STOCK_VERSION = [2, 2, 9, 22];
|
||||
export const BASE_STOCK_VERSION_TEXT = BASE_STOCK_VERSION.join(".");
|
||||
export const VALIDATED_STOCK_VERSION = [2, 2, 10, 10];
|
||||
export const VALIDATED_STOCK_VERSION_TEXT = VALIDATED_STOCK_VERSION.join(".");
|
||||
|
||||
export type FirmwareExtension =
|
||||
/** Nothing in the slot: stock firmware. */
|
||||
| { kind: "none" }
|
||||
/** Faceclaw's firmware at the given revision. */
|
||||
| { kind: "faceclaw"; version: number }
|
||||
/** Pre-revision Faceclaw firmware ("EVENCFW/<ver> <tokens>"). */
|
||||
| { kind: "legacy-faceclaw"; text: string }
|
||||
/** Custom firmware from some other project. */
|
||||
| { kind: "other"; text: string };
|
||||
|
||||
export function parseFirmwareExtension(extension: string): FirmwareExtension {
|
||||
const text = extension.trim();
|
||||
if (!text) return { kind: "none" };
|
||||
if (text.startsWith(FACECLAW_PREFIX)) {
|
||||
const version = parseInt(text.slice(FACECLAW_PREFIX.length), 10);
|
||||
if (Number.isFinite(version) && version >= 0) return { kind: "faceclaw", version };
|
||||
return { kind: "other", text };
|
||||
}
|
||||
if (text.startsWith(LEGACY_PREFIX)) return { kind: "legacy-faceclaw", text };
|
||||
return { kind: "other", text };
|
||||
}
|
||||
|
||||
/** Short user-facing description of what the extension slot reported. */
|
||||
export function describeFirmwareExtension(extension: FirmwareExtension): string {
|
||||
switch (extension.kind) {
|
||||
case "faceclaw":
|
||||
return `Faceclaw firmware revision ${extension.version}`;
|
||||
case "legacy-faceclaw":
|
||||
return `an older Faceclaw firmware (reported "${extension.text}")`;
|
||||
case "other":
|
||||
return `custom firmware from a different source (reported "${extension.text}")`;
|
||||
default:
|
||||
return "stock firmware";
|
||||
}
|
||||
}
|
||||
|
||||
function parseDottedVersion(version: string): number[] {
|
||||
return version
|
||||
@@ -36,66 +95,53 @@ function compareVersions(a: number[], b: number[]): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* True when the glasses run Faceclaw's firmware at the required revision or
|
||||
* newer. (A newer revision is accepted: revisions only add to the contract.)
|
||||
*/
|
||||
export function hasCompatibleFirmware(info: FirmwareInfo): boolean {
|
||||
const extension = parseFirmwareExtension(info.extension);
|
||||
return extension.kind === "faceclaw" && extension.version >= REQUIRED_FACECLAW_FIRMWARE_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Human-readable explanation of why this firmware cannot run Faceclaw, or
|
||||
* null if it is compatible. Returns null when no version was reported at all
|
||||
* null if it is compatible. Returns null when nothing was reported at all
|
||||
* (no data is not evidence of incompatibility).
|
||||
*/
|
||||
export function firmwareIncompatibilityMessage(info: FirmwareInfo): string | null {
|
||||
const reportedVersions = [info.leftVersion, info.rightVersion].filter((v) => v.trim().length > 0);
|
||||
if (reportedVersions.length === 0) return null;
|
||||
const extension = parseFirmwareExtension(info.extension);
|
||||
if (reportedVersions.length === 0 && extension.kind === "none") return null;
|
||||
|
||||
const minVersionText = MIN_FIRMWARE_VERSION.join(".");
|
||||
const versionsText = `L=${info.leftVersion || "unknown"} R=${info.rightVersion || "unknown"}`;
|
||||
const required = `Faceclaw firmware revision ${REQUIRED_FACECLAW_FIRMWARE_VERSION}`;
|
||||
|
||||
if (reportedVersions.some((v) => compareVersions(parseDottedVersion(v), MIN_FIRMWARE_VERSION) < 0)) {
|
||||
return (
|
||||
`The glasses report firmware ${versionsText}, but Faceclaw requires the modified firmware, ` +
|
||||
`version ${minVersionText} or newer. Displaying images will not work until the glasses firmware is updated.`
|
||||
);
|
||||
switch (extension.kind) {
|
||||
case "faceclaw":
|
||||
if (extension.version >= REQUIRED_FACECLAW_FIRMWARE_VERSION) return null;
|
||||
return (
|
||||
`The glasses run Faceclaw firmware revision ${extension.version} (base ${versionsText}), ` +
|
||||
`but this version of Faceclaw requires revision ${REQUIRED_FACECLAW_FIRMWARE_VERSION}. ` +
|
||||
"Install the updated custom firmware to continue."
|
||||
);
|
||||
case "legacy-faceclaw":
|
||||
return (
|
||||
`The glasses run an older version of Faceclaw's custom firmware (reported "${extension.text}", ` +
|
||||
`base ${versionsText}). This version of Faceclaw requires ${required}. ` +
|
||||
"Install the updated custom firmware to continue."
|
||||
);
|
||||
case "other":
|
||||
return (
|
||||
`The glasses run custom firmware from a different source (reported "${extension.text}", ` +
|
||||
`base ${versionsText}). Faceclaw requires ${required}; installing it will replace the current firmware.`
|
||||
);
|
||||
default:
|
||||
return (
|
||||
`The glasses report stock firmware ${versionsText}. Faceclaw requires ${required}. ` +
|
||||
"Displaying images will not work until the custom firmware is installed."
|
||||
);
|
||||
}
|
||||
|
||||
const tokens = info.capabilities.trim().split(/\s+/);
|
||||
const missingExtensions = REQUIRED_FIRMWARE_EXTENSIONS.filter(
|
||||
(extension) => !tokens.includes(extension),
|
||||
);
|
||||
if (missingExtensions.length) {
|
||||
return (
|
||||
`The glasses firmware (${versionsText}) does not advertise the required ` +
|
||||
`${missingExtensions.map((extension) => `"${extension}"`).join(" and ")} extension` +
|
||||
`${missingExtensions.length === 1 ? "" : "s"}` +
|
||||
`${info.capabilities.trim() ? ` (reported: ${info.capabilities.trim()})` : ", which suggests stock firmware"}. ` +
|
||||
`Faceclaw requires the modified firmware with the guarded 640x480 direct-framebuffer path and wear notifications.`
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/** True when the glasses advertise every custom-firmware extension Faceclaw needs. */
|
||||
export function hasCustomFirmware(info: FirmwareInfo): boolean {
|
||||
const tokens = info.capabilities.trim().split(/\s+/);
|
||||
return REQUIRED_FIRMWARE_EXTENSIONS.every((extension) => tokens.includes(extension));
|
||||
}
|
||||
|
||||
/**
|
||||
* True when the firmware advertises the optional mic-control extension: the
|
||||
* private field-103/104 channel for per-temple multi-microphone capture that
|
||||
* the Microphones app's 4-mic array mode and beamforming need. Absent on the
|
||||
* stock single-mono-stream path, which still works (firmware-computed
|
||||
* direction of arrival, one mixed channel).
|
||||
*/
|
||||
export function hasMicControl(info: FirmwareInfo): boolean {
|
||||
return info.capabilities.trim().split(/\s+/).includes("micctl");
|
||||
}
|
||||
|
||||
/**
|
||||
* True when the firmware advertises the optional ambient-light extension:
|
||||
* image-handler mode 16 (query / passive polling of the OPT3001 light sensor)
|
||||
* with field-105 reports, used to drive a phone-side brightness policy.
|
||||
*/
|
||||
export function hasAmbientLightSensor(info: FirmwareInfo): boolean {
|
||||
return info.capabilities.trim().split(/\s+/).includes("als16");
|
||||
}
|
||||
|
||||
/** The higher of the two arms' reported versions, or "" if none reported. */
|
||||
@@ -109,24 +155,56 @@ export function reportedFirmwareVersion(info: FirmwareInfo): string {
|
||||
|
||||
/**
|
||||
* How the pre-flash firmware check should treat the connected glasses:
|
||||
* - "custom": Faceclaw's firmware is already installed — nothing to flash.
|
||||
* - "custom": Faceclaw's firmware at the required revision (or newer) is
|
||||
* already installed — nothing to flash.
|
||||
* - "older-faceclaw": Faceclaw's firmware at an older revision (including
|
||||
* the pre-revision "EVENCFW" builds) — flash to update it.
|
||||
* - "other-custom": custom firmware from a different source — flash to
|
||||
* replace it.
|
||||
* - "flashable-stock": stock firmware at or below the version we build from.
|
||||
* - "newer-stock": stock firmware newer than we recognize — flash only on override.
|
||||
* - "newer-stock-validated": stock firmware newer than the version we build
|
||||
* from, on which the downgrade has been tested successfully
|
||||
* - "newer-stock-unvalidated": stock firmware newer than we recognize — flash only on override.
|
||||
* - "unknown": no version could be read (treated as a probe/connection failure).
|
||||
*/
|
||||
export type OnboardingFirmwareKind = "custom" | "flashable-stock" | "newer-stock" | "unknown";
|
||||
export type OnboardingFirmwareKind =
|
||||
| "custom"
|
||||
| "older-faceclaw"
|
||||
| "other-custom"
|
||||
| "flashable-stock"
|
||||
| "newer-stock-validated"
|
||||
| "newer-stock-unvalidated"
|
||||
| "unknown";
|
||||
|
||||
export function classifyOnboardingFirmware(info: FirmwareInfo): {
|
||||
kind: OnboardingFirmwareKind;
|
||||
version: string;
|
||||
extension: FirmwareExtension;
|
||||
} {
|
||||
if (hasCustomFirmware(info)) {
|
||||
return { kind: "custom", version: reportedFirmwareVersion(info) };
|
||||
}
|
||||
const extension = parseFirmwareExtension(info.extension);
|
||||
const version = reportedFirmwareVersion(info);
|
||||
switch (extension.kind) {
|
||||
case "faceclaw":
|
||||
return {
|
||||
kind: extension.version >= REQUIRED_FACECLAW_FIRMWARE_VERSION ? "custom" : "older-faceclaw",
|
||||
version,
|
||||
extension,
|
||||
};
|
||||
case "legacy-faceclaw":
|
||||
return { kind: "older-faceclaw", version, extension };
|
||||
case "other":
|
||||
return { kind: "other-custom", version, extension };
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (!version) {
|
||||
return { kind: "unknown", version: "" };
|
||||
return { kind: "unknown", version: "", extension };
|
||||
}
|
||||
if (compareVersions(parseDottedVersion(version), BASE_STOCK_VERSION) <= 0) {
|
||||
return { kind: "flashable-stock", version, extension };
|
||||
} else if (compareVersions(parseDottedVersion(version), VALIDATED_STOCK_VERSION) <= 0) {
|
||||
return { kind: "newer-stock-validated", version, extension };
|
||||
} else {
|
||||
return { kind: "newer-stock-unvalidated", version, extension };
|
||||
}
|
||||
const comparison = compareVersions(parseDottedVersion(version), FLASHABLE_STOCK_VERSION);
|
||||
return { kind: comparison <= 0 ? "flashable-stock" : "newer-stock", version };
|
||||
}
|
||||
@@ -19,168 +19,192 @@ export type FirmwarePatchSet = {
|
||||
export const CFW_PATCH_SET: FirmwarePatchSet = {
|
||||
"base": "g2_2.2.9.22.bin",
|
||||
"baseSha256": "a03fbea9f68a9de6bc271daabb9f3a41c59053d1086622c76a4e990f829cc561",
|
||||
"outputSha256": "920f5e45129453c155d7fb004b93049985594744be973e793cf41e8b6e07005a",
|
||||
"outputSha256": "32cea69474252a2b2f9c0fdc5f89bf0d5d6f745b4eec10aea8e9c34e3f106b3f",
|
||||
"patches": [
|
||||
{
|
||||
"offset": 935280,
|
||||
"old": "fff717f8",
|
||||
"new": "64f395fb",
|
||||
"desc": "bl cfw_message_bridge_received (ordered private bridge delivery before worker pool)"
|
||||
},
|
||||
{
|
||||
"offset": 935628,
|
||||
"old": "fef769ff",
|
||||
"new": "64f3e7fa",
|
||||
"desc": "bl cfw_message_bridge_received (ordered private bridge delivery before worker pool)"
|
||||
},
|
||||
{
|
||||
"offset": 943818,
|
||||
"old": "fcf76aff",
|
||||
"new": "62f3e8fa",
|
||||
"desc": "bl cfw_message_bridge_received (ordered private bridge delivery before worker pool)"
|
||||
},
|
||||
{
|
||||
"offset": 1415004,
|
||||
"old": "fcf745f8",
|
||||
"new": "eef23dfb",
|
||||
"desc": "bl cfw_receive_packet (private SID-f0 probe before TPL reassembly)"
|
||||
},
|
||||
{
|
||||
"offset": 1363762,
|
||||
"old": "7c20",
|
||||
"new": "7d20",
|
||||
"desc": "Set Local Feature: enable LE 2M bit 8"
|
||||
},
|
||||
{
|
||||
"offset": 4410298,
|
||||
"old": "0c001800",
|
||||
"new": "06000600",
|
||||
"desc": "fast connection interval min=max=7.5 ms; latency remains 0"
|
||||
},
|
||||
{
|
||||
"offset": 1053266,
|
||||
"old": "0500",
|
||||
"new": "a325",
|
||||
"desc": "_connectParamReq_impl: force requested mode to fast (0xa3); disables idle slow requests"
|
||||
},
|
||||
{
|
||||
"offset": 1124178,
|
||||
"old": "5ff43432",
|
||||
"new": "5ff43332",
|
||||
"desc": "reserve final 1 KiB of primary TLSF arena for CFW context anchor"
|
||||
},
|
||||
{
|
||||
"offset": 1524180,
|
||||
"old": "bdf82c10",
|
||||
"new": "40f24120",
|
||||
"desc": "container width <= 576"
|
||||
},
|
||||
{
|
||||
"offset": 1524380,
|
||||
"old": "bdf82e00",
|
||||
"new": "40f22111",
|
||||
"desc": "container height movw #0x121"
|
||||
},
|
||||
{
|
||||
"offset": 1524384,
|
||||
"old": "9128",
|
||||
"new": "8842",
|
||||
"desc": "container height cmp r0,r1"
|
||||
},
|
||||
{
|
||||
"offset": 1516784,
|
||||
"old": "70f775ff",
|
||||
"new": "d6f295fa",
|
||||
"desc": "bl snapshot_side @ 0x4ec0ee (shared image-complete helper)"
|
||||
},
|
||||
{
|
||||
"offset": 1516816,
|
||||
"old": "30d0",
|
||||
"new": "1cd0",
|
||||
"desc": "image-complete success -> immediate ACK (pipelining-safe)"
|
||||
},
|
||||
{
|
||||
"offset": 1222660,
|
||||
"old": "49f0daff",
|
||||
"new": "1ef30ff9",
|
||||
"desc": "bl image_deferred (deferred consumer -> FIFO restore + worker, both lenses)"
|
||||
},
|
||||
{
|
||||
"offset": 1242342,
|
||||
"old": "d4f790fb",
|
||||
"new": "1af3faf9",
|
||||
"new": "1af33cfc",
|
||||
"desc": "bl settings_send_wrapper (append caps field 100)"
|
||||
},
|
||||
{
|
||||
"offset": 1240038,
|
||||
"old": "f5f710f9",
|
||||
"new": "1af3bafb",
|
||||
"new": "1af3dafd",
|
||||
"desc": "bl settings_decode_wrapper (Faceclaw lease field 101)"
|
||||
},
|
||||
{
|
||||
"offset": 939336,
|
||||
"old": "0bf02af9",
|
||||
"new": "63f325fe",
|
||||
"desc": "bl faceclaw_display_start @ 0x45f146 (fail-open double-tap takeover)"
|
||||
"new": "64f351f8",
|
||||
"desc": "bl faceclaw_display_start @ 0x45f146 (fail-open wake takeover)"
|
||||
},
|
||||
{
|
||||
"offset": 939528,
|
||||
"old": "0bf0caf8",
|
||||
"new": "63f3c5fd",
|
||||
"desc": "bl faceclaw_display_start @ 0x45f206 (fail-open double-tap takeover)"
|
||||
"new": "64f3bff8",
|
||||
"desc": "bl faceclaw_display_start_headup @ 0x45f206 (fail-open wake takeover)"
|
||||
},
|
||||
{
|
||||
"offset": 939016,
|
||||
"old": "10f096f8",
|
||||
"new": "65f397fd",
|
||||
"desc": "bl headup_gate (head-up sensor event -> EvenHub sys event 12 under lease)"
|
||||
},
|
||||
{
|
||||
"offset": 939036,
|
||||
"old": "fff765fb",
|
||||
"new": "63f3ddff",
|
||||
"desc": "bl faceclaw_idle_input_gate (idle tap/long/release -> field-102 events 2/3/4)"
|
||||
},
|
||||
{
|
||||
"offset": 831036,
|
||||
"old": "1df057fc",
|
||||
"new": "7ff3b3fd",
|
||||
"new": "7ff373ff",
|
||||
"desc": "bl gesture_press (Faceclaw lease gates event 9 vs stock UI event 8)"
|
||||
},
|
||||
{
|
||||
"offset": 831042,
|
||||
"old": "24f023f9",
|
||||
"new": "7ff354fe",
|
||||
"new": "80f314f8",
|
||||
"desc": "bl gesture_short_long (Faceclaw lease gates event 11 vs stock Menu path)"
|
||||
},
|
||||
{
|
||||
"offset": 831800,
|
||||
"old": "1df0d9fa",
|
||||
"new": "7ff339fc",
|
||||
"new": "7ff3f9fd",
|
||||
"desc": "bl gesture_release (source-qualified event 10 vs stock UI event 0x4a)"
|
||||
},
|
||||
{
|
||||
"offset": 1553752,
|
||||
"old": "7fb50600",
|
||||
"new": "cef2afb9",
|
||||
"new": "cef2f1bb",
|
||||
"desc": "even_ai_display_ctrl entry -> conditional Faceclaw lease trampoline"
|
||||
},
|
||||
{
|
||||
"offset": 1047796,
|
||||
"old": "f6f7edff",
|
||||
"new": "45f37df9",
|
||||
"new": "45f32ffd",
|
||||
"desc": "bl display_copy_hook @ 0x4798f2 (640x480 direct framebuffer)"
|
||||
},
|
||||
{
|
||||
"offset": 1048112,
|
||||
"old": "f6f74fff",
|
||||
"new": "45f3dff8",
|
||||
"new": "45f391fc",
|
||||
"desc": "bl display_copy_hook @ 0x479a2e (640x480 direct framebuffer)"
|
||||
},
|
||||
{
|
||||
"offset": 1255404,
|
||||
"old": "d9f758ff",
|
||||
"new": "16f3fbfb",
|
||||
"new": "16f3f9fd",
|
||||
"desc": "bl faceclaw_send_wear_event @ 0x4ac3ea (outside onboarding)"
|
||||
},
|
||||
{
|
||||
"offset": 1255504,
|
||||
"old": "d9f726ff",
|
||||
"new": "16f3c9fb",
|
||||
"new": "16f3c7fd",
|
||||
"desc": "bl faceclaw_send_wear_event @ 0x4ac44e (outside onboarding)"
|
||||
},
|
||||
{
|
||||
"offset": 831998,
|
||||
"old": "1df076fa",
|
||||
"new": "79f3b8fe",
|
||||
"desc": "bl compass_event_forward (global IMU heading -> stock nav BLE notifier)"
|
||||
"offset": 1297700,
|
||||
"old": "65f0affd",
|
||||
"new": "0cf351f8",
|
||||
"desc": "bl compass_decode_capture (sample-matched GAF diagnostics)"
|
||||
},
|
||||
{
|
||||
"offset": 1296176,
|
||||
"old": "fff759fc",
|
||||
"new": "0cf3c7fb",
|
||||
"desc": "bl compass_report_event (stock UI + heading with diagnostics over BLE)"
|
||||
},
|
||||
{
|
||||
"offset": 4476518,
|
||||
"old": "",
|
||||
"new": "02fb01f000e000bfb0b54ff2ac44c2f229040146206846f23f52c5f28802b2eb500f40f258304cf2e9124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bf0846ffe7014640f258304cf20732c2f20000c0f24802104770b500284ed001684ef66962ccf2ff02914218bf70bd90f8081190f8095146f6756c8d42c0f2510c2ad205eb8501014491f80d2191f80e4191f80ae191f80b3191f80c1142ea0424012c4ff0010298bf14466e1c054680f80961b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f80811bde870406047e047d5f8040138b142f64d42c0f244022146bde87040104770bd00bf70b542f2ed23c0f2460314460d4698474ff2a841c2f229010e6831466ff39601b1f1005f0ad131684ef66962ccf2ff02914218bf0026412d03d070bd0026412dfbd1002cf9d04cf6dd71c0f2450105468847002e01462846efd00129edd196f807120029e9d02168002948bf70bd4ff27d42c0f2590208469047284670bd00bf2de9f04f9db04ff2a84ac2f2290adaf800b058466ff39600b0f1005f40f07d81dbf800004ef66967ccf2ff07b84240f074819bf82802002800f05d81dbf82442002c00f0588140f6b400c2f20000d0f8008004a802f0aaffb8f1000f00f0f881032045f24075cff68070a4f1600108f160026ff0bf03c0f2020500bf0e6ed41826664e6ec03366668e6eab42a666ce6ee6660e6f26674e6f66678e6fa667ce6fe667d1f88060c4f88060d1f88460c4f88460d1f88860c4f88860d1f88c60c4f88c60d1f89060c4f89060d1f89460c4f89460d1f89860c4f89860d1f89c60c4f89c60d1f8a060c4f8a060d1f8a460c4f8a460d1f8a860c4f8a860d1f8ac60c4f8ac60d1f8b060c4f8b060d1f8b460c4f8b460d1f8b860c4f8b860d1f8bc60c4f8bc6051f8c06fc4f8c0604e68c4f8c4608e68c4f8c860ce68c4f8cc600e69c4f8d0604e69c4f8d4608e69c4f8d860ce69c4f8dc600e6ac4f8e0604e6ac4f8e4608e6ac4f8e860ce6ac4f8ec600e6bc4f8f0604e6bc4f8f4608e6bc4f8f860ce6bc4f8fc600e6cc4f800614e6cc4f804618e6cc4f80861ce6cc4f80c610e6dc4f810614e6dc4f814618e6dc4f81861ce6dc4f81c617ff462afdaf800603040b0f1005f40f0b2803068b84240f0ae8096f8ce00002840f04f8196f8dc10002000298df8140000f0c78105a90a5c002a00f09a810a185378002b00f058819378002b00f05681d378002b00f054811379002b00f052815379002b00f050819379002b00f04e81d379002b00f04c81137a002b00f04a81537a002b00f04881937a002b00f04681d37a002b00f04481137b002b00f04281537b002b00f04081937b002b00f03e81d37b002b00f03c81137c002b00f03a81537c002b00f03881937c002b00f03681d37c002b00f03481137d002b00f03281537d002b00f03081937d002b00f02e81d37d002b00f02c81137e002b00f02a81537e002b00f02881937e002b00f02681d37e002b00f02481137f002b00f02281537f002b00f02081937f002b00f01e81d27f002a00f01c81203060287ff47baf3be19bf82a0270b1dbf82c0240b146f68051c2f207010968401a002800f3c98000208bf82a0240f6d100c0f247001db0bde8f04f00474ff4217004f071fd002800f09c804ff67c51cff6ff71002200bf43182e3183f8842283f8852283f8862283f8872283f8882283f8892283f88a2283f88b2283f88c2283f88d2283f88e2283f88f2283f8902283f8912283f8922283f8932283f8942283f8952283f8962283f8972283f8982283f8992283f89a2283f89b2283f89c2283f89d2283f89e2283f89f2283f8a02283f8a12283f8a22283f8a32283f8a42283f8a52283f8a62283f8a72283f8a82283f8a92283f8aa2283f8ab2283f8ac2283f8ad2283f8ae2283f8af2283f8b02283f8b122a0d1012180f8ce104ff0ff310760a0f8e010a0f8e210a0f8e410a0f8e610a0f8e810a0f8ea10a0f8ec10a0f8ee10a0f8f010a0f8f210a0f8f410a0f8f610a0f8f810a0f8fa10a0f8fc10a0f8fe1010e000208bf82802cbf824028bf82a0201208bf8290240f6d100c0f24700804715e00020caf8000000208bf82802cbf824024ff416304cf60361069005a8c0f24701cdf81480884701208bf82a0204a802f08bfecbf8d4001db0bde8f08f01303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f2821d84ff052020a541dd0014445225e284a7018d04f225d288a7014d052225c28ca7010d044225b280a710cd045225a284a7108d0522259288a7104d020225828ca7142f0178500208df87300012096f8dd10002900f0c280002105aa535c002b00f0a08057187b78002b5ed0bb78002b5dd0fb78002b5cd03b79002b5bd07b79002b5ad0bb79002b59d0fb79002b58d03b7a002b57d07b7a002b56d0bb7a002b55d0fb7a002b54d03b7b002b53d07b7b002b52d0bb7b002b51d0fb7b002b50d03b7c002b4fd07b7c002b4ed0bb7c002b4dd0fb7c002b4cd03b7d002b4bd07b7d002b4ad0bb7d002b49d0fb7d002b48d03b7e002b47d07b7e002b46d0bb7e002b45d0fb7e002b44d03b7f002b43d07b7f002b42d0bb7f002b41d0fb7f002b40d0203160297ff49aaf54e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2915d84ff05303535411d00a444b235e2953700cd049235d29937008d050235c29d37004d020235b29137140f0c28200218df87310013096f8de10002900f0be80002105aa535c002b00f0a08057187b78002b5ed0bb78002b5dd0fb78002b5cd03b79002b5bd07b79002b5ad0bb79002b59d0fb79002b58d03b7a002b57d07b7a002b56d0bb7a002b55d0fb7a002b54d03b7b002b53d07b7b002b52d0bb7b002b51d0fb7b002b50d03b7c002b4fd07b7c002b4ed0bb7c002b4dd0fb7c002b4cd03b7d002b4bd07b7d002b4ad0bb7d002b49d0fb7d002b48d03b7e002b47d07b7e002b46d0bb7e002b45d0fb7e002b44d03b7f002b43d07b7f002b42d0bb7f002b41d0fb7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e01Line truncated
|
||||
"new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf2de9f04fa5b04ef66c6b4ff2a84416460d46ccf2ff0bc2f229044ff6ff7900274ff00108019006e048f2c731c0f24501bff32f8f8847d4f800a0bff35f8f20680321cff680710140b1f1005fbff35f8f03d10168594500f0bb804ff4377005f039f8002800f0a1824ff62451cff6ff7142183d3182f8dc7282f8dd7282f8de7282f8df7282f8e07282f8e17282f8e27282f8e37282f8e47282f8e57282f8e67282f8e77282f8e87282f8e97282f8ea7282f8eb7282f8ec7282f8ed7282f8ee7282f8ef7282f8f07282f8f17282f8f27282f8f37282f8f47282f8f57282f8f67282f8f77282f8f87282f8f97282f8fa7282f8fb7282f8fc7282f8fd7282f8fe7282f8ff7282f8007382f8017382f8027382f8037382f8047382f8057382f8067382f8077382f8087382f8097382f80a7382f80b7382f80c7382f80d7382f80e7382f80f7382f8107382f8117382f8127382f8137382f8147382f8157382f8167382f8177382f8187382d1c0f800b080f80a80a0f81c90a0f81e90a0f82090a0f82290a0f82490a0f82690a0f82890a0f82a90a0f82c90a0f82e90a0f83090a0f83290a0f83490a0f83690a0f83890a0f83a9054e8001f51457ff436afbff35f8f44e8000121b154e8001f5145f8d02be7aa4645ea064100260127c0f8701206e048f2c731c0f24501bff32f8f88472568bff35f8f20680321cff680710140b1f1005fbff35f8f03d10168594500f0bc804ff4377004f05eff002800f0c6814ff62451cff6ff7100bf42183d3182f8dc6282f8dd6282f8de6282f8df6282f8e06282f8e16282f8e26282f8e36282f8e46282f8e56282f8e66282f8e76282f8e86282f8e96282f8ea6282f8eb6282f8ec6282f8ed6282f8ee6282f8ef6282f8f06282f8f16282f8f26282f8f36282f8f46282f8f56282f8f66282f8f76282f8f86282f8f96282f8fa6282f8fb6282f8fc6282f8fd6282f8fe6282f8ff6282f8006382f8016382f8026382f8036382f8046382f8056382f8066382f8076382f8086382f8096382f80a6382f80b6382f80c6382f80d6382f80e6382f80f6382f8106382f8116382f8126382f8136382f8146382f8156382f8166382f8176382f8186382d1c0f800b08772a0f81c90a0f81e90a0f82090a0f82290a0f82490a0f82690a0f82890a0f82a90a0f82c90a0f82e90a0f83090a0f83290a0f83490a0f83690a0f83890a0f83a9054e8001fa9427ff437afbff35f8f00bf44e8000121b154e8001fa942f8d02be7d0f8746242f6f767c0f24407002ebff35f8f00f0eb8007f19a0230464ff0ff314ff0ff379047002840f0418143f67750c0f24f00804700274ff001080397adf8107006e048f2c731c0f24501bff32f8f88472568bff35f8f20680321cff680710140b1f1005fbff35f8f03d10168594500f0e1804ff4377004f068fe002800f0d9804ff62451cff6ff7100bf42183d3182f8dc7282f8dd7282f8de7282f8df7282f8e07282f8e17282f8e27282f8e37282f8e47282f8e57282f8e67282f8e77282f8e87282f8e97282f8ea7282f8eb7282f8ec7282f8ed7282f8ee7282f8ef7282f8f07282f8f17282f8f27282f8f37282f8f47282f8f57282f8f67282f8f77282f8f87282f8f97282f8fa7282f8fb7282f8fc7282f8fd7282f8fe7282f8ff7282f8007382f8017382f8027382f8037382f8047382f8057382f8067382f8077382f8087382f8097382f80a7382f80b7382f80c7382f80d7382f80e7382f80f7382f8107382f8117382f8127382f8137382f8147382f8157382f8167382f8177382f8187382d1c0f800b080f80a80a0f81c90a0f81e90a0f82090a0f82290a0f82490a0f82690a0f82890a0f82a90a0f82c90a0f82e90a0f83090a0f83290a0f83490a0f83690a0f83890a0f83a9054e8001fa9427ff436afbff35f8f44e8000149b354e8001fa942f8d02be705460020b847b0b105f51d7151e8006f4eb9bff35f8f00bf41e8000292b151e8006f002ef8d00021bff32f8fbff35f8f21b10646f9e64ff0ff3742e007f5a9718847f2e60121f1e70020019d42f6f764002d4ff0010bc0f2440418bfbaf1000f33d10df108098046484602f07df903ab28465146012205f0abfc9df8111007464846002918bf4ff0ff3702f0a3fabbf1000f044608d19df8100028b949f28340c0f247004c308047b8f1000f18bfc8f80c4042f6f764c0f2440404f5807130468847384625b0bde8f08f2a7802f07f01a1f1150313f1030f0bd802f07b030b2b07d002f07e02082a03d0032901d00629b7d140b149f28341c0f247010746884797f8641111b14ff0ff37d6e738464ff0000ba6e770b500284dd001684ef66c62ccf2ff02914218bf70bd90f8441090f8455046f6756c8d42c0f2510c2ad205eb8501014491f8492091f84a4091f846e091f8473091f8481042ea0424012c4ff0010298bf14466e1c054680f84560b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f84410bde870406047e047286c38b142f64d42c0f244022146bde87040104770bd02464ff64b70cff6ff7042f6653c7844c0f2440c00210023604700bf2de9f04f9fb04ff2a840c2f229000668bff35f8f30466ff39600b0f1005f42d130684ef66c65ccf2ff05a8423bd196f8640130b3d6f860411cb340f6b400c2f20000076804a802f0a5f8002f00f06a8140f2030a384621464ff416320296cff6807a4ff6ff760397fff752fb4ff6245b48f2c738cff6ff7b00270124c0f245081ce096f8660170b1d6f8680140b146f68051c2f207010968401a002802f37080002086f8660140f6d100c0f247001fb0bde8f04f0047bff32f8fc0474ff2a840c2f22900d0f80090bff35f8f0Line truncated
|
||||
"desc": "append injected blobs to main-app payload"
|
||||
},
|
||||
{
|
||||
"offset": 779114,
|
||||
"old": "846a3800",
|
||||
"new": "0e073900",
|
||||
"new": "7c1b3900",
|
||||
"desc": "main-app subheader payload size (ps)"
|
||||
},
|
||||
{
|
||||
"offset": 152,
|
||||
"old": "046b3800",
|
||||
"new": "8e073900",
|
||||
"new": "fc1b3900",
|
||||
"desc": "main-app TOC entry size (ps + 128)"
|
||||
},
|
||||
{
|
||||
"offset": 779234,
|
||||
"old": "846a3804",
|
||||
"new": "0e073904",
|
||||
"new": "7c1b3904",
|
||||
"desc": "main-app preamble length (low 24 bits)"
|
||||
},
|
||||
{
|
||||
"offset": 779238,
|
||||
"old": "85c355a2",
|
||||
"new": "21ab3673",
|
||||
"new": "a1afb7e4",
|
||||
"desc": "[5] ota/s200_firmware_ota.bin preamble crc32"
|
||||
},
|
||||
{
|
||||
"offset": 156,
|
||||
"old": "ed292ee4",
|
||||
"new": "9e600c9c",
|
||||
"new": "b1adc0d0",
|
||||
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (TOC)"
|
||||
},
|
||||
{
|
||||
"offset": 779118,
|
||||
"old": "ed292ee4",
|
||||
"new": "9e600c9c",
|
||||
"new": "b1adc0d0",
|
||||
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (subheader)"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -0,0 +1,280 @@
|
||||
/**
|
||||
* 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
|
||||
* (below only the lock screen), so it never composites with the sidebar,
|
||||
* top bar, or the sleeping app's retained frame. The host owns that surface,
|
||||
* the visibility state machine (glance-state.ts), its auto-hide timer, and
|
||||
* the board's render loop; the controller feeds it sleep-time input and the
|
||||
* wake barrier, and takes the compositor back to blank when the board hides.
|
||||
*/
|
||||
import { GrayImage, G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../graphics/image";
|
||||
import { prepareFrameDraws } from "../graphics/glyph-wire";
|
||||
import { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../graphics/plane";
|
||||
import * as frameTimings from "../native/frame-timings";
|
||||
import { type DisplayTarget } from "../native/preview-display";
|
||||
import { minWindowTop } from "../ui/shell/geometry";
|
||||
import { beginRenderPass, endRenderPass } from "../util/render-freshness";
|
||||
import { type GlanceBoardInstance, type GlanceboardProvider } from "../apps/app-definition";
|
||||
import { GLANCE_HIDDEN, glanceEventForGesture, reduceGlance, type GlanceEvent, type GlanceState } from "./glance-state";
|
||||
|
||||
export const GLANCE_SURFACE_ID = "glance";
|
||||
/** Above the shell (1) and every window (0); below the lock screen (1000). */
|
||||
export const GLANCE_SURFACE_Z_ORDER = 900;
|
||||
|
||||
export type GlanceHostOptions = {
|
||||
getDisplay: () => DisplayTarget | null;
|
||||
getProvider: () => GlanceboardProvider | null;
|
||||
/** Whether a board may show right now (connected or preview, not locked). */
|
||||
canShow: () => boolean;
|
||||
/**
|
||||
* The controller's wake barrier: restore the EvenHub session if it was
|
||||
* suspended and unblank the compositor. Resolves once the frame is visible.
|
||||
*/
|
||||
ensureSessionActive: (frameId: number) => Promise<boolean>;
|
||||
/**
|
||||
* The board hid on its own (timer or release) with the shell still
|
||||
* asleep: the controller re-blanks and re-arms the screen-off power save.
|
||||
*/
|
||||
onHiddenWhileAsleep: () => void;
|
||||
/** Visibility changed either way (phone mirror refresh). */
|
||||
onVisibilityChanged: () => void;
|
||||
appendLog: (message: string) => void;
|
||||
};
|
||||
|
||||
export class GlanceHost {
|
||||
private state: GlanceState = GLANCE_HIDDEN;
|
||||
private board: GlanceBoardInstance | null = null;
|
||||
/** Whether the surface is currently visible on the compositor. */
|
||||
private shown = false;
|
||||
private hideTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
private configuredFor: DisplayTarget | null = null;
|
||||
/** Serializes show/hide against each other and against in-flight renders. */
|
||||
private queue: Promise<void> = Promise.resolve();
|
||||
private rendering = false;
|
||||
private renderPending = false;
|
||||
private nextRenderWantsFreshData = false;
|
||||
|
||||
constructor(private readonly options: GlanceHostOptions) {}
|
||||
|
||||
isVisible(): boolean {
|
||||
return this.state.visible;
|
||||
}
|
||||
|
||||
/** Whether sleep-time gestures should reach the board at all. */
|
||||
isEnabled(): boolean {
|
||||
return this.options.getProvider()?.isEnabled() ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The glance event a sleep-time gesture means under the board's settings,
|
||||
* or null when the shell should see the input as usual: nothing while the
|
||||
* board is disabled, no press from a tap when "Show on tap" is disabled,
|
||||
* no hold when "Show on long press" is off, no press from a head-tilt when
|
||||
* "Show on head tilt" is off (it then wakes the regular UI). A release
|
||||
* always passes so a hold in progress can end.
|
||||
*/
|
||||
eventForGesture(gesture: "head-tilt" | string): GlanceEvent | null {
|
||||
const provider = this.options.getProvider();
|
||||
if (!provider?.isEnabled()) return null;
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a glance event from sleep-time input. The frame is owned from here:
|
||||
* a show submits it with the board's first frame, anything else finishes it.
|
||||
*/
|
||||
async handleEvent(event: GlanceEvent, frameId: number): Promise<void> {
|
||||
const before = this.state;
|
||||
const timeoutMs = this.options.getProvider()?.tapTimeoutMs();
|
||||
this.state = reduceGlance(before, event, Date.now(), timeoutMs);
|
||||
this.armHideTimer();
|
||||
if (this.state.visible === before.visible) {
|
||||
frameTimings.finishFrame(frameId, this.state.visible ? "glanceboard stays up" : "glance event while hidden");
|
||||
return;
|
||||
}
|
||||
if (this.state.visible) {
|
||||
await this.enqueue(() => this.show(frameId));
|
||||
} else {
|
||||
frameTimings.finishFrame(frameId, "glanceboard hidden");
|
||||
await this.enqueue(() => this.hide(true));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide because the regular UI is waking (double-tap, a notification, ...):
|
||||
* the shell's own wake path handles the compositor from here, so no re-blank.
|
||||
*/
|
||||
dismiss(): void {
|
||||
if (!this.state.visible && !this.shown && !this.board) return;
|
||||
this.state = GLANCE_HIDDEN;
|
||||
this.armHideTimer();
|
||||
void this.enqueue(() => this.hide(false));
|
||||
}
|
||||
|
||||
/** The display target went away (disconnect, preview teardown): forget everything. */
|
||||
reset(): void {
|
||||
this.state = GLANCE_HIDDEN;
|
||||
this.armHideTimer();
|
||||
this.board?.stop();
|
||||
this.board = null;
|
||||
this.shown = false;
|
||||
this.configuredFor = null;
|
||||
this.renderPending = false;
|
||||
}
|
||||
|
||||
private enqueue(operation: () => Promise<void>): Promise<void> {
|
||||
const run = this.queue.then(operation, operation).catch((error) => {
|
||||
this.options.appendLog(`glanceboard operation failed: ${String(error)}`);
|
||||
});
|
||||
this.queue = run;
|
||||
return run;
|
||||
}
|
||||
|
||||
private armHideTimer(): void {
|
||||
if (this.hideTimer !== null) clearTimeout(this.hideTimer);
|
||||
this.hideTimer = null;
|
||||
const hideAtMs = this.state.hideAtMs;
|
||||
if (!this.state.visible || hideAtMs === null) return;
|
||||
this.hideTimer = setTimeout(() => {
|
||||
this.hideTimer = null;
|
||||
void this.handleEvent({ type: "timeout" }, frameTimings.startFrame("glanceboard timeout"));
|
||||
}, Math.max(0, hideAtMs - Date.now()));
|
||||
}
|
||||
|
||||
private async configureSurface(display: DisplayTarget): Promise<void> {
|
||||
await display.configureSurface(GLANCE_SURFACE_ID, {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: G2_LENS_WIDTH,
|
||||
height: G2_LENS_HEIGHT,
|
||||
zOrder: GLANCE_SURFACE_Z_ORDER,
|
||||
transparency: "opaque",
|
||||
});
|
||||
await display.setSurfaceVisible(GLANCE_SURFACE_ID, false);
|
||||
this.configuredFor = display;
|
||||
}
|
||||
|
||||
private async show(frameId: number): Promise<void> {
|
||||
if (!this.state.visible) {
|
||||
// Hidden again before this ran (a quick release); nothing to do.
|
||||
frameTimings.finishFrame(frameId, "glanceboard show superseded");
|
||||
return;
|
||||
}
|
||||
const display = this.options.getDisplay();
|
||||
const provider = this.options.getProvider();
|
||||
if (!display || !provider || !this.options.canShow()) {
|
||||
this.state = GLANCE_HIDDEN;
|
||||
this.armHideTimer();
|
||||
frameTimings.finishFrame(frameId, "glanceboard unavailable");
|
||||
return;
|
||||
}
|
||||
if (this.configuredFor !== display) await this.configureSurface(display);
|
||||
if (!this.board) {
|
||||
this.board = provider.createBoard(() => this.requestRender());
|
||||
this.board.start();
|
||||
}
|
||||
// Submit the first frame and reveal the surface while the compositor is
|
||||
// still blanked, so the unblank below composites the board on top of the
|
||||
// sleeping UI in one step rather than flashing the app first.
|
||||
await this.render(frameId);
|
||||
await display.setSurfaceVisible(GLANCE_SURFACE_ID, true);
|
||||
this.shown = true;
|
||||
const ready = await this.options.ensureSessionActive(frameId);
|
||||
if (!ready) this.options.appendLog("glanceboard: wake barrier did not complete");
|
||||
this.options.onVisibilityChanged();
|
||||
}
|
||||
|
||||
private async hide(stillAsleep: boolean): Promise<void> {
|
||||
const wasShown = this.shown;
|
||||
this.shown = false;
|
||||
const display = this.options.getDisplay();
|
||||
if (wasShown && display && this.configuredFor === display) {
|
||||
// Blank before revealing what is under the board: hiding the surface
|
||||
// first recomposites the sleeping UI's retained frames and transmits
|
||||
// them, a visible flash of the main UI before the screen goes dark.
|
||||
// Blanked, the surface change composites to the same black frame. (The
|
||||
// controller's screen-off path below blanks again, harmlessly.)
|
||||
if (stillAsleep) {
|
||||
await display.setScreenBlanked(true);
|
||||
}
|
||||
await display.setSurfaceVisible(GLANCE_SURFACE_ID, false);
|
||||
}
|
||||
this.board?.stop();
|
||||
this.board = null;
|
||||
this.renderPending = false;
|
||||
if (wasShown && stillAsleep) this.options.onHiddenWhileAsleep();
|
||||
if (wasShown) this.options.onVisibilityChanged();
|
||||
}
|
||||
|
||||
private requestRender(): void {
|
||||
if (!this.board) return;
|
||||
if (this.rendering) {
|
||||
this.renderPending = true;
|
||||
return;
|
||||
}
|
||||
void this.enqueue(() => this.render(frameTimings.startFrame("render:glanceboard")));
|
||||
}
|
||||
|
||||
/** Paint the board into a full-screen frame and submit it to the surface. */
|
||||
private async render(frameId: number): Promise<void> {
|
||||
const board = this.board;
|
||||
const display = this.options.getDisplay();
|
||||
if (!board || !display || this.configuredFor !== display) {
|
||||
frameTimings.finishFrame(frameId, "discarded: glanceboard not showing");
|
||||
return;
|
||||
}
|
||||
this.rendering = true;
|
||||
try {
|
||||
frameTimings.annotateFrame(frameId, "glanceboard");
|
||||
const wantFreshData = this.nextRenderWantsFreshData;
|
||||
this.nextRenderWantsFreshData = false;
|
||||
beginRenderPass(!wantFreshData);
|
||||
const paintStartedAtMs = Date.now();
|
||||
const frame = frameTimings.span(frameId, "paint", () =>
|
||||
frameTimings.runWithFrame(frameId, () => {
|
||||
const boardImage = board.paint();
|
||||
const full = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
||||
// Centred horizontally in the panel, in the standard window band
|
||||
// vertically (Display > Vertical position).
|
||||
const x = Math.max(0, ((G2_LENS_WIDTH - boardImage.width) / 2) | 0);
|
||||
const y = Math.max(0, Math.min(G2_LENS_HEIGHT - boardImage.height, minWindowTop()));
|
||||
boardImage.composeInto(full, x, y);
|
||||
return full;
|
||||
}),
|
||||
);
|
||||
const paintUsedStaleData = endRenderPass();
|
||||
const paintMs = Date.now() - paintStartedAtMs;
|
||||
const planes: Plane[] = [{ image: frame, x: 0, y: 0 }];
|
||||
const fingerprint = frameTimings.span(frameId, "fingerprint", () => planesFingerprint(planes));
|
||||
const { image, draws } = frameTimings.span(frameId, "flatten", () => flattenPlanesWithDraws(planes));
|
||||
const buffer = frameTimings.span(frameId, "to8bpp", () => image.to8bppBuffer());
|
||||
const preparedDraws = frameTimings.span(frameId, "prepareFrameDraws", () => prepareFrameDraws(draws));
|
||||
await frameTimings.spanAsync(frameId, "submit", () =>
|
||||
display.submitSurfaceFrame(
|
||||
GLANCE_SURFACE_ID,
|
||||
buffer,
|
||||
{ x: 0, y: 0, width: image.width, height: image.height },
|
||||
fingerprint,
|
||||
paintMs,
|
||||
frameId,
|
||||
preparedDraws,
|
||||
),
|
||||
);
|
||||
if (paintUsedStaleData) {
|
||||
// Same contract as the windows: a paint that used cached data (the
|
||||
// notification icons) gets one follow-up with fresh data.
|
||||
this.nextRenderWantsFreshData = true;
|
||||
this.renderPending = true;
|
||||
}
|
||||
} finally {
|
||||
this.rendering = false;
|
||||
if (this.renderPending && this.board) {
|
||||
this.renderPending = false;
|
||||
this.requestRender();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* The Glanceboard's visibility rules, as a pure reducer so they can be tested
|
||||
* without the display plumbing. The board is an alternate sleep-time display:
|
||||
* while the shell is asleep a press (single tap, or a head-tilt wake) shows it
|
||||
* for a short while, a hold (long-press or short-then-long-press) shows it until release,
|
||||
* and a double-tap dismisses it in favour of the regular UI. GlanceHost feeds
|
||||
* these events in and applies the resulting visibility to the compositor.
|
||||
*
|
||||
* No NativeScript imports: this module is compiled and run under plain node
|
||||
* by tests/glance-state.test.cjs.
|
||||
*/
|
||||
|
||||
/** Fallback press timeout when the host supplies none; each further press restarts it. */
|
||||
export const GLANCE_TIMEOUT_MS = 3000;
|
||||
|
||||
export type GlanceState = {
|
||||
visible: boolean;
|
||||
/** A long-press is holding the board up; the timer does not run meanwhile. */
|
||||
holding: boolean;
|
||||
/** When the board hides on its own (epoch ms), or null while held / hidden. */
|
||||
hideAtMs: number | null;
|
||||
};
|
||||
|
||||
export type GlanceEvent =
|
||||
/** Single tap or head-tilt wake: show, and (re)start the auto-hide timer. */
|
||||
| { type: "press" }
|
||||
/** Long-press: show and keep showing until the release. */
|
||||
| { type: "hold" }
|
||||
/** The long-press ended. */
|
||||
| { type: "release" }
|
||||
/** The auto-hide timer fired. */
|
||||
| { type: "timeout" }
|
||||
/** Double-tap (or any other wake of the regular UI): hide now. */
|
||||
| { type: "dismiss" };
|
||||
|
||||
export const GLANCE_HIDDEN: GlanceState = Object.freeze({ visible: false, holding: false, hideAtMs: null });
|
||||
|
||||
export function reduceGlance(
|
||||
state: GlanceState,
|
||||
event: GlanceEvent,
|
||||
nowMs: number,
|
||||
timeoutMs: number = GLANCE_TIMEOUT_MS,
|
||||
): GlanceState {
|
||||
switch (event.type) {
|
||||
case "press":
|
||||
// A tap during a hold changes nothing: the hold decides when it ends.
|
||||
if (state.holding) return state;
|
||||
return { visible: true, holding: false, hideAtMs: nowMs + timeoutMs };
|
||||
case "hold":
|
||||
return { visible: true, holding: true, hideAtMs: null };
|
||||
case "release":
|
||||
// Releases delivered late or after a disabled hold gesture mean nothing here.
|
||||
return state.holding ? GLANCE_HIDDEN : state;
|
||||
case "timeout":
|
||||
if (!state.visible || state.holding || state.hideAtMs === null || nowMs < state.hideAtMs) return state;
|
||||
return GLANCE_HIDDEN;
|
||||
case "dismiss":
|
||||
return GLANCE_HIDDEN;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Which glance event, if any, a shell input gesture means while the screen is
|
||||
* off. A double-tap only concerns the board while it is showing (it then
|
||||
* dismisses it before waking the regular UI); everything else the shell
|
||||
* already handles or ignores while asleep.
|
||||
*/
|
||||
export function glanceEventForGesture(
|
||||
gesture: "click" | "double-click" | "long-press" | "short-then-long-press" | "long-press-release" | "head-tilt" | string,
|
||||
boardVisible: boolean,
|
||||
): GlanceEvent | null {
|
||||
switch (gesture) {
|
||||
case "click":
|
||||
case "head-tilt":
|
||||
return { type: "press" };
|
||||
case "long-press":
|
||||
case "short-then-long-press":
|
||||
return { type: "hold" };
|
||||
case "long-press-release":
|
||||
return { type: "release" };
|
||||
case "double-click":
|
||||
return boardVisible ? { type: "dismiss" } : null;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+115
-31
@@ -1,6 +1,8 @@
|
||||
import * as protocol from './ble-protocol'
|
||||
import { iosBleTraffic } from './ble-traffic-counters'
|
||||
import { buildBoundingBoxPayload } from './ble-image-optimizer'
|
||||
import { buildBoundingBoxPayload, buildFullFrameBands } from './ble-image-optimizer'
|
||||
import { CfwTransport, CFW_MAX_MESSAGE, parseCfwAcks } from './cfw-transport'
|
||||
import { hasCompatibleFirmware, firmwareIncompatibilityMessage, REQUIRED_FACECLAW_FIRMWARE_VERSION } from './firmware-compat'
|
||||
import { hexToBytes } from '../util/hex-util'
|
||||
import { deviceAddressError } from './ios-peripheral-identity'
|
||||
|
||||
@@ -25,7 +27,9 @@ class AckTimeout extends Error {}
|
||||
// Match Android ConnectionOptions.WINDOW_SIZE. This bounds complete image
|
||||
// messages queued for writing or awaiting ACK, not individual BLE packets.
|
||||
const DISPLAY_WINDOW_SIZE = 3
|
||||
type DisplayFrame = { packed: Uint8Array; payload: Uint8Array; offset: number; pending: number }
|
||||
type CfwPending = { payload: Uint8Array; checksum: number; role: string; magic: number; ackLenses: number; retries: number;
|
||||
retryPending: boolean; deadline: number; resolve: () => void; reject: (error: Error) => void }
|
||||
type DisplayFrame = { packed: Uint8Array; commands: Uint8Array[]; offset: number; pending: number }
|
||||
|
||||
/** G2 session independent of the phone OS. Images go to L, control to R, as on Android. */
|
||||
export class GlassesSession {
|
||||
@@ -34,6 +38,9 @@ export class GlassesSession {
|
||||
private generation = 0
|
||||
private ids: Record<string, string> = {}
|
||||
private limits: Record<string, number> = {}
|
||||
private cfwPending: CfwPending[] = []
|
||||
private cfwTransports = new Map<string, CfwTransport>()
|
||||
private cfwTimer: number | null = null
|
||||
private pending = new Map<string, PendingAck>()
|
||||
private receiver = new protocol.MessageReceiver()
|
||||
private writes = new Map<string, Promise<void>>()
|
||||
@@ -68,7 +75,6 @@ export class GlassesSession {
|
||||
private microphoneWork: Promise<void> = Promise.resolve()
|
||||
private microphoneEnabled = false
|
||||
constructor(private readonly transport: SessionTransport,
|
||||
private readonly deflate: (data: Uint8Array) => Uint8Array,
|
||||
private readonly onState: (state: SessionState) => void,
|
||||
private readonly onInput: (input: protocol.GlassesInput) => void,
|
||||
private readonly log: (message: string) => void = () => {},
|
||||
@@ -114,9 +120,9 @@ export class GlassesSession {
|
||||
this.update('connecting', 'Checking glasses firmware…')
|
||||
const settings = await this.request('right', protocol.SID.settings, protocol.settingsQuery, 'Settings query')
|
||||
this.applySettings(settings)
|
||||
const caps = this.state.capabilities.split(/\s+/)
|
||||
if (!['img640', 'fbguard', 'wearnotify'].every(cap => caps.includes(cap)))
|
||||
throw new Error('The glasses do not report compatible Faceclaw firmware (img640, fbguard, wearnotify). Bluetooth is working, but this display requires the modified firmware. Flashing remains available on Android.')
|
||||
const firmware = { leftVersion: this.state.leftVersion, rightVersion: this.state.rightVersion, extension: this.state.capabilities }
|
||||
if (!hasCompatibleFirmware(firmware))
|
||||
throw new Error((firmwareIncompatibilityMessage(firmware) || `The glasses must report Faceclaw firmware revision ${REQUIRED_FACECLAW_FIRMWARE_VERSION} or newer.`) + ' Flashing remains available on Android.')
|
||||
this.update('connecting', 'Starting glasses display…')
|
||||
await this.request('right', protocol.SID.launch, () => protocol.prelude(), 'App launch', 3500, 0x20, 156)
|
||||
await this.lease(true)
|
||||
@@ -176,7 +182,7 @@ export class GlassesSession {
|
||||
private nextMagic(): number {
|
||||
for (let i = 0; i < 156; i++) {
|
||||
const magic = this.magic; this.magic = this.magic === 255 ? 100 : this.magic + 1
|
||||
if (magic !== 156 && ![...this.pending.keys()].some(key => key.endsWith(`:${magic}`))) return magic
|
||||
if (magic !== 156 && !this.cfwPending.some(item => item.magic === magic) && ![...this.pending.keys()].some(key => key.endsWith(`:${magic}`))) return magic
|
||||
}
|
||||
throw new Error('All message identifiers are in use')
|
||||
}
|
||||
@@ -200,15 +206,20 @@ export class GlassesSession {
|
||||
})
|
||||
}
|
||||
private send(role: string, sid: number, flag: number, payload: Uint8Array): Promise<void> {
|
||||
return this.writePackets(role, () => protocol.frameMessage(payload, sid, flag, this.sequence++, this.limits[role]))
|
||||
}
|
||||
private writePackets(role: string, build: () => Uint8Array[], current = () => true): Promise<void> {
|
||||
const identifier = this.ids[role], generation = this.generation
|
||||
if (!identifier) return Promise.reject(new Error(`No ${role} device connected`))
|
||||
const frames = protocol.frameMessage(payload, sid, flag, this.sequence++, this.limits[role])
|
||||
const previous = this.writes.get(identifier) ?? Promise.resolve()
|
||||
// A failed write poisons this link's queue until reset: do not transmit
|
||||
// later fragments after a hole in the image stream.
|
||||
const work = previous.then(async () => {
|
||||
for (const frame of frames) {
|
||||
this.check(generation)
|
||||
if (!current()) return
|
||||
for (const frame of build()) {
|
||||
this.check(generation)
|
||||
if (!current()) return
|
||||
await this.transport.write(identifier, protocol.G2_WRITE, frame)
|
||||
iosBleTraffic.recordWrite(frame.length)
|
||||
}
|
||||
@@ -221,6 +232,75 @@ export class GlassesSession {
|
||||
private lease(acquire: boolean): Promise<void[]> {
|
||||
return Promise.all(['right', 'left'].map(role => this.send(role, protocol.SID.settings, 0x20, protocol.framebufferLease(acquire))))
|
||||
}
|
||||
private requestCfw(role: string, payload: Uint8Array): Promise<void> {
|
||||
if (payload.length > CFW_MAX_MESSAGE) return Promise.reject(new Error('CFW message too large'))
|
||||
return new Promise((resolve, reject) => {
|
||||
const item: CfwPending = { role, payload, checksum: protocol.crc16(payload), magic: this.nextMagic(), ackLenses: 0, retries: 0,
|
||||
retryPending: false, deadline: 0, resolve, reject }
|
||||
this.cfwPending.push(item)
|
||||
this.sendCfw(item)
|
||||
})
|
||||
}
|
||||
private sendCfw(item: CfwPending): void {
|
||||
const generation = this.generation, magic = item.magic
|
||||
const current = () => generation === this.generation && item.magic === magic && this.cfwPending.includes(item)
|
||||
void this.writePackets(item.role, () => {
|
||||
let transport = this.cfwTransports.get(item.role)
|
||||
if (!transport) { transport = new CfwTransport(); this.cfwTransports.set(item.role, transport) }
|
||||
if (item.retries) transport.reset()
|
||||
return transport.encode(item.payload, magic, 3, this.limits[item.role])
|
||||
}, current).then(() => {
|
||||
if (!current()) return
|
||||
item.deadline = Date.now() + 500
|
||||
this.scheduleCfwRecovery()
|
||||
}).catch(error => { if (current()) this.fail(error, true) })
|
||||
}
|
||||
private receiveCfw(identifier: string, packet: Uint8Array): void {
|
||||
const acks = parseCfwAcks(packet)
|
||||
if (!acks) return
|
||||
for (const ack of acks) {
|
||||
// The ingress temple relays the other lens's result on the SAME link.
|
||||
const item = this.cfwPending.find(p => this.ids[p.role] === identifier && p.magic === ack.streamId)
|
||||
if (!item || ack.messageId !== 0) continue
|
||||
if (ack.nack) item.retryPending = true
|
||||
else if (ack.size === item.payload.length && ack.checksum === item.checksum) item.ackLenses |= ack.lens
|
||||
this.log(`CFW ${ack.nack ? 'NACK' : 'ACK'} stream=${ack.streamId} lens=${ack.lens} size=${ack.size} crc=${ack.checksum} confirmed=${item.ackLenses}`)
|
||||
}
|
||||
while (this.cfwPending.length) {
|
||||
const head = this.cfwPending[0]
|
||||
if (head.retryPending || head.ackLenses !== 3) break
|
||||
this.cfwPending.shift(); head.resolve()
|
||||
}
|
||||
this.scheduleCfwRecovery()
|
||||
}
|
||||
private scheduleCfwRecovery(): void {
|
||||
if (this.cfwTimer !== null) clearTimeout(this.cfwTimer)
|
||||
this.cfwTimer = null
|
||||
let deadline = Infinity
|
||||
for (const item of this.cfwPending) {
|
||||
if (item.retryPending) deadline = 0
|
||||
else if (item.ackLenses !== 3 && item.deadline) deadline = Math.min(deadline, item.deadline)
|
||||
}
|
||||
if (deadline === Infinity) return
|
||||
this.cfwTimer = setTimeout(() => {
|
||||
this.cfwTimer = null
|
||||
this.recoverCfw()
|
||||
}, Math.max(0, deadline - Date.now()))
|
||||
}
|
||||
private recoverCfw(): void {
|
||||
if (!this.cfwPending.some(p => p.retryPending || (p.ackLenses !== 3 && p.deadline > 0 && p.deadline <= Date.now()))) {
|
||||
this.scheduleCfwRecovery(); return
|
||||
}
|
||||
if (this.cfwPending.some(p => p.retries >= 3)) { this.fail(new Error('CFW recovery retry limit'), true); return }
|
||||
this.log(`CFW recovery: replay ${this.cfwPending.length} unresolved messages`)
|
||||
// Go back to the oldest unresolved command, including any ACKed tail.
|
||||
// Fresh stream IDs reject stale ACKs; each replay resets compression history.
|
||||
for (const item of this.cfwPending) {
|
||||
item.magic = this.nextMagic(); item.retries++; item.ackLenses = 0
|
||||
item.deadline = 0; item.retryPending = false
|
||||
}
|
||||
for (const item of this.cfwPending) this.sendCfw(item)
|
||||
}
|
||||
private receive(event: TransportEvent): void {
|
||||
if (!Object.values(this.ids).includes(event.identifier ?? '')) return
|
||||
if (event.kind === 'disconnected') {
|
||||
@@ -252,6 +332,10 @@ export class GlassesSession {
|
||||
}
|
||||
for (const message of this.receiver.receive(event.identifier!, data)) {
|
||||
this.log(`RX ${event.identifier === this.ids.left ? 'L' : 'R'} sid=${message.sid.toString(16)} flag=${message.flag.toString(16)} cmd=${message.command} magic=${message.magic}`)
|
||||
if (message.sid === protocol.SID.cfw) {
|
||||
this.receiveCfw(event.identifier!, message.packet!)
|
||||
continue
|
||||
}
|
||||
if (![1, 6].includes(message.flag)) {
|
||||
// A master arm can relay the other arm's ACK; magic is allocated
|
||||
// across BOTH links, matching Android's communicator.
|
||||
@@ -343,32 +427,32 @@ export class GlassesSession {
|
||||
// Compare with the last enqueued image, not the last ACKed one. In an
|
||||
// A -> B -> A sequence, B may still be in flight when A is requested.
|
||||
if (this.lastEnqueued && packed.every((value, i) => value === this.lastEnqueued![i])) continue
|
||||
const delta = buildBoundingBoxPayload(this.lastEnqueued, packed, 640, 480, this.nextImageFrameId, this.deflate)
|
||||
const payload = delta ?? protocol.concat(new Uint8Array([6]), this.deflate(protocol.rle4(packed)))
|
||||
if (payload.length > 165888) throw new Error('Compressed frame exceeds the glasses image buffer')
|
||||
if (delta) {
|
||||
const delta = buildBoundingBoxPayload(this.lastEnqueued, packed, 640, 480, this.nextImageFrameId)
|
||||
const payload = delta ?? protocol.concat(new Uint8Array([6]), protocol.rle4(packed))
|
||||
if (delta) this.nextImageFrameId = this.nextImageFrameId >= 0xfffe ? 1 : this.nextImageFrameId + 1
|
||||
const commands = payload.length <= CFW_MAX_MESSAGE ? [payload] : buildFullFrameBands(packed, 640, 480, this.nextImageFrameId)
|
||||
if (payload.length > CFW_MAX_MESSAGE) for (const _ of commands)
|
||||
this.nextImageFrameId = this.nextImageFrameId >= 0xfffe ? 1 : this.nextImageFrameId + 1
|
||||
this.log(`Display bbox ${delta[3] * 4}x${delta[4] * 2}+${delta[1] * 4}+${delta[2] * 2} fid=${delta[5] | (delta[6] << 8)} (${payload.length} bytes)`)
|
||||
} else this.log(`Display full 640x480 (${payload.length} bytes)`)
|
||||
this.displaySending = { packed, payload, offset: 0, pending: 0 }
|
||||
this.log(`Display ${delta ? 'bbox' : 'full'} (${commands.length} CFW commands)`)
|
||||
this.displaySending = { packed, commands, offset: 0, pending: 0 }
|
||||
this.displayFrames.push(this.displaySending); this.lastEnqueued = packed
|
||||
}
|
||||
const frame = this.displaySending, offset = frame.offset
|
||||
frame.offset += 3800; frame.pending++; this.displayInFlight++
|
||||
if (frame.offset >= frame.payload.length) this.displaySending = null
|
||||
// send() serializes whole messages on L, but request() waits for each
|
||||
// magic's ACK independently. Fill the other slots without awaiting it.
|
||||
void this.request('left', protocol.SID.hub, magic => protocol.imageFragment(magic, frame.payload, offset), 'Display frame').then(() => {
|
||||
const frame = this.displaySending, payload = frame.commands[frame.offset++]
|
||||
frame.pending++; this.displayInFlight++
|
||||
if (frame.offset >= frame.commands.length) this.displaySending = null
|
||||
// Writes serialize on L while up to three complete commands await their
|
||||
// two-lens ACKs. Retire commands in submission order.
|
||||
void this.requestCfw('left', payload).then(() => {
|
||||
if (generation !== this.generation) return
|
||||
frame.pending--; this.displayInFlight--; this.lastHeartbeat = Date.now()
|
||||
// Retire in submission order even if relayed ACKs arrive out of order.
|
||||
// A frame counts only after every fragment has been acknowledged.
|
||||
// A frame counts only after every command has been acknowledged.
|
||||
while (this.displayFrames.length) {
|
||||
const completed = this.displayFrames[0]
|
||||
if (completed.offset < completed.payload.length || completed.pending) break
|
||||
if (completed.offset < completed.commands.length || completed.pending) break
|
||||
this.displayFrames.shift(); this.displayed = completed.packed
|
||||
this.state.frames++; iosBleTraffic.recordDisplayFrame(); this.onState({ ...this.state })
|
||||
this.log(`Display frame ${this.state.frames} acknowledged (${completed.payload.length} bytes)`)
|
||||
this.log(`Display frame ${this.state.frames} acknowledged (${completed.commands.length} commands)`)
|
||||
}
|
||||
this.wake()
|
||||
}).catch(error => { if (generation === this.generation) this.fail(error, true) })
|
||||
@@ -404,6 +488,11 @@ export class GlassesSession {
|
||||
this.timer = this.retryTimer = null; this.pumping = false
|
||||
const pending = [...this.pending.values()]; this.pending.clear()
|
||||
for (const request of pending) { if (request.timer) clearTimeout(request.timer); request.reject(new Error('Connection ended')) }
|
||||
if (this.cfwTimer !== null) clearTimeout(this.cfwTimer)
|
||||
this.cfwTimer = null
|
||||
const custom = this.cfwPending; this.cfwPending = []
|
||||
for (const item of custom) item.reject(new Error('Connection ended'))
|
||||
this.cfwTransports.clear()
|
||||
this.receiver.clear(); this.writes.clear(); this.latest = this.displayed = null
|
||||
this.lastEnqueued = null; this.displayFrames = []; this.displaySending = null; this.displayInFlight = 0
|
||||
}
|
||||
@@ -436,12 +525,7 @@ export class GlassesSession {
|
||||
this.update('disconnecting', 'Disconnecting…'); this.reset()
|
||||
try {
|
||||
if (cleanup) {
|
||||
if (this.state.capabilities.split(/\s+/).includes('cleanup11'))
|
||||
await this.request('left', protocol.SID.hub, magic => protocol.imageFragment(magic, new Uint8Array([11]), 0), 'Display cleanup', 1200)
|
||||
else {
|
||||
await this.request('right', protocol.SID.hub, protocol.shutdown, 'Close display', 1200)
|
||||
await this.lease(false)
|
||||
}
|
||||
await this.requestCfw('left', new Uint8Array([11]))
|
||||
}
|
||||
} catch (error) { this.log(`Disconnect cleanup: ${this.message(error)}`) }
|
||||
finally { this.reset(); this.closeLinks(); this.update('disconnected', 'Preview only') }
|
||||
|
||||
@@ -308,8 +308,7 @@ export class IosPreviewController {
|
||||
const addresses = loadDeviceAddresses(), error = deviceAddressError(addresses)
|
||||
if (error) { this.onError(error); return }
|
||||
if (!this.session) {
|
||||
const { deflate } = require('pako') as { deflate: (data: Uint8Array) => Uint8Array }
|
||||
this.session = new GlassesSession(iosBluetooth(), deflate, state => {
|
||||
this.session = new GlassesSession(iosBluetooth(), state => {
|
||||
if (state.phase !== 'connected') iosVoiceInput.handleSessionEnded()
|
||||
shell.setBatteryLevels({ headset: state.battery, headsetCharging: state.charging })
|
||||
this.syncRuntime()
|
||||
|
||||
+71
-2
@@ -14,6 +14,12 @@
|
||||
* stream to the watch as events so a query made from the wrist can be read
|
||||
* from the wrist.
|
||||
*
|
||||
* The watch's own battery flows the other way for the glasses' top-bar and
|
||||
* Glanceboard indicators: the phone polls it (the watch answers from a
|
||||
* listener service even while its app is closed) and the open watch app
|
||||
* pushes changes unprompted. The level lives in shell.getBatteryLevels()
|
||||
* beside the G2 and R1 ones and is cleared when no watch is reachable.
|
||||
*
|
||||
* Transport is app/native/wear-bridge.ts (Java FaceclawWearBridge); the
|
||||
* message shapes are documented in wear/PROTOCOL.md.
|
||||
*/
|
||||
@@ -88,6 +94,14 @@ const MAX_TEXT_LENGTH = 2000;
|
||||
const STATE_PUBLISH_DEBOUNCE_MS = 150;
|
||||
const STATE_REFRESH_INTERVAL_MS = 30_000;
|
||||
const ASSISTANT_STREAM_MIN_INTERVAL_MS = 250;
|
||||
// Each poll wakes the watch app's process for a moment; the level changes
|
||||
// slowly, and a charger being plugged in is pushed at once whenever the
|
||||
// watch app is open, so a leisurely cadence is enough.
|
||||
const WATCH_BATTERY_POLL_INTERVAL_MS = 5 * 60_000;
|
||||
// Floor between polls that state changes (a watch coming into range, the
|
||||
// glasses connecting) would otherwise trigger back to back.
|
||||
const WATCH_BATTERY_POLL_MIN_GAP_MS = 20_000;
|
||||
const WATCH_BATTERY_URGENT_POLL_LIMIT = 3;
|
||||
|
||||
/** What the dashboard controller lends the watch remote. */
|
||||
export type WearRemoteHost = {
|
||||
@@ -120,6 +134,11 @@ export class WearRemote {
|
||||
private assistantStreamTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
private assistantPendingText: string | null = null;
|
||||
private lastAssistantSentAtMs = 0;
|
||||
private lastWatchBatteryPollAtMs = 0;
|
||||
private watchBatteryKnown = false;
|
||||
// Urgent polls that got no answer; a watch app too old to answer them
|
||||
// must not be poked every publish, so after a few the cadence drops back.
|
||||
private watchBatteryPollsUnanswered = 0;
|
||||
|
||||
constructor(private readonly host: WearRemoteHost) {
|
||||
this.active = wearBridge.isAvailable();
|
||||
@@ -141,8 +160,16 @@ export class WearRemote {
|
||||
connection.reachable ? `watch: ${connection.watchName || "watch"} reachable` : "watch: no watch reachable",
|
||||
);
|
||||
}
|
||||
// A watch that just came into range gets the current state at once.
|
||||
if (connection.reachable) this.publishNow(true);
|
||||
// A watch that just came into range gets the current state at once,
|
||||
// and is asked for its battery; one that left takes its indicator
|
||||
// with it (no placeholder).
|
||||
if (changed) this.watchBatteryPollsUnanswered = 0;
|
||||
if (connection.reachable) {
|
||||
this.publishNow(true);
|
||||
this.pollWatchBattery(true);
|
||||
} else if (changed) {
|
||||
this.setWatchBattery(null, null);
|
||||
}
|
||||
});
|
||||
shell.onAssistantActivity((event) => this.forwardAssistantActivity(event));
|
||||
shell.onAlertShown((text) => {
|
||||
@@ -155,9 +182,38 @@ export class WearRemote {
|
||||
// Catch-all refresh for state the controller does not announce (cheap:
|
||||
// identical states are dropped on the Java side).
|
||||
setInterval(() => this.schedulePublish(), STATE_REFRESH_INTERVAL_MS);
|
||||
setInterval(() => this.pollWatchBattery(false), WATCH_BATTERY_POLL_INTERVAL_MS);
|
||||
this.schedulePublish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask the reachable watch for its battery. `urgent` skips the poll gap for
|
||||
* a level that is not known yet (the glasses just connected, the watch
|
||||
* just appeared); a level already on screen waits for the regular cadence.
|
||||
*/
|
||||
private pollWatchBattery(urgent: boolean): void {
|
||||
if (!this.active || !this.watchReachable) return;
|
||||
const now = Date.now();
|
||||
const hurry = urgent && !this.watchBatteryKnown && this.watchBatteryPollsUnanswered < WATCH_BATTERY_URGENT_POLL_LIMIT;
|
||||
const gap = hurry ? WATCH_BATTERY_POLL_MIN_GAP_MS : WATCH_BATTERY_POLL_INTERVAL_MS;
|
||||
if (now - this.lastWatchBatteryPollAtMs < gap) return;
|
||||
this.lastWatchBatteryPollAtMs = now;
|
||||
this.watchBatteryPollsUnanswered++;
|
||||
wearBridge.sendToWatch(WEAR_PATHS.batteryRequest, {});
|
||||
}
|
||||
|
||||
/** Record a watch battery report (or its absence) and repaint the indicators. */
|
||||
private setWatchBattery(battery: number | null, charging: boolean | null): void {
|
||||
const current = shell.getBatteryLevels();
|
||||
if (current.watch === battery && current.watchCharging === charging) return;
|
||||
this.watchBatteryKnown = battery !== null;
|
||||
shell.setBatteryLevels({ watch: battery, watchCharging: charging });
|
||||
// Repaint the top bar, as the controller does for G2/R1 reports.
|
||||
const phase = this.host.getState().phase;
|
||||
if (phase === "connected" || phase === "charging") this.host.requestShellRender();
|
||||
this.host.appendLog(battery === null ? "watch: battery unknown" : `watch: battery ${battery}%${charging ? " (charging)" : ""}`);
|
||||
}
|
||||
|
||||
/** Whether a watch running the Faceclaw watch app is reachable right now. */
|
||||
isWatchReachable(): boolean {
|
||||
return this.watchReachable;
|
||||
@@ -183,6 +239,10 @@ export class WearRemote {
|
||||
} catch (error) {
|
||||
this.host.appendLog(`watch: state publish failed: ${formatError(error)}`);
|
||||
}
|
||||
// The indicator is only ever drawn while the glasses are connected, so
|
||||
// a still-unknown level is worth asking for as soon as they are.
|
||||
const phase = this.host.getState().phase;
|
||||
if (phase === "connected" || phase === "charging") this.pollWatchBattery(true);
|
||||
}
|
||||
|
||||
private buildState(): Record<string, unknown> {
|
||||
@@ -240,6 +300,15 @@ export class WearRemote {
|
||||
ack(true);
|
||||
return;
|
||||
}
|
||||
if (message.path === WEAR_PATHS.battery) {
|
||||
// Status, not control: not gated by the remote setting and never
|
||||
// acked (the watch sends it fire-and-forget, without a seq).
|
||||
this.watchBatteryPollsUnanswered = 0;
|
||||
const battery = readNumber(message.payload.battery, -1);
|
||||
const valid = Number.isInteger(battery) && battery >= 0 && battery <= 100;
|
||||
this.setWatchBattery(valid ? battery : null, valid ? message.payload.charging === true : null);
|
||||
return;
|
||||
}
|
||||
if (!watchRemoteEnabledSetting.get()) {
|
||||
ack(false, "Watch control is turned off in Faceclaw's Settings > Watch.");
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user