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

+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 { type LayerActions } from "../ui/layers";
import {
brightnessSetting,
brightnessSettingToLevel,
elevenLabsApiKeySetting,
openAiApiKeySetting,
nightscoutApiTokenSetting,
@@ -164,6 +166,8 @@ class DashboardController {
private batteryOptimizationWarningVisible = false;
private displayPreview: ImageSource | null = createInitialDisplayPreview();
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
// drop-off right after a low reading can be explained as a flat battery.
private lastHeadsetBattery: number | null = null;
@@ -278,6 +282,7 @@ class DashboardController {
this.emit();
// Apply a firmware-debug-flags toggle live while connected (Java dedups).
this.pushFirmwareDebugFlags();
this.pushBrightness();
});
}
@@ -288,6 +293,21 @@ class DashboardController {
.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
* 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
// mode-7 control message once the dashboard container is warmed up.
this.pushFirmwareDebugFlags();
this.pushBrightness(true);
}
this.setPhase(mappedPhase);
this.setStatus(state.status);
+5
View File
@@ -359,6 +359,11 @@ export class FaceclawCommunicatorBridge {
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. */
async configureCompositorScreen(width: number, height: number): Promise<void> {
await this.enqueueJavaCall(() => {
+27 -3
View File
@@ -24,6 +24,11 @@ export type NightscoutSettings = {
export type BatteryDisplayMode = "icon" | "percentage";
export type TimeFormat = "24h" | "12h";
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";
type ConfigSettingOptions<TValue, TId extends string> = {
@@ -204,6 +209,15 @@ export const timeFormatSetting = new ConfigSettingEnum<TimeFormat>({
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>({
id: "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 {
return value === "never" ? "Never" : value;
}
@@ -437,15 +460,16 @@ export function enumSettingMenuItem<TValue extends string, TId extends string =
opts?.onChange?.(ctx, newValue, oldValue);
} else {
const submenu = new MenuLayer(setting.label, setting.values.map((value) => ({
label: value,
label: setting.displayValue(value),
onSelect: () => {
const oldValue = setting.get();
setting.set(value);
opts?.onChange?.(ctx, value, setting.get());
opts?.onChange?.(ctx, value, oldValue);
ctx.stack.pop();
},
render: ({ image, x, y }) => {
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);
+4
View File
@@ -4,6 +4,7 @@ import { shell } from "../shell/shell";
import {
anthropicApiKeySetting,
batteryDisplayModeSetting,
brightnessSetting,
elevenLabsApiKeySetting,
openAiApiKeySetting,
enumSettingMenuItem,
@@ -33,6 +34,9 @@ function settingsSections(): SettingsSection[] {
{
label: "Display",
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, {
onChange: () => {
shell.noteUserActivity();