forked from Blendman974/faceclaw
Case battery: stop showing stale charging; read after the layout
Review fixes for the charging-case battery: - The case reports whether the glasses are docked. An empty caseInfo (the reply out of the case) now parses as "not docked, no level" instead of nothing, and undocking is reported even when the level and charge state are unchanged. TS keeps the last level but clears caseCharging while the glasses are out of the case. - The phone line shows the charging mark only while it is live: G2 and Case only with a link to the glasses (connected or charging), and Case only while docked. Levels stay as the last known ones. - The session-start case read waits until the layout is up, so a firmware that ignored it could no longer hold up the first frame. When the glasses are already charging at connect, the charging-mode read is the only one; the old duplicate read and its "late ACK" log are gone. - Case dedup state resets on every connect, as wearState does, so each session's read reaches TS. - caseCharging uses > 0 like the headset, and is normalized to 0/1. - iOS now feeds the reading into the shell battery state, and the assistant's describeState includes the case level. - The batteryLine accessors move above connectionStatusLabel's doc comment.
This commit is contained in:
1 parent
9c0535014a
commit
fa7f33bfe8
15 files changed
+199
-61
No files matched your search
@@ -221,6 +221,12 @@ function describeState(): string {
|
||||
const charging = battery.headsetCharging ? ", 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())}.`);
|
||||
return parts.join(" ");
|
||||
}
|
||||
|
||||
@@ -1589,9 +1589,14 @@ class DashboardController {
|
||||
this.emit();
|
||||
});
|
||||
this.offCaseBattery = communicator.onCaseState((state) => {
|
||||
// Kept across disconnects: the case only reports while the glasses are
|
||||
// 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.
|
||||
shell.setBatteryLevels({ case: state.battery, caseCharging: state.charging });
|
||||
// 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) => {
|
||||
|
||||
@@ -883,6 +883,13 @@ export class IosPreviewController {
|
||||
if (this.active) this.onConnectionState({ ...this.state })
|
||||
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 => {
|
||||
if (this.communicator !== communicator) return
|
||||
this.logBluetooth(`Firmware: L=${info.leftVersion || '?'} R=${info.rightVersion || '?'}` +
|
||||
|
||||
@@ -43,7 +43,7 @@ export type HeadsetBatteryState = {
|
||||
};
|
||||
|
||||
/** See the Android communicator's CaseBatteryState. */
|
||||
export type CaseBatteryState = { battery: number; charging: boolean };
|
||||
export type CaseBatteryState = { battery: number | null; charging: boolean; docked: boolean };
|
||||
|
||||
export type FrameMetrics = {
|
||||
paintMs: number;
|
||||
@@ -123,8 +123,8 @@ class SessionListener extends NSObject {
|
||||
onBatteryStateHeadsetBatteryHeadsetChargingRingBatteryRingCharging(headsetBattery: number, headsetCharging: number, ringBattery: number, ringCharging: number): void {
|
||||
this.bridge.handleBatteryState(Number(headsetBattery), Number(headsetCharging), Number(ringBattery), Number(ringCharging));
|
||||
}
|
||||
onCaseStateCaseBatteryCaseCharging(caseBattery: number, caseCharging: number): void {
|
||||
this.bridge.handleCaseState(Number(caseBattery), Number(caseCharging) === 1);
|
||||
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)); }
|
||||
onWearStateWearing(wearing: boolean): void { this.bridge.handleWearState(Boolean(wearing)); }
|
||||
@@ -288,8 +288,12 @@ export class FaceclawCommunicatorBridge {
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
handleCaseState(battery: number, charging: boolean): void {
|
||||
this.emitAsync(this.caseListeners, { battery, charging });
|
||||
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 */
|
||||
|
||||
@@ -29,8 +29,12 @@ export type HeadsetBatteryState = {
|
||||
ringChargingStatus?: number;
|
||||
};
|
||||
|
||||
/** The charging case's level (0..100) and whether it is itself charging, as the glasses relay it. */
|
||||
export type CaseBatteryState = { battery: number; charging: boolean };
|
||||
/**
|
||||
* 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 = {
|
||||
paintMs: number;
|
||||
@@ -216,8 +220,13 @@ export class FaceclawCommunicatorBridge {
|
||||
};
|
||||
this.emitAsync(this.batteryListeners, state);
|
||||
},
|
||||
onCaseState: (caseBattery: number, caseCharging: number) => {
|
||||
this.emitAsync(this.caseListeners, { battery: Number(caseBattery), charging: Number(caseCharging) === 1 });
|
||||
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) => {
|
||||
this.emitAsync(this.silentModeListeners, Boolean(silent));
|
||||
@@ -339,7 +348,10 @@ export class FaceclawCommunicatorBridge {
|
||||
return () => this.batteryListeners.delete(listener);
|
||||
}
|
||||
|
||||
/** Charging-case readings: read on docking, then pushed by the glasses on every change. */
|
||||
/**
|
||||
* 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);
|
||||
|
||||
@@ -34,13 +34,17 @@ type LayoutOrientation = "portrait" | "landscape";
|
||||
|
||||
/**
|
||||
* The line under the mirror: each device whose level is known, e.g.
|
||||
* "G2 100% · Case 98% ⚡ · R1 72%" (⚡ = charging). The case level is the last
|
||||
* one the glasses relayed; it only reports while they are docked.
|
||||
* "G2 100% · Case 98% ⚡ · R1 72%" (⚡ = charging). Levels are the last known
|
||||
* ones (the case only reports while the glasses are docked), so ⚡ appears only
|
||||
* while it is live: with a link to the glasses, and for the case only while
|
||||
* they are docked (caseCharging is null otherwise).
|
||||
*/
|
||||
function formatBatteryLine(levels: DashboardSnapshot["batteries"]): string {
|
||||
function formatBatteryLine(snapshot: Pick<DashboardSnapshot, "batteries" | "phase">): string {
|
||||
const levels = snapshot.batteries;
|
||||
const live = snapshot.phase === "connected" || snapshot.phase === "charging";
|
||||
const devices: Array<[string, number | null, boolean | null]> = [
|
||||
["G2", levels.headset, levels.headsetCharging],
|
||||
["Case", levels.case, levels.caseCharging],
|
||||
["G2", levels.headset, live && levels.headsetCharging],
|
||||
["Case", levels.case, live && levels.caseCharging],
|
||||
["R1", levels.ring, levels.ringCharging],
|
||||
];
|
||||
return devices
|
||||
@@ -108,7 +112,7 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
this.displayPreview = snapshot.displayPreview;
|
||||
this.displayPreviewMessage = snapshot.displayPreviewMessage;
|
||||
this.phase = snapshot.phase;
|
||||
this.batteryLine = formatBatteryLine(snapshot.batteries);
|
||||
this.batteryLine = formatBatteryLine(snapshot);
|
||||
this.activeTextSettingId = snapshot.activeTextSettingId;
|
||||
this.activeTextEditorTitle = snapshot.activeTextEditorTitle;
|
||||
this.activeTextSettingTitle = snapshot.activeTextSettingTitle;
|
||||
@@ -163,11 +167,6 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Short connection indicator for the action bar. The full status string
|
||||
* (which can be a sentence, e.g. a failure reason) stays available by
|
||||
* tapping the indicator.
|
||||
*/
|
||||
get batteryLine(): string {
|
||||
return this._batteryLine;
|
||||
}
|
||||
@@ -183,6 +182,11 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
return this._batteryLine ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
/**
|
||||
* Short connection indicator for the action bar. The full status string
|
||||
* (which can be a sentence, e.g. a failure reason) stays available by
|
||||
* tapping the indicator.
|
||||
*/
|
||||
get connectionStatusLabel(): string {
|
||||
switch (this._phase) {
|
||||
case "connected":
|
||||
|
||||
@@ -488,7 +488,9 @@ export type ShellChromeState = {
|
||||
watchCharging: boolean | null;
|
||||
/**
|
||||
* The glasses' charging case, last known (it only reports while the
|
||||
* glasses are docked); null until it does. Shown on the phone, not here.
|
||||
* 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;
|
||||
|
||||
Reference in new issue
Block a user