Add brightness setting

This commit is contained in:
James Babcock committed 2026-07-23 10:48:35 -07:00
1 parent afc05d6a19
commit 7455775390
7 files changed
+116 -3

No files matched your search

@@ -288,6 +288,28 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
interruptibleSleep.interrupt(); interruptibleSleep.interrupt();
} }
/**
* Set the lens brightness. Fire-and-forget, like the IMU control: the
* message is queued ahead of other traffic and any not-yet-sent brightness
* message is superseded. When autoAdjust is true the ambient-light sensor
* drives brightness and brightnessLevel is ignored; otherwise
* brightnessLevel (0-100) is applied directly.
*/
public void setBrightness(boolean autoAdjust, int brightnessLevel) {
synchronized (lock) {
if (!running || !sessionReady) {
logLine("skip brightness set; session not ready");
return;
}
clearMessagesOfKindLocked("brightness-control");
OutboundMessage message = messageBuilder.setBrightness(autoAdjust, brightnessLevel);
message.onTimeout = () -> logLine("brightness control ack timeout");
pendingMessages.addFirst(message);
logLine("queue brightness " + (autoAdjust ? "auto" : "level=" + brightnessLevel));
}
interruptibleSleep.interrupt();
}
public void addImuListener(FaceclawImuListener listener) { public void addImuListener(FaceclawImuListener listener) {
if (listener != null) { if (listener != null) {
imuListeners.add(listener); imuListeners.add(listener);
@@ -271,6 +271,28 @@ public class BleProtocol {
return wrapEvenHub(CMD_OPEN_IMU, magic, 22, concat(inner)); return wrapEvenHub(CMD_OPEN_IMU, magic, 22, concat(inner));
} }
/**
* Set the lens brightness: G2SettingPackage{commandId=1 (DeviceReceiveInfo),
* deviceReceiveInfoFromApp(3){deviceReceiveBrightness(1){autoAdjust(1),
* brightnessLevel(2)}}} on sid 0x09. brightnessLevel is 0-100 (nonlinear;
* 0 is dim-but-visible, not off). When autoAdjust is set the ambient-light
* sensor drives brightness, so the level field is omitted; otherwise the
* level is always encoded (explicit zero included) so brightnessLevel=0
* reaches the wire.
*/
public static byte[] buildSetBrightness(int magic, boolean autoAdjust, int brightnessLevel) {
List<byte[]> brightness = new ArrayList<>();
brightness.add(encodeVarintField(1, autoAdjust ? 1 : 0));
if (!autoAdjust) {
brightness.add(encodeVarintField(2, brightnessLevel));
}
return concat(CollectionUtils.listOf(
encodeVarintField(1, 1),
encodeVarintField(2, magic),
encodeMessageField(3, encodeMessageField(1, concat(brightness)))
));
}
public static byte[] buildSettingsQuery(int magic) { public static byte[] buildSettingsQuery(int magic) {
byte[] request = encodeVarintField(1, 1); byte[] request = encodeVarintField(1, 1);
return concat(CollectionUtils.listOf( return concat(CollectionUtils.listOf(
@@ -122,6 +122,21 @@ public class MessageBuilder {
); );
} }
public OutboundMessage setBrightness(boolean autoAdjust, int brightnessLevel) {
int magic = magicPool.allocate();
return new OutboundMessage(
"brightness-control",
autoAdjust ? "brightness auto" : "brightness level=" + brightnessLevel,
BleProtocol.SID_UI_SETTING,
BleProtocol.FLAG_REQUEST,
magic,
BleProtocol.buildSetBrightness(magic, autoAdjust, brightnessLevel),
ACK_TIMEOUT_MS,
-1,
false
);
}
public OutboundMessage createLayout(BleProtocol.ImageTileOptions... tiles) { public OutboundMessage createLayout(BleProtocol.ImageTileOptions... tiles) {
int magic = magicPool.allocate(); int magic = magicPool.allocate();
return new OutboundMessage( return new OutboundMessage(
+21
View File
@@ -67,6 +67,8 @@ import { type InProcessAppOptions, type InProcessWindow } from "../ui/shell/in-p
import { APP_VIEWPORT } from "../ui/shell/geometry"; import { APP_VIEWPORT } from "../ui/shell/geometry";
import { type LayerActions } from "../ui/layers"; import { type LayerActions } from "../ui/layers";
import { import {
brightnessSetting,
brightnessSettingToLevel,
elevenLabsApiKeySetting, elevenLabsApiKeySetting,
openAiApiKeySetting, openAiApiKeySetting,
nightscoutApiTokenSetting, nightscoutApiTokenSetting,
@@ -164,6 +166,8 @@ class DashboardController {
private batteryOptimizationWarningVisible = false; private batteryOptimizationWarningVisible = false;
private displayPreview: ImageSource | null = createInitialDisplayPreview(); private displayPreview: ImageSource | null = createInitialDisplayPreview();
private silentMode = false; private silentMode = false;
// Brightness value last pushed to the glasses; see pushBrightness.
private lastPushedBrightness: string | null = null;
// Last battery level the glasses reported, kept across disconnects so a // Last battery level the glasses reported, kept across disconnects so a
// drop-off right after a low reading can be explained as a flat battery. // drop-off right after a low reading can be explained as a flat battery.
private lastHeadsetBattery: number | null = null; private lastHeadsetBattery: number | null = null;
@@ -278,6 +282,7 @@ class DashboardController {
this.emit(); this.emit();
// Apply a firmware-debug-flags toggle live while connected (Java dedups). // Apply a firmware-debug-flags toggle live while connected (Java dedups).
this.pushFirmwareDebugFlags(); this.pushFirmwareDebugFlags();
this.pushBrightness();
}); });
} }
@@ -288,6 +293,21 @@ class DashboardController {
.catch(() => {}); .catch(() => {});
} }
/**
* Push the brightness setting to the glasses. Deduped TS-side (the change
* listener fires for every setting, and each push queues a real BLE
* message); `force` skips the dedup so a fresh connection always gets the
* configured value regardless of what the firmware restored.
*/
private pushBrightness(force = false): void {
if (!this.communicator) return;
const value = brightnessSetting.get();
if (!force && value === this.lastPushedBrightness) return;
this.lastPushedBrightness = value;
const level = brightnessSettingToLevel(value);
void this.communicator.setBrightness(level === null, level ?? 0).catch(() => {});
}
/** /**
* Save the current composited screen as the raw headerless 4bpp frame * Save the current composited screen as the raw headerless 4bpp frame
* buffer the wire compressor sees; test data for compression experiments. * buffer the wire compressor sees; test data for compression experiments.
@@ -470,6 +490,7 @@ class DashboardController {
// Push the CFW firmware-debug-flags overlay preference; Java emits the // Push the CFW firmware-debug-flags overlay preference; Java emits the
// mode-7 control message once the dashboard container is warmed up. // mode-7 control message once the dashboard container is warmed up.
this.pushFirmwareDebugFlags(); this.pushFirmwareDebugFlags();
this.pushBrightness(true);
} }
this.setPhase(mappedPhase); this.setPhase(mappedPhase);
this.setStatus(state.status); this.setStatus(state.status);
+5
View File
@@ -359,6 +359,11 @@ export class FaceclawCommunicatorBridge {
await this.enqueueJavaCall(() => this.communicator.setFirmwareDebugFlags(Boolean(enabled))); await this.enqueueJavaCall(() => this.communicator.setFirmwareDebugFlags(Boolean(enabled)));
} }
/** Set lens brightness: auto (ambient sensor) or an explicit 0-100 level. */
async setBrightness(autoAdjust: boolean, level: number): Promise<void> {
await this.enqueueJavaCall(() => this.communicator.setBrightness(Boolean(autoAdjust), Math.round(level)));
}
/** Set the compositor's output frame size. Call before configuring surfaces. */ /** Set the compositor's output frame size. Call before configuring surfaces. */
async configureCompositorScreen(width: number, height: number): Promise<void> { async configureCompositorScreen(width: number, height: number): Promise<void> {
await this.enqueueJavaCall(() => { await this.enqueueJavaCall(() => {
+27 -3
View File
@@ -24,6 +24,11 @@ export type NightscoutSettings = {
export type BatteryDisplayMode = "icon" | "percentage"; export type BatteryDisplayMode = "icon" | "percentage";
export type TimeFormat = "24h" | "12h"; export type TimeFormat = "24h" | "12h";
export type ScreenTimeoutSetting = "15s" | "30s" | "1m" | "never"; export type ScreenTimeoutSetting = "15s" | "30s" | "1m" | "never";
// "auto" lets the glasses' ambient-light sensor drive brightness; the numeric
// values are exact levels on the firmware's 0-100 scale (nonlinear: ~30 is
// dim-but-readable indoors, ~60 is bright outdoors).
export const BRIGHTNESS_VALUES = ["auto", "0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"] as const;
export type BrightnessSetting = (typeof BRIGHTNESS_VALUES)[number];
export type WakeWordAction = "voice-input" | "off" | "turn-screen-on"; export type WakeWordAction = "voice-input" | "off" | "turn-screen-on";
type ConfigSettingOptions<TValue, TId extends string> = { type ConfigSettingOptions<TValue, TId extends string> = {
@@ -204,6 +209,15 @@ export const timeFormatSetting = new ConfigSettingEnum<TimeFormat>({
formatValue: timeFormatLabel, formatValue: timeFormatLabel,
}); });
export const brightnessSetting = new ConfigSettingEnum<BrightnessSetting>({
id: "brightness",
label: "Brightness",
storageKey: "display.brightness",
defaultValue: "auto",
values: BRIGHTNESS_VALUES,
formatValue: brightnessLabel,
});
export const screenTimeoutSetting = new ConfigSettingEnum<ScreenTimeoutSetting>({ export const screenTimeoutSetting = new ConfigSettingEnum<ScreenTimeoutSetting>({
id: "screen-timeout", id: "screen-timeout",
label: "Screen timeout", label: "Screen timeout",
@@ -366,6 +380,15 @@ export function screenTimeoutSettingToMs(value: ScreenTimeoutSetting): number |
} }
} }
export function brightnessLabel(value: BrightnessSetting): string {
return value === "auto" ? "Auto" : value;
}
/** The exact level for the wire, or null when the ambient sensor drives it. */
export function brightnessSettingToLevel(value: BrightnessSetting): number | null {
return value === "auto" ? null : Number(value);
}
export function screenTimeoutLabel(value: ScreenTimeoutSetting): string { export function screenTimeoutLabel(value: ScreenTimeoutSetting): string {
return value === "never" ? "Never" : value; return value === "never" ? "Never" : value;
} }
@@ -437,15 +460,16 @@ export function enumSettingMenuItem<TValue extends string, TId extends string =
opts?.onChange?.(ctx, newValue, oldValue); opts?.onChange?.(ctx, newValue, oldValue);
} else { } else {
const submenu = new MenuLayer(setting.label, setting.values.map((value) => ({ const submenu = new MenuLayer(setting.label, setting.values.map((value) => ({
label: value, label: setting.displayValue(value),
onSelect: () => { onSelect: () => {
const oldValue = setting.get();
setting.set(value); setting.set(value);
opts?.onChange?.(ctx, value, setting.get()); opts?.onChange?.(ctx, value, oldValue);
ctx.stack.pop(); ctx.stack.pop();
}, },
render: ({ image, x, y }) => { render: ({ image, x, y }) => {
const selected = setting.get() === value ? " *" : ""; const selected = setting.get() === value ? " *" : "";
image.drawText(getDefaultSmallFont(), x, y + 3, `${value}${selected}`, 200); image.drawText(getDefaultSmallFont(), x, y + 3, `${setting.displayValue(value)}${selected}`, 200);
} }
}))); })));
ctx.stack.push(submenu); ctx.stack.push(submenu);
+4
View File
@@ -4,6 +4,7 @@ import { shell } from "../shell/shell";
import { import {
anthropicApiKeySetting, anthropicApiKeySetting,
batteryDisplayModeSetting, batteryDisplayModeSetting,
brightnessSetting,
elevenLabsApiKeySetting, elevenLabsApiKeySetting,
openAiApiKeySetting, openAiApiKeySetting,
enumSettingMenuItem, enumSettingMenuItem,
@@ -33,6 +34,9 @@ function settingsSections(): SettingsSection[] {
{ {
label: "Display", label: "Display",
items: [ items: [
// Auto (ambient sensor) or an exact level; pushed to the glasses by
// the dashboard controller when changed and on each connect.
enumSettingMenuItem(brightnessSetting, { style: "submenu" }),
enumSettingMenuItem(screenTimeoutSetting, { enumSettingMenuItem(screenTimeoutSetting, {
onChange: () => { onChange: () => {
shell.noteUserActivity(); shell.noteUserActivity();