Brightness control

This commit is contained in:
James Babcock committed 2026-11-05 11:18:17 -08:00
1 parent 739e81c8a6
commit f803f4212c
9 files changed
+233 -23

No files matched your search

+7
View File
@@ -1,5 +1,12 @@
export const DEFAULT_BRIGHTNESS_CURVE = "0:0,0.2:7,1.5:33,5:100";
const PREVIOUS_DEFAULT_CURVE = "0:0,1:10,10:30,100:65,1000:100";
/**
* The RayNeo iO's sensor reads real lux, far above the G2's behind-the-lens values, so the
* G2's curve would sit at maximum in any lit room. These knots put the default 20–100 range on
* the stock firmware's own scene levels: 29, 41, 41, 53, 65, 76, 94 and 100 percent at 3, 10,
* 200, 300, 600, 1000, 4000 and 5000 lux.
*/
export const RAYNEO_IO_BRIGHTNESS_CURVE = "0:0,3:11,10:26,200:26,300:41,600:56,1000:70,4000:93,5000:100";
/** Percent of the configured range; defaults (20–100) give 20/26/46/100. */
export function brightnessCurveError(value: string): string | null {
+13 -4
View File
@@ -1,6 +1,6 @@
import { normalizeNightscoutThreshold, type NightscoutThresholds } from "../apps/nightscout/nightscout-alerts";
import { GESTURE_DOUBLE_CLICK, InputEvent } from "./gestures";
import { DEFAULT_BRIGHTNESS_CURVE, normalizeBrightnessCurve, brightnessCurveError } from "../g2/brightness-curve";
import { DEFAULT_BRIGHTNESS_CURVE, RAYNEO_IO_BRIGHTNESS_CURVE, normalizeBrightnessCurve, brightnessCurveError } from "../g2/brightness-curve";
import {
getBooleanSetting,
getStringSetting,
@@ -215,6 +215,8 @@ type ConfigSettingStringOptions<TId extends string> = ConfigSettingOptions<strin
inputKind?: "text" | "email" | "password";
normalize?: (value: string | null | undefined) => string;
validate?: (value: string) => string | null;
/** The default while nothing is stored, when it depends on context (else `defaultValue`). */
dynamicDefault?: () => string | undefined;
};
// Every string setting by id, so isolates that can only pass an id over a
@@ -232,6 +234,7 @@ export class ConfigSettingString<TId extends string = string> extends ConfigSett
readonly inputKind: "text" | "email" | "password";
private readonly normalizer: (value: string | null | undefined) => string;
private readonly validator?: (value: string) => string | null;
private readonly dynamicDefault: (() => string | undefined) | undefined;
constructor(options: ConfigSettingStringOptions<TId>) {
super(options);
@@ -240,11 +243,16 @@ export class ConfigSettingString<TId extends string = string> extends ConfigSett
this.inputKind = options.inputKind ?? "text";
this.normalizer = options.normalize ?? ((value) => value ?? "");
this.validator = options.validate;
this.dynamicDefault = options.dynamicDefault;
stringSettingsById.set(this.id, this);
}
private currentDefault(): string {
return this.dynamicDefault?.() ?? this.defaultValue;
}
get(): string {
return this.normalizer(getStringSetting(this.storageKey, this.defaultValue));
return this.normalizer(getStringSetting(this.storageKey, this.currentDefault()));
}
set(value: string): string {
@@ -263,8 +271,8 @@ export class ConfigSettingString<TId extends string = string> extends ConfigSett
getValidValue(): string {
const value = this.get();
if (!this.validationError(value)) return value;
const saved = this.normalizer(getStringSetting(this.storageKey + ".valid", this.defaultValue));
return this.validationError(saved) ? this.defaultValue : saved;
const saved = this.normalizer(getStringSetting(this.storageKey + ".valid", this.currentDefault()));
return this.validationError(saved) ? this.currentDefault() : saved;
}
}
@@ -592,6 +600,7 @@ export const autoBrightnessMaxSetting = new ConfigSettingEnum({
export const autoBrightnessCurveSetting = new ConfigSettingString({
id: "autoBrightnessCurve", label: "Auto light curve", storageKey: "display.autoBrightnessCurve",
defaultValue: DEFAULT_BRIGHTNESS_CURVE, normalize: normalizeBrightnessCurve, validate: brightnessCurveError,
dynamicDefault: () => (glassesTypeSetting.get() === "rayneo-io" ? RAYNEO_IO_BRIGHTNESS_CURVE : undefined),
description: "2–16 lux:percent pairs, separated by commas. Percent is within your minimum–maximum range. Start at 0:0, end at 100%, and increase lux without decreasing percent. Incomplete edits stay in the preview; brightness keeps using the last valid curve.",
});
/** The screen on/off fade at Normal speed. */