Make 2720 Flip lid switching instant and route closed-flip events to the cover
The lid daemon re-derived "observed" from a stale EV_SW mask on every 100 ms iteration and only read the raw hall lines every 200 ms, so the candidate oscillated and the 80 ms debounce almost never completed. A controlled hall transition on the live phone took over 2.2 s to blank and lock the main panel. The hall reading is now sticky, every EV_SW edge forces an immediate hall re-read, the loop and debounce are 20 ms, and the daemon writes the lid state, lock flag, Sxmo state and both backlights synchronously in C before spawning hooks. A direct xset DPMS off/on stops or resumes Xorg's SPI flushes at once. bananarchy-lid-state.sh guards the asynchronous hooks by lid state and a transition generation counter, so a late screenoff cannot re-lock a flip that was just opened. bananarchy-lid-gate.sh now gates sxmo_wm.sh display on, the screen-wake helper, the backlight udev helper, sxmo_state.sh set unlock (dwm calls it directly) and both input handler copies. While the flip is closed it blocks the main panel and keypad backlight, forces brightness/kbd/DPMS off against stray writes, and forwards a WAKE datagram to the cover display. Ring, notification and call-state hooks publish to the cover, and the cover daemon gained WAKE, event wakes, immunity to repeated LID CLOSED rebroadcasts and a bounded retry for a DPMS-deferred draw. Live verification with controlled hall transitions and uinput switch/key injection: close blanks and locks in ~45-90 ms (hall-poll fallback ~100-220 ms), open restores brightness, keypad backlight, unlock and DPMS in ~10-130 ms with no stale-hook re-lock. All three external keys and an incoming call leave brightness=0, kbd_backlight=0 and DPMS=Off while the cover reports backend=spidev visible=1; opening returns mux=open. Rebuilt the a1108/dejavu nokia-beatles image and pinned the verified hash 0f33aa6e9fc70022574b453aaafb9307c4d185431d3be272782c8403dd0fb291 in check-rebuild.sh. e2fsck -fn passed on both partitions, debugfs confirms twelve updated rootfs files byte-for-byte, and the bootfs sync, boot image check, artifact sync, host tests and rebuild preflight all pass. This is an intermediate checkpoint: eyes-on cover illumination and the remaining polarity/CS fixes are still required.
This commit is contained in:
1 parent
40a840b49b
commit
2857ef4374
29 files changed
+567
-49
No files matched your search
@@ -78,6 +78,10 @@ Keep this file short. Full details live in `README.md`, `MANUAL.md`, `SDK.md`, `
|
||||
- Keep the internal beatles panel at 25 MHz, `dc_gpio = -1` for the spidev fallback, external-panel firmware and
|
||||
initramfs module lists, the Xorg `card0` pin, `bananarchy-cover-diagnose.sh`, and the
|
||||
`scripts/test-cover-dt.py` / `scripts/test-cover-spidev.py` guards.
|
||||
- Keep the 2720 Flip lid handling event-driven and instant: sticky hall state, immediate hall re-read on `EV_SW`
|
||||
edges, 20 ms debounce, and synchronous lid-state/lock/backlight/DPMS writes in `bananarchy-lid.c`. Every main-panel
|
||||
wake path must call `bananarchy-lid-gate.sh`; a closed flip may only light the cover. `sxmo_state.sh set unlock` is
|
||||
gated too because `dwm` calls it directly. Guard `scripts/test-lid-gate.py`.
|
||||
- Build the lk2nd display image from pinned `bootloader/lk2nd/nokia-beatles.patch`. Exact stock IDs, 512 MiB memory
|
||||
fallback, appended DTB, `quiet splash`, and the low-bit reboot cookie matter. `check-lk2nd-beatles.py`,
|
||||
`test-lk2nd-beatles-port.py`, `check-beatles-bootimg.py`, `sync-beatles-bootfs.py --check`, and `check-rebuild.sh`
|
||||
|
||||
+9
-1
@@ -13,6 +13,14 @@ Release versions follow the `<year-letter><MM><DD>` format (where `2026` is `a`,
|
||||
|
||||
Work since `a1108` has focused on reliable 2720 Flip hardware support and a reproducible boot/flash path. Earlier incremental and superseded diagnostic entries are consolidated here.
|
||||
|
||||
### Instant flip lid switching and closed-flip event routing
|
||||
|
||||
- **Root cause of the close lag**: `bananarchy-lid.c` recomputed `observed` from a stale `EV_SW` mask on every 100 ms iteration and only consulted the raw hall lines every 200 ms, so `candidate` oscillated open/closed and the 80 ms debounce rarely completed. With a controlled hall-file transition on the live phone a close took over 2.2 s to blank the main panel. The hall reading is now sticky, any `EV_SW` edge forces an immediate hall re-read, the loop/debounce are 20 ms, and the daemon writes the lid state, lock flag, Sxmo state and all backlights synchronously in C before spawning hooks. A direct `xset dpms force off/on` stops or resumes Xorg's SPI flushes immediately; the Sxmo hooks run through `bananarchy-lid-state.sh`, which refuses stale spawns by lid state and a transition generation counter so a late screenoff hook cannot re-lock a just-opened flip.
|
||||
- **Closed flip is cover-only**: `bananarchy-lid-gate.sh` is called by `sxmo_wm.sh display on`, `bananarchy-screen-wake.sh`, `bananarchy-display-power-sync`, `sxmo_state.sh set unlock` and both `sxmo_hook_inputhandler.sh` copies. While `/run/bananarchy/lid-state` is `closed` it blocks the main panel and keypad backlight, hard-forces brightness/kbd/DPMS off against stray writes, and forwards a `WAKE` datagram to the cover display. Ring, notification, missed-call, pickup and hangup hooks also publish their state to the cover. The cover daemon gained `WAKE`, wakes on `CALL`/`NOTIFY`/`SMS`, ignores repeated `LID CLOSED` rebroadcasts instead of clearing a wake, and retries a DPMS-deferred draw for a bounded 3 s.
|
||||
- **Live verification** (root SSH, controlled hall transitions plus `/dev/uinput` switch/key injection): close now blanks + locks in ~45-90 ms with an `EV_SW` edge (~100-220 ms on the hall-poll fallback) instead of >2.2 s; open restores brightness, keypad backlight, unlock and DPMS in ~10-130 ms (~240 ms for DPMS) with no stale-hook re-lock after 2.4 s. All three external keys (volume up/down and End/Power) and an incoming call/notification left `brightness=0`, `kbd_backlight=0`, `DPMS=Off`, `state=screenoff/lock`, while the cover reported `backend=spidev visible=1 mux=closed`; the wake survived the 2 s lid rebroadcast. Opening returned `mux=open`, `backend=idle`, main panel on.
|
||||
- **Image persistence**: rebuilt `images/bananarchy-nokia-beatles.img` at `a1108` / `dejavu` with the instant lid handling; verified raw hash `0f33aa6e9fc70022574b453aaafb9307c4d185431d3be272782c8403dd0fb291`, pinned by `scripts/check-rebuild.sh`. `debugfs` confirms the image rootfs carries the rebuilt lid/cover daemons and all ten gated scripts byte-for-byte; `e2fsck -fn` passed on both partitions; bootfs sync, boot image check, artifact sync, host tests and rebuild preflight pass. The standalone boot image hash is unchanged.
|
||||
- **Guards**: `scripts/test-lid-gate.py` compiles the lid daemon on the host, checks the event-driven structure and generation guard, verifies every wake path is gated, and exercises the gate script against stubbed lid states. `scripts/test-cover-spidev.py` covers `WAKE`, repeated `LID CLOSED`, the DPMS-On gate and the bounded pending retry. `scripts/check-rebuild.sh` guards the new scripts, tokens and host tests.
|
||||
|
||||
### Closed-flip external panel on the shipping 2720 Flip image
|
||||
|
||||
- **Problem**: both GC9305 panels share one BLSP1 QUP5 SPI bus through a gpio13 mux. The shipping image registers only the 240x320 internal panel, so `bananarchy-cover-idle` had no `/dev/fb1` and reported `backend=none`: the cover screen was never driven in the closed flip state. Registering both panels in the DT (`devices/nokia-beatles/qcom-msm8905-nokia-beatles-cover.dts`) does produce `/dev/fb1`, but an earlier live test darkened the main panel, so that layout is deliberately opt-in.
|
||||
@@ -20,7 +28,7 @@ Work since `a1108` has focused on reliable 2720 Flip hardware support and a repr
|
||||
- **Hardware measurements**: on the live `nokia-beatles` target over root SSH, `/sys/kernel/debug/gpio` showed gpio13 `out low` with the main panel active (low = internal, high = cover), gpio21/gpio23 free inputs, gpio25 (`reset`) and gpio110 (`dc`) claimed by `panel-mipi-dbi-spi`, and `l17`/`l6` panel rails enabled. gpio13 therefore stays an output-low mux select and the daemon never requests gpio110. Polarities were *not* confirmed with eyes on the cover panel, so they remain config keys and runtime `bananarchy-coverctl SET` knobs, with `SET backend none` as a one-command rollback.
|
||||
- **Live verification**: the rebuilt ARM daemon, config, service and diagnostics were deployed to the phone. With the flip open, `STATUS` reports `backend=idle spi=1 mux=free` and gpio13 stays low. After `LID CLOSED` + `BUTTON` (lid broadcaster stopped, main panel DPMS-off to emulate a closed flip), `STATUS` reports `backend=spidev visible=1 mux=closed`, gpio13 goes high, the daemon holds `/dev/gpiochip0`, two `gpio-linehandle` fds and `/dev/spidev0.1`, and every init/frame ioctl succeeds. `BLANK` sends display-off; `LID OPEN` restores gpio13 low and `mux=open`. Xorg, dwm, `card0-SPI-1 dpms=On` and backlight 14 were restored afterwards, the lid service was restarted, and stopping the cover service leaves gpio13 output-low. Physical illumination of the cover still needs eyes-on sign-off.
|
||||
- **Guards and docs**: `scripts/test-cover-spidev.py` compiles the daemon in SPI simulation mode and verifies the open-flip bus silence, the DPMS-On gate, mux-first ordering, firmware replay, RGB565 frame size, display-off on blank, handover on open, polarity knobs, `SET backend none` rollback and `/dev/fb1` precedence. `scripts/check-rebuild.sh` guards the new source/config tokens and both compiled ARM copies. `bananarchy-cover-diagnose.sh` reports the spidev node, TLMM lines and polarity config. README, MANUAL and `AGENTS.md` describe the closed-flip-only ownership; the shipping DTB stays single-panel and the two-panel DT stays opt-in. `prebuilt/bananarchy-daemons/usr/bin/bananarchy-cover-idle` and its overlay mirror were rebuilt with `scripts/build-bananarchy-daemons.sh`.
|
||||
- **Image persistence**: rebuilt `images/bananarchy-nokia-beatles.img` at `a1108` / `dejavu` with the closed-flip external-panel backend; the verified raw hash is `ccc8c44517a6a3b78e16e45e9dddbf89f6f04a35ee4c52246d38d89970bd13ac`, pinned by `scripts/check-rebuild.sh`. `debugfs` confirms the image rootfs carries the rebuilt `bananarchy-cover-idle` and the new config, service and diagnostics byte-for-byte; `e2fsck -fn` passed on both `pmOS_boot` and `pmOS_root`; `sync-beatles-bootfs.py --check`, `check-beatles-bootimg.py`, artifact sync and `check-rebuild.sh` pass. The standalone `boot-bananarchy-nokia-beatles.img` hash is unchanged. Eyes-on confirmation that the cover panel lights up is still pending, so this is an intermediate build.
|
||||
- **Image persistence**: rebuilt `images/bananarchy-nokia-beatles.img` at `a1108` / `dejavu` with the closed-flip external-panel backend; the verified raw hash at that point was `ccc8c44517a6a3b78e16e45e9dddbf89f6f04a35ee4c52246d38d89970bd13ac` (superseded by the instant-lid rebuild below). `debugfs` confirms the image rootfs carries the rebuilt `bananarchy-cover-idle` and the new config, service and diagnostics byte-for-byte; `e2fsck -fn` passed on both `pmOS_boot` and `pmOS_root`; `sync-beatles-bootfs.py --check`, `check-beatles-bootimg.py`, artifact sync and `check-rebuild.sh` pass. The standalone `boot-bananarchy-nokia-beatles.img` hash is unchanged. Eyes-on confirmation that the cover panel lights up is still pending, so this is an intermediate build.
|
||||
|
||||
### Power menu label
|
||||
|
||||
|
||||
@@ -455,7 +455,7 @@ Three native X11 games (`/usr/bin/snake`, `/usr/bin/tetris`, and `/usr/bin/scoun
|
||||
- **Wi-Fi and Bluetooth missing**: both radios depend on the shared WCNSS remote processor. `msm-firmware-loader` must start in sysinit before udev and mount the stock `modem` and `persist` partitions under `/run/msm-firmware-loader/mnt`; it then exposes `wcnss.mdt` and the factory `WCNSS_qcom_wlan_nv.bin` through the kernel firmware path. Check `rc-service msm-firmware-loader status`, `cat /sys/class/remoteproc/remoteproc1/state`, and `dmesg | grep -Ei 'wcnss|remoteproc|firmware'`. A `Direct firmware load for wcnss.mdt failed` message means the loader package or its sysinit link is missing, not that the Wi-Fi and Bluetooth drivers are absent. After a successful boot, `wlan0` and `hci0` enumerate automatically; Bluetooth userspace still starts on demand from the Networks/Bluetooth UI to save power.
|
||||
- **X startup and keypad**: OpenRC starts independent services in parallel; `etc/init.d/local` replaces its stock `after *` dependency, which deadlocked with parallel startup on this image. `udev_settle_timeout=2` stops missing modem firmware from holding the display manager behind a long `udevadm settle`, and `bananarchy-sshd-debug` starts independently of `local.d`. A boot-open flip reads `/run/bananarchy/lid-state` and starts in `state=unlock` with no passcode screen, so the keypad is live as soon as `dwm` starts. If the keypad is dead, check `rc-service bananarchy-lid status`, `cat /run/bananarchy/lid-state`, `sxmo_state.sh get`, `/tmp/bananarchy_screen_locked`, `DISPLAY=:0 xwininfo -id 0xa00001` and `DISPLAY=:0 xinput list`.
|
||||
- **Display distortion above 71% brightness**: the internal panel uses 25 MHz SPI on `nokia-beatles`, rather than the 50 MHz timing used by the other targets. This keeps the link stable when the MPP2 backlight PWM duty rises above the level-10/14 operating point. The brightness range remains 1–14 with no artificial cap, and panel offsets/init registers are unchanged. The timing can be checked with `dtc -I dtb -O dts /boot/qcom-msm8905-nokia-beatles.dtb | grep -A8 'display@0'`.
|
||||
- **Closing the flip**: `bananarchy-lid` reads the current `EV_SW` switch mask from `/dev/input/event2`, follows hall edge events with an 80 ms stability window, and reconciles the raw gpio36/gpio92 debugfs levels every 200 ms even while evdev is present. This covers missed edges and stale `EVIOCGSW` state without a busy-polling loop. On close it blanks the main panel and keypad LED immediately, runs `sxmo_state.sh set screenoff` and tells the cover daemon `LID CLOSED`; on open it clears the lock flag, restores both backlights, sends a trusted `CLOSE` to `locker.so` and runs `sxmo_state.sh set unlock`. Check `rc-service bananarchy-lid status`, `sxmo_state.sh get` and `grep -E " gpio(36|92) " /sys/kernel/debug/gpio`. If the hall polarity is inverted on your unit, set `BANANARCHY_LID_GPIO_FILE` to a different debugfs GPIO file for the fallback path.
|
||||
- **Closing the flip**: `bananarchy-lid` reads the current `EV_SW` switch mask from `/dev/input/event2`, follows hall edge events with an 80 ms stability window, and reconciles the raw gpio36/gpio92 debugfs levels every 200 ms even while evdev is present. This covers missed edges and stale `EVIOCGSW` state without a busy-polling loop. On close it blanks the main panel and keypad LED immediately, runs `sxmo_state.sh set screenoff` and tells the cover daemon `LID CLOSED`; on open it clears the lock flag, restores both backlights, sends a trusted `CLOSE` to `locker.so` and runs `sxmo_state.sh set unlock`. Check `rc-service bananarchy-lid status`, `sxmo_state.sh get` and `grep -E " gpio(36|92) " /sys/kernel/debug/gpio`. If the hall polarity is inverted on your unit, set `BANANARCHY_LID_GPIO_FILE` to a different debugfs GPIO file for the fallback path. **Lag fix**: the hall reading is sticky and every `EV_SW` edge forces an immediate re-read, with a 20 ms debounce and 20 ms loop; the daemon writes `/run/bananarchy/lid-state`, `/tmp/bananarchy_screen_locked`, `sxmo.state`, both backlights and DPMS synchronously before spawning any hook. A close is now ~45-90 ms (was over 2 s) and an open ~10-130 ms. `bananarchy-lid-state.sh` drops stale hook spawns by lid state and a generation counter, so a late screenoff cannot re-lock a freshly opened flip.
|
||||
- **Cover display status and behaviour**: `bananarchy-cover-idle` is the compiled 0%-CPU default daemon and answers `bananarchy-coverctl` (`PING`, `STATUS`, `LID CLOSED|OPEN`, `BUTTON`, `NETWORK`, `BATTERY`, `NOTIFY`, `BLANK`/`UNBLANK`, `TEST`, `SET`); the native `bananarchy-coverd` is retained only for diagnostics. With the flip **open** the external panel is fully off and the daemon does not touch the shared QUP5 SPI bus at all; activation also requires `card0-SPI-1/dpms = Off`, so a transient lid-state flap cannot steal the bus from a live main panel. With the flip **closed** the daemon claims gpio13 (SPI bus mux), gpio21 (external D/C) and gpio23 (external reset) via `/dev/gpiochip0`, drives the mux to the cover panel, resets the GC9305, replays `/lib/firmware/nokia,beatles-gc9305-ext-panel.bin` over `/dev/spidev0.1` at 25 MHz and writes 240x240 RGB565 frames. `STATUS` reports `backend=spidev` and `mux=closed` while the cover owns the bus, and `mux=open` after `LID OPEN`, which sends display-off, restores the mux to the internal panel and releases the D/C and reset lines before Xorg flushes another frame. This is why the shipping image can use the cover screen without registering a second panel in the DT: both GC9305s share one SPI bus and the main panel is DPMS-off whenever the flip is closed. The panel stays off until an external side key is pressed: `bananarchy-volume-keys` reads `/run/bananarchy/lid-state` and sends the trusted `BUTTON` datagram instead of changing the volume, which shows the live clock, date, battery percentage and the compact main network indicators (`4G SIG75 WIFI`-style, published by `bananarchy-cover-status.sh` from the NetworkManager dispatcher and at service start). No further button blanks the cover after exactly the same **Config -> Screen blank** timeout that `dwm` uses (`~/.config/sxmo/idle_blank_timeout`, default 300 s, `0` = never; `blank_timeout = auto` in `/etc/bananarchy/cover-display.conf` selects it, a numeric value overrides it). The daemon blocks in `poll()` with no timer while off, so idle CPU stays at 0%. `backend = auto` prefers `/dev/fb1` when the opt-in two-panel DT is installed, using the 32-bpp fbdev `write()` path (not `mmap()`, which raises `SIGBUS`) and `FBIOBLANK`/`FB_BLANK_POWERDOWN` for "fully off". `backend = spidev` forces the userspace path, `backend = fb` forces the fbdev path and `backend = none` releases the bus; `SET backend none` is a live rollback. The external D/C, reset and mux polarities are config keys (`mux_closed_level`, `mux_open_level`, `dc_command_level`, `dc_data_level`, `reset_assert_level`, `reset_idle_level`) and runtime `SET` knobs, so physical sign-off needs no rebuild: close the flip (or hold `LID CLOSED` with the lid broadcaster stopped), run `bananarchy-coverctl TEST bars`, then try `SET mux_closed_level 0|1`, `SET reset_assert_level 0|1` and `SET dc_command_level 0|1` until the bars appear. The shipping DTS deliberately keeps the verified single-panel layout, so `/dev/fb1` is normally absent. A live test with two panels registered produced a working 240x240 external framebuffer but made the main panel go dark, so the two-panel `spi-mux` wiring is opt-in in `devices/nokia-beatles/qcom-msm8905-nokia-beatles-cover.dts`: build it with `scripts/build-beatles-cover-panel.py`, install the resulting DTB/boot.img into `pmOS_boot`, and verify the main panel before keeping it. `scripts/build-beatles-no-cover-dtb.py` builds the single-panel rollback DTB. The external firmware and `mux-core`/`mux-gpio`/`spi-mux` modules are already provisioned in the initramfs; `scripts/test-cover-idle.py`, `scripts/test-cover-spidev.py` and `scripts/test-cover-dt.py` verify the state machine, the closed-flip bus handover and both DT layouts on the host. Physical sign-off of the external D/C and reset polarity and of the cover backlight is still required with eyes on a live 2720 Flip; `devices/nokia-beatles/cover-panel.dtsi` remains a compile-checked reference for older DTBs. Run `bananarchy-cover-diagnose.sh` on the phone to check `/dev/fb1`, `/dev/spidev0.1`, the GPIO lines, the mux/panel modules, the firmware, the lid state and `bananarchy-coverctl STATUS` in one report. If the external panel disturbs the main display during sign-off, `SET backend none` releases the bus immediately and `scripts/build-beatles-no-cover-dtb.py --install` rebuilds the verified single-panel DTB/boot image for `pmOS_boot`.
|
||||
- **Camera app frozen / UI unresponsive**: check `top` for `bananarchy-volume-keys`. The daemon must be a single instance at 0% CPU; stale evdev fds are pruned by `prune_devices()`/`drop_device()` and guarded by `flock`. `rc-service bananarchy-volume-keys status` and `bananarchy-keypad-diagnose.sh` report its state. `xcamera` should return immediately and `bananarchy-photo <file>` should write a 600x800 JPEG.
|
||||
- **Camera**: `/dev/video0` is provided by the out-of-tree `msm8905-cam` module, loaded at boot by `/etc/modules-load.d/bananarchy-hardware.conf` and `etc/local.d/10-bananarchy-hardware.start`. Check with `v4l2-ctl --list-devices`; a missing node means the module did not load (previously caused by a missing `/bin/sed` breaking the `modules` service).
|
||||
|
||||
@@ -50,7 +50,7 @@ Instead of spawning slow shell scripts for everyday phone tasks, Bananarchy runs
|
||||
- **Kopher SmallWeb browser (`xkopher` / `kopher` / `xsmallweb` / `smallweb.so`)**: multi-protocol SmallWeb client for **Gopher** (`gopher://`) with optional TLS (`gophers://`), **Gemini** (`gemini://`), **Spartan** (`spartan://`), and **Nex** (`nex://`), featuring WAP-style default keypad controls from [Kopher](https://code.luxferre.top/luxferre/kopher.git), user-adjustable keybindings (`~/.config/sxmo/smallweb_controls.tsv`), 10 bookmarks, custom homepage support, and link focus that always scrolls the viewport to the focused link in both wrapped and unwrapped modes.
|
||||
- **Webarchy Web browser (`webarchy` / `xwebarchy` / `webarchy.so`)**: full-featured HTML5/CSS3/JS web browser built on WPE / WebKit (`webkit2gtk-4.1` + `libwpe-1.0`) with Adreno 304 hardware acceleration (`WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS`, WebGL, accelerated 2D canvas, and 512 MB RAM pressure tuning), default KaiOS 4.0 User-Agent (`Mozilla/5.0 (Mobile; rv:123.0) Gecko/123.0 Firefox/123.0 KAIOS/4.0`) with preset and custom User-Agent override (`~/.config/sxmo/webarchy_ua.txt`), `UTF-8` default encoding fallback, `Noto Sans` / `Noto Serif` (`font-noto` + `font-noto-emoji`) as the default non-monospace browser fonts and `Fira Code` with OpenType ligatures as the monospace font, full GStreamer multimedia (`MediaSource` / MSE, WebAudio, inline HTML5 `<video>`/`<audio>` autoplay without user gesture requirements), unobtrusive bookmarking (`*HTTPS`/`*HTTP` header badge, `*`+`0-9` save / `#`+`0-9` load chords, and bookmark manager), and dual navigation modes (keypad link-stepping mode with NeoUI multi-tap form input by default, plus an optional `*#` accelerated mouse cursor emulation mode), and a device-aware renderer profile: the 2720 Flip uses the WebKit CPU renderer (with automatic software fallback after a WebProcess crash) while the 8110 4G keeps Adreno 304 acceleration; `~/.config/sxmo/webarchy_software_renderer` forces the CPU profile on any target. The image build also compiles the installed GSettings schema XML into `usr/share/glib-2.0/schemas/gschemas.compiled`; without that database WebKit's network process aborts with an internal error before any renderer policy can help.
|
||||
- **GPS-only system time**: **Config -> Time source** switches from NTP to GNSS only (stopping `chronyd` and disabling every network-up NTP burst) and **Config -> Sync GPS time** steps the clock from a ModemManager GPS UTC value or a valid RMC fix, writes the RTC and refreshes the status bar. All GPS queries now resolve the GNSS-capable modem through `bananarchy-gps-modem.sh` instead of the ambiguous `mmcli -m any`, which fixes empty GPS data on the dual-SIM 2720 Flip. See `MANUAL.md` sections 5.6 and 5.8.
|
||||
- **2720 Flip cover display behaviour**: the compiled `bananarchy-cover-idle` renderer keeps the external panel fully off while the flip is open, waits for a side-button `BUTTON` event when closed, then shows the clock, battery and compact main network indicators until the same **Config -> Screen blank** timeout expires with no further button press. `bananarchy-volume-keys` turns the external keys into trusted cover wake events, `bananarchy-cover-status.sh` publishes modem/Wi-Fi indicators from network events, and the daemon blocks in `poll()` with no timer while off. **The external 240x240 GC9305 is now driven on the shipping single-panel image**: with the flip closed the daemon claims gpio13 (SPI mux), gpio21 (D/C) and gpio23 (reset) through `/dev/gpiochip0`, replays `/lib/firmware/nokia,beatles-gc9305-ext-panel.bin` over `/dev/spidev0.1` at the verified 25 MHz, and pushes RGB565 frames, but only while the main panel is DPMS-off; on open it sends display-off, restores the mux to the internal panel and releases the panel lines before Xorg can flush another main-panel frame. `backend = auto` prefers `/dev/fb1` when the opt-in two-panel DT is installed. All mux/D-C/reset polarities are config keys plus live `bananarchy-coverctl SET` knobs, and `SET backend none` is a one-command rollback. The two-panel `spi-mux` DT (`devices/nokia-beatles/qcom-msm8905-nokia-beatles-cover.dts`, built with `scripts/build-beatles-cover-panel.py`) stays **opt-in**: a live test produced `/dev/fb1` (240x240, 32bpp) but darkened the main panel, so the shipping DTB keeps the verified single-panel layout until gpio13 and the external D/C/reset polarities are probed with eyes on the phone. `FBIOBLANK` powers the cover fbdev down when it is off, `bananarchy-cover-diagnose.sh` reports the live panel state, `scripts/test-cover-idle.py`, `scripts/test-cover-spidev.py` and `scripts/test-cover-dt.py` validate the renderer, the closed-flip backend and both DT layouts on the host, and `scripts/build-beatles-no-cover-dtb.py` builds the single-panel rollback.
|
||||
- **2720 Flip cover display behaviour**: the compiled `bananarchy-cover-idle` renderer keeps the external panel fully off while the flip is open, waits for a side-button `BUTTON` event when closed, then shows the clock, battery and compact main network indicators until the same **Config -> Screen blank** timeout expires with no further button press. `bananarchy-volume-keys` turns the external keys into trusted cover wake events, `bananarchy-cover-status.sh` publishes modem/Wi-Fi indicators from network events, and the daemon blocks in `poll()` with no timer while off. **The external 240x240 GC9305 is now driven on the shipping single-panel image**: with the flip closed the daemon claims gpio13 (SPI mux), gpio21 (D/C) and gpio23 (reset) through `/dev/gpiochip0`, replays `/lib/firmware/nokia,beatles-gc9305-ext-panel.bin` over `/dev/spidev0.1` at the verified 25 MHz, and pushes RGB565 frames, but only while the main panel is DPMS-off; on open it sends display-off, restores the mux to the internal panel and releases the panel lines before Xorg can flush another main-panel frame. `backend = auto` prefers `/dev/fb1` when the opt-in two-panel DT is installed. All mux/D-C/reset polarities are config keys plus live `bananarchy-coverctl SET` knobs, and `SET backend none` is a one-command rollback. The two-panel `spi-mux` DT (`devices/nokia-beatles/qcom-msm8905-nokia-beatles-cover.dts`, built with `scripts/build-beatles-cover-panel.py`) stays **opt-in**: a live test produced `/dev/fb1` (240x240, 32bpp) but darkened the main panel, so the shipping DTB keeps the verified single-panel layout until gpio13 and the external D/C/reset polarities are probed with eyes on the phone. `FBIOBLANK` powers the cover fbdev down when it is off, `bananarchy-cover-diagnose.sh` reports the live panel state, `scripts/test-cover-idle.py`, `scripts/test-cover-spidev.py` and `scripts/test-cover-dt.py` validate the renderer, the closed-flip backend and both DT layouts on the host, and `scripts/build-beatles-no-cover-dtb.py` builds the single-panel rollback. **Closing the flip now blanks and locks the main panel in tens of milliseconds**: an `EV_SW` edge triggers an immediate hall re-read, and the compiled lid daemon writes the lid state, lock flag, Sxmo state and backlights synchronously before any shell hook runs. While closed, `bananarchy-lid-gate.sh` blocks every main-panel wake (dwm, Sxmo hooks, incoming calls, external keys) and forwards it as a cover `WAKE`, so the three side buttons and any event can only light the outer panel; opening the flip instantly hands the shared bus back to the main panel. See `scripts/test-lid-gate.py`.
|
||||
- **GPS reception test utility (`bananarchy-gps`) and OpenStreetMap navigator (`xgps` / `xmaps` / `xnav` / `gps.so`)**: CLI GNSS/GPS diagnostic tool (`bananarchy-gps status|enable|disable|nmea|watch`) and 3-tab NeoUI GPS navigator (`1:GPS Status`, `2:OSM Map`, `3:Nav/Search`) with live NMEA/QMI PDS satellite and 3GPP cell telemetry, interactive `240x212` OpenStreetMap slippy-map tile viewer with offline PNG tile cache (`~/.cache/sxmo/osm_tiles/`), Nominatim place search, saved waypoints, and OSRM turn-by-turn route geometry and step navigation.
|
||||
- **Themes (`xthemes`), wallpapers (`xwallpapers`), and ringtones (`xringtones`)**: installable `.Xresources` color and font themes (`~/.xthemes/*.xth`, 21 preinstalled schemes including `LynxLair.xth`) with live zero-restart reload across the entire UI, `dunst` notification popups (`bananarchy-sync-dunst-theme`), and terminal, alongside dedicated managers for desktop wallpapers and 3-tab call ringtones & notification/SMS alerts (`1:Ringtone`, `2:Notif/SMS`, `3:Settings`, supporting standard audio, tracker modules, and Nokia RTTTL `.nrt`/`.rtttl`/`.rtx`, Ericsson eMelody `.emy`, and IrDA iMelody `.imy` monophonic ringtones via `/usr/bin/bananarchy-melody`, wired into `sxmo_notifs.sh` and `sxmo_hook_notification.sh`) with 3-level vibration control.
|
||||
|
||||
|
||||
@@ -9,6 +9,13 @@
|
||||
|
||||
ACTION="$1"
|
||||
|
||||
# A closed flip has no reachable keypad: external keys, wake gestures and
|
||||
# power-button events must only light the outer cover panel, never unlock the
|
||||
# session or relight the main panel / keypad backlight.
|
||||
if ! "${BANANARCHY_LID_GATE:-/usr/bin/bananarchy-lid-gate.sh}" wake; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# include common definitions
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. sxmo_common.sh
|
||||
|
||||
@@ -35,7 +35,11 @@ case "$EVENT" in
|
||||
# bananarchy-volume-keys when the flip is closed).
|
||||
/usr/bin/bananarchy-coverctl BUTTON >/dev/null 2>&1 || true
|
||||
;;
|
||||
wake|refresh|theme)
|
||||
wake)
|
||||
# Every blocked main-panel wake request is forwarded here by the lid gate.
|
||||
/usr/bin/bananarchy-coverctl WAKE >/dev/null 2>&1 || true
|
||||
;;
|
||||
refresh|theme)
|
||||
/usr/bin/bananarchy-coverctl RELOAD_THEME >/dev/null 2>&1 || true
|
||||
;;
|
||||
*)
|
||||
|
||||
Binary file not shown.
@@ -18,6 +18,16 @@ case "$br" in ''|*[!0-9]*) br=1 ;; esac
|
||||
cur=On
|
||||
[ -r "$DPMS_PATH" ] && { read -r cur < "$DPMS_PATH" 2>/dev/null || cur=On; }
|
||||
|
||||
# Hard gate: while the flip is closed no path may relight the main panel or
|
||||
# the keypad backlight. This also enforces DPMS-off, which is the condition
|
||||
# the cover daemon needs before it takes the shared QUP5 SPI bus.
|
||||
if ! "${BANANARCHY_LID_GATE:-/usr/bin/bananarchy-lid-gate.sh}"; then
|
||||
printf '0\n' > /sys/class/leds/white:kbd_backlight/brightness 2>/dev/null || true
|
||||
[ "$br" -eq 0 ] || printf '0\n' > "$BR_PATH" 2>/dev/null || true
|
||||
[ "$cur" = "Off" ] || DISPLAY=:0 xset dpms force off >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$br" -eq 0 ]; then
|
||||
[ "$cur" = "Off" ] || DISPLAY=:0 xset dpms force off >/dev/null 2>&1 || true
|
||||
else
|
||||
|
||||
Binary file not shown.
+25
@@ -0,0 +1,25 @@
|
||||
#!/bin/sh
|
||||
# Closed-flip main-panel gate for the 2720 Flip.
|
||||
#
|
||||
# Returns 0 when the main panel / keypad backlight may be lit, 1 when the flip
|
||||
# is closed. With the "wake" argument a blocked main-panel wake request is
|
||||
# forwarded to the cover display, so an incoming call, SMS, notification or
|
||||
# external button can only light the outer panel.
|
||||
#
|
||||
# Every wake path (sxmo_wm.sh display on, bananarchy-screen-wake.sh,
|
||||
# bananarchy-display-power-sync, the input handler) calls this helper, which
|
||||
# makes /run/bananarchy/lid-state the single source of truth. The compiled lid
|
||||
# daemon writes that file synchronously before any other transition work.
|
||||
set -u
|
||||
|
||||
PROFILE="${BANANARCHY_LID_PROFILE:-/usr/share/bananarchy/lid-profile}"
|
||||
STATE="${BANANARCHY_LID_STATE:-/run/bananarchy/lid-state}"
|
||||
COVERCTL="${BANANARCHY_COVERCTL:-/usr/bin/bananarchy-coverctl}"
|
||||
|
||||
[ "$(cat "$PROFILE" 2>/dev/null)" = "flip" ] || exit 0
|
||||
[ "$(cat "$STATE" 2>/dev/null)" = "closed" ] || exit 0
|
||||
|
||||
if [ "${1:-}" = "wake" ] && [ -x "$COVERCTL" ]; then
|
||||
"$COVERCTL" WAKE >/dev/null 2>&1 || true
|
||||
fi
|
||||
exit 1
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
# Guarded Sxmo state transition for the 2720 Flip lid daemon.
|
||||
#
|
||||
# The compiled lid daemon already writes the state, the lock flag and the
|
||||
# backlights synchronously; this wrapper only starts the Sxmo hooks. A slow
|
||||
# "screenoff" spawn from a close must not run after the flip has opened and
|
||||
# re-lock or re-blank the phone, so it re-checks the lid state at exec time.
|
||||
set -u
|
||||
|
||||
EXPECTED="${1:-}"
|
||||
ACTION="${2:-}"
|
||||
GENERATION="${3:-}"
|
||||
STATE_FILE="${BANANARCHY_LID_STATE:-/run/bananarchy/lid-state}"
|
||||
GEN_FILE="${BANANARCHY_LID_GENERATION:-/run/bananarchy/lid-generation}"
|
||||
|
||||
[ -n "$EXPECTED" ] && [ -n "$ACTION" ] && [ -n "$GENERATION" ] || exit 0
|
||||
[ "$(cat "$STATE_FILE" 2>/dev/null)" = "$EXPECTED" ] || exit 0
|
||||
[ "$(cat "$GEN_FILE" 2>/dev/null)" = "$GENERATION" ] || exit 0
|
||||
exec /usr/bin/sxmo_state.sh set "$ACTION"
|
||||
@@ -2,6 +2,11 @@
|
||||
# Wake the screen for an external event (incoming call / SMS / notification)
|
||||
# and reset dwm's idle-blank timer so it cannot blank again immediately.
|
||||
export DISPLAY="${DISPLAY:-:0}"
|
||||
# With the flip closed every wake is cover-only: do not touch the main panel,
|
||||
# the keypad backlight, the idle timer or the Sxmo state machine.
|
||||
if ! "${BANANARCHY_LID_GATE:-/usr/bin/bananarchy-lid-gate.sh}" wake; then
|
||||
exit 0
|
||||
fi
|
||||
# Cancel a pending idle-blank lock before the panel is powered on, so a wake
|
||||
# does not race with the screenoff transition started by the blank handler.
|
||||
"${BANANARCHY_IDLE_LOCK_HELPER:-/usr/bin/bananarchy-idle-lock.sh}" cancel >/dev/null 2>&1 || true
|
||||
|
||||
@@ -160,6 +160,12 @@ case "$action" in
|
||||
read_state
|
||||
"$action" "$@" ;;
|
||||
set)
|
||||
# dwm calls "sxmo_state.sh set unlock" directly on every key press.
|
||||
# A closed flip must stay locked: forward the request to the cover.
|
||||
if [ "${1:-}" = "unlock" ] && \
|
||||
! "${BANANARCHY_LID_GATE:-/usr/bin/bananarchy-lid-gate.sh}" wake; then
|
||||
exit 0
|
||||
fi
|
||||
lock_exclusive
|
||||
read_state
|
||||
case " $SXMO_STATES " in
|
||||
|
||||
@@ -62,6 +62,11 @@ xorgdisplay() {
|
||||
/usr/bin/bananarchy-power-policy.sh screenoff >/dev/null 2>&1 &
|
||||
;;
|
||||
on)
|
||||
# A closed flip must never relight the main panel or keypad backlight.
|
||||
# The gate forwards the wake request to the outer cover panel instead.
|
||||
if ! "${BANANARCHY_LID_GATE:-/usr/bin/bananarchy-lid-gate.sh}" wake; then
|
||||
return 0
|
||||
fi
|
||||
if [ -w /sys/devices/system/cpu/cpufreq/policy0/scaling_governor ]; then
|
||||
printf 'schedutil\n' > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor 2>/dev/null || true
|
||||
fi
|
||||
|
||||
@@ -2,3 +2,6 @@
|
||||
# configversion: 226734e9b1dd5ffb1a8c45a6c88bd741
|
||||
|
||||
# This script is executed (asynchronously) when you hangup an incoming call
|
||||
|
||||
# Keep the outer cover panel in sync with the call state.
|
||||
/usr/bin/bananarchy-cover-event.sh ended >/dev/null 2>&1 || true
|
||||
@@ -9,6 +9,13 @@
|
||||
|
||||
ACTION="$1"
|
||||
|
||||
# A closed flip has no reachable keypad: external keys, wake gestures and
|
||||
# power-button events must only light the outer cover panel, never unlock the
|
||||
# session or relight the main panel / keypad backlight.
|
||||
if ! "${BANANARCHY_LID_GATE:-/usr/bin/bananarchy-lid-gate.sh}" wake; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# include common definitions
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. sxmo_common.sh
|
||||
|
||||
@@ -10,4 +10,7 @@
|
||||
# $1 = Contact Name or Number (if not in contacts)
|
||||
|
||||
# kill existing ring playback
|
||||
|
||||
# Keep the outer cover panel in sync with the call state.
|
||||
/usr/bin/bananarchy-cover-event.sh missed >/dev/null 2>&1 || true
|
||||
sxmo_jobs.sh stop ringing
|
||||
@@ -54,6 +54,8 @@ exec 8>&-
|
||||
|
||||
# SMS / notification: turn the panel on immediately and reset the idle timer.
|
||||
/usr/bin/bananarchy-screen-wake.sh >/dev/null 2>&1 || true
|
||||
# Cover-only when the flip is closed (the lid gate handles the wake itself).
|
||||
/usr/bin/bananarchy-cover-event.sh notification >/dev/null 2>&1 || true
|
||||
|
||||
if [ -f "$XDG_CONFIG_HOME/sxmo/ringsettings" ]; then
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
# This script is executed (asynchronously) when you pick up an incoming call
|
||||
|
||||
# kill existing ring playback
|
||||
|
||||
# Keep the outer cover panel in sync with the call state.
|
||||
/usr/bin/bananarchy-cover-event.sh active >/dev/null 2>&1 || true
|
||||
rm -f /tmp/sxmo_call_ringing 2>/dev/null || true
|
||||
sxmo_jobs.sh stop ringing
|
||||
pkill -TERM -f sxmo_hook_ring.sh 2>/dev/null || true
|
||||
|
||||
@@ -14,6 +14,8 @@ export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
|
||||
|
||||
# Incoming call: turn the panel on immediately and reset the idle timer.
|
||||
/usr/bin/bananarchy-screen-wake.sh >/dev/null 2>&1 || true
|
||||
# The lid gate turns that wake into a cover-only event; publish the call state.
|
||||
/usr/bin/bananarchy-cover-event.sh ring >/dev/null 2>&1 || true
|
||||
|
||||
if [ -z "${SXMO_VIBRATE_DEV:-}" ] && [ ! -e /dev/input/by-path/platform-vibrator-event ]; then
|
||||
for vdev in /dev/input/by-path/*vibrator*-event; do
|
||||
|
||||
@@ -35,7 +35,11 @@ case "$EVENT" in
|
||||
# bananarchy-volume-keys when the flip is closed).
|
||||
/usr/bin/bananarchy-coverctl BUTTON >/dev/null 2>&1 || true
|
||||
;;
|
||||
wake|refresh|theme)
|
||||
wake)
|
||||
# Every blocked main-panel wake request is forwarded here by the lid gate.
|
||||
/usr/bin/bananarchy-coverctl WAKE >/dev/null 2>&1 || true
|
||||
;;
|
||||
refresh|theme)
|
||||
/usr/bin/bananarchy-coverctl RELOAD_THEME >/dev/null 2>&1 || true
|
||||
;;
|
||||
*)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -373,7 +373,7 @@ fi
|
||||
echo "[check] Known-good flashable image set..."
|
||||
for pair in \
|
||||
"69a44f60eb123ebddf600be927155dc4a599ec35b7a0cf80060f4ba01f599f08 images/bananarchy-nokia-argon.img" \
|
||||
"ccc8c44517a6a3b78e16e45e9dddbf89f6f04a35ee4c52246d38d89970bd13ac images/bananarchy-nokia-beatles.img" \
|
||||
"0f33aa6e9fc70022574b453aaafb9307c4d185431d3be272782c8403dd0fb291 images/bananarchy-nokia-beatles.img" \
|
||||
"2b5c61aba307dbbda61f3b19a2ad5770f9854f41cba4e2c97e24efb7e20879f3 images/boot-bananarchy-nokia-beatles.img" \
|
||||
"b5549698c20f4de7603fc746d32bb5baa96ec377e41e74407823c98506fc185d images/boot-lk2nd-nokia-beatles-display.img"; do
|
||||
set -- $pair
|
||||
@@ -419,7 +419,9 @@ for src in src/bananarchy-daemons/common.h \
|
||||
fi
|
||||
done
|
||||
if ! grep -q 'CLOSED_MASK' "$BASE_DIR/src/bananarchy-daemons/bananarchy-lid.c" || \
|
||||
! grep -q 'sxmo_state.sh' "$BASE_DIR/src/bananarchy-daemons/bananarchy-lid.c" || \
|
||||
! grep -q 'bananarchy-lid-state.sh' "$BASE_DIR/src/bananarchy-daemons/bananarchy-lid.c" || \
|
||||
! grep -q 'sxmo_state.sh' \
|
||||
"$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-lid-state.sh" || \
|
||||
! grep -q 'strcmp(level, "low")' "$BASE_DIR/src/bananarchy-daemons/bananarchy-lid.c"; then
|
||||
fail "the compiled lid daemon lost its raw hall GPIO fallback"
|
||||
fi
|
||||
@@ -580,6 +582,8 @@ for f in overlay/rootfs/usr/lib/udev/rules.d/99-bananarchy-keypad.rules \
|
||||
overlay/rootfs/usr/bin/bananarchy-keypad-diagnose.sh \
|
||||
overlay/rootfs/usr/bin/bananarchy-coverd \
|
||||
overlay/rootfs/usr/bin/bananarchy-cover-msg \
|
||||
overlay/rootfs/usr/bin/bananarchy-lid-gate.sh \
|
||||
overlay/rootfs/usr/bin/bananarchy-lid-state.sh \
|
||||
overlay/rootfs/etc/init.d/bananarchy-cover-display \
|
||||
overlay/rootfs/etc/bananarchy/cover-display.conf \
|
||||
devices/nokia-beatles/cover-panel.dtsi \
|
||||
@@ -895,15 +899,61 @@ fi
|
||||
|
||||
echo "[check] Flip lid responsiveness..."
|
||||
LID_SRC="$BASE_DIR/src/bananarchy-daemons/bananarchy-lid.c"
|
||||
for token in '#define LID_STABLE_MS 80' '#define HALL_POLL_MS 200' 'BA_EVIOCGSW' 'LID_STATE_FILE' \
|
||||
'LOCKER_FIFO' 'unlink(LOCK_FLAG)' 'now - last_hall_poll >= HALL_POLL_MS'; do
|
||||
for token in '#define LID_DEBOUNCE_MS 20' '#define HALL_EDGE_MS 20' \
|
||||
'#define LID_LOOP_MS 20' 'BA_EVIOCGSW' 'LID_STATE_FILE' \
|
||||
'LOCKER_FIFO' 'unlink(LOCK_FLAG)' 'hall_observed' 'fast_until' \
|
||||
'if(edge)' 'write_session_file(state, "screenoff")' \
|
||||
'write_session_file(state, "unlock")' 'cover_send("OPEN")' \
|
||||
'LID_GENERATION_FILE' 'run_dpms' \
|
||||
'bananarchy-lid-state.sh'; do
|
||||
if ! grep -qF "$token" "$LID_SRC"; then
|
||||
fail "the compiled lid daemon lost the low-latency EV_SW/unlock path ($token)"
|
||||
fail "the compiled lid daemon lost the instant EV_SW/hall path ($token)"
|
||||
fi
|
||||
done
|
||||
if grep -qF 'closed != was_closed' "$LID_SRC" || \
|
||||
grep -qF '#define LID_STABLE_MS 600' "$LID_SRC"; then
|
||||
fail "the compiled lid daemon still accepts slow immediate hall transitions"
|
||||
grep -qF '#define LID_STABLE_MS 600' "$LID_SRC" || \
|
||||
grep -qF '#define LID_STABLE_MS 80' "$LID_SRC" || \
|
||||
grep -qF 'observed = (switch_mask &' "$LID_SRC"; then
|
||||
fail "the compiled lid daemon still oscillates on a stale EV_SW mask"
|
||||
fi
|
||||
|
||||
echo "[check] Closed-flip main-panel gate..."
|
||||
LID_GATE="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-lid-gate.sh"
|
||||
if [ ! -x "$LID_GATE" ] || ! sh -n "$LID_GATE" 2>/dev/null; then
|
||||
fail "bananarchy-lid-gate.sh is missing or has bad syntax"
|
||||
fi
|
||||
for f in overlay/rootfs/usr/bin/sxmo_wm.sh \
|
||||
overlay/rootfs/usr/bin/sxmo_state.sh \
|
||||
overlay/rootfs/usr/bin/bananarchy-screen-wake.sh \
|
||||
overlay/rootfs/usr/bin/bananarchy-display-power-sync \
|
||||
overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_inputhandler.sh \
|
||||
overlay/rootfs/etc/skel/.config/sxmo/hooks/sxmo_hook_inputhandler.sh; do
|
||||
if ! grep -qF 'bananarchy-lid-gate.sh' "$BASE_DIR/$f"; then
|
||||
fail "$f can still light the main panel with the flip closed"
|
||||
fi
|
||||
done
|
||||
if ! grep -qF 'coverctl WAKE' \
|
||||
"$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-cover-event.sh" || \
|
||||
! grep -qF 'bananarchy-cover-event.sh ring' \
|
||||
"$BASE_DIR/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_ring.sh" || \
|
||||
! grep -qF 'bananarchy-cover-event.sh notification' \
|
||||
"$BASE_DIR/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_notification.sh"; then
|
||||
fail "closed-flip events are no longer forwarded to the cover display"
|
||||
fi
|
||||
if ! grep -qF 'cover_wake' "$BASE_DIR/src/bananarchy-daemons/bananarchy-cover-idle.c" || \
|
||||
! grep -qF 'strcmp(command, "WAKE")' \
|
||||
"$BASE_DIR/src/bananarchy-daemons/bananarchy-cover-idle.c"; then
|
||||
fail "the cover daemon no longer honours a closed-flip WAKE"
|
||||
fi
|
||||
if [ ! -x "$BASE_DIR/scripts/test-lid-gate.py" ] || \
|
||||
! "$BASE_DIR/scripts/test-lid-gate.py" >/dev/null 2>&1; then
|
||||
fail "host instant-lid / closed-flip gate test failed"
|
||||
fi
|
||||
LID_WRAPPER="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-lid-state.sh"
|
||||
if [ ! -x "$LID_WRAPPER" ] || \
|
||||
! grep -qF 'lid-generation' "$LID_WRAPPER" || \
|
||||
! grep -qF 'lid-generation' "$LID_SRC"; then
|
||||
fail "the guarded lid hook wrapper / generation check is missing"
|
||||
fi
|
||||
|
||||
echo "[check] Fast X startup and boot keypad state..."
|
||||
|
||||
@@ -139,6 +139,7 @@ def main():
|
||||
for token in ("cover_hw_release", "cover_spi_draw", "hw_init_panel",
|
||||
"mux_closed_level", "spi_speed_hz", "FBIOBLANK",
|
||||
"BANANARCHY_COVER_SPI_SIM", "cover_main_panel_is_off",
|
||||
"cover_wake", "pending_until",
|
||||
"0x28", "0x29"):
|
||||
if token not in source:
|
||||
sys.stderr.write("FAIL: cover daemon lost %s\n" % token)
|
||||
@@ -273,6 +274,45 @@ def main():
|
||||
finally:
|
||||
off.close()
|
||||
|
||||
# A forwarded main-panel wake lights the outer panel only.
|
||||
wake, _ = run_case(root, exe, {})
|
||||
try:
|
||||
wake.send("LID CLOSED")
|
||||
if "visible=1" in wake.send("STATUS"):
|
||||
return not check(False, "a closed flip lit the cover without an event")
|
||||
wake.send("WAKE")
|
||||
if not wake.wait_event("frame lit=1 size=115200"):
|
||||
return not check(False, "WAKE did not light the cover panel")
|
||||
if "visible=1" not in wake.send("STATUS"):
|
||||
return not check(False, "WAKE did not mark the cover visible")
|
||||
# The lid daemon rebroadcasts LID CLOSED every 2 s; it must not undo it.
|
||||
lit = [e for e in wake.events() if e.startswith("frame lit=1")]
|
||||
wake.send("LID CLOSED")
|
||||
time.sleep(0.3)
|
||||
if "visible=0" in wake.send("STATUS"):
|
||||
return not check(False, "a repeated LID CLOSED cleared the cover wake")
|
||||
if len([e for e in wake.events() if e.startswith("frame lit=1")]) != len(lit):
|
||||
return not check(False, "a repeated LID CLOSED redrew the cover")
|
||||
print("[ok] WAKE lights the outer panel; repeated LID CLOSED is ignored")
|
||||
finally:
|
||||
wake.close()
|
||||
|
||||
# A pending DPMS-off must be retried without another event.
|
||||
pend, pendcase = run_case(root, exe, {}, dpms="On")
|
||||
try:
|
||||
pend.send("LID CLOSED")
|
||||
pend.send("WAKE")
|
||||
if "backend=pending" not in pend.send("STATUS"):
|
||||
return not check(False, "a live main panel did not defer the cover")
|
||||
(pendcase / "dpms").write_text("Off\n")
|
||||
if not pend.wait_event("frame lit=1 size=115200", timeout=1.5):
|
||||
return not check(False, "a deferred cover draw was not retried")
|
||||
if "backend=spidev" not in pend.send("STATUS"):
|
||||
return not check(False, "the retried draw did not switch to spidev")
|
||||
print("[ok] deferred cover draw is retried once DPMS goes off")
|
||||
finally:
|
||||
pend.close()
|
||||
|
||||
# A transient lid flap must never steal the bus from a live main panel.
|
||||
live, _ = run_case(root, exe, {}, dpms="On")
|
||||
try:
|
||||
|
||||
@@ -69,6 +69,7 @@ def main():
|
||||
"XDG_CONFIG_HOME": str(home / ".config"),
|
||||
"FAKE_ROOT": str(root),
|
||||
"BANANARCHY_WM_CMD": str(bindir / "sxmo_wm.sh"),
|
||||
"BANANARCHY_LID_GATE": "/bin/true",
|
||||
"BANANARCHY_STATE_CMD": str(bindir / "sxmo_state.sh"),
|
||||
"BANANARCHY_IDLE_LOCK_HELPER": str(LOCK),
|
||||
"BANANARCHY_IDLE_LOCK_PIDFILE": str(root / "lock.pid"),
|
||||
|
||||
Executable
+156
@@ -0,0 +1,156 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Host test for the 2720 Flip instant lid handling and closed-lid gate.
|
||||
|
||||
Checks the compiled lid daemon's event-driven structure, that every main-panel
|
||||
wake path is gated on /run/bananarchy/lid-state, and that the gate forwards a
|
||||
blocked wake to the cover display instead of the main panel.
|
||||
"""
|
||||
import os
|
||||
import pathlib
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
BASE = pathlib.Path(__file__).resolve().parent.parent
|
||||
LID_SRC = BASE / "src/bananarchy-daemons/bananarchy-lid.c"
|
||||
COVER_SRC = BASE / "src/bananarchy-daemons/bananarchy-cover-idle.c"
|
||||
GATE = BASE / "overlay/rootfs/usr/bin/bananarchy-lid-gate.sh"
|
||||
LID_WRAPPER = BASE / "overlay/rootfs/usr/bin/bananarchy-lid-state.sh"
|
||||
WM = BASE / "overlay/rootfs/usr/bin/sxmo_wm.sh"
|
||||
STATE_SH = BASE / "overlay/rootfs/usr/bin/sxmo_state.sh"
|
||||
WAKE = BASE / "overlay/rootfs/usr/bin/bananarchy-screen-wake.sh"
|
||||
DPMS_SYNC = BASE / "overlay/rootfs/usr/bin/bananarchy-display-power-sync"
|
||||
INPUT_HOOKS = (
|
||||
BASE / "overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_inputhandler.sh",
|
||||
BASE / "overlay/rootfs/etc/skel/.config/sxmo/hooks/sxmo_hook_inputhandler.sh",
|
||||
)
|
||||
EVENT = BASE / "overlay/rootfs/usr/bin/bananarchy-cover-event.sh"
|
||||
HOOKS = (
|
||||
BASE / "overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_ring.sh",
|
||||
BASE / "overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_notification.sh",
|
||||
BASE / "overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_missed_call.sh",
|
||||
BASE / "overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_pickup.sh",
|
||||
BASE / "overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_hangup.sh",
|
||||
)
|
||||
|
||||
|
||||
def fail(message):
|
||||
sys.stderr.write("FAIL: %s\n" % message)
|
||||
return 1
|
||||
|
||||
|
||||
def run_gate(profile, state, arg="", stub=None):
|
||||
env = dict(os.environ)
|
||||
env["BANANARCHY_LID_PROFILE"] = str(profile)
|
||||
env["BANANARCHY_LID_STATE"] = str(state)
|
||||
if stub:
|
||||
env["BANANARCHY_COVERCTL"] = str(stub)
|
||||
return subprocess.run([str(GATE)] + ([arg] if arg else []),
|
||||
env=env, capture_output=True, text=True)
|
||||
|
||||
|
||||
def main():
|
||||
paths = [LID_SRC, COVER_SRC, GATE, LID_WRAPPER, WM, STATE_SH, WAKE,
|
||||
DPMS_SYNC, EVENT, *INPUT_HOOKS, *HOOKS]
|
||||
for path in paths:
|
||||
if not path.is_file():
|
||||
return fail("missing %s" % path.relative_to(BASE))
|
||||
lid = LID_SRC.read_text(encoding="utf-8")
|
||||
for token in ("LID_DEBOUNCE_MS 20", "HALL_EDGE_MS 20", "LID_LOOP_MS 20",
|
||||
"hall_observed", "fast_until", "write_session_file",
|
||||
"write_lid_state(closed)", 'write_session_file(state, "screenoff")',
|
||||
'write_session_file(state, "unlock")', 'cover_send("OPEN")',
|
||||
"read_ready(&list, fds, nfds, &switch_mask, &edge)",
|
||||
"LID_GENERATION_FILE", "run_dpms",
|
||||
"bananarchy-lid-state.sh"):
|
||||
if token not in lid:
|
||||
return fail("lid daemon lost instant handling: %s" % token)
|
||||
# The cover daemon must be told to release the bus before the panel is lit.
|
||||
if lid.index('cover_send("OPEN")') > lid.index('write_sysfs_int(BRIGHTNESS, bl)'):
|
||||
return fail("the SPI bus is released after the main panel is relit")
|
||||
lid_close = lid[lid.index('if(closed) {'):lid.index(' } else {')]
|
||||
if lid_close.index('write_session_file(LOCK_FLAG, "1")') > \
|
||||
lid_close.index('write_text_file(BRIGHTNESS, "0")'):
|
||||
return fail("the screen is locked after the panel is blanked")
|
||||
print("[ok] lid daemon: sticky hall state, edge wakeup and synchronous lock")
|
||||
|
||||
scratch = pathlib.Path("/tmp/bantam/9064bb701d9e9f7c6412f0ea6846d88a")
|
||||
scratch.mkdir(parents=True, exist_ok=True)
|
||||
build = subprocess.run(
|
||||
["gcc", "-std=c11", "-O2", "-Wall", "-Wextra", "-Werror",
|
||||
"-I" + str(LID_SRC.parent), str(LID_SRC), "-o",
|
||||
str(scratch / "lid-gate-host")],
|
||||
capture_output=True, text=True)
|
||||
if build.returncode:
|
||||
sys.stderr.write(build.stderr)
|
||||
return fail("lid daemon does not compile on the host")
|
||||
print("[ok] host build of the compiled lid daemon")
|
||||
|
||||
wrapper = LID_WRAPPER.read_text(encoding="utf-8")
|
||||
if "lid-generation" not in wrapper or "lid-state" not in wrapper:
|
||||
return fail("the lid hook wrapper is not guarded by lid state/generation")
|
||||
for path in (GATE, LID_WRAPPER, WM, STATE_SH, WAKE, DPMS_SYNC, EVENT,
|
||||
*INPUT_HOOKS, *HOOKS):
|
||||
if subprocess.run(["sh", "-n", str(path)], capture_output=True).returncode:
|
||||
return fail("shell syntax: %s" % path.relative_to(BASE))
|
||||
for path in (WM, STATE_SH, WAKE, DPMS_SYNC, *INPUT_HOOKS):
|
||||
if "bananarchy-lid-gate.sh" not in path.read_text(encoding="utf-8"):
|
||||
return fail("%s is not gated on the flip lid" % path.relative_to(BASE))
|
||||
if "bananarchy-cover-event.sh ring" not in HOOKS[0].read_text():
|
||||
return fail("ring hook does not publish the call to the cover")
|
||||
if "bananarchy-cover-event.sh notification" not in HOOKS[1].read_text():
|
||||
return fail("notification hook does not publish to the cover")
|
||||
event = EVENT.read_text(encoding="utf-8")
|
||||
if " wake)" not in event or "coverctl WAKE" not in event:
|
||||
return fail("cover event bridge lost the wake forwarding case")
|
||||
cover = COVER_SRC.read_text(encoding="utf-8")
|
||||
if "cover_wake" not in cover or 'strcmp(command, "WAKE")' not in cover:
|
||||
return fail("cover daemon lost the WAKE command")
|
||||
print("[ok] every main-panel wake path is gated and forwarded to the cover")
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="bananarchy-lid-gate-") as tmp:
|
||||
root = pathlib.Path(tmp)
|
||||
profile = root / "lid-profile"
|
||||
state = root / "lid-state"
|
||||
calls = root / "coverctl.calls"
|
||||
stub = root / "coverctl"
|
||||
stub.write_text('#!/bin/sh\nprintf "%s\\n" "$*" >> "%s"\n' %
|
||||
("%s", calls))
|
||||
stub.chmod(0o755)
|
||||
|
||||
profile.write_text("bar\n")
|
||||
state.write_text("closed\n")
|
||||
if run_gate(profile, state, stub=stub).returncode != 0:
|
||||
return fail("a non-flip device was blocked by the lid gate")
|
||||
print("[ok] non-flip devices are unaffected")
|
||||
|
||||
profile.write_text("flip\n")
|
||||
state.write_text("open\n")
|
||||
if run_gate(profile, state, "wake", stub).returncode != 0:
|
||||
return fail("an open flip was blocked by the lid gate")
|
||||
if calls.exists() and calls.read_text().strip():
|
||||
return fail("an open flip forwarded a wake to the cover")
|
||||
print("[ok] open flip: main panel allowed, no cover wake")
|
||||
|
||||
state.write_text("closed\n")
|
||||
if run_gate(profile, state, stub=stub).returncode != 1:
|
||||
return fail("a closed flip was allowed to light the main panel")
|
||||
if calls.exists() and calls.read_text().strip():
|
||||
return fail("a non-wake gate call forwarded to the cover")
|
||||
if run_gate(profile, state, "wake", stub).returncode != 1:
|
||||
return fail("a closed flip wake was not blocked")
|
||||
if "WAKE" not in calls.read_text():
|
||||
return fail("a blocked main-panel wake was not forwarded to the cover")
|
||||
print("[ok] closed flip: main panel blocked, WAKE forwarded to cover")
|
||||
|
||||
state.write_text("unknown\n")
|
||||
if run_gate(profile, state, "wake", stub).returncode != 0:
|
||||
return fail("a missing/unknown lid state blocked the main panel")
|
||||
print("[ok] unknown lid state fails open for the main panel")
|
||||
|
||||
print("instant flip lid handling: all checks passed")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -1046,6 +1046,18 @@ static int test_value(const char *mode)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* A closed flip lights the outer panel only. Status updates (NETWORK,
|
||||
* BATTERY) refresh an already visible cover but never wake it; real events
|
||||
* (BUTTON, WAKE, CALL, NOTIFY, SMS) do. */
|
||||
static void cover_wake(struct state *state, int *redraw)
|
||||
{
|
||||
if(strcmp(state->lid, "closed") == 0 && state->enabled && !state->test) {
|
||||
state->visible = 1;
|
||||
state->last_input_ms = now_ms();
|
||||
*redraw = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_command(char *buffer, struct state *state,
|
||||
struct cover_hw *hw, int *redraw)
|
||||
{
|
||||
@@ -1058,19 +1070,23 @@ static void handle_command(char *buffer, struct state *state,
|
||||
upper_string(command);
|
||||
if(strcmp(command, "LID") == 0) {
|
||||
char *value = strtok_r(NULL, " \t\r\n", &save);
|
||||
int new_closed = value && strcasecmp(value, "CLOSED") == 0;
|
||||
int old_closed = strcmp(state->lid, "closed") == 0;
|
||||
safe_copy(state->lid, sizeof(state->lid),
|
||||
value && strcasecmp(value, "CLOSED") == 0 ? "closed" : "open");
|
||||
/* An open flip is always fully off; a closed flip waits for a button. */
|
||||
state->visible = 0;
|
||||
state->last_input_ms = now_ms();
|
||||
*redraw = 1;
|
||||
} else if(strcmp(command, "BUTTON") == 0) {
|
||||
/* Trusted external side-button event from bananarchy-volume-keys. */
|
||||
if(strcmp(state->lid, "closed") == 0 && state->enabled && !state->test) {
|
||||
state->visible = 1;
|
||||
new_closed ? "closed" : "open");
|
||||
/* The lid daemon rebroadcasts its state every 2 s. Only a real
|
||||
* transition blanks the cover; a repeating LID CLOSED must not undo a
|
||||
* WAKE from an incoming call or an external side button. */
|
||||
if(new_closed != old_closed) {
|
||||
state->visible = 0;
|
||||
state->last_input_ms = now_ms();
|
||||
*redraw = 1;
|
||||
}
|
||||
} else if(strcmp(command, "BUTTON") == 0 ||
|
||||
strcmp(command, "WAKE") == 0) {
|
||||
/* Trusted external side button, or a main-panel wake request that the
|
||||
* closed-lid gate forwarded to the cover display. */
|
||||
cover_wake(state, redraw);
|
||||
} else if(strcmp(command, "NETWORK") == 0) {
|
||||
char *rest = save;
|
||||
while(rest && (*rest == ' ' || *rest == '\t'))
|
||||
@@ -1085,6 +1101,7 @@ static void handle_command(char *buffer, struct state *state,
|
||||
rest++;
|
||||
safe_copy(state->message, sizeof(state->message), rest ? rest : "");
|
||||
trim(state->message);
|
||||
cover_wake(state, redraw);
|
||||
if(state->visible)
|
||||
*redraw = 1;
|
||||
} else if(strcmp(command, "CALL") == 0) {
|
||||
@@ -1092,11 +1109,14 @@ static void handle_command(char *buffer, struct state *state,
|
||||
if(value) {
|
||||
safe_copy(state->call, sizeof(state->call), value);
|
||||
lower_string(state->call);
|
||||
if(strcmp(state->call, "none") != 0)
|
||||
cover_wake(state, redraw);
|
||||
}
|
||||
} else if(strcmp(command, "SMS") == 0) {
|
||||
char *value = strtok_r(NULL, " \t\r\n", &save);
|
||||
if(value)
|
||||
state->sms = (int)strtol(value, NULL, 10);
|
||||
cover_wake(state, redraw);
|
||||
} else if(strcmp(command, "BATTERY") == 0) {
|
||||
char *value = strtok_r(NULL, " \t\r\n", &save);
|
||||
if(value)
|
||||
@@ -1201,6 +1221,7 @@ int main(int argc, char **argv)
|
||||
struct state state;
|
||||
struct cover_hw hw;
|
||||
long long last_draw = 0;
|
||||
long long pending_until = 0;
|
||||
int redraw = 1;
|
||||
if(lock_fd < 0)
|
||||
return 1;
|
||||
@@ -1263,13 +1284,24 @@ int main(int argc, char **argv)
|
||||
set_backlight(&state, cover_is_lit(&state));
|
||||
snprintf(state.backend, sizeof(state.backend), "%s",
|
||||
cover_draw(&hw, fb_path, &state));
|
||||
/* The lid daemon forces DPMS off asynchronously. Retry a pending draw
|
||||
* for a bounded window so the cover lights even if the first draw ran
|
||||
* before Xorg stopped flushing the main panel. */
|
||||
pending_until = strcmp(state.backend, "pending") == 0 ?
|
||||
now + 3000 : 0;
|
||||
last_draw = now;
|
||||
redraw = 0;
|
||||
}
|
||||
if(pending_until > now)
|
||||
timeout_ms = 50;
|
||||
pfd.fd = server;
|
||||
pfd.events = POLLIN;
|
||||
pfd.revents = 0;
|
||||
if(poll(&pfd, 1, timeout_ms) > 0 && (pfd.revents & POLLIN)) {
|
||||
if(poll(&pfd, 1, timeout_ms) == 0 && pending_until > now &&
|
||||
strcmp(state.backend, "pending") == 0) {
|
||||
redraw = 1;
|
||||
}
|
||||
if(pfd.revents & POLLIN) {
|
||||
nread = recvfrom(server, buffer, sizeof(buffer) - 1, 0,
|
||||
(struct sockaddr *)&peer, &peer_len);
|
||||
if(nread > 0) {
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
/* Compiled flip-lid handler for nokia-beatles. No Python in the idle path. */
|
||||
/* Compiled flip-lid handler for nokia-beatles. No Python in the idle path.
|
||||
*
|
||||
* A closed flip must blank and lock the main panel immediately, and an open
|
||||
* flip must hand the shared QUP5 bus back to the main panel immediately.
|
||||
* The old loop re-derived "observed" from a stale EV_SW mask on every 100 ms
|
||||
* iteration and only consulted the real hall lines every 200 ms, so the
|
||||
* candidate oscillated open/closed and the 80 ms debounce almost never
|
||||
* completed: a close could take seconds. The hall reading is now sticky and
|
||||
* any EV_SW edge forces an immediate hall re-read, with a 20 ms debounce.
|
||||
*/
|
||||
#include <poll.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/socket.h>
|
||||
@@ -11,10 +20,20 @@
|
||||
|
||||
#define LID_LOCK "/run/bananarchy-lid.lock"
|
||||
#define LID_STATE_FILE "/run/bananarchy/lid-state"
|
||||
#define LID_GENERATION_FILE "/run/bananarchy/lid-generation"
|
||||
#define LOCK_FLAG "/tmp/bananarchy_screen_locked"
|
||||
#define LOCKER_FIFO "/tmp/dwm_plugin_locker.fifo"
|
||||
#define LID_STABLE_MS 80
|
||||
#define HALL_POLL_MS 200
|
||||
#define SXMO_STATE_FILE "/run/user/10000/sxmo.state"
|
||||
#define BRIGHTNESS "/sys/class/backlight/backlight/brightness"
|
||||
#define BL_POWER "/sys/class/backlight/backlight/bl_power"
|
||||
#define KBD_BACKLIGHT "/sys/class/leds/white:kbd_backlight/brightness"
|
||||
#define BRIGHTNESS_SAVE "/tmp/sxmo_saved_brightness"
|
||||
#define KBD_SAVE "/tmp/sxmo_saved_kbd_brightness"
|
||||
#define LID_DEBOUNCE_MS 20
|
||||
#define HALL_POLL_MS 100
|
||||
#define HALL_EDGE_MS 20
|
||||
#define LID_LOOP_MS 20
|
||||
#define LID_MIN_GAP_MS 50
|
||||
#define GPIO_FILE "/sys/kernel/debug/gpio"
|
||||
#define COVER_SOCKET "/run/bananarchy/cover.sock"
|
||||
#define LID_CLIENT_SOCKET "/run/bananarchy/lid-client.sock"
|
||||
@@ -35,14 +54,71 @@ static char *const session_env[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
static void run_sxmo_state(const char *action)
|
||||
/* Hooks are asynchronous. Each spawn carries the transition generation and
|
||||
* the expected lid state; the wrapper refuses to run if either changed, so a
|
||||
* late screenoff spawn can never re-lock a flip that was just opened. */
|
||||
static unsigned long lid_generation = 0;
|
||||
|
||||
static void run_sxmo_state(const char *action, const char *expected_lid)
|
||||
{
|
||||
char generation[32];
|
||||
char *const argv[] = {
|
||||
(char *)"/usr/bin/bananarchy-lid-state.sh", (char *)expected_lid,
|
||||
(char *)action, generation, NULL
|
||||
};
|
||||
snprintf(generation, sizeof(generation), "%lu", lid_generation);
|
||||
daemon_spawn_env(argv, (char *const *)session_env);
|
||||
}
|
||||
|
||||
/* DPMS is the gate the cover daemon uses before taking the shared SPI bus.
|
||||
* The udev backlight helper is too slow on its own, so force it directly. */
|
||||
static void run_dpms(const char *mode)
|
||||
{
|
||||
char *const argv[] = {
|
||||
(char *)"/usr/bin/sxmo_state.sh", (char *)"set", (char *)action, NULL
|
||||
(char *)"/usr/bin/xset", (char *)"dpms", (char *)"force",
|
||||
(char *)mode, NULL
|
||||
};
|
||||
daemon_spawn_env(argv, (char *const *)session_env);
|
||||
}
|
||||
|
||||
/* Files the user session also writes must stay owned by the session user. */
|
||||
static void write_session_file(const char *path, const char *value)
|
||||
{
|
||||
int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
|
||||
if(fd < 0)
|
||||
return;
|
||||
(void)!write(fd, value, strlen(value));
|
||||
fchown(fd, SESSION_UID, SESSION_GID);
|
||||
fchmod(fd, 0644);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static int read_int_file(const char *path, int fallback)
|
||||
{
|
||||
FILE *handle = fopen(path, "r");
|
||||
int value = fallback;
|
||||
if(!handle)
|
||||
return fallback;
|
||||
if(fscanf(handle, "%d", &value) != 1)
|
||||
value = fallback;
|
||||
fclose(handle);
|
||||
return value;
|
||||
}
|
||||
|
||||
static void write_int_file(const char *path, int value)
|
||||
{
|
||||
char buf[32];
|
||||
snprintf(buf, sizeof(buf), "%d", value);
|
||||
write_session_file(path, buf);
|
||||
}
|
||||
|
||||
static void write_sysfs_int(const char *path, int value)
|
||||
{
|
||||
char buf[32];
|
||||
snprintf(buf, sizeof(buf), "%d", value);
|
||||
write_text_file(path, buf);
|
||||
}
|
||||
|
||||
static void write_lid_state(int closed)
|
||||
{
|
||||
const char *value = closed ? "closed\n" : "open\n";
|
||||
@@ -95,24 +171,55 @@ static void locker_send(const char *payload)
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static const char *sxmo_state_path(void)
|
||||
{
|
||||
const char *path = getenv("SXMO_STATE");
|
||||
return path && *path ? path : SXMO_STATE_FILE;
|
||||
}
|
||||
|
||||
/* Everything user-visible happens synchronously here: no shell, no fork and
|
||||
* no scheduler wait before the main panel is dark and the screen is locked.
|
||||
* The Sxmo state hooks are spawned afterwards and only repeat these writes. */
|
||||
static void on_transition(int closed)
|
||||
{
|
||||
const char *state = sxmo_state_path();
|
||||
char generation[32];
|
||||
lid_generation++;
|
||||
snprintf(generation, sizeof(generation), "%lu", lid_generation);
|
||||
write_session_file(LID_GENERATION_FILE, generation);
|
||||
/* Publish first: every main-panel wake path is gated on this file. */
|
||||
write_lid_state(closed);
|
||||
if(closed) {
|
||||
write_text_file("/sys/class/backlight/backlight/brightness", "0");
|
||||
write_text_file("/sys/class/backlight/backlight/bl_power", "4");
|
||||
write_text_file("/sys/class/leds/white:kbd_backlight/brightness", "0");
|
||||
int saved_bl = read_int_file(BRIGHTNESS, -1);
|
||||
int saved_kbd = read_int_file(KBD_BACKLIGHT, -1);
|
||||
write_session_file(LOCK_FLAG, "1");
|
||||
write_session_file(state, "screenoff");
|
||||
if(saved_bl > 0)
|
||||
write_int_file(BRIGHTNESS_SAVE, saved_bl);
|
||||
if(saved_kbd > 0)
|
||||
write_int_file(KBD_SAVE, saved_kbd);
|
||||
write_text_file(KBD_BACKLIGHT, "0");
|
||||
/* The brightness uevent drives bananarchy-display-power-sync (DPMS off),
|
||||
* which is also the gate the cover daemon uses to take the SPI bus. */
|
||||
write_text_file(BRIGHTNESS, "0");
|
||||
write_text_file(BL_POWER, "4");
|
||||
run_dpms("off");
|
||||
cover_send("CLOSED");
|
||||
locker_send("SCREENOFF\n");
|
||||
run_sxmo_state("screenoff");
|
||||
run_sxmo_state("screenoff", "closed");
|
||||
} else {
|
||||
unlink(LOCK_FLAG);
|
||||
write_text_file("/sys/class/backlight/backlight/bl_power", "0");
|
||||
write_text_file("/sys/class/backlight/backlight/brightness", "10");
|
||||
write_text_file("/sys/class/leds/white:kbd_backlight/brightness", "1");
|
||||
int bl = read_int_file(BRIGHTNESS_SAVE, 10);
|
||||
int kbd = read_int_file(KBD_SAVE, 1);
|
||||
/* Release the cover's shared SPI bus before relighting the main panel. */
|
||||
cover_send("OPEN");
|
||||
unlink(LOCK_FLAG);
|
||||
write_session_file(state, "unlock");
|
||||
write_text_file(BL_POWER, "0");
|
||||
write_sysfs_int(BRIGHTNESS, bl);
|
||||
write_sysfs_int(KBD_BACKLIGHT, kbd);
|
||||
run_dpms("on");
|
||||
locker_send("CLOSE\n");
|
||||
run_sxmo_state("unlock");
|
||||
run_sxmo_state("unlock", "open");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,7 +321,7 @@ static int current_switch_mask(int *found)
|
||||
}
|
||||
|
||||
static void read_ready(struct watch_list *list, struct pollfd *fds, int nfds,
|
||||
int *switch_mask)
|
||||
int *switch_mask, int *edge)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < nfds; i++) {
|
||||
@@ -233,6 +340,7 @@ static void read_ready(struct watch_list *list, struct pollfd *fds, int nfds,
|
||||
bit = switch_bit(ev.code);
|
||||
if(!bit)
|
||||
continue;
|
||||
*edge = 1;
|
||||
if(ev.value)
|
||||
*switch_mask |= (int)bit;
|
||||
else
|
||||
@@ -255,17 +363,22 @@ int main(void)
|
||||
long long last_transition = 0;
|
||||
long long last_broadcast = 0;
|
||||
long long candidate_since;
|
||||
long long fast_until = 0;
|
||||
int evdev_found = 0;
|
||||
int switch_mask;
|
||||
int stable_closed;
|
||||
int candidate;
|
||||
int hall;
|
||||
int hall_observed;
|
||||
int edge;
|
||||
int observed;
|
||||
if(lock_fd < 0)
|
||||
return 1;
|
||||
install_reaper();
|
||||
memset(&list, 0, sizeof(list));
|
||||
switch_mask = current_switch_mask(&evdev_found);
|
||||
hall = hall_state();
|
||||
hall_observed = hall;
|
||||
if(hall >= 0)
|
||||
stable_closed = hall;
|
||||
else if(evdev_found)
|
||||
@@ -282,8 +395,6 @@ int main(void)
|
||||
struct pollfd fds[WATCH_MAX];
|
||||
int nfds = 0;
|
||||
int i;
|
||||
int observed;
|
||||
now = now_ms();
|
||||
if(now - last_scan > 2000) {
|
||||
scan_devices(&list, WATCH_SWITCHES);
|
||||
last_scan = now;
|
||||
@@ -297,28 +408,39 @@ int main(void)
|
||||
fds[nfds].revents = 0;
|
||||
nfds++;
|
||||
}
|
||||
if(poll(fds, (nfds_t)nfds, 100) < 0 && errno != EINTR) {
|
||||
if(poll(fds, (nfds_t)nfds, LID_LOOP_MS) < 0 && errno != EINTR) {
|
||||
for(i = 0; i < list.count; i++)
|
||||
drop_device(&list, list.devs[i].fd);
|
||||
}
|
||||
now = now_ms();
|
||||
edge = 0;
|
||||
if(nfds > 0)
|
||||
read_ready(&list, fds, nfds, &switch_mask);
|
||||
observed = (switch_mask & (int)CLOSED_MASK) != 0;
|
||||
/* EV_SW can miss edges or report a stale mask on the 2720 hall sensors.
|
||||
* Reconcile with the raw lines even while evdev remains available. */
|
||||
if(now - last_hall_poll >= HALL_POLL_MS) {
|
||||
read_ready(&list, fds, nfds, &switch_mask, &edge);
|
||||
/* An EV_SW edge is the hardware interrupt: read the raw hall lines at
|
||||
* once instead of waiting for the next reconciliation tick. The result
|
||||
* is sticky, so a stale EV_SW mask cannot flip the candidate back. */
|
||||
if(edge) {
|
||||
hall = hall_state();
|
||||
hall_observed = hall >= 0 ? hall :
|
||||
((switch_mask & (int)CLOSED_MASK) != 0);
|
||||
last_hall_poll = now;
|
||||
fast_until = now + 120;
|
||||
} else if(now - last_hall_poll >=
|
||||
(now < fast_until ? HALL_EDGE_MS : HALL_POLL_MS)) {
|
||||
hall = hall_state();
|
||||
if(hall >= 0)
|
||||
observed = hall;
|
||||
hall_observed = hall;
|
||||
last_hall_poll = now;
|
||||
}
|
||||
observed = hall_observed >= 0 ? hall_observed :
|
||||
((switch_mask & (int)CLOSED_MASK) != 0);
|
||||
if(observed != candidate) {
|
||||
candidate = observed;
|
||||
candidate_since = now;
|
||||
}
|
||||
if(candidate >= 0 && candidate != stable_closed &&
|
||||
now - candidate_since >= LID_STABLE_MS &&
|
||||
now - last_transition >= 150) {
|
||||
if(candidate != stable_closed &&
|
||||
now - candidate_since >= LID_DEBOUNCE_MS &&
|
||||
now - last_transition >= LID_MIN_GAP_MS) {
|
||||
stable_closed = candidate;
|
||||
last_transition = now;
|
||||
on_transition(stable_closed);
|
||||
|
||||
Reference in new issue
Block a user