Skip to content

omamobile-sensors 0.2.2, omamobile-shell 0.2.116: automatic brightness from the ambient light - #636

Open
jkjoplin wants to merge 3 commits into
derekross:mainfrom
jkjoplin:sensors-automatic-brightness
Open

jkjoplin wants to merge 3 commits into
derekross:mainfrom
jkjoplin:sensors-automatic-brightness

Conversation

@jkjoplin

Copy link
Copy Markdown
Contributor

What and why

Nothing reads the AoC's light sensor, so the panel stays wherever the slider was left. My Pixel 7 Pro sat at 85 % (level 1740) in a room of about 85 lux and drew about 4 W in use. The sensor already reaches the system bus through omamobile-sensor-proxy (LightLevel in lux, AOC-PLAN C6), so this adds the missing loop: omamobile-autobrightness, a user service in omamobile-sensors modelled on omamobile-autorotate, and a switch for it in the quick settings.

The curve. The target luminance is interpolated in log-log space between (lux, nits) points, so equal ratios of light give equal steps of perceived brightness. The level comes from the panel's range in DISPLAY-PLAN 2.4 (levels 4-2047 for about 2-600 nits, taken as linear between them; 0 turns the pixels off, so 4 is the floor, and HBM above 2047 is left alone if a kernel ever offers it):

lux ≤ 1 10 85 100 1000 ≥ 10000
nits 3 25 99 110 300 600
level 7 83 336 373 1022 2047

So 85 lux gets level 336 instead of 1740. The panel range is looked up by the board's compatible string (PANELS; only cheetah has an entry). The Pixel 6 Pro also installs omamobile-sensors and has a light sensor, so it gets the tile too; there the same nits are spread over its whole backlight range from level 1, with a line in the journal, until it has an entry or a "panel" in ~/.config/omamobile/autobrightness.json. I don't know raven's panel range.

Smoothing, hysteresis, ramps. A median of the last three readings drops a lone spike; a log-domain average (up in about 1 s, down in about 3 s) follows. The level moves only when the average and the median have both stayed beyond +26 % for 1.5 s, or beyond -29 % for 10 s. The long wait before dimming is because the sensor is under the panel and a hand shades it in use (below). The backlight then moves on a perceptual scale: up in about a third of a second, down over about three seconds; the first reading after a wake applies at once.

A manual change is a preference, not a fight. Any write the daemon didn't make (the slider's brightnessctl, anything else) stops it at once: every brightness write notifies actual_brightness, and it reads the level again before each of its own writes. After 2 s the level becomes the user's point on the curve, in the manner of Android's auto-brightness adjustment: a gamma (1/3-3) on the panel's perceptual range bends the curve through it, and where the gamma can't reach, the curve blends into the point over a decade of lux. The level stays exactly where the user put it, the preference carries over to other light, the panel's ends stay put (daylight is still the maximum), and the point is saved in ~/.local/state/omamobile/autobrightness.json. The power key's and the lock's changes teach nothing: a zero, a change from zero (omamobile-keys puts 40 % back when a wake finds the panel at 0), a change while the panel is off, and anything in the first second after a wake.

Writes go through logind's SetBrightness on session/auto, as brightnessctl does for the slider: brightness is root's, only bl_power is the video group's. A write that fails (logind refusing, or no answer in 2 s) changes nothing the daemon believes: the panel keeps its level, nothing is learned from it, and it retries 5 s later; a timed-out write that lands after all is recognised as its own.

Screen off. bl_power not 0, or the DSI connector's DPMS not On. Neither is signalled (Hyprland 0.57 has no DPMS event on its socket, and neither sysfs file notifies), so it reads both once a second, on GLib's whole-second timer. While the panel is off it releases the light claim, so the proxy stops the sensor, and writes nothing. With no backlight at all the service exits with status 78, which its unit doesn't restart.

Switching it. omamobile-toggle-autobrightness [toggle|on|off|status|reset], in the manner of Omarchy's toggles. In the quick settings, the brightness row's icon (which did nothing on a tap) switches it and shows 󰃡 while it runs, and an "Auto brightness" tile does the same; the tile is in the catalog under "Add tiles", not in the default layout, so nobody's pages move. It says "Not installed" without the toggle and "No sensor" without a light sensor or a backlight. The sheet reads its state as a new step in #518's staggered open refresh, right after the brightness. The slider's code is unchanged: with the service on, its level becomes the daemon's point. The service is off by default, like auto-rotate; whether new installs should get it on is your call.

