Enable incremental frames; add config setting for controlling custom firmware debug flags

This commit is contained in:
James Babcock committed 2026-07-06 12:42:58 -07:00
1 parent 2bc53b8c0e
commit 1533c550b4
7 files changed
+92 -8

No files matched your search

@@ -62,6 +62,11 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
private boolean fixedLayoutCreated;
private boolean warmedUp;
private boolean shutdownRequested;
// CFW firmware-debug-flags overlay (mode 7). Desired value pushed from TS; the
// sub-op last sent this session (-1 = not yet), reset on (re)connect so the
// overlay state is re-asserted on every reconnect and whenever the value changes.
private volatile boolean firmwareDebugFlagsEnabled;
private int firmwareDebugFlagsLastSent = -1;
private boolean startupProbePending;
private long reconnectAfterMs;
@@ -84,6 +89,10 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
private int nextTransportSeq = 0x40;
private int nextMapSessionId = 0;
private int nextImageUpdateId = 1;
// Wire frame id for mode-3 deltas (CFW reorder/skip/dup diagnostic). uint16,
// advanced by 1 per emitted delta; kept in [1, 0xfffe] to avoid the CFW's
// 0xffff "empty" sentinel.
private int nextImageFrameId = 1;
private int lastShutdownAckMagic = 0;
private long lastShutdownExitAtMs = 0;
private int headsetBattery = -1;
@@ -183,6 +192,12 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
mainHandler.post(() -> updateG2ScreenWakeLock(screenOn));
}
public void setFirmwareDebugFlags(boolean enabled) {
// Just record it; the drive loop emits the mode-7 control message when the
// session is warmed up and idle, and re-emits when this value changes.
firmwareDebugFlagsEnabled = enabled;
}
public boolean startG2AudioCapture(FaceclawAudioPacketListener listener) {
if (listener == null) {
throw new IllegalArgumentException("listener is required");
@@ -818,6 +833,13 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
enqueueWarmupLocked();
}
if (messageToPrewrite == null && !shutdownRequested && fixedLayoutCreated && warmedUp
&& (firmwareDebugFlagsEnabled ? 2 : 1) != firmwareDebugFlagsLastSent
&& pendingMessages.isEmpty() && inFlightMessages.isEmpty()) {
Log.i(TAG, "enqueueing firmware debug flags " + (firmwareDebugFlagsEnabled ? "show" : "hide"));
enqueueFirmwareDebugFlagsLocked();
}
if (messageToPrewrite == null && handleHeartbeat()) {
return ConnectionOptions.IDLE_SLEEP_MS;
}
@@ -1165,6 +1187,9 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
}
private void enqueueCreateLayoutLocked() {
// New session/container: re-assert the firmware-debug-flags overlay once it's
// warmed up again (the mode-7 send is gated on this having reset).
firmwareDebugFlagsLastSent = -1;
OutboundMessage message = messageBuilder.createLayout(DASHBOARD_TILE);
message.onAck = () -> {
startupProbePending = false;
@@ -1246,6 +1271,25 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
logLine("queue blank warmup");
}
/**
* Send the CFW mode-7 diagnostic-flag control op to the dashboard container:
* [7][2] to show the on-glasses debug-flag overlay, [7][1] to hide it. Uses the
* arbitrary-payload image path (no bmp/dedup/frame-timing interaction) and does
* nothing on stock firmware (which ignores unknown image modes).
*/
private void enqueueFirmwareDebugFlagsLocked() {
boolean show = firmwareDebugFlagsEnabled;
int sub = show ? 2 : 1;
byte[] payload = new byte[] { (byte) 7, (byte) sub };
OutboundMessage message = messageBuilder.imagePayload(
DASHBOARD_TILE, nextMapSessionId(), payload,
"fw-debug-flags " + (show ? "show" : "hide"),
connectionOptions.sendImagesToLeft);
pendingMessages.addLast(message);
firmwareDebugFlagsLastSent = sub;
logLine("queue firmware debug flags " + (show ? "show" : "hide"));
}
private void enqueueDesiredImageLocked() {
String fingerprint = getDesiredFingerprint();
byte[] bmp;
@@ -1272,7 +1316,12 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
// paths, so a non-empty value means display state is trusted.
byte[] incrementalPayload = null;
if (connectionOptions.INCREMENTAL_FRAMES && displayedBmp.length > 0) {
incrementalPayload = BleImageOptimizer.buildIncrementalImagePayload(displayedBmp, bmp);
incrementalPayload = BleImageOptimizer.buildIncrementalImagePayload(displayedBmp, bmp, nextImageFrameId);
if (incrementalPayload != null) {
// advance only when a delta is actually emitted, so consecutive
// deltas carry consecutive ids (CFW skip/reorder detection)
nextImageFrameId = nextImageFrameId >= 0xfffe ? 1 : nextImageFrameId + 1;
}
}
BleImageOptimizer.TileImagePlan plan = incrementalPayload != null
? new BleImageOptimizer.TileImagePlan(0, DASHBOARD_TILE, bmp, nextMapSessionId(), incrementalPayload)
@@ -104,14 +104,18 @@ public final class BleImageOptimizer {
* Build a mode-3 bounding-box incremental payload, or null when a full
* update should be sent instead (frames not comparable, or the changed
* region spans the whole screen). Wire format:
* [3][left/4][top/2][width/4][height/2][zlib of headerless 4bpp region]
* [3][left/4][top/2][width/4][height/2][fid_lo][fid_hi][zlib of headerless 4bpp region]
* The region is top-down rows of the NEW frame, stride width/2 bytes. The
* box is aligned so left/width are multiples of 4 pixels and top/height
* multiples of 2 rows, letting each coordinate fit one byte and avoiding
* 4bpp byte-boundary corner cases. Identical frames yield null too; the
* caller's dedup check should normally catch that first.
*
* frameId is a little-endian uint16 the CFW uses to detect reordered,
* skipped or duplicated deltas (its diagnostic overlay); the caller advances
* it by 1 per emitted delta so consecutive deltas are consecutive.
*/
public static byte[] buildIncrementalImagePayload(byte[] previousBmp, byte[] newBmp) {
public static byte[] buildIncrementalImagePayload(byte[] previousBmp, byte[] newBmp, int frameId) {
int width = BmpUtil.readBmpWidth(newBmp);
int height = BmpUtil.readBmpHeight(newBmp);
if (width <= 0 || height <= 0
@@ -173,13 +177,15 @@ public final class BleImageOptimizer {
System.arraycopy(next, (top + y) * stride + (left >> 1), region, y * regionStride, regionStride);
}
byte[] compressed = deflate(region);
byte[] out = new byte[5 + compressed.length];
byte[] out = new byte[7 + compressed.length];
out[0] = 3;
out[1] = (byte) (left / 4);
out[2] = (byte) (top / 2);
out[3] = (byte) (boxWidth / 4);
out[4] = (byte) (boxHeight / 2);
System.arraycopy(compressed, 0, out, 5, compressed.length);
out[5] = (byte) (frameId & 0xff); // fid_lo
out[6] = (byte) ((frameId >> 8) & 0xff); // fid_hi
System.arraycopy(compressed, 0, out, 7, compressed.length);
return out;
}
@@ -38,5 +38,5 @@ public class ConnectionOptions {
// back, apparently display-driver buffer swapping), so partial updates
// composite onto stale content per-lens. Re-enable once the firmware
// guarantees the compositing base.
final boolean INCREMENTAL_FRAMES = false;
final boolean INCREMENTAL_FRAMES = true;
}
+18 -1
View File
@@ -30,6 +30,7 @@ import {
import {
elevenLabsApiKeySetting,
nightscoutApiTokenSetting,
firmwareDebugFlagsSetting,
nightscoutSiteUrlSetting,
onAnySettingChanged,
rawScreenshotsEnabledSetting,
@@ -188,7 +189,18 @@ class DashboardController {
});
// Settings toggled from the glasses can change what the phone UI shows
// (e.g. the raw-screenshot button), so re-emit the snapshot on any change.
onAnySettingChanged(() => this.emit());
onAnySettingChanged(() => {
this.emit();
// Apply a firmware-debug-flags toggle live while connected (Java dedups).
this.pushFirmwareDebugFlags();
});
}
private pushFirmwareDebugFlags(): void {
if (!this.communicator) return;
void this.communicator
.setFirmwareDebugFlags(firmwareDebugFlagsSetting.get())
.catch(() => {});
}
/**
@@ -346,6 +358,11 @@ class DashboardController {
// phone can sleep normally while they charge.
void this.communicator?.setG2ScreenOn(false).catch(() => {});
}
if (mappedPhase === "connected" && this.phase !== "connected") {
// Push the CFW firmware-debug-flags overlay preference; Java emits the
// mode-7 control message once the dashboard container is warmed up.
this.pushFirmwareDebugFlags();
}
this.setPhase(mappedPhase);
this.setStatus(state.status);
});
+4
View File
@@ -311,6 +311,10 @@ export class FaceclawCommunicatorBridge {
await this.enqueueJavaCall(() => this.communicator.setG2ScreenOn(Boolean(screenOn)));
}
async setFirmwareDebugFlags(enabled: boolean): Promise<void> {
await this.enqueueJavaCall(() => this.communicator.setFirmwareDebugFlags(Boolean(enabled)));
}
async submitDashboardImage(image8bpp: Uint8Array, width: number, height: number, fingerprint: string, paintMs = -1, frameId = 0): Promise<void> {
// Snapshot because the Java call is deferred; the buffer is passed as an
// ArrayBuffer, which NativeScript marshals to a ByteBuffer without the
+7
View File
@@ -267,6 +267,13 @@ export const rawScreenshotsEnabledSetting = new ConfigSettingBoolean({
defaultValue: false,
});
export const firmwareDebugFlagsSetting = new ConfigSettingBoolean({
id: "firmware-debug-flags",
label: "Firmware debug flags",
storageKey: "developer.firmwareDebugFlags",
defaultValue: false,
});
export type VoiceProvider = "onboard" | "elevenlabs";
export const voiceProviderSetting = new ConfigSettingEnum<VoiceProvider>({
+2 -1
View File
@@ -1,5 +1,5 @@
import { dashboardState, TOP_LEFT_MENU_LAYOUT } from "../dashboard";
import { batteryDisplayModeSetting, dashboardSlotIds, elevenLabsApiKeySetting, enumSettingMenuItem, rawScreenshotsEnabledSetting, saveVoiceRecordingsSetting, showSignalStrengthSetting, showAndroidNotificationsSetting, showBatteryIndicatorsSetting, showFaceclawLogoSetting, systemCardNameSetting, textSettingMenuItem, toggleSettingMenuItem, voiceProviderSetting, dashboardSlotSettings, nightscoutSiteUrlSetting, nightscoutApiTokenSetting, screenTimeoutSetting } from "../dashboard-settings";
import { batteryDisplayModeSetting, dashboardSlotIds, elevenLabsApiKeySetting, enumSettingMenuItem, firmwareDebugFlagsSetting, rawScreenshotsEnabledSetting, saveVoiceRecordingsSetting, showSignalStrengthSetting, showAndroidNotificationsSetting, showBatteryIndicatorsSetting, showFaceclawLogoSetting, systemCardNameSetting, textSettingMenuItem, toggleSettingMenuItem, voiceProviderSetting, dashboardSlotSettings, nightscoutSiteUrlSetting, nightscoutApiTokenSetting, screenTimeoutSetting } from "../dashboard-settings";
import { MenuLayer } from "../menu";
export function createSettingsMenuLayer(): MenuLayer {
@@ -47,6 +47,7 @@ function createDeveloperSettingsMenuLayer(): MenuLayer {
[
toggleSettingMenuItem(rawScreenshotsEnabledSetting),
toggleSettingMenuItem(saveVoiceRecordingsSetting),
toggleSettingMenuItem(firmwareDebugFlagsSetting),
],
TOP_LEFT_MENU_LAYOUT,
);