forked from Blendman974/faceclaw
Merge branch 'case-battery-ui'
This commit is contained in:
commit
c896ce9ac8
31 files changed
+729
-35
No files matched your search
@@ -221,6 +221,12 @@ function describeState(): string {
|
|||||||
const charging = battery.headsetCharging ? ", charging" : "";
|
const charging = battery.headsetCharging ? ", charging" : "";
|
||||||
parts.push(`Headset battery: ${battery.headset}%${charging}.`);
|
parts.push(`Headset battery: ${battery.headset}%${charging}.`);
|
||||||
}
|
}
|
||||||
|
if (battery.case !== null) {
|
||||||
|
// caseCharging is null while the glasses are out of the case: the level is the last one seen.
|
||||||
|
const detail = battery.caseCharging === null ? " (last reading, glasses not in the case)"
|
||||||
|
: battery.caseCharging ? ", charging" : "";
|
||||||
|
parts.push(`Charging case battery: ${battery.case}%${detail}.`);
|
||||||
|
}
|
||||||
parts.push(`Local time: ${formatDateTime(new Date())}.`);
|
parts.push(`Local time: ${formatDateTime(new Date())}.`);
|
||||||
return parts.join(" ");
|
return parts.join(" ");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,13 +98,21 @@ import { createNotificationsAppWindow, NOTIFICATIONS_SURFACE_ID, NOTIFICATIONS_W
|
|||||||
import { isInstalledPackagePresent } from "../apps/evenhub/updates";
|
import { isInstalledPackagePresent } from "../apps/evenhub/updates";
|
||||||
import { wearerVerificationOptions } from "../apps/microphones/speakers";
|
import { wearerVerificationOptions } from "../apps/microphones/speakers";
|
||||||
import { micSession } from "../apps/microphones/mic-session";
|
import { micSession } from "../apps/microphones/mic-session";
|
||||||
import { glassesDisplayAsleep, glassesDisplayLabel, type GlassesDisplayState } from "./glasses-display-state";
|
import {
|
||||||
|
chargingPreviewMessage,
|
||||||
|
glassesDisplayAsleep,
|
||||||
|
glassesDisplayDetail,
|
||||||
|
glassesDisplayLabel,
|
||||||
|
type GlassesDisplayState,
|
||||||
|
} from "./glasses-display-state";
|
||||||
import { PreviewDisplayTarget, type DisplayTarget } from "../native/preview-display";
|
import { PreviewDisplayTarget, type DisplayTarget } from "../native/preview-display";
|
||||||
|
|
||||||
type ConnectionPhase = "disconnected" | "connecting" | "connected" | "charging" | "disconnecting";
|
type ConnectionPhase = "disconnected" | "connecting" | "connected" | "charging" | "disconnecting";
|
||||||
|
|
||||||
export type DashboardSnapshot = {
|
export type DashboardSnapshot = {
|
||||||
phase: ConnectionPhase;
|
phase: ConnectionPhase;
|
||||||
|
/** Last-known battery levels: the glasses, their charging case, the R1 ring and a Wear OS watch. */
|
||||||
|
batteries: ReturnType<typeof shell.getBatteryLevels>;
|
||||||
status: string;
|
status: string;
|
||||||
displayPreview: ImageSource | null;
|
displayPreview: ImageSource | null;
|
||||||
/**
|
/**
|
||||||
@@ -340,6 +348,7 @@ class DashboardController {
|
|||||||
private offState: (() => void) | null = null;
|
private offState: (() => void) | null = null;
|
||||||
private offRing: (() => void) | null = null;
|
private offRing: (() => void) | null = null;
|
||||||
private offBattery: (() => void) | null = null;
|
private offBattery: (() => void) | null = null;
|
||||||
|
private offCaseBattery: (() => void) | null = null;
|
||||||
private offSilentMode: (() => void) | null = null;
|
private offSilentMode: (() => void) | null = null;
|
||||||
private offWearState: (() => void) | null = null;
|
private offWearState: (() => void) | null = null;
|
||||||
private offPhoneLockState: (() => void) | null = null;
|
private offPhoneLockState: (() => void) | null = null;
|
||||||
@@ -1156,6 +1165,7 @@ class DashboardController {
|
|||||||
alarmReliabilityMessage: this.alarmReliabilityMessage,
|
alarmReliabilityMessage: this.alarmReliabilityMessage,
|
||||||
previewMode: this.isPreviewDisplayActive(),
|
previewMode: this.isPreviewDisplayActive(),
|
||||||
evenHubPhoneUi: phoneUiButton(),
|
evenHubPhoneUi: phoneUiButton(),
|
||||||
|
batteries: shell.getBatteryLevels(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1173,7 +1183,7 @@ class DashboardController {
|
|||||||
*/
|
*/
|
||||||
private displayPreviewMessage(): string {
|
private displayPreviewMessage(): string {
|
||||||
if (this.phase === "charging") {
|
if (this.phase === "charging") {
|
||||||
return this.glassesDisplayLabel();
|
return chargingPreviewMessage(this.glassesDisplayState());
|
||||||
}
|
}
|
||||||
if (this.silentMode && this.phase === "connected") {
|
if (this.silentMode && this.phase === "connected") {
|
||||||
// Say how to leave it. Silent mode is entered and exited only by the
|
// Say how to leave it. Silent mode is entered and exited only by the
|
||||||
@@ -1205,17 +1215,25 @@ class DashboardController {
|
|||||||
return glassesDisplayLabel(this.glassesDisplayState());
|
return glassesDisplayLabel(this.glassesDisplayState());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The smaller line the watch face shows under that one, or "" (the case level while charging). */
|
||||||
|
glassesDisplayDetail(): string {
|
||||||
|
return glassesDisplayDetail(this.glassesDisplayState());
|
||||||
|
}
|
||||||
|
|
||||||
/** Whether that line reads "Display off" (the watch face adds a wake hint under it). */
|
/** Whether that line reads "Display off" (the watch face adds a wake hint under it). */
|
||||||
glassesDisplayAsleep(): boolean {
|
glassesDisplayAsleep(): boolean {
|
||||||
return glassesDisplayAsleep(this.glassesDisplayState());
|
return glassesDisplayAsleep(this.glassesDisplayState());
|
||||||
}
|
}
|
||||||
|
|
||||||
private glassesDisplayState(): GlassesDisplayState {
|
private glassesDisplayState(): GlassesDisplayState {
|
||||||
|
const batteries = shell.getBatteryLevels();
|
||||||
return {
|
return {
|
||||||
phase: this.phase,
|
phase: this.phase,
|
||||||
silentMode: this.silentMode,
|
silentMode: this.silentMode,
|
||||||
screenOn: shell.isScreenOn(),
|
screenOn: shell.isScreenOn(),
|
||||||
battery: this.lastHeadsetBattery,
|
battery: this.lastHeadsetBattery,
|
||||||
|
caseBattery: batteries.case,
|
||||||
|
caseCharging: batteries.caseCharging,
|
||||||
foregroundTitle: shell.getForegroundApp()?.title ?? null,
|
foregroundTitle: shell.getForegroundApp()?.title ?? null,
|
||||||
previewMode: this.isPreviewDisplayActive(),
|
previewMode: this.isPreviewDisplayActive(),
|
||||||
};
|
};
|
||||||
@@ -1619,6 +1637,17 @@ class DashboardController {
|
|||||||
// the watch state, so refresh both consumers on every report.
|
// the watch state, so refresh both consumers on every report.
|
||||||
this.emit();
|
this.emit();
|
||||||
});
|
});
|
||||||
|
this.offCaseBattery = communicator.onCaseState((state) => {
|
||||||
|
// The level is kept when a reading has none (the glasses left the case)
|
||||||
|
// and across disconnects: the case only reports while the glasses are
|
||||||
|
// docked and only drains while charging them, so the last level holds.
|
||||||
|
// Whether the case is on USB is only known while they are docked.
|
||||||
|
shell.setBatteryLevels({
|
||||||
|
...(state.battery !== null ? { case: state.battery } : {}),
|
||||||
|
caseCharging: state.docked ? state.charging : null,
|
||||||
|
});
|
||||||
|
this.emit();
|
||||||
|
});
|
||||||
this.offEvenAppConflict = communicator.onEvenAppConflict((message) => {
|
this.offEvenAppConflict = communicator.onEvenAppConflict((message) => {
|
||||||
this.refreshEvenAppStatus();
|
this.refreshEvenAppStatus();
|
||||||
if (!this.evenNotificationActive) {
|
if (!this.evenNotificationActive) {
|
||||||
@@ -1739,6 +1768,8 @@ class DashboardController {
|
|||||||
this.offRing = null;
|
this.offRing = null;
|
||||||
this.offBattery?.();
|
this.offBattery?.();
|
||||||
this.offBattery = null;
|
this.offBattery = null;
|
||||||
|
this.offCaseBattery?.();
|
||||||
|
this.offCaseBattery = null;
|
||||||
this.offSilentMode?.();
|
this.offSilentMode?.();
|
||||||
this.offSilentMode = null;
|
this.offSilentMode = null;
|
||||||
this.offWearState?.();
|
this.offWearState?.();
|
||||||
@@ -1851,6 +1882,8 @@ class DashboardController {
|
|||||||
this.offRing = null;
|
this.offRing = null;
|
||||||
this.offBattery?.();
|
this.offBattery?.();
|
||||||
this.offBattery = null;
|
this.offBattery = null;
|
||||||
|
this.offCaseBattery?.();
|
||||||
|
this.offCaseBattery = null;
|
||||||
this.offSilentMode?.();
|
this.offSilentMode?.();
|
||||||
this.offSilentMode = null;
|
this.offSilentMode = null;
|
||||||
this.offWearState?.();
|
this.offWearState?.();
|
||||||
|
|||||||
@@ -3,6 +3,13 @@ export type GlassesDisplayState = {
|
|||||||
silentMode: boolean;
|
silentMode: boolean;
|
||||||
screenOn: boolean;
|
screenOn: boolean;
|
||||||
battery: number | null;
|
battery: number | null;
|
||||||
|
/**
|
||||||
|
* The charging case's last-known level, and whether it is on USB (null
|
||||||
|
* while the glasses are out of the case). Shown only while charging, when
|
||||||
|
* the glasses are docked and the case reading is live.
|
||||||
|
*/
|
||||||
|
caseBattery: number | null;
|
||||||
|
caseCharging: boolean | null;
|
||||||
foregroundTitle: string | null;
|
foregroundTitle: string | null;
|
||||||
/** The headless preview display is standing in for a connection (preview-only mode). */
|
/** The headless preview display is standing in for a connection (preview-only mode). */
|
||||||
previewMode: boolean;
|
previewMode: boolean;
|
||||||
@@ -29,6 +36,20 @@ export function glassesDisplayLabel(state: GlassesDisplayState): string {
|
|||||||
return state.foregroundTitle || "Launcher";
|
return state.foregroundTitle || "Launcher";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The smaller line under that label on the watch face, or "": the case
|
||||||
|
* level while the glasses charge in it.
|
||||||
|
*/
|
||||||
|
export function glassesDisplayDetail(state: GlassesDisplayState): string {
|
||||||
|
if (state.phase !== "charging") return "";
|
||||||
|
return validBatteryLevel(state.caseBattery) ? batteryEntry("Case", state.caseBattery, state.caseCharging) : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The phone mirror's stand-in while charging: the label and its detail on one line. */
|
||||||
|
export function chargingPreviewMessage(state: GlassesDisplayState): string {
|
||||||
|
return [glassesDisplayLabel(state), glassesDisplayDetail(state)].filter(Boolean).join(" · ");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True when the label reads "Display off": the screen is dark but the glasses
|
* True when the label reads "Display off": the screen is dark but the glasses
|
||||||
* (or the preview standing in for them) would light it on a wake gesture.
|
* (or the preview standing in for them) would light it on a wake gesture.
|
||||||
@@ -46,6 +67,40 @@ export function chargingDisplayLabel(battery: number | null): string {
|
|||||||
return validBatteryLevel(battery) ? `Charging · G2 ${battery}%` : "Charging";
|
return validBatteryLevel(battery) ? `Charging · G2 ${battery}%` : "Charging";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The shell's last-known battery levels (ShellChromeState["battery"]), as far as the phone shows them. */
|
||||||
|
export type BatteryLevels = {
|
||||||
|
headset: number | null;
|
||||||
|
headsetCharging: boolean | null;
|
||||||
|
case: number | null;
|
||||||
|
caseCharging: boolean | null;
|
||||||
|
ring: number | null;
|
||||||
|
ringCharging: boolean | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The phone Settings tab's battery row: each device whose level is known,
|
||||||
|
* e.g. "G2 100% · Case 98% ⚡ · R1 72%" (⚡ = charging), or "" when none
|
||||||
|
* is. Levels are the last known ones (the case only reports while the glasses
|
||||||
|
* are docked), so ⚡ appears only while it is live: G2 and Case only with a
|
||||||
|
* link to the glasses (`glassesLinked`: connected or charging), and Case only
|
||||||
|
* while they are docked (caseCharging is null otherwise).
|
||||||
|
*/
|
||||||
|
export function formatBatteryLine(levels: BatteryLevels, glassesLinked: boolean): string {
|
||||||
|
const devices: Array<[string, number | null, boolean | null]> = [
|
||||||
|
["G2", levels.headset, glassesLinked && levels.headsetCharging],
|
||||||
|
["Case", levels.case, glassesLinked && levels.caseCharging],
|
||||||
|
["R1", levels.ring, levels.ringCharging],
|
||||||
|
];
|
||||||
|
return devices
|
||||||
|
.filter((device): device is [string, number, boolean | null] => validBatteryLevel(device[1]))
|
||||||
|
.map(([label, level, charging]) => batteryEntry(label, level, charging))
|
||||||
|
.join(" · ");
|
||||||
|
}
|
||||||
|
|
||||||
|
function batteryEntry(label: string, level: number, charging: boolean | null): string {
|
||||||
|
return `${label} ${level}%${charging ? " ⚡" : ""}`;
|
||||||
|
}
|
||||||
|
|
||||||
function validBatteryLevel(battery: number | null): battery is number {
|
function validBatteryLevel(battery: number | null): battery is number {
|
||||||
return battery !== null && Number.isInteger(battery) && battery >= 0 && battery <= 100;
|
return battery !== null && Number.isInteger(battery) && battery >= 0 && battery <= 100;
|
||||||
}
|
}
|
||||||
@@ -883,6 +883,13 @@ export class IosPreviewController {
|
|||||||
if (this.active) this.onConnectionState({ ...this.state })
|
if (this.active) this.onConnectionState({ ...this.state })
|
||||||
this.requestShellRender()
|
this.requestShellRender()
|
||||||
}),
|
}),
|
||||||
|
communicator.onCaseState(state => {
|
||||||
|
if (this.communicator !== communicator) return
|
||||||
|
// As on Android: keep the last level when a reading has none (out of the case);
|
||||||
|
// the case's own charging is only known while the glasses are docked.
|
||||||
|
shell.setBatteryLevels({ ...(state.battery !== null ? { case: state.battery } : {}),
|
||||||
|
caseCharging: state.docked ? state.charging : null })
|
||||||
|
}),
|
||||||
communicator.onFirmwareInfo(info => {
|
communicator.onFirmwareInfo(info => {
|
||||||
if (this.communicator !== communicator) return
|
if (this.communicator !== communicator) return
|
||||||
this.logBluetooth(`Firmware: L=${info.leftVersion || '?'} R=${info.rightVersion || '?'}` +
|
this.logBluetooth(`Firmware: L=${info.leftVersion || '?'} R=${info.rightVersion || '?'}` +
|
||||||
|
|||||||
@@ -263,6 +263,8 @@ export class WearRemote {
|
|||||||
listening: voiceActivity.isActive(),
|
listening: voiceActivity.isActive(),
|
||||||
battery: state.lastHeadsetBattery,
|
battery: state.lastHeadsetBattery,
|
||||||
charging: state.phase === "charging" || battery.headsetCharging === true,
|
charging: state.phase === "charging" || battery.headsetCharging === true,
|
||||||
|
caseBattery: battery.case,
|
||||||
|
caseCharging: battery.caseCharging,
|
||||||
silentMode: state.silentMode,
|
silentMode: state.silentMode,
|
||||||
foreground: foreground ? { appId: foreground.appId, title: foreground.title } : null,
|
foreground: foreground ? { appId: foreground.appId, title: foreground.title } : null,
|
||||||
windows: shell.getWindows().map((window) => ({
|
windows: shell.getWindows().map((window) => ({
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ export type HeadsetBatteryState = {
|
|||||||
ringChargingStatus?: number;
|
ringChargingStatus?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** See the Android communicator's CaseBatteryState. */
|
||||||
|
export type CaseBatteryState = { battery: number | null; charging: boolean; docked: boolean };
|
||||||
|
|
||||||
export type FrameMetrics = {
|
export type FrameMetrics = {
|
||||||
paintMs: number;
|
paintMs: number;
|
||||||
transmitMs: number;
|
transmitMs: number;
|
||||||
@@ -120,6 +123,9 @@ class SessionListener extends NSObject {
|
|||||||
onBatteryStateHeadsetBatteryHeadsetChargingRingBatteryRingCharging(headsetBattery: number, headsetCharging: number, ringBattery: number, ringCharging: number): void {
|
onBatteryStateHeadsetBatteryHeadsetChargingRingBatteryRingCharging(headsetBattery: number, headsetCharging: number, ringBattery: number, ringCharging: number): void {
|
||||||
this.bridge.handleBatteryState(Number(headsetBattery), Number(headsetCharging), Number(ringBattery), Number(ringCharging));
|
this.bridge.handleBatteryState(Number(headsetBattery), Number(headsetCharging), Number(ringBattery), Number(ringCharging));
|
||||||
}
|
}
|
||||||
|
onCaseStateCaseBatteryCaseChargingCaseDocked(caseBattery: number, caseCharging: number, caseDocked: boolean): void {
|
||||||
|
this.bridge.handleCaseState(Number(caseBattery), Number(caseCharging), Boolean(caseDocked));
|
||||||
|
}
|
||||||
onSilentModeSilent(silent: boolean): void { this.bridge.handleSilentMode(Boolean(silent)); }
|
onSilentModeSilent(silent: boolean): void { this.bridge.handleSilentMode(Boolean(silent)); }
|
||||||
onWearStateWearing(wearing: boolean): void { this.bridge.handleWearState(Boolean(wearing)); }
|
onWearStateWearing(wearing: boolean): void { this.bridge.handleWearState(Boolean(wearing)); }
|
||||||
onPhoneLockStateLocked(locked: boolean): void { this.bridge.handlePhoneLockState(Boolean(locked)); }
|
onPhoneLockStateLocked(locked: boolean): void { this.bridge.handlePhoneLockState(Boolean(locked)); }
|
||||||
@@ -215,6 +221,7 @@ export class FaceclawCommunicatorBridge {
|
|||||||
private readonly stateListeners = new Set<(state: CommunicatorState) => void>();
|
private readonly stateListeners = new Set<(state: CommunicatorState) => void>();
|
||||||
private readonly ringListeners = new Set<(event: RawInputEvent) => void>();
|
private readonly ringListeners = new Set<(event: RawInputEvent) => void>();
|
||||||
private readonly batteryListeners = new Set<(state: HeadsetBatteryState) => void>();
|
private readonly batteryListeners = new Set<(state: HeadsetBatteryState) => void>();
|
||||||
|
private readonly caseListeners = new Set<(state: CaseBatteryState) => void>();
|
||||||
private readonly silentModeListeners = new Set<(silent: boolean) => void>();
|
private readonly silentModeListeners = new Set<(silent: boolean) => void>();
|
||||||
private readonly wearStateListeners = new Set<(wearing: boolean) => void>();
|
private readonly wearStateListeners = new Set<(wearing: boolean) => void>();
|
||||||
private readonly phoneLockStateListeners = new Set<(locked: boolean) => void>();
|
private readonly phoneLockStateListeners = new Set<(locked: boolean) => void>();
|
||||||
@@ -284,6 +291,15 @@ export class FaceclawCommunicatorBridge {
|
|||||||
this.emitAsync(this.batteryListeners, { battery, chargingStatus, ringBattery, ringChargingStatus });
|
this.emitAsync(this.batteryListeners, { battery, chargingStatus, ringBattery, ringChargingStatus });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
handleCaseState(battery: number, charging: number, docked: boolean): void {
|
||||||
|
this.emitAsync(this.caseListeners, {
|
||||||
|
battery: Number.isInteger(battery) && battery >= 0 && battery <= 100 ? battery : null,
|
||||||
|
charging: charging > 0,
|
||||||
|
docked,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
handleSilentMode(silent: boolean): void { this.emitAsync(this.silentModeListeners, silent); }
|
handleSilentMode(silent: boolean): void { this.emitAsync(this.silentModeListeners, silent); }
|
||||||
|
|
||||||
@@ -375,6 +391,11 @@ export class FaceclawCommunicatorBridge {
|
|||||||
return () => this.batteryListeners.delete(listener);
|
return () => this.batteryListeners.delete(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onCaseState(listener: (state: CaseBatteryState) => void): () => void {
|
||||||
|
this.caseListeners.add(listener);
|
||||||
|
return () => this.caseListeners.delete(listener);
|
||||||
|
}
|
||||||
|
|
||||||
onSilentMode(listener: (silent: boolean) => void): () => void {
|
onSilentMode(listener: (silent: boolean) => void): () => void {
|
||||||
this.silentModeListeners.add(listener);
|
this.silentModeListeners.add(listener);
|
||||||
return () => this.silentModeListeners.delete(listener);
|
return () => this.silentModeListeners.delete(listener);
|
||||||
|
|||||||
@@ -29,6 +29,13 @@ export type HeadsetBatteryState = {
|
|||||||
ringChargingStatus?: number;
|
ringChargingStatus?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A charging-case reading, as the glasses relay it. battery is 0..100, or null when the reading
|
||||||
|
* has none (the glasses are out of the case). charging (the case is on USB) is only known while
|
||||||
|
* docked.
|
||||||
|
*/
|
||||||
|
export type CaseBatteryState = { battery: number | null; charging: boolean; docked: boolean };
|
||||||
|
|
||||||
export type FrameMetrics = {
|
export type FrameMetrics = {
|
||||||
paintMs: number;
|
paintMs: number;
|
||||||
transmitMs: number;
|
transmitMs: number;
|
||||||
@@ -151,6 +158,7 @@ export class FaceclawCommunicatorBridge {
|
|||||||
private readonly stateListeners = new Set<(state: CommunicatorState) => void>();
|
private readonly stateListeners = new Set<(state: CommunicatorState) => void>();
|
||||||
private readonly ringListeners = new Set<(event: RawInputEvent) => void>();
|
private readonly ringListeners = new Set<(event: RawInputEvent) => void>();
|
||||||
private readonly batteryListeners = new Set<(state: HeadsetBatteryState) => void>();
|
private readonly batteryListeners = new Set<(state: HeadsetBatteryState) => void>();
|
||||||
|
private readonly caseListeners = new Set<(state: CaseBatteryState) => void>();
|
||||||
private readonly silentModeListeners = new Set<(silent: boolean) => void>();
|
private readonly silentModeListeners = new Set<(silent: boolean) => void>();
|
||||||
private readonly wearStateListeners = new Set<(wearing: boolean) => void>();
|
private readonly wearStateListeners = new Set<(wearing: boolean) => void>();
|
||||||
private readonly phoneLockStateListeners = new Set<(locked: boolean) => void>();
|
private readonly phoneLockStateListeners = new Set<(locked: boolean) => void>();
|
||||||
@@ -214,6 +222,14 @@ export class FaceclawCommunicatorBridge {
|
|||||||
};
|
};
|
||||||
this.emitAsync(this.batteryListeners, state);
|
this.emitAsync(this.batteryListeners, state);
|
||||||
},
|
},
|
||||||
|
onCaseState: (caseBattery: number, caseCharging: number, caseDocked: boolean) => {
|
||||||
|
const battery = Number(caseBattery);
|
||||||
|
this.emitAsync(this.caseListeners, {
|
||||||
|
battery: Number.isInteger(battery) && battery >= 0 && battery <= 100 ? battery : null,
|
||||||
|
charging: Number(caseCharging) > 0,
|
||||||
|
docked: Boolean(caseDocked),
|
||||||
|
});
|
||||||
|
},
|
||||||
onSilentMode: (silent: boolean) => {
|
onSilentMode: (silent: boolean) => {
|
||||||
this.emitAsync(this.silentModeListeners, Boolean(silent));
|
this.emitAsync(this.silentModeListeners, Boolean(silent));
|
||||||
},
|
},
|
||||||
@@ -334,6 +350,15 @@ export class FaceclawCommunicatorBridge {
|
|||||||
return () => this.batteryListeners.delete(listener);
|
return () => this.batteryListeners.delete(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Charging-case readings: read at session start and on docking, then pushed by the glasses
|
||||||
|
* on every change, including leaving the case.
|
||||||
|
*/
|
||||||
|
onCaseState(listener: (state: CaseBatteryState) => void): () => void {
|
||||||
|
this.caseListeners.add(listener);
|
||||||
|
return () => this.caseListeners.delete(listener);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Silent mode, toggled on the glasses by long-pressing both touchpads. While
|
* Silent mode, toggled on the glasses by long-pressing both touchpads. While
|
||||||
* it is on the firmware ignores all input and blanks the display.
|
* it is on the firmware ignores all input and blanks the display.
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import { sampleBleTraffic } from '../native/ble-traffic'
|
|||||||
import { onAnySettingChanged, mirrorTouchSetting, showBleBandwidthSetting } from '../ui/dashboard-settings'
|
import { onAnySettingChanged, mirrorTouchSetting, showBleBandwidthSetting } from '../ui/dashboard-settings'
|
||||||
import { loadDeviceAddresses } from '../g2/device-addresses'
|
import { loadDeviceAddresses } from '../g2/device-addresses'
|
||||||
import { deviceAddressError } from '../g2/ios-peripheral-identity'
|
import { deviceAddressError } from '../g2/ios-peripheral-identity'
|
||||||
|
import { formatBatteryLine } from '../g2/glasses-display-state'
|
||||||
|
import { shell } from '../ui/shell/shell'
|
||||||
|
|
||||||
export function createMainPage(): Page {
|
export function createMainPage(): Page {
|
||||||
const page = new Page()
|
const page = new Page()
|
||||||
@@ -70,6 +72,10 @@ export function createMainPage(): Page {
|
|||||||
keyboardPanel.bindingContext = keyboardModel
|
keyboardPanel.bindingContext = keyboardModel
|
||||||
GridLayout.setRow(keyboardPanel, 1); root.addChild(keyboardPanel)
|
GridLayout.setRow(keyboardPanel, 1); root.addChild(keyboardPanel)
|
||||||
let focusTimer: ReturnType<typeof setTimeout> | null = null
|
let focusTimer: ReturnType<typeof setTimeout> | null = null
|
||||||
|
// The Settings tab's battery row. iOS reports charging sessions as
|
||||||
|
// connected, so "connected" is the whole live-link condition here.
|
||||||
|
let glassesLinked = false
|
||||||
|
const refreshBatteryLine = () => { model.batteryLine = formatBatteryLine(shell.getBatteryLevels(), glassesLinked) }
|
||||||
const keyboardField = () => keyboardPanel.getViewById<TextView>('keyboardInputField')
|
const keyboardField = () => keyboardPanel.getViewById<TextView>('keyboardInputField')
|
||||||
const controller = new IosPreviewController((image, label) => {
|
const controller = new IosPreviewController((image, label) => {
|
||||||
mirror.imageSource = image; model.set('padFocusLine', label)
|
mirror.imageSource = image; model.set('padFocusLine', label)
|
||||||
@@ -79,6 +85,7 @@ export function createMainPage(): Page {
|
|||||||
state.text = ({ connected: 'Connected', disconnected: 'Preview', connecting: 'Connecting',
|
state.text = ({ connected: 'Connected', disconnected: 'Preview', connecting: 'Connecting',
|
||||||
retrying: 'Reconnecting', disconnecting: 'Disconnecting', error: 'Failed' })[connection.phase]
|
retrying: 'Reconnecting', disconnecting: 'Disconnecting', error: 'Failed' })[connection.phase]
|
||||||
warning.visibility = connection.firmwareWarning ? 'visible' : 'collapse'
|
warning.visibility = connection.firmwareWarning ? 'visible' : 'collapse'
|
||||||
|
glassesLinked = connection.phase === 'connected'; refreshBatteryLine()
|
||||||
}, session => {
|
}, session => {
|
||||||
keyboardModel.setSession(session)
|
keyboardModel.setSession(session)
|
||||||
controls.visibility = session ? 'collapse' : 'visible'
|
controls.visibility = session ? 'collapse' : 'visible'
|
||||||
@@ -256,6 +263,7 @@ export function createMainPage(): Page {
|
|||||||
const resume = () => { foreground = true; controller.resume(); syncBandwidth() }
|
const resume = () => { foreground = true; controller.resume(); syncBandwidth() }
|
||||||
let keyboardObserver: any = null
|
let keyboardObserver: any = null
|
||||||
let offSettings: (() => void) | null = null
|
let offSettings: (() => void) | null = null
|
||||||
|
let offBattery: (() => void) | null = null
|
||||||
page.on('loaded', () => {
|
page.on('loaded', () => {
|
||||||
if (!keyboardObserver) keyboardObserver = NSNotificationCenter.defaultCenter.addObserverForNameObjectQueueUsingBlock(
|
if (!keyboardObserver) keyboardObserver = NSNotificationCenter.defaultCenter.addObserverForNameObjectQueueUsingBlock(
|
||||||
UIKeyboardWillChangeFrameNotification, null, NSOperationQueue.mainQueue, notification => {
|
UIKeyboardWillChangeFrameNotification, null, NSOperationQueue.mainQueue, notification => {
|
||||||
@@ -266,14 +274,15 @@ export function createMainPage(): Page {
|
|||||||
})
|
})
|
||||||
Application.on(Application.suspendEvent, pause); Application.on(Application.resumeEvent, resume)
|
Application.on(Application.suspendEvent, pause); Application.on(Application.resumeEvent, resume)
|
||||||
offSettings?.(); offSettings = onAnySettingChanged(() => { model.refreshDisplayControls(); syncBandwidth() })
|
offSettings?.(); offSettings = onAnySettingChanged(() => { model.refreshDisplayControls(); syncBandwidth() })
|
||||||
model.refreshDisplayControls(); resume()
|
offBattery?.(); offBattery = shell.onBatteryLevelsChanged(refreshBatteryLine)
|
||||||
|
model.refreshDisplayControls(); refreshBatteryLine(); resume()
|
||||||
if (!isPreviewOnlyMode() && !isAutoReconnectSuppressed() && !deviceAddressError(loadDeviceAddresses())) void controller.connect()
|
if (!isPreviewOnlyMode() && !isAutoReconnectSuppressed() && !deviceAddressError(loadDeviceAddresses())) void controller.connect()
|
||||||
})
|
})
|
||||||
page.on('unloaded', () => {
|
page.on('unloaded', () => {
|
||||||
if (keyboardObserver) NSNotificationCenter.defaultCenter.removeObserver(keyboardObserver)
|
if (keyboardObserver) NSNotificationCenter.defaultCenter.removeObserver(keyboardObserver)
|
||||||
keyboardObserver = null
|
keyboardObserver = null
|
||||||
root.paddingBottom = 0
|
root.paddingBottom = 0
|
||||||
pause(); offSettings?.(); offSettings = null
|
pause(); offSettings?.(); offSettings = null; offBattery?.(); offBattery = null
|
||||||
Application.off(Application.suspendEvent, pause); Application.off(Application.resumeEvent, resume)
|
Application.off(Application.suspendEvent, pause); Application.off(Application.resumeEvent, resume)
|
||||||
})
|
})
|
||||||
return page
|
return page
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
type View,
|
type View,
|
||||||
} from "@nativescript/core";
|
} from "@nativescript/core";
|
||||||
import { dashboardController, type MirrorTouchKind } from "../g2/dashboard-controller";
|
import { dashboardController, type MirrorTouchKind } from "../g2/dashboard-controller";
|
||||||
|
import { formatBatteryLine } from "../g2/glasses-display-state";
|
||||||
import {
|
import {
|
||||||
mirrorTouchSetting,
|
mirrorTouchSetting,
|
||||||
onAnySettingChanged,
|
onAnySettingChanged,
|
||||||
@@ -90,6 +91,10 @@ export class MainViewModel extends RemoteControlsViewModel {
|
|||||||
this.displayPreview = snapshot.displayPreview;
|
this.displayPreview = snapshot.displayPreview;
|
||||||
this.displayPreviewMessage = snapshot.displayPreviewMessage;
|
this.displayPreviewMessage = snapshot.displayPreviewMessage;
|
||||||
this.phase = snapshot.phase;
|
this.phase = snapshot.phase;
|
||||||
|
this.batteryLine = formatBatteryLine(
|
||||||
|
snapshot.batteries,
|
||||||
|
snapshot.phase === "connected" || snapshot.phase === "charging",
|
||||||
|
);
|
||||||
this.activeTextSettingId = snapshot.activeTextSettingId;
|
this.activeTextSettingId = snapshot.activeTextSettingId;
|
||||||
this.activeTextEditorTitle = snapshot.activeTextEditorTitle;
|
this.activeTextEditorTitle = snapshot.activeTextEditorTitle;
|
||||||
this.activeTextSettingTitle = snapshot.activeTextSettingTitle;
|
this.activeTextSettingTitle = snapshot.activeTextSettingTitle;
|
||||||
@@ -1068,10 +1073,16 @@ export class MainViewModel extends RemoteControlsViewModel {
|
|||||||
return dashboardController.glassesDisplayAsleep();
|
return dashboardController.glassesDisplayAsleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override get padDetailLine(): string {
|
||||||
|
return dashboardController.glassesDisplayDetail();
|
||||||
|
}
|
||||||
|
|
||||||
private refreshPadFocusLine(): void {
|
private refreshPadFocusLine(): void {
|
||||||
this.notifyPropertyChange("padFocusLine", this.padFocusLine);
|
this.notifyPropertyChange("padFocusLine", this.padFocusLine);
|
||||||
this.notifyPropertyChange("padFocusClass", this.padFocusClass);
|
this.notifyPropertyChange("padFocusClass", this.padFocusClass);
|
||||||
this.notifyPropertyChange("padWakeHintVisibility", this.padWakeHintVisibility);
|
this.notifyPropertyChange("padWakeHintVisibility", this.padWakeHintVisibility);
|
||||||
|
this.notifyPropertyChange("padDetailLine", this.padDetailLine);
|
||||||
|
this.notifyPropertyChange("padDetailVisibility", this.padDetailVisibility);
|
||||||
}
|
}
|
||||||
|
|
||||||
async onPadTap(): Promise<void> {
|
async onPadTap(): Promise<void> {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ let lastControlsTab: ControlsTab = 'watch';
|
|||||||
/** Shared state and actions for remote-controls.xml; transport stays in the host. */
|
/** Shared state and actions for remote-controls.xml; transport stays in the host. */
|
||||||
export class RemoteControlsViewModel extends Observable {
|
export class RemoteControlsViewModel extends Observable {
|
||||||
private _controlsTab: ControlsTab = lastControlsTab;
|
private _controlsTab: ControlsTab = lastControlsTab;
|
||||||
|
private _batteryLine = "";
|
||||||
|
|
||||||
get settingsTabVisibility(): "visible" | "collapse" {
|
get settingsTabVisibility(): "visible" | "collapse" {
|
||||||
return this._controlsTab === "settings" ? "visible" : "collapse";
|
return this._controlsTab === "settings" ? "visible" : "collapse";
|
||||||
@@ -50,6 +51,19 @@ export class RemoteControlsViewModel extends Observable {
|
|||||||
return this.padDisplayAsleep ? "visible" : "collapse";
|
return this.padDisplayAsleep ? "visible" : "collapse";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A smaller line under the watch face's status line, or "" to hide it: the
|
||||||
|
* charging case's level while the glasses charge in it. The host overrides
|
||||||
|
* this and notifies padDetailLine and padDetailVisibility when it changes.
|
||||||
|
*/
|
||||||
|
get padDetailLine(): string {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
get padDetailVisibility(): "visible" | "collapse" {
|
||||||
|
return this.padDetailLine ? "visible" : "collapse";
|
||||||
|
}
|
||||||
|
|
||||||
onSettingsTabTap(): void {
|
onSettingsTabTap(): void {
|
||||||
this.setControlsTab("settings");
|
this.setControlsTab("settings");
|
||||||
}
|
}
|
||||||
@@ -76,7 +90,23 @@ export class RemoteControlsViewModel extends Observable {
|
|||||||
this.notifyPropertyChange("ringTabClass", this.ringTabClass);
|
this.notifyPropertyChange("ringTabClass", this.ringTabClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- display mode and brightness, on the Settings tab ----
|
// ---- display mode, brightness and battery levels, on the Settings tab ----
|
||||||
|
|
||||||
|
/** The Settings tab's battery row (formatBatteryLine), or "" to hide it; set by the host. */
|
||||||
|
get batteryLine(): string {
|
||||||
|
return this._batteryLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
set batteryLine(value: string) {
|
||||||
|
if (this._batteryLine === value) return;
|
||||||
|
this._batteryLine = value;
|
||||||
|
this.notifyPropertyChange("batteryLine", value);
|
||||||
|
this.notifyPropertyChange("batteryLineVisibility", this.batteryLineVisibility);
|
||||||
|
}
|
||||||
|
|
||||||
|
get batteryLineVisibility(): "visible" | "collapse" {
|
||||||
|
return this._batteryLine ? "visible" : "collapse";
|
||||||
|
}
|
||||||
|
|
||||||
get displayModeLabel(): string {
|
get displayModeLabel(): string {
|
||||||
return displayLayoutSetting.displayValue() + " ▾";
|
return displayLayoutSetting.displayValue() + " ▾";
|
||||||
|
|||||||
@@ -91,6 +91,9 @@
|
|||||||
font-size: 13;
|
font-size: 13;
|
||||||
margin-right: 2;
|
margin-right: 2;
|
||||||
}
|
}
|
||||||
|
.settings-battery-line {
|
||||||
|
font-size: 14;
|
||||||
|
}
|
||||||
.touchpad {
|
.touchpad {
|
||||||
height: 230;
|
height: 230;
|
||||||
background-color: #1f1f1f;
|
background-color: #1f1f1f;
|
||||||
@@ -113,6 +116,12 @@
|
|||||||
color: #6a6a6a;
|
color: #6a6a6a;
|
||||||
margin-top: 4;
|
margin-top: 4;
|
||||||
}
|
}
|
||||||
|
/* The charging case's level under "Charging · G2 n%". */
|
||||||
|
.pad-detail {
|
||||||
|
font-size: 15;
|
||||||
|
color: #b0b0b0;
|
||||||
|
margin-top: 4;
|
||||||
|
}
|
||||||
.action-row {
|
.action-row {
|
||||||
margin-top: 6;
|
margin-top: 6;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<!--
|
<!--
|
||||||
The phone's controller for the glasses, as a three-tab area below the mirror:
|
The phone's controller for the glasses, as a three-tab area below the mirror:
|
||||||
Settings (screen size + brightness), Watch (the simulated watch face: same
|
Settings (display mode, brightness and battery levels), Watch (the
|
||||||
scheme as the watch pad - tap = select, double-tap or two fingers = back,
|
simulated watch face: same scheme as the watch pad - tap = select,
|
||||||
hold = menu, swipes navigate), and Ring (a touchpad on the ring's own
|
double-tap or two fingers = back, hold = menu, swipes navigate), and Ring
|
||||||
scheme: vertical swipes scroll, tap/double-tap/hold = click/double-click/
|
(a touchpad on the ring's own scheme: vertical swipes scroll,
|
||||||
long-press). Tap-then-hold on either pad is the G2 system-menu gesture. The
|
tap/double-tap/hold = click/double-click/long-press). Tap-then-hold on either pad is the G2 system-menu gesture. The
|
||||||
narrow mic and keyboard buttons at the tab bar's right edge fire the
|
narrow mic and keyboard buttons at the tab bar's right edge fire the
|
||||||
wakeword / open the keyboard dialog without changing the selected tab. Used
|
wakeword / open the keyboard dialog without changing the selected tab. Used
|
||||||
by main-page.xml in both orientations; binds to the page's MainViewModel,
|
by main-page.xml in both orientations; binds to the page's MainViewModel,
|
||||||
@@ -49,15 +49,24 @@
|
|||||||
<Switch checked="{{ brightnessAuto }}" checkedChange="{{ onBrightnessAutoChange }}" />
|
<Switch checked="{{ brightnessAuto }}" checkedChange="{{ onBrightnessAutoChange }}" />
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
</GridLayout>
|
</GridLayout>
|
||||||
|
<!-- Last-known levels of the glasses, their charging case and the R1;
|
||||||
|
collapsed until one is known. Last so its appearing doesn't move
|
||||||
|
the controls above. -->
|
||||||
|
<GridLayout rows="auto" columns="auto,*" class="settings-row" visibility="{{ batteryLineVisibility }}">
|
||||||
|
<Label col="0" text="Battery" class="settings-row-label" verticalAlignment="center" />
|
||||||
|
<Label col="1" text="{{ batteryLine }}" textWrap="true" class="settings-battery-line" verticalAlignment="center" />
|
||||||
|
</GridLayout>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
|
|
||||||
<!-- Watch tab: centered in the leftover height, capped at the 1.5:1 face
|
<!-- Watch tab: centered in the leftover height, capped at the 1.5:1 face
|
||||||
aspect (watchFaceWidth = min(available, 1.5 x face height). The star
|
aspect (watchFaceWidth = min(available, 1.5 x face height). The star
|
||||||
rows center the status line, plus the wake hint under it while the
|
rows center the status line, plus the wake hint under it while the
|
||||||
display is off (a double-tap is the only gesture that wakes it). -->
|
display is off (a double-tap is the only gesture that wakes it), or
|
||||||
<GridLayout visibility="{{ watchTabVisibility }}" width="{{ watchFaceWidth }}" height="{{ watchFaceHeight }}" rows="*,auto,auto,*" horizontalAlignment="center" verticalAlignment="center" class="touchpad" android:tap="{{ onPadTap }}" android:doubleTap="{{ onPadDoubleTap }}" android:longPress="{{ onPadLongPress }}" android:swipe="{{ onPadSwipe }}" touch="{{ onPadTouch }}">
|
the charging case's level while the glasses charge in it. -->
|
||||||
|
<GridLayout visibility="{{ watchTabVisibility }}" width="{{ watchFaceWidth }}" height="{{ watchFaceHeight }}" rows="*,auto,auto,auto,*" horizontalAlignment="center" verticalAlignment="center" class="touchpad" android:tap="{{ onPadTap }}" android:doubleTap="{{ onPadDoubleTap }}" android:longPress="{{ onPadLongPress }}" android:swipe="{{ onPadSwipe }}" touch="{{ onPadTouch }}">
|
||||||
<Label row="1" isUserInteractionEnabled="false" text="{{ padFocusLine }}" class="{{ padFocusClass }}" horizontalAlignment="center" />
|
<Label row="1" isUserInteractionEnabled="false" text="{{ padFocusLine }}" class="{{ padFocusClass }}" horizontalAlignment="center" />
|
||||||
<Label row="2" isUserInteractionEnabled="false" text="●● wake" visibility="{{ padWakeHintVisibility }}" class="pad-wake-hint" horizontalAlignment="center" />
|
<Label row="2" isUserInteractionEnabled="false" text="●● wake" visibility="{{ padWakeHintVisibility }}" class="pad-wake-hint" horizontalAlignment="center" />
|
||||||
|
<Label row="3" isUserInteractionEnabled="false" text="{{ padDetailLine }}" visibility="{{ padDetailVisibility }}" class="pad-detail" horizontalAlignment="center" />
|
||||||
</GridLayout>
|
</GridLayout>
|
||||||
|
|
||||||
<!-- Ring tab: a touchpad on the ring's own scheme. Vertical swipes only
|
<!-- Ring tab: a touchpad on the ring's own scheme. Vertical swipes only
|
||||||
|
|||||||
@@ -486,6 +486,14 @@ export type ShellChromeState = {
|
|||||||
/** The Wear OS watch (app/g2/wear-remote.ts); null when no watch is reachable. */
|
/** The Wear OS watch (app/g2/wear-remote.ts); null when no watch is reachable. */
|
||||||
watch: number | null;
|
watch: number | null;
|
||||||
watchCharging: boolean | null;
|
watchCharging: boolean | null;
|
||||||
|
/**
|
||||||
|
* The glasses' charging case, last known (it only reports while the
|
||||||
|
* glasses are docked); null until it does. caseCharging is null while the
|
||||||
|
* glasses are out of the case, where they can't see whether it is on USB.
|
||||||
|
* Shown on the phone, not here.
|
||||||
|
*/
|
||||||
|
case: number | null;
|
||||||
|
caseCharging: boolean | null;
|
||||||
};
|
};
|
||||||
/** App-provided tray images, drawn between notification icons and batteries. */
|
/** App-provided tray images, drawn between notification icons and batteries. */
|
||||||
trayIcons: ShellChromeTrayIcon[];
|
trayIcons: ShellChromeTrayIcon[];
|
||||||
|
|||||||
@@ -452,6 +452,7 @@ class Shell {
|
|||||||
private lastInput: InputEvent | null = null;
|
private lastInput: InputEvent | null = null;
|
||||||
private battery: ShellChromeState["battery"] = {
|
private battery: ShellChromeState["battery"] = {
|
||||||
headset: null, headsetCharging: null, ring: null, ringCharging: null, watch: null, watchCharging: null,
|
headset: null, headsetCharging: null, ring: null, ringCharging: null, watch: null, watchCharging: null,
|
||||||
|
case: null, caseCharging: null,
|
||||||
};
|
};
|
||||||
private readonly batteryListeners = new Set<() => void>();
|
private readonly batteryListeners = new Set<() => void>();
|
||||||
private attention = new Map<string, boolean>();
|
private attention = new Map<string, boolean>();
|
||||||
|
|||||||
+7
@@ -23,6 +23,13 @@ interface FaceclawBleCommunicatorListener {
|
|||||||
ringCharging: Int,
|
ringCharging: Int,
|
||||||
): Unit
|
): Unit
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A new charging-case reading. caseBattery is 0..100, or -1 when the reading has no level
|
||||||
|
* (the glasses are out of the case; keep the last one). caseCharging 1 = the case is on
|
||||||
|
* USB, known only while caseDocked (0 otherwise).
|
||||||
|
*/
|
||||||
|
fun onCaseState(caseBattery: Int, caseCharging: Int, caseDocked: Boolean): Unit
|
||||||
|
|
||||||
fun onSilentMode(silent: Boolean): Unit
|
fun onSilentMode(silent: Boolean): Unit
|
||||||
|
|
||||||
fun onWearState(wearing: Boolean): Unit
|
fun onWearState(wearing: Boolean): Unit
|
||||||
|
|||||||
@@ -90,6 +90,12 @@ class BleProtocol {
|
|||||||
|
|
||||||
const val SID_ONBOARDING: Int = 0x10
|
const val SID_ONBOARDING: Int = 0x10
|
||||||
|
|
||||||
|
/** Charging case (UX_GLASSES_CASE_APP_ID): GlassesCaseDataPackage, see [CaseInfoSnapshot]. */
|
||||||
|
const val SID_GLASSES_CASE: Int = 0x81
|
||||||
|
|
||||||
|
/** eGlassesCaseCommandId.CASE_INFO. */
|
||||||
|
const val GLASSES_CASE_CMD_CASE_INFO: Int = 1
|
||||||
|
|
||||||
/** G2SettingPackage.commandId for device-initiated pushes (vs. 2 = app read). */
|
/** G2SettingPackage.commandId for device-initiated pushes (vs. 2 = app read). */
|
||||||
const val SETTINGS_CMD_DEVICE_SEND_TO_APP: Int = 3
|
const val SETTINGS_CMD_DEVICE_SEND_TO_APP: Int = 3
|
||||||
|
|
||||||
@@ -899,6 +905,42 @@ class BleProtocol {
|
|||||||
return BatterySnapshot(battery, charging, silentMode)
|
return BatterySnapshot(battery, charging, silentMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** GlassesCaseDataPackage{commandId=CASE_INFO, magicRandom, caseInfo={}}, as the Even app sends it. */
|
||||||
|
@JvmStatic
|
||||||
|
fun buildCaseInfoQuery(magic: Int): ByteArray {
|
||||||
|
return concat(
|
||||||
|
CollectionUtils.listOf(
|
||||||
|
encodeVarintField(1, GLASSES_CASE_CMD_CASE_INFO),
|
||||||
|
encodeVarintField(2, magic),
|
||||||
|
encodeMessageField(3, ByteArray(0)),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The GlassesCaseInfo (field 3) of a sid-0x81 CASE_INFO reply or push, or null when there
|
||||||
|
* is none. Out of the case the glasses answer with an empty one, which parses as
|
||||||
|
* not docked and without a level.
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun parseCaseInfo(pb: ByteArray?): CaseInfoSnapshot? {
|
||||||
|
if (pb == null) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
val root: ByteArray = stripTrailingCrc(pb)
|
||||||
|
if (readVarintFieldValue(root, 1, -1) != GLASSES_CASE_CMD_CASE_INFO) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
val info: ByteArray = readFieldBytes(root, 3) ?: return null
|
||||||
|
return CaseInfoSnapshot(
|
||||||
|
readVarintFieldValue(info, 1, -1),
|
||||||
|
readVarintFieldValue(info, 2, 0),
|
||||||
|
readVarintFieldValue(info, 3, 0),
|
||||||
|
readVarintFieldValue(info, 4, 0),
|
||||||
|
readVarintFieldValue(info, 5, 0),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Silent mode from an unsolicited settings push. The wearer toggles silent mode by
|
* Silent mode from an unsolicited settings push. The wearer toggles silent mode by
|
||||||
* long-pressing both touchpads at once; the firmware then sends
|
* long-pressing both touchpads at once; the firmware then sends
|
||||||
@@ -1590,6 +1632,33 @@ class BleProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GlassesCaseInfo {soc=1, chargeStatus=2, lidStatus=3, inCaseStatus=4, errorCode=5}. As seen
|
||||||
|
* on G2 2.3.0.24 / Faceclaw/38: docked, the right temple pushes one (flag 0x01, its own
|
||||||
|
* magic) on every change -- docking, lid, USB, each 1% -- and answers a CASE_INFO read with
|
||||||
|
* full data; out of the case it answers with an empty caseInfo. Docking pushes
|
||||||
|
* {inCaseStatus=1} first and the level about 0.7 s later; proto3 drops zero fields, so a
|
||||||
|
* missing soc reads as -1 ("no level"), never 0%.
|
||||||
|
*/
|
||||||
|
data class CaseInfoSnapshot(
|
||||||
|
/** State of charge, 1..100; -1 when the message left it out. */
|
||||||
|
@JvmField val soc: Int,
|
||||||
|
/** 1 = the case itself is charging (on USB); only 0 and 1 have been seen. */
|
||||||
|
@JvmField val chargeStatus: Int,
|
||||||
|
/** 1 = lid closed, 0 = open. */
|
||||||
|
@JvmField val lidStatus: Int,
|
||||||
|
/** 1 = glasses docked. */
|
||||||
|
@JvmField val inCaseStatus: Int,
|
||||||
|
/** g2.common.eErrorCode; 0 = SUCCESS. */
|
||||||
|
@JvmField val errorCode: Int,
|
||||||
|
) {
|
||||||
|
fun hasLevel(): Boolean = errorCode == 0 && soc in 0..100
|
||||||
|
|
||||||
|
fun isDocked(): Boolean = inCaseStatus > 0
|
||||||
|
|
||||||
|
fun isCaseCharging(): Boolean = chargeStatus > 0
|
||||||
|
}
|
||||||
|
|
||||||
class FirmwareInfo {
|
class FirmwareInfo {
|
||||||
companion object {
|
companion object {
|
||||||
/** Prefix of the firmware-extension string on Faceclaw's custom firmware. */
|
/** Prefix of the firmware-extension string on Faceclaw's custom firmware. */
|
||||||
|
|||||||
+3
@@ -42,6 +42,9 @@ class ConnectionOptions {
|
|||||||
// Poll cadence while in charging mode; also bounds how quickly we notice
|
// Poll cadence while in charging mode; also bounds how quickly we notice
|
||||||
// the glasses coming back out of the case.
|
// the glasses coming back out of the case.
|
||||||
const val CHARGING_BATTERY_POLL_MS = 30_000
|
const val CHARGING_BATTERY_POLL_MS = 30_000
|
||||||
|
// After the case reports the glasses docking, read the battery this
|
||||||
|
// soon (rather than at the next refresh) so charging mode follows.
|
||||||
|
const val DOCKED_BATTERY_CHECK_DELAY_MS = 3_000
|
||||||
const val IMAGE_FRAGMENT_SIZE = 3800
|
const val IMAGE_FRAGMENT_SIZE = 3800
|
||||||
const val IMAGE_RETRY_DELAY_MS = 2_000
|
const val IMAGE_RETRY_DELAY_MS = 2_000
|
||||||
const val MAX_CONSECUTIVE_ACK_TIMEOUTS = 8
|
const val MAX_CONSECUTIVE_ACK_TIMEOUTS = 8
|
||||||
|
|||||||
+15
@@ -262,6 +262,21 @@ class MessageBuilder {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun caseInfoQuery(): OutboundMessage {
|
||||||
|
val magic: Int = magicPool.allocate()
|
||||||
|
return OutboundMessage(
|
||||||
|
"case-info",
|
||||||
|
"case info",
|
||||||
|
BleProtocol.SID_GLASSES_CASE,
|
||||||
|
BleProtocol.FLAG_REQUEST,
|
||||||
|
magic,
|
||||||
|
BleProtocol.buildCaseInfoQuery(magic),
|
||||||
|
ACK_TIMEOUT_MS,
|
||||||
|
-1,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun faceclawWakeControl(operation: Int, nonce: Int, leftArm: Boolean): OutboundMessage {
|
fun faceclawWakeControl(operation: Int, nonce: Int, leftArm: Boolean): OutboundMessage {
|
||||||
return OutboundMessage(
|
return OutboundMessage(
|
||||||
"wake-lease-control",
|
"wake-lease-control",
|
||||||
|
|||||||
+44
@@ -726,6 +726,50 @@ internal fun GlassesSessionCore.emitBatteryState(headsetBattery: Int, headsetCha
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report a charging-case reading when it differs from the last one. Docked, a reading counts
|
||||||
|
* only once it carries a level (docking pushes {inCaseStatus=1} first and the level about 0.7 s
|
||||||
|
* later). Undocked -- the empty reply to a read, or an undock push -- it is reported even without
|
||||||
|
* a level, so the listener learns the case's charge state is no longer known.
|
||||||
|
*/
|
||||||
|
internal fun GlassesSessionCore.updateCaseInfoLocked(info: BleProtocol.CaseInfoSnapshot) {
|
||||||
|
if (info.errorCode != 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val docked = info.isDocked()
|
||||||
|
if (docked && !info.hasLevel()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val level = if (info.hasLevel()) info.soc else -1
|
||||||
|
// Out of the case the glasses can't see the case's USB state.
|
||||||
|
val charging = if (docked && info.isCaseCharging()) 1 else 0
|
||||||
|
val dockedState = if (docked) 1 else 0
|
||||||
|
if (level == caseBattery && charging == caseCharging && dockedState == caseDocked) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val wasOutOfCase = caseDocked == 0
|
||||||
|
caseBattery = level
|
||||||
|
caseCharging = charging
|
||||||
|
caseDocked = dockedState
|
||||||
|
logLine("charging case: $info")
|
||||||
|
if (docked && wasOutOfCase && !chargingMode) {
|
||||||
|
// The glasses just went into the case. Only the battery reply says
|
||||||
|
// they are charging, and the regular poll is minutes away (and skipped
|
||||||
|
// altogether while the display is suspended, as it is once they come
|
||||||
|
// off the face), so read it shortly: charging mode then follows.
|
||||||
|
dockedBatteryCheckAtMs = now() + ConnectionOptions.DOCKED_BATTERY_CHECK_DELAY_MS
|
||||||
|
logLine("glasses docked; battery check scheduled")
|
||||||
|
}
|
||||||
|
val current = listener ?: return
|
||||||
|
host.postToMain {
|
||||||
|
try {
|
||||||
|
current.onCaseState(level, charging, docked)
|
||||||
|
} catch (t: Throwable) {
|
||||||
|
logWarn("listener onCaseState failed", t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal fun GlassesSessionCore.emitFirmwareInfo(info: BleProtocol.FirmwareInfo) {
|
internal fun GlassesSessionCore.emitFirmwareInfo(info: BleProtocol.FirmwareInfo) {
|
||||||
val current = listener ?: return
|
val current = listener ?: return
|
||||||
host.postToMain {
|
host.postToMain {
|
||||||
|
|||||||
+27
@@ -388,6 +388,17 @@ class GlassesSessionCore(
|
|||||||
// frames while claiming the glasses role).
|
// frames while claiming the glasses role).
|
||||||
internal var lastDirectRingRaw = ""
|
internal var lastDirectRingRaw = ""
|
||||||
internal var lastDirectRingRawAtMs = 0L
|
internal var lastDirectRingRawAtMs = 0L
|
||||||
|
// Last charging-case reading reported to the listener (-1 = none yet this
|
||||||
|
// connection). See updateCaseInfoLocked.
|
||||||
|
internal var caseBattery = -1
|
||||||
|
internal var caseCharging = -1
|
||||||
|
internal var caseDocked = -1
|
||||||
|
// The session-start case read is still to be sent. It waits for the layout
|
||||||
|
// (see the drive loop), so a firmware that ignores it can't delay the first frame.
|
||||||
|
internal var caseInfoReadPending = false
|
||||||
|
// When to read the battery after the case reported the glasses docking
|
||||||
|
// (0 = not scheduled). See updateCaseInfoLocked and the drive loop.
|
||||||
|
internal var dockedBatteryCheckAtMs = 0L
|
||||||
// Silent mode: 1 = on, 0 = off, -1 = not yet known. See updateSilentModeLocked.
|
// Silent mode: 1 = on, 0 = off, -1 = not yet known. See updateSilentModeLocked.
|
||||||
internal var silentMode = -1
|
internal var silentMode = -1
|
||||||
internal var wearState = -1
|
internal var wearState = -1
|
||||||
@@ -1939,6 +1950,11 @@ class GlassesSessionCore(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (frame.ok && frame.sid == BleProtocol.SID_GLASSES_CASE) {
|
||||||
|
// Read replies and the glasses' own pushes (flag 0x01, which
|
||||||
|
// skips the ack path below) carry the same reading.
|
||||||
|
BleProtocol.parseCaseInfo(frame.pb)?.let { updateCaseInfoLocked(it) }
|
||||||
|
}
|
||||||
if (!faceclawWakeNotification
|
if (!faceclawWakeNotification
|
||||||
&& decodedWearState < 0
|
&& decodedWearState < 0
|
||||||
&& frame.ok
|
&& frame.ok
|
||||||
@@ -2186,6 +2202,11 @@ class GlassesSessionCore(
|
|||||||
// reconnect; forget ours too, or the new session's first report
|
// reconnect; forget ours too, or the new session's first report
|
||||||
// (the CFW query reply) is deduped away and TS never relearns it.
|
// (the CFW query reply) is deduped away and TS never relearns it.
|
||||||
wearState = -1
|
wearState = -1
|
||||||
|
// Same for the case: the glasses may have left it while the link
|
||||||
|
// was down, and the new session's read should reach TS either way.
|
||||||
|
caseBattery = -1
|
||||||
|
caseCharging = -1
|
||||||
|
caseDocked = -1
|
||||||
}
|
}
|
||||||
setStateDisplay("connecting", "Connecting to the glasses...")
|
setStateDisplay("connecting", "Connecting to the glasses...")
|
||||||
ConnectionCounters.increment("g2.connect-attempt")
|
ConnectionCounters.increment("g2.connect-attempt")
|
||||||
@@ -2217,6 +2238,7 @@ class GlassesSessionCore(
|
|||||||
lastConnectionOrInputAtMs = lastAckAtMs
|
lastConnectionOrInputAtMs = lastAckAtMs
|
||||||
lastSessionReadyAtMs = lastAckAtMs
|
lastSessionReadyAtMs = lastAckAtMs
|
||||||
lastBatteryRefreshAtMs = 0
|
lastBatteryRefreshAtMs = 0
|
||||||
|
dockedBatteryCheckAtMs = 0
|
||||||
imageRetryAfterMs = 0
|
imageRetryAfterMs = 0
|
||||||
lastHeartbeatSentAtMs = 0
|
lastHeartbeatSentAtMs = 0
|
||||||
lastHeartbeatAckedAtMs = 0
|
lastHeartbeatAckedAtMs = 0
|
||||||
@@ -2255,6 +2277,11 @@ class GlassesSessionCore(
|
|||||||
lastBatteryRefreshAtMs = now()
|
lastBatteryRefreshAtMs = now()
|
||||||
pendingMessages.addLast(createBatteryQueryMessageLocked())
|
pendingMessages.addLast(createBatteryQueryMessageLocked())
|
||||||
logLine("queue settings query for firmware info")
|
logLine("queue settings query for firmware info")
|
||||||
|
// The case reports only while the glasses are docked, possibly
|
||||||
|
// fully charged and so not in charging mode; out of the case
|
||||||
|
// this read comes back empty. Later changes are pushed. The
|
||||||
|
// drive loop sends it once the layout is up.
|
||||||
|
caseInfoReadPending = true
|
||||||
}
|
}
|
||||||
// Wake the ring worker; it owns the (blocking) ring connect.
|
// Wake the ring worker; it owns the (blocking) ring connect.
|
||||||
monitor.signalAll()
|
monitor.signalAll()
|
||||||
|
|||||||
+22
@@ -57,6 +57,16 @@ internal fun GlassesSessionCore.driveSession(): Long {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
drainCfwAcknowledgementsLocked()
|
drainCfwAcknowledgementsLocked()
|
||||||
|
if (dockedBatteryCheckAtMs != 0L && now >= dockedBatteryCheckAtMs) {
|
||||||
|
// Queued rather than polled: pending messages still go out while
|
||||||
|
// the display is suspended, which the regular poll waits out.
|
||||||
|
dockedBatteryCheckAtMs = 0L
|
||||||
|
if (sessionReady && !chargingMode && !hasPendingOrInflightKindLocked("battery")) {
|
||||||
|
lastBatteryRefreshAtMs = now
|
||||||
|
pendingMessages.addLast(createBatteryQueryMessageLocked())
|
||||||
|
logLine("queue battery query: glasses docked")
|
||||||
|
}
|
||||||
|
}
|
||||||
if (cfwCleanupDelivered) {
|
if (cfwCleanupDelivered) {
|
||||||
/* Successful mode 11 must be the last Faceclaw write. Drop
|
/* Successful mode 11 must be the last Faceclaw write. Drop
|
||||||
* anything a late external producer attempted to enqueue
|
* anything a late external producer attempted to enqueue
|
||||||
@@ -165,6 +175,14 @@ internal fun GlassesSessionCore.driveSession(): Long {
|
|||||||
enqueueFirmwareDebugFlagsLocked()
|
enqueueFirmwareDebugFlagsLocked()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (messageToPrewrite == null && !shutdownRequested && fixedLayoutCreated
|
||||||
|
&& caseInfoReadPending
|
||||||
|
&& pendingMessages.isEmpty() && inFlightMessages.isEmpty()) {
|
||||||
|
caseInfoReadPending = false
|
||||||
|
logLine("enqueueing case info read")
|
||||||
|
pendingMessages.addLast(messageBuilder.caseInfoQuery())
|
||||||
|
}
|
||||||
|
|
||||||
if (messageToPrewrite == null && !shutdownRequested && fixedLayoutCreated
|
if (messageToPrewrite == null && !shutdownRequested && fixedLayoutCreated
|
||||||
&& (if (compassOwners.isEmpty()) 0 else 1) != compassControlLastSent
|
&& (if (compassOwners.isEmpty()) 0 else 1) != compassControlLastSent
|
||||||
&& pendingMessages.isEmpty() && inFlightMessages.isEmpty()) {
|
&& pendingMessages.isEmpty() && inFlightMessages.isEmpty()) {
|
||||||
@@ -1100,6 +1118,10 @@ internal fun GlassesSessionCore.updateChargingModeLocked(charging: Boolean, batt
|
|||||||
if (charging) {
|
if (charging) {
|
||||||
chargingMode = true
|
chargingMode = true
|
||||||
clearAllMessagesLocked("glasses charging")
|
clearAllMessagesLocked("glasses charging")
|
||||||
|
// Docked is when the case reports. No layout is created while
|
||||||
|
// charging, so this read stands in for the session-start one.
|
||||||
|
caseInfoReadPending = false
|
||||||
|
pendingMessages.addLast(messageBuilder.caseInfoQuery())
|
||||||
fixedLayoutCreated = false
|
fixedLayoutCreated = false
|
||||||
startupProbePending = false
|
startupProbePending = false
|
||||||
displayedFingerprint = ""
|
displayedFingerprint = ""
|
||||||
|
|||||||
@@ -1,13 +1,22 @@
|
|||||||
const test = require("node:test");
|
const test = require("node:test");
|
||||||
const assert = require("node:assert/strict");
|
const assert = require("node:assert/strict");
|
||||||
|
|
||||||
const { chargingDisplayLabel, glassesDisplayAsleep, glassesDisplayLabel } = require("../.test-build/app/g2/glasses-display-state.js");
|
const {
|
||||||
|
chargingDisplayLabel,
|
||||||
|
chargingPreviewMessage,
|
||||||
|
formatBatteryLine,
|
||||||
|
glassesDisplayAsleep,
|
||||||
|
glassesDisplayDetail,
|
||||||
|
glassesDisplayLabel,
|
||||||
|
} = require("../.test-build/app/g2/glasses-display-state.js");
|
||||||
|
|
||||||
const connected = {
|
const connected = {
|
||||||
phase: "connected",
|
phase: "connected",
|
||||||
silentMode: false,
|
silentMode: false,
|
||||||
screenOn: true,
|
screenOn: true,
|
||||||
battery: 72,
|
battery: 72,
|
||||||
|
caseBattery: null,
|
||||||
|
caseCharging: null,
|
||||||
foregroundTitle: "Music",
|
foregroundTitle: "Music",
|
||||||
previewMode: false,
|
previewMode: false,
|
||||||
};
|
};
|
||||||
@@ -37,3 +46,33 @@ test("charging takes precedence and includes the last-known G2 battery", () => {
|
|||||||
assert.equal(chargingDisplayLabel(-1), "Charging");
|
assert.equal(chargingDisplayLabel(-1), "Charging");
|
||||||
assert.equal(chargingDisplayLabel(101), "Charging");
|
assert.equal(chargingDisplayLabel(101), "Charging");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("while charging, the case level is the watch face's second line and joins the mirror's message", () => {
|
||||||
|
const charging = { ...connected, phase: "charging", caseBattery: 64, caseCharging: false };
|
||||||
|
assert.equal(glassesDisplayLabel(charging), "Charging · G2 72%");
|
||||||
|
assert.equal(glassesDisplayDetail(charging), "Case 64%");
|
||||||
|
assert.equal(glassesDisplayDetail({ ...charging, caseCharging: true }), "Case 64% ⚡");
|
||||||
|
assert.equal(chargingPreviewMessage(charging), "Charging · G2 72% · Case 64%");
|
||||||
|
// No case level yet: the label alone.
|
||||||
|
assert.equal(glassesDisplayDetail({ ...charging, caseBattery: null }), "");
|
||||||
|
assert.equal(chargingPreviewMessage({ ...charging, caseBattery: null, battery: null }), "Charging");
|
||||||
|
// Out of the case the level is stale, so it is not shown.
|
||||||
|
assert.equal(glassesDisplayDetail({ ...connected, caseBattery: 64 }), "");
|
||||||
|
});
|
||||||
|
|
||||||
|
const levels = {
|
||||||
|
headset: 87, headsetCharging: true, case: 64, caseCharging: true, ring: 72, ringCharging: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
test("the Settings battery line lists each known level, with ⚡ only while the reading is live", () => {
|
||||||
|
assert.equal(formatBatteryLine(levels, true), "G2 87% ⚡ · Case 64% ⚡ · R1 72%");
|
||||||
|
// Without a link to the glasses their charging state and the case's are stale.
|
||||||
|
assert.equal(formatBatteryLine({ ...levels, ringCharging: true }, false), "G2 87% · Case 64% · R1 72% ⚡");
|
||||||
|
// caseCharging is null while the glasses are out of the case.
|
||||||
|
assert.equal(formatBatteryLine({ ...levels, caseCharging: null }, true), "G2 87% ⚡ · Case 64% · R1 72%");
|
||||||
|
assert.equal(formatBatteryLine({ ...levels, case: null, ring: null }, true), "G2 87% ⚡");
|
||||||
|
assert.equal(
|
||||||
|
formatBatteryLine({ headset: null, headsetCharging: null, case: null, caseCharging: null, ring: null, ringCharging: null }, true),
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
});
|
||||||
@@ -218,6 +218,9 @@ test('iOS bandwidth footer toggles live, polls only in foreground and resets its
|
|||||||
'../g2/ios-peripheral-identity': { deviceAddressError: () => 'no test devices' },
|
'../g2/ios-peripheral-identity': { deviceAddressError: () => 'no test devices' },
|
||||||
'./onboarding-state': { isPreviewOnlyMode: () => false },
|
'./onboarding-state': { isPreviewOnlyMode: () => false },
|
||||||
'../g2/reconnect-policy': { isAutoReconnectSuppressed: () => false },
|
'../g2/reconnect-policy': { isAutoReconnectSuppressed: () => false },
|
||||||
|
'../g2/glasses-display-state': require('../.test-build/app/g2/glasses-display-state.js'),
|
||||||
|
'../ui/shell/shell': { shell: { onBatteryLevelsChanged: () => () => {}, getBatteryLevels: () => ({
|
||||||
|
headset: null, headsetCharging: null, case: null, caseCharging: null, ring: null, ringCharging: null }) } },
|
||||||
};
|
};
|
||||||
modules['./keyboard-input-view-model'] = load('app/phone-ui/keyboard-input-view-model.ts', { require: id => modules[id] });
|
modules['./keyboard-input-view-model'] = load('app/phone-ui/keyboard-input-view-model.ts', { require: id => modules[id] });
|
||||||
modules['./remote-controls-view-model'] = load('app/phone-ui/remote-controls-view-model.ts', { require: id => modules[id] });
|
modules['./remote-controls-view-model'] = load('app/phone-ui/remote-controls-view-model.ts', { require: id => modules[id] });
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ function fixture() {
|
|||||||
constructor() { super(); bridge = this; }
|
constructor() { super(); bridge = this; }
|
||||||
on(kind, fn) { this.listeners[kind] = fn; return () => { if (this.listeners[kind] === fn) delete this.listeners[kind]; }; }
|
on(kind, fn) { this.listeners[kind] = fn; return () => { if (this.listeners[kind] === fn) delete this.listeners[kind]; }; }
|
||||||
onStateChange(fn) { return this.on('state', fn); } onRingEvent(fn) { return this.on('ring', fn); }
|
onStateChange(fn) { return this.on('state', fn); } onRingEvent(fn) { return this.on('ring', fn); }
|
||||||
onWearState(fn) { return this.on('wear', fn); } onBatteryState(fn) { return this.on('battery', fn); } onFirmwareInfo() { return noop(); }
|
onWearState(fn) { return this.on('wear', fn); } onBatteryState(fn) { return this.on('battery', fn); } onCaseState(fn) { return this.on('case', fn); } onFirmwareInfo() { return noop(); }
|
||||||
onFrameMetrics() { return noop(); } onPreviewAnimationFrame() { return noop(); } addCompassListener() { return noop(); } onAncsRelayFrame() { return noop(); }
|
onFrameMetrics() { return noop(); } onPreviewAnimationFrame() { return noop(); } addCompassListener() { return noop(); } onAncsRelayFrame() { return noop(); }
|
||||||
onAncsAuthorization() { return noop(); } setRequiresAncs() {} rightWriteLimit() { return 20; } onPhoneLockSignal() {}
|
onAncsAuthorization() { return noop(); } setRequiresAncs() {} rightWriteLimit() { return 20; } onPhoneLockSignal() {}
|
||||||
async writeRawToRight() {} async configureBrightness() {} async setBrightness() {} async enableWearDetectionAndRequestState() {} async playBuzzerSequence() {} async close() {}
|
async writeRawToRight() {} async configureBrightness() {} async setBrightness() {} async enableWearDetectionAndRequestState() {} async playBuzzerSequence() {} async close() {}
|
||||||
@@ -115,6 +115,7 @@ function fixture() {
|
|||||||
emitRing(input) { this.listeners.ring?.(input); }
|
emitRing(input) { this.listeners.ring?.(input); }
|
||||||
emitWear(wearing) { this.listeners.wear?.(wearing); }
|
emitWear(wearing) { this.listeners.wear?.(wearing); }
|
||||||
emitBattery(state) { this.listeners.battery?.(state); }
|
emitBattery(state) { this.listeners.battery?.(state); }
|
||||||
|
emitCase(state) { this.listeners.case?.(state); }
|
||||||
async start() { this.emitState('connected', 'Connected.'); }
|
async start() { this.emitState('connected', 'Connected.'); }
|
||||||
async disconnect() { this.emitState('disconnected', 'Disconnected.'); }
|
async disconnect() { this.emitState('disconnected', 'Disconnected.'); }
|
||||||
waitForFrameFinished() { return Promise.resolve('sent'); }
|
waitForFrameFinished() { return Promise.resolve('sent'); }
|
||||||
@@ -268,6 +269,16 @@ test('ring battery reported through the glasses reaches the shell while connecte
|
|||||||
assert.deepEqual([f.battery.ring, f.battery.ringCharging], [null, null]);
|
assert.deepEqual([f.battery.ring, f.battery.ringCharging], [null, null]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('the charging case reading reaches the shell and keeps its level once the glasses leave the case', async () => {
|
||||||
|
const f = fixture();
|
||||||
|
await f.connect();
|
||||||
|
f.bridge.emitCase({ battery: 64, charging: true, docked: true });
|
||||||
|
assert.deepEqual([f.battery.case, f.battery.caseCharging], [64, true]);
|
||||||
|
// Out of the case there is no level, and whether the case is on USB is unknown.
|
||||||
|
f.bridge.emitCase({ battery: null, charging: false, docked: false });
|
||||||
|
assert.deepEqual([f.battery.case, f.battery.caseCharging], [64, null]);
|
||||||
|
});
|
||||||
|
|
||||||
test('the switcher can open the Notifications window in the background, once, with a live surface', async () => {
|
test('the switcher can open the Notifications window in the background, once, with a live surface', async () => {
|
||||||
const f = fixture();
|
const f = fixture();
|
||||||
await f.render();
|
await f.render();
|
||||||
|
|||||||
@@ -70,6 +70,10 @@ private class FakeLink(private val platform: ProtocolPlatform) : SessionLink {
|
|||||||
* arms ("" is stock firmware, which omits the field), or null for an ack without firmware info.
|
* arms ("" is stock firmware, which omits the field), or null for an ack without firmware info.
|
||||||
*/
|
*/
|
||||||
@Volatile var firmwareExtension: String? = null
|
@Volatile var firmwareExtension: String? = null
|
||||||
|
/** The GlassesCaseInfo body case-info queries are answered with; null answers without one. */
|
||||||
|
@Volatile var caseInfo: ByteArray? = null
|
||||||
|
/** Settings READ acks report the glasses charging in their case (80%). */
|
||||||
|
@Volatile var headsetCharging = false
|
||||||
@Volatile var connects = 0
|
@Volatile var connects = 0
|
||||||
var seq = 0
|
var seq = 0
|
||||||
|
|
||||||
@@ -123,12 +127,16 @@ private class FakeLink(private val platform: ProtocolPlatform) : SessionLink {
|
|||||||
val extension = firmwareExtension
|
val extension = firmwareExtension
|
||||||
val body = if (sid == BleProtocol.SID_SECURITY_AUTH)
|
val body = if (sid == BleProtocol.SID_SECURITY_AUTH)
|
||||||
BleProtocol.encodeVarintField(1, 4) + BleProtocol.encodeVarintField(2, magic) + byteArrayOf(0x1a, 0x00)
|
BleProtocol.encodeVarintField(1, 4) + BleProtocol.encodeVarintField(2, magic) + byteArrayOf(0x1a, 0x00)
|
||||||
else if (kind == "battery" && extension != null)
|
else if (kind == "battery" && (extension != null || headsetCharging))
|
||||||
BleProtocol.encodeVarintField(1, 1) + BleProtocol.encodeVarintField(2, magic) +
|
BleProtocol.encodeVarintField(1, 1) + BleProtocol.encodeVarintField(2, magic) +
|
||||||
BleProtocol.encodeBytesField(4,
|
BleProtocol.encodeBytesField(4,
|
||||||
BleProtocol.encodeBytesField(5, STOCK_VERSION.encodeToByteArray()) +
|
(if (extension == null) ByteArray(0) else
|
||||||
BleProtocol.encodeBytesField(6, STOCK_VERSION.encodeToByteArray())) +
|
BleProtocol.encodeBytesField(5, STOCK_VERSION.encodeToByteArray()) +
|
||||||
(if (extension.isEmpty()) ByteArray(0) else BleProtocol.encodeBytesField(100, extension.encodeToByteArray()))
|
BleProtocol.encodeBytesField(6, STOCK_VERSION.encodeToByteArray())) +
|
||||||
|
(if (headsetCharging) BleProtocol.encodeVarintField(12, 80) + BleProtocol.encodeVarintField(13, 1) else ByteArray(0))) +
|
||||||
|
(if (extension.isNullOrEmpty()) ByteArray(0) else BleProtocol.encodeBytesField(100, extension.encodeToByteArray()))
|
||||||
|
else if (kind == "case-info")
|
||||||
|
casePackage(magic, caseInfo)
|
||||||
else
|
else
|
||||||
BleProtocol.encodeVarintField(1, 1) + BleProtocol.encodeVarintField(2, magic)
|
BleProtocol.encodeVarintField(1, 1) + BleProtocol.encodeVarintField(2, magic)
|
||||||
return BleProtocol.framePb(body, sid, 0x00, seq++)[0]
|
return BleProtocol.framePb(body, sid, 0x00, seq++)[0]
|
||||||
@@ -152,6 +160,19 @@ private class FakeLink(private val platform: ProtocolPlatform) : SessionLink {
|
|||||||
override fun recordDisplayFrameSent() {}
|
override fun recordDisplayFrameSent() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun hex(value: String): ByteArray = value.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
|
||||||
|
|
||||||
|
/** GlassesCaseDataPackage{commandId=CASE_INFO, magicRandom, caseInfo}; caseInfo omitted when null. */
|
||||||
|
private fun casePackage(magic: Int, caseInfo: ByteArray?): ByteArray =
|
||||||
|
BleProtocol.encodeVarintField(1, BleProtocol.GLASSES_CASE_CMD_CASE_INFO) + BleProtocol.encodeVarintField(2, magic) +
|
||||||
|
(if (caseInfo == null) ByteArray(0) else BleProtocol.encodeBytesField(3, caseInfo))
|
||||||
|
|
||||||
|
/** GlassesCaseInfo with proto3 zero-omission: soc=1, chargeStatus=2, lidStatus=3, inCaseStatus=4, errorCode=5. */
|
||||||
|
private fun caseInfoBody(soc: Int, charge: Int = 0, lid: Int = 0, inCase: Int = 0, error: Int = 0): ByteArray =
|
||||||
|
listOf(soc, charge, lid, inCase, error).withIndex()
|
||||||
|
.filter { it.value != 0 }
|
||||||
|
.fold(ByteArray(0)) { acc, field -> acc + BleProtocol.encodeVarintField(field.index + 1, field.value) }
|
||||||
|
|
||||||
private fun cfwAck(streamId: Int, lens: Int, size: Int, checksum: Int): ByteArray {
|
private fun cfwAck(streamId: Int, lens: Int, size: Int, checksum: Int): ByteArray {
|
||||||
val packet = ByteArray(19)
|
val packet = ByteArray(19)
|
||||||
packet[0] = 0xaa.toByte()
|
packet[0] = 0xaa.toByte()
|
||||||
@@ -237,6 +258,12 @@ private class FakeListener : FaceclawBleCommunicatorListener {
|
|||||||
batteries.add("$headsetBattery/$headsetCharging/$ringBattery/$ringCharging")
|
batteries.add("$headsetBattery/$headsetCharging/$ringBattery/$ringCharging")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val cases = ArrayList<String>()
|
||||||
|
|
||||||
|
override fun onCaseState(caseBattery: Int, caseCharging: Int, caseDocked: Boolean) {
|
||||||
|
cases.add("$caseBattery/$caseCharging/" + (if (caseDocked) "docked" else "out"))
|
||||||
|
}
|
||||||
|
|
||||||
override fun onSilentMode(silent: Boolean) {}
|
override fun onSilentMode(silent: Boolean) {}
|
||||||
|
|
||||||
override fun onWearState(wearing: Boolean) {}
|
override fun onWearState(wearing: Boolean) {}
|
||||||
@@ -691,4 +718,141 @@ class GlassesSessionCoreTest {
|
|||||||
assertTrue(info("Faceclaw/1").isCompatible(0))
|
assertTrue(info("Faceclaw/1").isCompatible(0))
|
||||||
assertFalse(info("EVENCFW/22").isCompatible(0))
|
assertFalse(info("EVENCFW/22").isCompatible(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun caseInfoQueryMatchesTheEvenAppAndRepliesParse() {
|
||||||
|
// commandId=CASE_INFO, magicRandom=42, empty caseInfo.
|
||||||
|
assertContentEquals(hex("0801102a1a00"), BleProtocol.buildCaseInfoQuery(42))
|
||||||
|
// Through a real frame, so the trailing CRC is present as it is on the wire.
|
||||||
|
fun parse(pb: ByteArray) = BleProtocol.parseCaseInfo(
|
||||||
|
BleProtocol.parseFrame(BleProtocol.framePb(pb, BleProtocol.SID_GLASSES_CASE, 0x00, 3)[0]).pb)
|
||||||
|
val full = parse(casePackage(7, caseInfoBody(64, charge = 1, lid = 1, inCase = 1)))!!
|
||||||
|
assertEquals(BleProtocol.CaseInfoSnapshot(64, 1, 1, 1, 0), full)
|
||||||
|
assertTrue(full.hasLevel() && full.isDocked() && full.isCaseCharging())
|
||||||
|
assertFalse(parse(casePackage(7, caseInfoBody(80, error = 7)))!!.hasLevel())
|
||||||
|
// An empty caseInfo is a reading: not docked, no level.
|
||||||
|
val out = parse(casePackage(7, ByteArray(0)))!!
|
||||||
|
assertEquals(BleProtocol.CaseInfoSnapshot(-1, 0, 0, 0, 0), out)
|
||||||
|
assertFalse(out.isDocked() || out.hasLevel())
|
||||||
|
// No caseInfo at all, or another command, is not.
|
||||||
|
assertEquals(null, parse(casePackage(7, null)))
|
||||||
|
assertEquals(null, parse(BleProtocol.encodeVarintField(2, 7) + BleProtocol.encodeBytesField(3, caseInfoBody(50))))
|
||||||
|
assertEquals(null, BleProtocol.parseCaseInfo(null))
|
||||||
|
// Captured from G2 2.3.0.24 / Faceclaw/38 (CRC stripped). Out of the case the reply is empty;
|
||||||
|
// docking pushes inCase alone (proto3 dropped soc: no level, not 0%), then the level.
|
||||||
|
assertEquals(out, parse(hex("08011086011a00")))
|
||||||
|
val docked = parse(hex("08011a022001"))!!
|
||||||
|
assertEquals(BleProtocol.CaseInfoSnapshot(-1, 0, 0, 1, 0), docked)
|
||||||
|
assertTrue(docked.isDocked())
|
||||||
|
assertFalse(docked.hasLevel())
|
||||||
|
assertEquals(BleProtocol.CaseInfoSnapshot(88, 0, 0, 1, 0), parse(hex("080110011a0408582001")))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun theCaseIsReadAfterTheLayoutAndOnDockingThenPushesCarryIt() {
|
||||||
|
val s = Session()
|
||||||
|
try {
|
||||||
|
// Out of the case the session-start read answers with an empty caseInfo,
|
||||||
|
// which reports "not docked" once.
|
||||||
|
s.link.caseInfo = ByteArray(0)
|
||||||
|
s.startAndAwaitLayout()
|
||||||
|
fun queries() = s.link.writes.filter { it.kind == "case-info" }
|
||||||
|
assertTrue(waitUntil(5_000) { queries().size == 1 })
|
||||||
|
assertTrue(waitUntil(5_000) { s.listener.cases.isNotEmpty() })
|
||||||
|
assertEquals(listOf("-1/0/out"), s.listener.cases)
|
||||||
|
// It waits for the layout, so a firmware that ignores it can't delay the first frame.
|
||||||
|
assertTrue(s.link.writes.indexOf(queries()[0]) > s.link.writes.indexOfFirst { it.kind == "create-layout" })
|
||||||
|
s.link.caseInfo = caseInfoBody(64, charge = 1, inCase = 1)
|
||||||
|
s.core.monitor.withLock { s.core.updateChargingModeLocked(true, 80) }
|
||||||
|
s.core.interruptibleSleep.interrupt()
|
||||||
|
assertTrue(waitUntil(5_000) { s.listener.cases.size == 2 }, s.host.logs().takeLast(10).toString())
|
||||||
|
assertEquals("64/1/docked", s.listener.cases.last())
|
||||||
|
assertEquals(listOf(RIGHT, RIGHT), queries().map { it.address })
|
||||||
|
// Pushes (flag 0x01, the glasses' own magic) update it without being taken for acks.
|
||||||
|
fun push(info: ByteArray) = s.core.onNotification(RIGHT, BleProtocol.NOTIFY_CHAR_UUID,
|
||||||
|
BleProtocol.framePb(casePackage(200, info), BleProtocol.SID_GLASSES_CASE, BleProtocol.FLAG_NOTIFY, 99)[0])
|
||||||
|
push(caseInfoBody(63, lid = 1, inCase = 1))
|
||||||
|
assertEquals("63/0/docked", s.listener.cases.last())
|
||||||
|
// Unchanged level and charge, docked with no level yet, or a failed read: nothing to report.
|
||||||
|
push(caseInfoBody(63, inCase = 1))
|
||||||
|
push(caseInfoBody(0, inCase = 1))
|
||||||
|
push(caseInfoBody(70, inCase = 1, error = 3))
|
||||||
|
assertEquals(3, s.listener.cases.size)
|
||||||
|
assertFalse(s.host.hasLog("unexpected"), s.host.logs().filter { it.contains("unexpected") }.toString())
|
||||||
|
// Later charging-mode battery polls do not read the case again.
|
||||||
|
s.platform.offsetMs += 2L * ConnectionOptions.CHARGING_BATTERY_POLL_MS
|
||||||
|
s.core.interruptibleSleep.interrupt()
|
||||||
|
sleepMs(300)
|
||||||
|
assertEquals(2, queries().size)
|
||||||
|
// Leaving the case is reported even with the same level, and without one.
|
||||||
|
push(caseInfoBody(63))
|
||||||
|
assertEquals("63/0/out", s.listener.cases.last())
|
||||||
|
push(ByteArray(0))
|
||||||
|
assertEquals("-1/0/out", s.listener.cases.last())
|
||||||
|
push(ByteArray(0))
|
||||||
|
assertEquals(5, s.listener.cases.size)
|
||||||
|
} finally {
|
||||||
|
s.core.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun dockingReadsTheBatteryEvenWithTheDisplaySuspended() {
|
||||||
|
val s = Session()
|
||||||
|
s.link.caseInfo = ByteArray(0)
|
||||||
|
try {
|
||||||
|
s.startAndAwaitLayout()
|
||||||
|
assertTrue(waitUntil(5_000) { s.listener.cases == listOf("-1/0/out") }, s.listener.cases.toString())
|
||||||
|
// Off the face the display is suspended, which stops the regular battery poll.
|
||||||
|
s.core.monitor.withLock { s.core.shutdownRequested = true }
|
||||||
|
fun batteryQueries() = s.link.writes.count { it.kind == "battery" }
|
||||||
|
val before = batteryQueries()
|
||||||
|
val wait = ConnectionOptions.DOCKED_BATTERY_CHECK_DELAY_MS + 1_000L
|
||||||
|
s.platform.offsetMs += wait
|
||||||
|
s.core.interruptibleSleep.interrupt()
|
||||||
|
sleepMs(300)
|
||||||
|
assertEquals(before, batteryQueries())
|
||||||
|
// Docking: the case push schedules a battery read a few seconds later.
|
||||||
|
s.core.onNotification(RIGHT, BleProtocol.NOTIFY_CHAR_UUID, BleProtocol.framePb(
|
||||||
|
casePackage(200, caseInfoBody(98, inCase = 1)), BleProtocol.SID_GLASSES_CASE, BleProtocol.FLAG_NOTIFY, 99)[0])
|
||||||
|
assertEquals("98/0/docked", s.listener.cases.last())
|
||||||
|
s.core.interruptibleSleep.interrupt()
|
||||||
|
sleepMs(300)
|
||||||
|
assertEquals(before, batteryQueries(), "not before the delay")
|
||||||
|
s.platform.offsetMs += wait
|
||||||
|
s.core.interruptibleSleep.interrupt()
|
||||||
|
assertTrue(waitUntil(5_000) { batteryQueries() == before + 1 }, s.host.logs().takeLast(10).toString())
|
||||||
|
// It reads once; the docking push is not repeated for later level changes.
|
||||||
|
s.core.onNotification(RIGHT, BleProtocol.NOTIFY_CHAR_UUID, BleProtocol.framePb(
|
||||||
|
casePackage(201, caseInfoBody(97, inCase = 1)), BleProtocol.SID_GLASSES_CASE, BleProtocol.FLAG_NOTIFY, 100)[0])
|
||||||
|
s.platform.offsetMs += wait
|
||||||
|
s.core.interruptibleSleep.interrupt()
|
||||||
|
sleepMs(300)
|
||||||
|
assertEquals(before + 1, batteryQueries())
|
||||||
|
} finally {
|
||||||
|
s.core.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun glassesChargingAtConnectReadTheCaseOnce() {
|
||||||
|
val s = Session()
|
||||||
|
s.link.headsetCharging = true
|
||||||
|
s.link.caseInfo = caseInfoBody(90, charge = 1, lid = 1, inCase = 1)
|
||||||
|
try {
|
||||||
|
assertTrue(s.core.start())
|
||||||
|
assertTrue(waitUntil(5_000) { s.listener.cases.isNotEmpty() }, s.host.logs().takeLast(10).toString())
|
||||||
|
assertEquals(listOf("90/1/docked"), s.listener.cases)
|
||||||
|
// Charging mode skips the layout, and with it the session-start read;
|
||||||
|
// the charging-mode read is the only one.
|
||||||
|
s.platform.offsetMs += 2L * ConnectionOptions.CHARGING_BATTERY_POLL_MS
|
||||||
|
s.core.interruptibleSleep.interrupt()
|
||||||
|
sleepMs(300)
|
||||||
|
assertEquals(1, s.link.writes.count { it.kind == "case-info" })
|
||||||
|
assertEquals(0, s.link.writes.count { it.kind == "create-layout" })
|
||||||
|
assertFalse(s.host.hasLog("late ACK"), s.host.logs().filter { it.contains("late ACK") }.toString())
|
||||||
|
} finally {
|
||||||
|
s.core.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -130,6 +130,10 @@ private class MainThreadListener : FaceclawBleCommunicatorListener {
|
|||||||
if (!NSThread.isMainThread) offMainCallbacks++
|
if (!NSThread.isMainThread) offMainCallbacks++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onCaseState(caseBattery: Int, caseCharging: Int, caseDocked: Boolean) {
|
||||||
|
if (!NSThread.isMainThread) offMainCallbacks++
|
||||||
|
}
|
||||||
|
|
||||||
override fun onSilentMode(silent: Boolean) {}
|
override fun onSilentMode(silent: Boolean) {}
|
||||||
|
|
||||||
override fun onWearState(wearing: Boolean) {}
|
override fun onWearState(wearing: Boolean) {}
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ dashboard state, re-sent whenever it changes (and at least every 30 s):
|
|||||||
"phase": "connected", "status": "…", "connected": true,
|
"phase": "connected", "status": "…", "connected": true,
|
||||||
"screenOn": true, "locked": false, "worn": true, "listening": false,
|
"screenOn": true, "locked": false, "worn": true, "listening": false,
|
||||||
"battery": 78, "charging": false, "silentMode": false,
|
"battery": 78, "charging": false, "silentMode": false,
|
||||||
|
"caseBattery": 64, "caseCharging": true,
|
||||||
"foreground": {"appId": "music", "title": "Music"},
|
"foreground": {"appId": "music", "title": "Music"},
|
||||||
"windows": [{"windowId": "…", "title": "…", "appId": "…", "focused": true, "closeable": true, "acceptsText": false}],
|
"windows": [{"windowId": "…", "title": "…", "appId": "…", "focused": true, "closeable": true, "acceptsText": false}],
|
||||||
"apps": [{"appId": "timer", "title": "Timer"}],
|
"apps": [{"appId": "timer", "title": "Timer"}],
|
||||||
@@ -71,6 +72,12 @@ dashboard state, re-sent whenever it changes (and at least every 30 s):
|
|||||||
`silentMode` identify the two states in which the glasses display is not
|
`silentMode` identify the two states in which the glasses display is not
|
||||||
visible even though the BLE session remains available.
|
visible even though the BLE session remains available.
|
||||||
|
|
||||||
|
`caseBattery` is the last-known charging-case percentage, or null until the
|
||||||
|
glasses have reported one; the case only reports while the glasses are docked,
|
||||||
|
so outside charging it can be stale. `caseCharging` is whether the case is on
|
||||||
|
USB, or null while the glasses are out of the case (they can't see it then).
|
||||||
|
The watch shows the case level under the charging line.
|
||||||
|
|
||||||
`protocol` is reserved for incompatible revisions of this format (nothing
|
`protocol` is reserved for incompatible revisions of this format (nothing
|
||||||
checks it yet). `crownClockwiseNext` mirrors the
|
checks it yet). `crownClockwiseNext` mirrors the
|
||||||
on-glasses Settings > Watch toggle; when false (the default), clockwise crown
|
on-glasses Settings > Watch toggle; when false (the default), clockwise crown
|
||||||
|
|||||||
@@ -95,6 +95,10 @@ data class PhoneState(
|
|||||||
/** Current or last-known G2 charge percentage. */
|
/** Current or last-known G2 charge percentage. */
|
||||||
val battery: Int?,
|
val battery: Int?,
|
||||||
val charging: Boolean,
|
val charging: Boolean,
|
||||||
|
/** Last-known charging-case percentage; live only while the glasses are docked. */
|
||||||
|
val caseBattery: Int?,
|
||||||
|
/** The case is on USB; null while the glasses are out of the case. */
|
||||||
|
val caseCharging: Boolean?,
|
||||||
val silentMode: Boolean,
|
val silentMode: Boolean,
|
||||||
val foreground: AppEntry?,
|
val foreground: AppEntry?,
|
||||||
val windows: List<WindowEntry>,
|
val windows: List<WindowEntry>,
|
||||||
@@ -123,6 +127,8 @@ data class PhoneState(
|
|||||||
listening = o.optBoolean("listening", false),
|
listening = o.optBoolean("listening", false),
|
||||||
battery = if (o.isNull("battery")) null else o.optInt("battery", -1).takeIf { it in 0..100 },
|
battery = if (o.isNull("battery")) null else o.optInt("battery", -1).takeIf { it in 0..100 },
|
||||||
charging = o.optBoolean("charging", false),
|
charging = o.optBoolean("charging", false),
|
||||||
|
caseBattery = if (o.isNull("caseBattery")) null else o.optInt("caseBattery", -1).takeIf { it in 0..100 },
|
||||||
|
caseCharging = if (o.isNull("caseCharging")) null else o.optBoolean("caseCharging"),
|
||||||
silentMode = o.optBoolean("silentMode", false),
|
silentMode = o.optBoolean("silentMode", false),
|
||||||
foreground = foreground?.let {
|
foreground = foreground?.let {
|
||||||
AppEntry(it.optString("appId", ""), it.optString("title", ""))
|
AppEntry(it.optString("appId", ""), it.optString("title", ""))
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
|
||||||
import androidx.compose.ui.unit.IntOffset
|
import androidx.compose.ui.unit.IntOffset
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
@@ -64,13 +63,10 @@ fun AmbientScreen(link: PhoneLink, ambient: AmbientMode) {
|
|||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
modifier = Modifier.align(Alignment.Center),
|
modifier = Modifier.align(Alignment.Center),
|
||||||
)
|
)
|
||||||
Text(
|
PadStatusText(
|
||||||
text = padLine(state, linkStatus).text,
|
pad = padLine(state, linkStatus),
|
||||||
style = MaterialTheme.typography.title3,
|
|
||||||
color = statusColor,
|
color = statusColor,
|
||||||
textAlign = TextAlign.Center,
|
detailColor = statusColor,
|
||||||
maxLines = 1,
|
|
||||||
overflow = TextOverflow.Ellipsis,
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.align(Alignment.Center)
|
.align(Alignment.Center)
|
||||||
.offset(y = 46.dp)
|
.offset(y = 46.dp)
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.layout.Layout
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
@@ -59,8 +60,11 @@ fun NoticeOverlay(notice: Notice?) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The pad's single indicator line, with a tone that picks its colour. */
|
/**
|
||||||
data class StatusLine(val text: String, val tone: StatusTone)
|
* The pad's indicator line, with a tone that picks its colour, and an
|
||||||
|
* optional smaller line under it (the charging case's level while charging).
|
||||||
|
*/
|
||||||
|
data class StatusLine(val text: String, val tone: StatusTone, val detail: String? = null)
|
||||||
|
|
||||||
enum class StatusTone { GOOD, BUSY, OFF, PROBLEM }
|
enum class StatusTone { GOOD, BUSY, OFF, PROBLEM }
|
||||||
|
|
||||||
@@ -76,7 +80,8 @@ fun padLine(state: PhoneState?, link: LinkStatus): StatusLine = when {
|
|||||||
state == null -> StatusLine("Waiting for phone", StatusTone.BUSY)
|
state == null -> StatusLine("Waiting for phone", StatusTone.BUSY)
|
||||||
state.remoteEnabled == false -> StatusLine("Watch control off", StatusTone.PROBLEM)
|
state.remoteEnabled == false -> StatusLine("Watch control off", StatusTone.PROBLEM)
|
||||||
state.connected -> when {
|
state.connected -> when {
|
||||||
state.charging || state.phase == "charging" -> StatusLine(chargingLine(state.battery), StatusTone.BUSY)
|
state.charging || state.phase == "charging" ->
|
||||||
|
StatusLine(chargingLine(state.battery), StatusTone.BUSY, caseLine(state))
|
||||||
state.silentMode -> StatusLine("Silent mode", StatusTone.OFF)
|
state.silentMode -> StatusLine("Silent mode", StatusTone.OFF)
|
||||||
state.locked -> StatusLine("Locked", StatusTone.OFF)
|
state.locked -> StatusLine("Locked", StatusTone.OFF)
|
||||||
!state.screenOn -> StatusLine("●● Wake", StatusTone.OFF)
|
!state.screenOn -> StatusLine("●● Wake", StatusTone.OFF)
|
||||||
@@ -91,6 +96,56 @@ fun padLine(state: PhoneState?, link: LinkStatus): StatusLine = when {
|
|||||||
private fun chargingLine(battery: Int?): String =
|
private fun chargingLine(battery: Int?): String =
|
||||||
if (battery != null) "Charging · G2 $battery%" else "Charging"
|
if (battery != null) "Charging · G2 $battery%" else "Charging"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "Case 64%", with ⚡ while the case is on USB; null when the level is
|
||||||
|
* unknown. Matches the phone's watch face (glassesDisplayDetail). The case is
|
||||||
|
* only reported while the glasses are docked, so the line is only drawn while
|
||||||
|
* they charge.
|
||||||
|
*/
|
||||||
|
private fun caseLine(state: PhoneState): String? =
|
||||||
|
state.caseBattery?.let { "Case $it%" + if (state.caseCharging == true) " ⚡" else "" }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [pad]'s status line, with its detail (if any) drawn under it. Only the
|
||||||
|
* status line counts toward the measured height, so a caller that centres
|
||||||
|
* this keeps the status line in the same place whether or not a detail shows.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
fun PadStatusText(pad: StatusLine, color: Color, detailColor: Color, modifier: Modifier = Modifier) {
|
||||||
|
Layout(
|
||||||
|
modifier = modifier,
|
||||||
|
content = {
|
||||||
|
Text(
|
||||||
|
text = pad.text,
|
||||||
|
style = MaterialTheme.typography.title3,
|
||||||
|
color = color,
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
)
|
||||||
|
pad.detail?.let { detail ->
|
||||||
|
Text(
|
||||||
|
text = detail,
|
||||||
|
style = MaterialTheme.typography.caption1,
|
||||||
|
color = detailColor,
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
) { measurables, constraints ->
|
||||||
|
val placeables = measurables.map { it.measure(constraints.copy(minWidth = 0, minHeight = 0)) }
|
||||||
|
val status = placeables.first()
|
||||||
|
val width = placeables.maxOf { it.width }.coerceIn(constraints.minWidth, constraints.maxWidth)
|
||||||
|
val height = status.height.coerceIn(constraints.minHeight, constraints.maxHeight)
|
||||||
|
layout(width, height) {
|
||||||
|
status.placeRelative((width - status.width) / 2, 0)
|
||||||
|
placeables.getOrNull(1)?.let { it.placeRelative((width - it.width) / 2, status.height) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun StatusTone.color(): Color = when (this) {
|
fun StatusTone.color(): Color = when (this) {
|
||||||
StatusTone.GOOD -> Color(0xFF7BD88F)
|
StatusTone.GOOD -> Color(0xFF7BD88F)
|
||||||
StatusTone.BUSY -> Color(0xFFF2C14E)
|
StatusTone.BUSY -> Color(0xFFF2C14E)
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ import androidx.compose.ui.platform.LocalViewConfiguration
|
|||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
@@ -307,13 +306,10 @@ fun RemoteScreen(
|
|||||||
modifier = Modifier.align(Alignment.Center).offset(y = 46.dp),
|
modifier = Modifier.align(Alignment.Center).offset(y = 46.dp),
|
||||||
) {
|
) {
|
||||||
val pad = padLine(state, linkStatus)
|
val pad = padLine(state, linkStatus)
|
||||||
Text(
|
PadStatusText(
|
||||||
text = pad.text,
|
pad = pad,
|
||||||
style = MaterialTheme.typography.title3,
|
|
||||||
color = if (pad.tone == StatusTone.GOOD) MaterialTheme.colors.onSurface else pad.tone.color(),
|
color = if (pad.tone == StatusTone.GOOD) MaterialTheme.colors.onSurface else pad.tone.color(),
|
||||||
textAlign = TextAlign.Center,
|
detailColor = MaterialTheme.colors.onSurfaceVariant,
|
||||||
maxLines = 1,
|
|
||||||
overflow = TextOverflow.Ellipsis,
|
|
||||||
modifier = Modifier.padding(horizontal = 42.dp),
|
modifier = Modifier.padding(horizontal = 42.dp),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user