forked from Blendman974/faceclaw
Add brightness setting
This commit is contained in:
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
if (listener != null) {
|
||||
imuListeners.add(listener);
|
||||
|
||||
@@ -271,6 +271,28 @@ public class BleProtocol {
|
||||
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) {
|
||||
byte[] request = encodeVarintField(1, 1);
|
||||
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) {
|
||||
int magic = magicPool.allocate();
|
||||
return new OutboundMessage(
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
@@ -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,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();
|
||||
|
||||
Reference in new issue
Block a user