Device and build

  • Phone: Pixel 7 Pro (cheetah), Omarchy 4.5.0-3
  • Kernel release (uname -r): 7.3.0-rc6-omamobile-g2219cc6cda77
  • Packages changed, with versions: omamobile-sensors 0.2.2, omamobile-shell 0.2.116 (provisional: main is at 0.2.115, and no open pull request claims a higher number today; renumber as you like)

Checks (no phone needed)

  • tools/pr-check origin/main passes
  • tests/all passes, except three parts that need a kernel build setup, which the phone I ran them on doesn't have: tests/kernel-pr-check ("the kernel config doesn't configure", then "a new board with a sibling's message"), tests/boot-method ("display-msm should log not stamping on empty tree") and tests/release ("asks for the boot record of the exact release"). All three fail the same way in a clean checkout of origin/main on the same phone, and this change touches none of what they test. I ran every part after kernel-pr-check separately, since tests/all stops at the first failure.
  • tests/packages passes, 30 of 31 suites, omamobile-sensors and omamobile-shell among them. The one that fails is omamobile-settings: its test builds the app with make, which the phone I ran it on doesn't have ("make: command not found"), and this change doesn't touch that package.
  • Each changed package has its version bumped, and the new version is in the commit subject
  • Commits have area prefixes and bodies that say why; any AI help is a Co-Authored-By: or Assisted-by: trailer, never a Signed-off-by:

test/autobrightness.py (27 unit tests on a fake clock, needing no D-Bus or phone) covers the curve and the user's point (exact at every lux and level on a grid, monotonic, the gamma within its limits, daylight staying at the maximum, a saved gamma held to its range), the board's panel range, the filter (steady-room noise, steps up and down, a spike, flicker, a reading that is never repeated), the ramps, and the controller: a slider level becoming the user's point with no writes while it settles and none afterwards, the slider winning during a ramp, a change the daemon wasn't told about, a slider moved just after a wake, writes that fail or land late, the screen going off and on, a wake from level 0, and a saved point coming back. Each test written for a fix fails against the code before it: I ran them against the previous version, and the one for the check before each write against a copy without that check. test/all also runs the toggle against stand-ins for systemctl and busctl (with and without a backlight), and a D-Bus round trip through the proxy's test backend with a directory standing in for the backlight: it follows the light, releases the sensor while bl_power is 4, claims it again, and keeps a level written by hand. For the shell, test/all checks the icon, the toggle command, the status read and its wording, and the backend; tiles-model.js lists the new tile under "Add tiles"; quicksettings-refresh has the new step in its order.

On the phone

  • I ran this on my own phone, booted into this build: not the package build. The phone runs omamobile-sensors 0.2.1 and omamobile-shell 0.2.100; I ran the daemon from the branch as a transient user unit. Two versions of lib/autobrightness.py ran there: the first filter (blob bd01d3f, or a copy made three minutes before it that differed in one log line) and the second (4cc0459). Times are the phone's (-0700). Details are in the NOTES entry this adds.
    • Read-only first: the proxy's light sensor gives about a reading a second (77.9-88.2 lux in that room), and up to ten a second while the light changes. Ten logind writes of the current level from a systemd-run --user unit took 2.1-9.6 ms, and each woke a poll() on actual_brightness.
    • A dry run (--dry-run --verbose, writes nothing; bd01d3f) through a wake at 16:44:18 and three minutes of use in a dim room. It found that a hand shades the sensor under the panel: at about 14 lux it read 1-7 lux for 7-8 s at a time, a few seconds apart. With 5 s before dimming the level would have moved 11 times in 2.3 minutes, four of them a dim and a brighten seconds apart, and a "brighten" decided on the lagging average once set a darker reading (12.8 to 11.0 lux). 4cc0459 fixed both (10 s before dimming; the median must agree). Replaying the same 330 readings through it gave 4 moves, all real. The replay isn't in the repository; a 64 s stretch of the shaded readings is, as a unit test, with the brighten that went away.
    • Attended, writing the backlight (16:50-16:52, 4cc0459): started at level 716 in 52 lux, it claimed the sensor in 17 ms and set 245 within 0.1 s, then held it. brightnessctl set 50% was seen 13 ms later, became my point 2.0 s later (1024 at 52 lux) and stayed for the 20 s after. --reset eased it back to 311 (76 lux) within 8 s. omarchy-brightness-display off released the sensor within about a second; on claimed it again and applied 61 lux (level 271) at once. 1.0 s of CPU over the 59 s run. Level 300 against 1500 at a steady 40 lux read 40.2 and 40.0 lux: the panel's own light doesn't reach the proxy's reading.
    • Not on the phone: a review of the branch then found that a failed write was learned as my preference, that a slider moved in the first 3 s after a wake was undone, and that the panel range was keyed on max_brightness. The fixes (a8718c8, the head's daemon) ran in the unit tests only.
    • The quick settings, offscreen, on this branch's head: test/quicksettings-render pointed at the phone's own Omarchy shell and themes (instead of the container's mounts), with the tile first in the layout, three times: with the branch's toggle on PATH (the tile reads "Off"), without it ("Not installed", dimmed), and with a stand-in that reports it on ("On" with 󰃡, as the slider's icon then shows). 184 checks each, no QML errors. No screenshots attached, because the shots show my Wi-Fi network's name.
  • What I did not test: the packages built and installed; the unit started by omamobile-toggle-autobrightness on, at a login and after a reboot; the icon and tile in the live shell (that needs omamobile-shell installed and the shell restarted); the head's daemon on the phone; a day of use with it on; a fingerprint unlock more than a second after a wake (whether LHBM changes brightness, which the daemon would then take as the user's); any other phone, raven included. The panel's level-to-nits mapping is taken as linear between DISPLAY-PLAN's two points, not measured. If you'd like a run of the installed packages on a 7 Pro before merging (the shell restarted, the icon and tile on and off, toggleTile auto-brightness, a reboot with it on), I can do it.
  • Nothing in this change writes outside slot B and userdata, weakens the storage guard, or reads registers from userspace (AGENTS.md §1)

The NOTES entry goes on top of device/cheetah/NOTES.md; if #554 lands first, whichever comes second needs a rebase there.

tools/phone-smoke report

phone-smoke: cheetah

Kernel 7.3.0-rc6-omamobile-g2219cc6cda77, tools at 52f5200, 2026-11-10T05:28Z.

Check Result Detail
boot (required) ok kernel 7.3.0-rc6-omamobile-g2219cc6cda77, slot b, up 7202s
storage guard (required) ok 55 partitions; only userdata and slot B's boot images writable
root (required) ok ext4 on userdata, 91G free
kernel health (required) ok no oops or BUG; 0 WARN, 98 error lines in dmesg (97 known, of them ASoC no backend DAIs (PipeWire probe) x1, UFS dme-set 0x4021 (s2idle) x1, 1 new)
new dmesg errors not ok cma: Failed to reserve N MiB x1
systemd units ok none failed
USB gadget (required) ok bound to 11210000.usb
display ok card2-DSI-1 connected, 1440x3120
GPU ok render node on panthor
session (required) ok Hyprland and the Omarchy shell running
lock ok PAM file present (the shell didn't answer lock status)
touch ok Synaptics TouchComm Touchscreen
buttons ok gpio-keys
Wi-Fi ok wlp1s0 on brcmfmac, link up
Bluetooth ok hci0, powered false
battery ok 76% Charging, 37 °C
sound cards ok googleaocsndcar
sensors ok Accelerometer AmbientLight Proximity
cameras not ok libcamera lists none (or a camera app holds them)
thermal ok hottest zone 64 °C

Packages: hyprland 0.57.0-3.1, libcamera 0.7.2-4.22, mesa 1:26.2.4-1.4, omacam 0.3.3-1, omamessages 0.2.2-1, omamobile-apps 0.2.2-1, omamobile-audio 0.5.13-1, omamobile-boot-update 0.1.0-1, omamobile-device-cheetah 0.1.44-1, omamobile-fingerprint 0.1.15-1, omamobile-firstboot 0.1.3-1, omamobile-gnss 0.2.7-1, omamobile-keyring 20261026-1, omamobile-mirror 0.1.1-1, omamobile-modem 0.1.16-1, omamobile-omarchy 0.1.36-1, omamobile-owl-widgets 0.1.2-1, omamobile-sensors 0.2.1-1, omamobile-shell 0.2.100-1, omaphone 0.2.3-1, omarchy 4.5.0-3, omatel-agent 0.2.4-2, quickshell 0.3.2.r7.g2b4501a-1

Run on the phone itself as my user (--here, with SMOKE_DEVICE and SMOKE_REPO set as the laptop wrapper sets them), not as root over SSH. The two "not ok" lines aren't from this change, which isn't installed: the CMA line is at 0.000000 s, the kernel's first memory reservation at boot, and as my user libcamera lists no cameras (my earlier reports, as root, listed four). The thermal reading follows tests/packages on the phone.

🤖 Generated with Claude Code

jkjoplin and others added 3 commits November 9, 2026 22:13
The phone draws about 4 W in use, and the panel stays wherever the
slider was left: 85 % in a room of about 85 lux on my Pixel 7 Pro. The
AoC's light sensor already reaches the system bus through
omamobile-sensor-proxy (LightLevel in lux), but nothing read it.

omamobile-autobrightness is a user service in the manner of
omamobile-autorotate. While the screen is on it claims the light sensor
and sets the backlight from a log-log curve: 3 nits in the dark, 25 at
10 lux, 110 at 100, 300 at 1000, the panel's 600 from 10000. That puts
85 lux at level 336 (99 nits) instead of 1740. The panel's range is the
board's (PANELS): cheetah's from DISPLAY-PLAN 2.4, levels 4-2047 for
about 2-600 nits, HBM above that left alone. Another board gets the
same nits over its whole range, with a line in the journal, until it
has an entry or a "panel" in ~/.config/omamobile/autobrightness.json.

- Smoothing and hysteresis: a median of three readings drops a lone
  spike, then a log-domain average (up in about 1 s, down in about 3 s).
  The level moves only once the average and the median have both stayed
  beyond +26 % for 1.5 s, or beyond -29 % for 10 s. The sensor is under
  the panel, and a hand shades it in use: in a dim room it read 1-7 lux
  instead of about 14 for 7-8 s at a time, a few seconds apart, which a
  5 s wait before dimming turned into a dim and a brighten again.
- Ramps on a perceptual scale: up in a third of a second, down over
  about three seconds; the first reading after a wake applies at once.
- A level the daemon didn't write (the quick-settings slider,
  brightnessctl) stops it at once: every write notifies
  actual_brightness, and it reads the level before each of its own
  writes. After 2 s the level becomes the user's point on the curve,
  Android-style: a gamma (1/3-3) on the panel's perceptual range bends
  the curve through it, blending over a decade where the gamma can't
  reach. The level stays where the user put it, the preference carries
  over to other light, daylight stays at the maximum, and the point is
  saved. A zero, a change from zero, a change while the panel is off and
  the first second after a wake (the power key's and the lock's) teach
  nothing.
- A write that fails (logind refuses it or doesn't answer in 2 s)
  changes nothing the daemon believes: the panel's level stays, nothing
  is learned from it, and it tries again 5 s later. A timed-out write
  that lands after all is recognised as its own.
- Screen off (bl_power not 0, or DSI DPMS not On; read once a second on
  GLib's whole-second timer, since neither is signalled): the light
  claim is released and nothing is written.
- Writes go through logind's SetBrightness, as brightnessctl's do (2-10
  ms each on the phone). With no backlight the service exits with status
  78, which its unit doesn't restart.

omamobile-toggle-autobrightness [toggle|on|off|status|reset] switches
the service, as Omarchy's toggles do; status says whether there is a
light sensor and a backlight. It is off by default, like auto-rotate.

Tests: test/autobrightness.py, 27 unit tests on a fake clock: the curve
and the user's point, the filter (with the phone's own readings of a
hand over the sensor, and a burst of light that went away), the ramps,
manual levels (also one the daemon wasn't told about, and one just
after a wake), failed and late writes, the screen going off and on, a
saved point, the board's panel range. Each test written for a fix fails
without it. test/all also runs the toggle against stand-ins for
systemctl and busctl, and a D-Bus round trip through the proxy's test
backend with a directory standing in for the backlight.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n and a tile

omamobile-sensors 0.2.2 adds omamobile-autobrightness, a user service
that sets the backlight from the light sensor. Quick settings switch it
the way the rotation lock tile switches auto-rotate:

- the brightness row's icon (until now it did nothing on a tap) turns
  it on and off through omamobile-toggle-autobrightness, and shows the
  auto glyph while it runs;
- an Auto brightness tile does the same. It is in the catalog, under
  "Add tiles", not in the default layout, so nobody's pages move. "Not
  installed" without the command, "No sensor" without a light sensor or
  a backlight.

The slider keeps writing the backlight through brightnessctl while
automatic brightness runs: the daemon takes a level set there as the
user's point on its curve instead of undoing it. That needs nothing
from the shell, so the slider's code is unchanged. omamobile-sensors is
an optional dependency.

The sheet reads the switch's state in its staggered open refresh
(derekross#518), right after the brightness.

Tests: test/all checks the icon, the toggle command, the status read
and its wording, and the backend; tiles-model.js lists the new tile
under "Add tiles"; quicksettings-refresh has the new step in its order. On the phone, test/quicksettings-render (pointed at
the phone's own Omarchy shell and themes instead of the container's)
drew the sheet with the tile first, off and on, with no QML errors: 184
checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
How omamobile-autobrightness (omamobile-sensors 0.2.2) was tested on a
Pixel 7 Pro, run from the branch and not installed, with the daemon's
version for each run: the light sensor through the proxy, writes through
logind from a user service, the screen-off path, a dry run through a
wake and three minutes of use (which found the hand over the sensor and
changed the filter), and an attended run that wrote the backlight. The
panel's own light didn't reach the lux; the slider's level stuck;
display off and on released and claimed the sensor. What the review
fixed after that ran in the unit tests only. Still to do: the installed
packages, the icon and tile in the live shell, and a day of use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derekross

Copy link
Copy Markdown
Owner

Thanks, @jkjoplin, this is a careful piece of work: the read-before-write so the slider always wins, the rule that changes to or from zero and changes around a wake teach nothing (I walked omamobile-keys' lock and wake sequences against it and they come out right), failed writes that aren't learned, the sensor released while the panel is off, and a report that says exactly which version ran where. Leaving it off by default and the tile out of the default layout is what I'd have asked for.

It merges onto today's main with only the version file to resolve. Both this and #635 say omamobile-shell 0.2.116, which main has used since this afternoon (it's at 0.2.117), so I'll set the number myself at merge; no need to renumber.

Before I merge, I'll run the installed packages on my Pixel 7 Pro, since the head's daemon and the unit started from the toggle haven't run on a phone yet: off by default, a dry run, on from the icon, the slider, a dark room, a hand over the sensor, the power key (also during a dimming ramp), fingerprint unlock in the dark, a call, a sleep and a reboot. Things I'd like your view on meanwhile:

  1. The power key during a ramp. _ramp_step reads the level and then writes; if omamobile-keys' write of 0 lands between the two, the next step overwrites the 0 and the phone locks behind a lit screen for a moment, which is the flash the 0 is there to prevent. I could reproduce it on a fake backlight. It's a few milliseconds in every 50 ms step, but dimming ramps run for seconds and often while the phone is going into a pocket. If you see a cheap way to close it (a re-read after the write that puts a replaced 0 back, say), please add it; otherwise I'll see how often it shows.
  2. A hand over the sensor, then the slider. With the sensor covered for more than ten seconds the level falls, and if I push the slider back up while it's still covered, that becomes my point at 1 lux (on a fake clock: 206 nits at 1 lux, gamma 0.33), so a dark room later gets level 700. Would it be reasonable not to learn a point, or to learn it only for that light and not bend the curve, when the reading is at the floor and has been for less than, say, a minute?
  3. The Pixel 6 Pro. It gets the switch with a guessed range from level 1. Our s6e3hc3 driver has the same 4-2047 as the 7 Pro's, but nobody has run it there. I'd rather status said unavailable on a board without a PANELS entry until an owner has tried it; a raven entry can follow with their run.
  4. The icon. One tap on an icon that used to do nothing now turns on a persistent service and the level jumps. I'll decide after trying it with a thumb whether it stays a tap or becomes a long press; no change needed from you yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants