Implement 2720 Flip cover display behaviour

This commit is contained in:
Luxferre committed 2026-11-10 13:23:03 +02:00
1 parent a50c01b416
commit ec55fb1457
20 files changed
+630 -49

No files matched your search

+2 -2
View File
@@ -34,7 +34,7 @@ It uses a pure **X11 (`Xlibre` + `sxmo-de-dwm`)** stack (no Wayland) with **Adre
- `scripts/rootfs-prune-packages.txt`: denylist of Wayland-only, Rust-based, and retired packages purged from existing rootfs trees by `bootstrap-rootfs-container.sh` and `rebuild-image.sh`.
- `scripts/prune-rootfs-packages.sh`: two-phase rootfs pruner (`world` before `apk add`, `purge` after) that reads the denylist and pins `install_if` packages with negative `!pkg` world constraints plus `apk fix`; the `world` phase is required so apk can atomically replace Rust `sudo-rs` with C `sudo`.
- **Flip lid and cover daemon**: the compiled C `bananarchy-lid` (service `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 raw gpio36/gpio92 debugfs levels every 200 ms even when switch evdev is present, because the 2720 can miss edges or leave `EVIOCGSW` stale. The main beatles panel uses 25 MHz SPI (other targets stay at 50 MHz) to prevent high-backlight PWM noise from corrupting the display at brightness levels above 10/14. It publishes `/run/bananarchy/lid-state` so a boot-open flip starts X unlocked, directly blanks/restores the main backlight and `white:kbd_backlight`, clears the lock flag and sends a trusted `CLOSE` to `locker.so` on open, and broadcasts `LID CLOSED|OPEN` to the cover IPC. The compiled C `bananarchy-cover-idle` replaces the CPU-spinning native `bananarchy-coverd` in the default runlevel: it is a 0%-CPU Unix SOCK_DGRAM server implementing the `bananarchy-coverctl` protocol and renders a 240x240 XRGB8888 clock or `TEST bars` to the 32-bpp `/dev/fb1` with `write()`/`fsync()`. The shipping beatles DTS keeps the known-good single internal panel and `spidev@1`; `cover-panel.dtsi` is again compile-checked but hardware-gated after live testing broke the main panel/keypad path.
- **Flip lid and cover daemon**: the compiled C `bananarchy-lid` (service `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 raw gpio36/gpio92 debugfs levels every 200 ms even when switch evdev is present, because the 2720 can miss edges or leave `EVIOCGSW` stale. The main beatles panel uses 25 MHz SPI (other targets stay at 50 MHz) to prevent high-backlight PWM noise from corrupting the display at brightness levels above 10/14. It publishes `/run/bananarchy/lid-state` so a boot-open flip starts X unlocked, directly blanks/restores the main backlight and `white:kbd_backlight`, clears the lock flag and sends a trusted `CLOSE` to `locker.so` on open, and broadcasts `LID CLOSED|OPEN` to the cover IPC. The compiled C `bananarchy-cover-idle` replaces the CPU-spinning native `bananarchy-coverd` in the default runlevel: it is a 0%-CPU Unix SOCK_DGRAM server implementing the `bananarchy-coverctl` protocol and renders a 240x240 XRGB8888 clock or `TEST bars` to the 32-bpp `/dev/fb1` with `write()`/`fsync()`. It keeps the cover fully off while the flip is open, shows clock/battery/network indicators only after a trusted `BUTTON` from `bananarchy-volume-keys` while closed, and blanks again after the same `~/.config/sxmo/idle_blank_timeout` used by `dwm` (`blank_timeout = auto` in `/etc/bananarchy/cover-display.conf`). The shipping beatles DTS keeps the known-good single internal panel and `spidev@1`; `cover-panel.dtsi` is again compile-checked but hardware-gated after live testing broke the main panel/keypad path.
- **Camera, volume keys and cover spi-mux**: `etc/modules-load.d/bananarchy-hardware.conf` plus `etc/local.d/10-bananarchy-hardware.start` load `msm8905-cam` (registers `/dev/video0`) and `spidev`. The demosaic sampler rotates frames 180 degrees only when `of_machine_is_compatible("nokia,beatles")`, correcting the Flip's raw V4L2 orientation without changing other targets or adding a frame copy. `scripts/busybox-sbin-applets.txt` restores the missing `/sbin` applets including `reboot`/`poweroff`. The compiled C `bananarchy-volume-keys` (OpenRC service `bananarchy-volume-keys`) handles `KEY_VOLUMEUP`/`KEY_VOLUMEDOWN` straight from evdev because the dwm passive X grab is unreliable; `sxmo_audio.sh` mirrors the logical volume into the first live PipeWire sink via `bananarchy_set_sink_volume()` and debounces double steps with `bananarchy_vol_debounce()`. The shipping beatles DTS keeps `spidev@1` and does not apply `cover-panel.dtsi`; the external panel remains hardware-gated. `dc_gpio = -1` remains in `/etc/bananarchy/cover-display.conf` for the retained native spidev fallback.
- **BusyBox applet completeness**: `scripts/busybox-applets.txt` is the canonical `/bin` applet list and `apply-bananarchy-overlay.sh` recreates any missing symlinks. A rootfs snapshot without `/bin/ash` (the `user` login shell) or `/bin/grep` (used by `openrc-run.sh`) breaks sshd logins and prevents the sysinit `udev` service from starting; without udev, input nodes stay root-owned and untagged, elogind gives Xorg no devices and the keypad is dead. `overlay/rootfs/etc/udev/rules.d/99-bananarchy-input-seat.rules` forces `TAG+="seat"`, `GROUP="input"`, `MODE="0660"`; restart `tinydm` after starting udev. The lk2nd `paint_boot_banner()` in `bootloader/lk2nd/nokia-beatles.patch` draws the branded RGB565 boot splash, not the old striped test pattern.
- **First-boot access (2720 Flip)**: `overlay/rootfs/etc/pam.d/sshd` supplies an explicit `pam_unix` stack and `overlay/rootfs/etc/ssh/sshd_config.d/90-bananarchy-access.conf` enables password/keyboard-interactive auth, because `50-postmarketos-ui-policy.conf` sets `UsePAM yes` while the plain `/usr/sbin/sshd` rejects that directive; `overlay/rootfs/etc/conf.d/sshd` pins `/usr/sbin/sshd.pam`. `overlay/rootfs/etc/ssh/sshd_config_debug` plus `etc/local.d/20-bananarchy-sshd-debug.start` keep a USB-only (172.16.42.1:2222) PAM-free fallback login; `keys/phone_id_ed25519.pub` is pre-authorized for `user` and `root`. The shipping `extlinux.conf` must contain `quiet splash` (the pmOS initramfs defaults to `nosplash=y`); `scripts/sync-beatles-bootfs.py` restores it and `scripts/check-beatles-bootimg.py` rejects debug cmdlines. `overlay/rootfs/usr/lib/udev/rules.d/99-bananarchy-keypad.rules` and `usr/share/X11/xorg.conf.d/60-bananarchy-keypad.conf` force X to attach the GPIO matrix keypad; `usr/bin/bananarchy-keypad-diagnose.sh` collects live input state. The external 240x240 panel firmware lives in `devices/nokia-beatles/nokia,beatles-gc9305-ext-panel.bin/.txt`; `devices/nokia-beatles/cover-panel.dtsi` is a compile-checked but unapplied reference; `devices/nokia-beatles/qcom-msm8905-nokia-beatles.dts` keeps the shipping single-panel layout, and `scripts/check-rebuild.sh` verifies DTB/DTS sync and rejects an accidentally applied cover overlay. The `mux-core`, `mux-gpio` and `spi-mux` modules are built and loaded. The recovered native `usr/bin/bananarchy-coverd` is retained only for diagnostics; `dc_gpio = -1` and the external node's missing `dc-gpios` property keep it from fighting `panel-mipi-dbi-spi` for gpio110. gpio13 selection and external reset polarity still require a physical cover-panel sign-off.
@@ -57,7 +57,7 @@ All cross-compilation scripts run inside rootless Docker (`alpine:3.24` `armv7`
- `./scripts/prune-rootfs-packages.sh <rootfs-dir> world|purge` — removes Wayland-only, Rust-based, and retired packages from a target rootfs inside the build container.
- `./scripts/build-bananarchy-daemons.sh` — cross-builds the three compiled ARM idle daemons (`bananarchy-lid`, `bananarchy-cover-idle`, `bananarchy-volume-keys`) from `src/bananarchy-daemons/`; `--check` validates the ARM ELF artifacts and overlay sync. No Python-based daemon runs in the idle system.
- `./scripts/build-lk2nd-beatles.sh` — cross-builds all three beatles lk2nd images (normal, diagnostic and display; the display image is the flasher default) from the pinned upstream lk2nd commit plus `bootloader/lk2nd/nokia-beatles.patch` in rootless Docker (`--check` validates all three shipped images, `--only normal|diagnostic|display` builds one, `--force-panel-init` forces the panel replay, `--with-display` enables SPI display during boot). Offline validators: `scripts/check-lk2nd-beatles.py` and `scripts/test-lk2nd-beatles-port.py`.
- `./scripts/test-webarchy-renderer.py`, `./scripts/test-idle-blank-lock.py`, `./scripts/test-bluetooth-scan.py`, `./scripts/test-battery-charge-event.py` and `./scripts/test-gps-time-sync.py` — host unit/integration tests for the Webarchy renderer profile, the idle-blank screenlock wiring, the Bluetooth discovery parser, the charger plug/unplug icon refresh and the GPS-only time source (all also run by `check-rebuild.sh`).
- `./scripts/test-webarchy-renderer.py`, `./scripts/test-idle-blank-lock.py`, `./scripts/test-bluetooth-scan.py`, `./scripts/test-battery-charge-event.py`, `./scripts/test-gps-time-sync.py` and `./scripts/test-cover-idle.py` — host unit/integration tests for the Webarchy renderer profile, the idle-blank screenlock wiring, the Bluetooth discovery parser, the charger plug/unplug icon refresh, the GPS-only time source and the cover display state machine (all also run by `check-rebuild.sh`).
- `./scripts/check-rebuild.sh` — offline preflight for a clean clone (syntax, package list, plugin artifacts, overlay sync, SMS long-message rendering guard, ignored local agent config, Docker, version helper).
- `./scripts/sync-prebuilt-overlay.sh [--check]` — mirrors `prebuilt/` artifacts into `overlay/rootfs/`; `--check` only reports drift.
- `./scripts/bootstrap-flash-deps.sh` — installs `pyusb` and `pyserial` into the gitignored `.flash-deps/` directory for `flash-edl.py`.
+6
View File
@@ -13,6 +13,12 @@ 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.
### 2720 Flip cover display behaviour
- **External panel never showed anything useful**: `bananarchy-cover-idle` repainted a clock every 30 s regardless of lid state, ignored its `blank_timeout` setting, had no button input and drew no network indicators. It now implements the full behaviour contract: an **open flip** is fully off (black frame + backlight 0 and `BUTTON` ignored), a **closed flip** waits off until a trusted `BUTTON` datagram arrives, and that button shows the live clock, date, battery and a compact network line. The cover then blanks after exactly the main **Config -> Screen blank** timeout (`~/.config/sxmo/idle_blank_timeout`, default 300 s, `0` = never; `blank_timeout = auto` follows it). While off the daemon blocks in `poll()` with no timer at all, so it stays at 0% CPU.
- `bananarchy-volume-keys` now reads `/run/bananarchy/lid-state` and turns external side keys (volume up/down and End/Power) into cover wake buttons while the flip is closed instead of changing the volume. `bananarchy-cover-status.sh` publishes `4G SIG75 WIFI`-style indicators and battery state to the daemon from the NetworkManager dispatcher, the cover service start, and `bananarchy-cover-event.sh network|button`. `bananarchy-coverctl STATUS` now reports `lid`, `visible`, `blank_ms` and `network`.
- `scripts/test-cover-idle.py` compiles the daemon on the host and drives its real socket protocol against a fake framebuffer/backlight, verifying open/closed gating, button wake, indicator republishing, the shared blank timeout (including `0` = never) and backlight state. `check-rebuild.sh` guards the rebuilt ARM daemons and the IPC wiring. The shipping beatles DTB intentionally still keeps the single internal panel: gpio13 mux selection and external reset polarity remain hardware-gated, but the compile-tested `cover-panel.dtsi` now uses the verified 25 MHz internal-panel clock so enabling it later cannot reintroduce high-brightness corruption. Physical `/dev/fb1` validation is still required before the overlay is applied.
### GPS reception and GPS-only system time
- **GPS never produced a fix**: `bananarchy-gps`, `gps.so` and the new helpers all used `mmcli -m any`, which is ambiguous on the dual-SIM QMI stack of the 2720 Flip and can resolve to a modem without a Location interface. `/usr/bin/bananarchy-gps-modem.sh` now lists the modems, prefers the one advertising `gps-nmea`, enables the modem plus `3gpp`, `gps-nmea`, `gps-raw` and a 2 s refresh rate, and falls back to `any` only when nothing is enumerated. `gps.so`, the CLI (`status|nmea|watch|enable|disable|modem`) and the time helper share this resolver, so `nokia-argon` keeps its single-modem behaviour.
+1 -1
View File
@@ -456,7 +456,7 @@ Three native X11 games (`/usr/bin/snake`, `/usr/bin/tetris`, and `/usr/bin/scoun
- **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.
- **Cover display status**: `bananarchy-cover-idle` is the compiled 0%-CPU default daemon and answers `bananarchy-coverctl`; the native `bananarchy-coverd` is retained only for diagnostics. The shipping DTS keeps the known-good single internal panel; `cover-panel.dtsi` is compile-tested but not applied. The expected live state is no `/dev/fb1` and `bananarchy-coverctl STATUS` reporting `backend=none`. The renderer uses the 32-bpp fbdev `write()` path for future hardware (not `mmap()`, which raises `SIGBUS` on the DRM fbdev). gpio13 selection and external reset polarity still require physical sign-off before the overlay is re-enabled.
- **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`); the native `bananarchy-coverd` is retained only for diagnostics. With the flip **open** the external panel is fully off (all-black frame plus backlight 0) and `BUTTON` is ignored. With the flip **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%. The renderer uses the 32-bpp fbdev `write()` path (not `mmap()`, which raises `SIGBUS` on the DRM fbdev). The shipping DTS keeps the known-good single internal panel; `cover-panel.dtsi` is compile-tested but not applied, so the expected live state is still no `/dev/fb1` and `bananarchy-coverctl STATUS` reporting `backend=none` until gpio13 selection and external reset polarity receive physical sign-off. The reference overlay now keeps the verified 25 MHz internal-panel clock so enabling it later cannot reintroduce high-brightness corruption. `scripts/test-cover-idle.py` verifies the full lid/button/timeout/indicator state machine on the host with a fake framebuffer.
- **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).
- **Side volume keys**: the compiled evdev daemon `bananarchy-volume-keys` reads `KEY_VOLUMEUP`/`KEY_VOLUMEDOWN` directly and calls `sxmo_audio.sh vol up/down 5`; `sxmo_audio.sh` mirrors that percentage into the live PipeWire sink (the MSM8905 mainline kernel has no ALSA card yet). Press a side button and check `wpctl get-volume <sink-id>`; `bananarchy-keypad-diagnose.sh` reports the XKB mapping and both volume values.
+1
View File
@@ -50,6 +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.
- **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 kernel cover-panel DT overlay stays hardware-gated until gpio13/reset polarity is physically signed off; the software path is verified by `scripts/test-cover-idle.py` against a fake framebuffer.
- **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.
+3 -1
View File
@@ -55,7 +55,9 @@
display@0 {
compatible = "nokia,beatles-gc9305-panel", "panel-mipi-dbi-spi";
reg = <0>;
spi-max-frequency = <50000000>;
/* Keep the Flip's verified 25 MHz internal-panel clock: applying
* this overlay with 50 MHz reintroduced high-brightness corruption. */
spi-max-frequency = <25000000>;
reset-gpios = <0x27 25 0>;
dc-gpios = <0x27 110 0>;
backlight = <0x6b>;
@@ -30,4 +30,10 @@ show_notify = 0
mask_logs = 1
clock24 = 1
brightness = 160
blank_timeout = 120
# Follow Config -> Screen blank (~/.config/sxmo/idle_blank_timeout, default
# 300 s, 0 = never). A numeric value here overrides it for the cover panel.
blank_timeout = auto
# Optional sysfs node for the external panel backlight. Empty while the cover
# panel DT overlay is hardware-gated: the daemon still writes an all-black
# frame, which is the software-visible "fully off" state.
backlight_path =
@@ -31,4 +31,7 @@ start() {
return 0
fi
default_start
# Seed the compact network/battery indicators once at boot; later changes
# arrive from the NetworkManager dispatcher (bananarchy-cover-event.sh).
/usr/bin/bananarchy-cover-event.sh network >/dev/null 2>&1 &
}
@@ -27,6 +27,14 @@ case "$EVENT" in
screenoff)
/usr/bin/bananarchy-coverctl REFRESH >/dev/null 2>&1 || true
;;
network)
/usr/bin/bananarchy-cover-status.sh >/dev/null 2>&1 || true
;;
button)
# Trusted external side-button wake (also sent directly by
# bananarchy-volume-keys when the flip is closed).
/usr/bin/bananarchy-coverctl BUTTON >/dev/null 2>&1 || true
;;
wake|refresh|theme)
/usr/bin/bananarchy-coverctl RELOAD_THEME >/dev/null 2>&1 || true
;;
Binary file not shown.
+56
View File
@@ -0,0 +1,56 @@
#!/bin/sh
# Publish compact main-network indicators to the 2720 Flip cover display.
# Event-driven: called from the NetworkManager dispatcher and Sxmo hooks, so
# the idle cover daemon never has to poll mmcli/nmcli itself.
set -u
COVERCTL="${BANANARCHY_COVERCTL:-/usr/bin/bananarchy-coverctl}"
MMCLI="${BANANARCHY_MMCLI:-/usr/bin/mmcli}"
GPS_MODEM="${BANANARCHY_GPS_MODEM:-/usr/bin/bananarchy-gps-modem.sh}"
modem=""
if [ -x "$GPS_MODEM" ]; then
modem="$("$GPS_MODEM" path 2>/dev/null | head -n1)"
fi
case "$modem" in ''|*[!0-9a-zA-Z/_-]*) modem=any ;; esac
tech=""
signal=""
if command -v jq >/dev/null 2>&1; then
info="$("$MMCLI" -m "$modem" -J 2>/dev/null || true)"
if [ -n "$info" ]; then
rawtech="$(printf '%s' "$info" | jq -r \
'.modem.generic."access-technologies"[0]? // empty' 2>/dev/null || true)"
case "$rawtech" in
*5gnr*) tech="5G" ;;
*lte*) tech="4G" ;;
*hspa*|*umts*|*hsupa*|*hsdpa*) tech="3G" ;;
*edge*) tech="E" ;;
*gsm*|*gprs*) tech="2G" ;;
esac
signal="$(printf '%s' "$info" | jq -r \
'.modem.generic."signal-quality".value // empty' 2>/dev/null || true)"
fi
fi
line=""
[ -n "$tech" ] && line="$tech"
case "$signal" in ''|*[!0-9]*) ;; *) line="$line SIG$signal" ;; esac
if command -v nmcli >/dev/null 2>&1; then
case "$(nmcli -t -f TYPE,STATE device 2>/dev/null || true)" in
*wifi:connected*) line="$line WIFI" ;;
esac
fi
line="$(printf '%s' "$line" | tr -s ' ' | sed 's/^ *//' | cut -c1-40)"
[ -n "$line" ] && "$COVERCTL" NETWORK "$line" >/dev/null 2>&1 || true
for d in /sys/class/power_supply/*; do
[ -r "$d/type" ] && [ -r "$d/capacity" ] || continue
read -r pstype < "$d/type" 2>/dev/null || continue
[ "$pstype" = "Battery" ] || continue
read -r pct < "$d/capacity" 2>/dev/null || continue
case "$pct" in ''|*[!0-9]*) ;; *) "$COVERCTL" BATTERY "$pct" >/dev/null 2>&1 || true ;; esac
break
done
exit 0
@@ -48,4 +48,7 @@ case "$ACTION" in
;;
*) exit 0 ;;
esac
# Feed the flip's external panel with the same main network indicators the
# status bar shows. No-op on non-flip targets and when the cover daemon is off.
/usr/bin/bananarchy-cover-event.sh network >/dev/null 2>&1 || true
exit 0
Binary file not shown.
@@ -27,6 +27,14 @@ case "$EVENT" in
screenoff)
/usr/bin/bananarchy-coverctl REFRESH >/dev/null 2>&1 || true
;;
network)
/usr/bin/bananarchy-cover-status.sh >/dev/null 2>&1 || true
;;
button)
# Trusted external side-button wake (also sent directly by
# bananarchy-volume-keys when the flip is closed).
/usr/bin/bananarchy-coverctl BUTTON >/dev/null 2>&1 || true
;;
wake|refresh|theme)
/usr/bin/bananarchy-coverctl RELOAD_THEME >/dev/null 2>&1 || true
;;
+2
View File
@@ -177,6 +177,8 @@ chmod 0755 "$TARGET_ROOTFS/usr/bin/bananarchy-idle-blank.sh" \
"$TARGET_ROOTFS/usr/bin/bananarchy-idle-lock.sh" \
"$TARGET_ROOTFS/usr/bin/bananarchy-screen-wake.sh" \
"$TARGET_ROOTFS/usr/bin/bananarchy-battery-charge-event.sh" \
"$TARGET_ROOTFS/usr/bin/bananarchy-cover-status.sh" \
"$TARGET_ROOTFS/usr/bin/bananarchy-cover-event.sh" \
"$TARGET_ROOTFS/usr/bin/bananarchy-gps-modem.sh" \
"$TARGET_ROOTFS/usr/bin/bananarchy-gps-time-sync.sh" \
"$TARGET_ROOTFS/usr/bin/bananarchy-sync-gps-time.sh" \
+54
View File
@@ -1253,6 +1253,60 @@ if [ -x "$BASE_DIR/scripts/test-gps-time-sync.py" ] && \
fail "host GPS-only time source test failed"
fi
echo "[check] Cover display behaviour..."
COVER_SRC="$BASE_DIR/src/bananarchy-daemons/bananarchy-cover-idle.c"
VOL_SRC="$BASE_DIR/src/bananarchy-daemons/bananarchy-volume-keys.c"
COVER_CONF="$BASE_DIR/overlay/rootfs/etc/bananarchy/cover-display.conf"
COVER_EVENT="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-cover-event.sh"
COVER_STATUS="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-cover-status.sh"
COVER_INIT="$BASE_DIR/overlay/rootfs/etc/init.d/bananarchy-cover-display"
NET_EVENT="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-network-event.sh"
for token in 'BUTTON' 'NETWORK' 'blank_timeout_ms' 'set_backlight' \
'idle_blank_timeout' 'CLOCK_REDRAW_MS'; do
if ! grep -qF -- "$token" "$COVER_SRC"; then
fail "bananarchy-cover-idle.c is missing cover behaviour: $token"
fi
done
for token in 'cover_button' 'lid_is_closed' 'KEY_POWER'; do
if ! grep -qF -- "$token" "$VOL_SRC"; then
fail "bananarchy-volume-keys.c no longer wakes the cover: $token"
fi
done
if ! grep -qF 'blank_timeout = auto' "$COVER_CONF" || \
! grep -qF 'backlight_path' "$COVER_CONF"; then
fail "cover display config no longer shares the Screen blank timeout"
fi
for f in "$COVER_EVENT" "$COVER_STATUS" "$NET_EVENT" "$COVER_INIT"; do
if ! sh -n "$f" 2>/dev/null; then
fail "shell syntax: ${f#$BASE_DIR/}"
fi
done
if [ ! -x "$COVER_STATUS" ]; then
fail "bananarchy-cover-status.sh is missing or not executable"
fi
if ! grep -qF 'bananarchy-cover-status.sh' "$COVER_EVENT" || \
! grep -qF 'BUTTON' "$COVER_EVENT" || \
! grep -qF 'network)' "$COVER_EVENT"; then
fail "cover event bridge lost the network/button commands"
fi
if ! grep -qF 'bananarchy-cover-event.sh network' "$NET_EVENT" || \
! grep -qF 'bananarchy-cover-event.sh network' "$COVER_INIT"; then
fail "network indicators are not published to the cover daemon"
fi
for f in "$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/bananarchy-cover-idle" \
"$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/bananarchy-volume-keys"; do
if ! strings "$f" 2>/dev/null | grep -qF 'BUTTON'; then
fail "${f#$BASE_DIR/} is stale: rebuild with scripts/build-bananarchy-daemons.sh"
fi
done
if [ ! -x "$BASE_DIR/scripts/test-cover-idle.py" ]; then
fail "missing host integration test scripts/test-cover-idle.py"
fi
if command -v gcc >/dev/null 2>&1 && \
! "$BASE_DIR/scripts/test-cover-idle.py" >/dev/null 2>&1; then
fail "host cover display behaviour test failed"
fi
if [ "$FAILURES" -ne 0 ]; then
echo "[check] $FAILURES check(s) failed."
exit 1
+225
View File
@@ -0,0 +1,225 @@
#!/usr/bin/env python3
"""Host integration test for the 2720 Flip cover display behaviour.
Compiles bananarchy-cover-idle.c on the host, runs it against a fake
framebuffer/backlight, and drives its real IPC protocol to verify:
- flip open => fully off (black frame, backlight 0);
- flip closed + external BUTTON => clock, date and network indicators;
- no button => the main Screen blank timeout blanks the cover again;
- blank_timeout = auto follows Config -> Screen blank (0 = never).
"""
import hashlib
import os
import pathlib
import socket
import subprocess
import sys
import tempfile
import time
BASE = pathlib.Path(__file__).resolve().parent.parent
SRC = BASE / "src/bananarchy-daemons/bananarchy-cover-idle.c"
VOL_SRC = BASE / "src/bananarchy-daemons/bananarchy-volume-keys.c"
FB_WIDTH, FB_HEIGHT, FB_BPP = 240, 240, 32
FRAME_SIZE = FB_WIDTH * FB_HEIGHT * (FB_BPP // 8)
class Cover:
def __init__(self, root, exe, config, main_cfg):
self.root = root
self.sock_path = root / "cover.sock"
self.fb = root / "fb1"
self.backlight = root / "backlight"
self.fb.write_bytes(b"\x00" * FRAME_SIZE)
self.backlight.write_text("0")
self.env = dict(os.environ)
self.env.update({
"BANANARCHY_COVER_LOCK": str(root / "daemon.lock"),
"BANANARCHY_COVER_FB_GEOM": "%d,%d,%d" % (FB_WIDTH, FB_HEIGHT, FB_BPP),
"BANANARCHY_COVER_MAIN_BLANK_CFG": str(main_cfg),
})
self.proc = subprocess.Popen([str(exe), "--config", str(config)],
env=self.env, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
self.client_path = root / "client.sock"
if self.client_path.exists():
self.client_path.unlink()
self.client = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
self.client.bind(str(self.client_path))
self.client.settimeout(2)
deadline = time.time() + 3
while time.time() < deadline and not self.sock_path.exists():
time.sleep(0.05)
def send(self, command):
self.client.sendto(command.encode(), str(self.sock_path))
try:
return self.client.recv(512).decode().strip()
except socket.timeout:
return ""
def frame(self):
data = self.fb.read_bytes()
return hashlib.sha256(data).hexdigest(), any(data)
def backlight_value(self):
return self.backlight.read_text().strip()
def close(self):
try:
self.send("QUIT")
except OSError:
pass
self.client.close()
try:
self.proc.wait(timeout=3)
except subprocess.TimeoutExpired:
self.proc.kill()
self.proc.wait()
if self.client_path.exists():
self.client_path.unlink()
def wait_for(predicate, timeout=3.0):
end = time.time() + timeout
while time.time() < end:
if predicate():
return True
time.sleep(0.05)
return False
def main():
if not SRC.is_file() or not VOL_SRC.is_file():
sys.stderr.write("FAIL: missing daemon sources\n")
return 1
with tempfile.TemporaryDirectory(prefix="bananarchy-cover-") as tmp:
root = pathlib.Path(tmp)
exe = root / "cover-idle"
build = subprocess.run(
["gcc", "-std=c11", "-O2", "-Wall", "-Wextra", "-Werror",
"-I" + str(SRC.parent), str(SRC), "-o", str(exe)],
capture_output=True, text=True)
if build.returncode:
sys.stderr.write(build.stderr)
return 1
vbuild = subprocess.run(
["gcc", "-std=c11", "-O2", "-Wall", "-Wextra", "-Werror",
"-I" + str(VOL_SRC.parent), str(VOL_SRC), "-o", str(root / "volume-keys")],
capture_output=True, text=True)
if vbuild.returncode:
sys.stderr.write(vbuild.stderr)
return 1
print("[ok] host build of the compiled cover and volume-key daemons")
main_cfg = root / "idle_blank_timeout"
main_cfg.write_text("300\n")
config = root / "cover.conf"
config.write_text(
"socket_path = %s\nfb_device = %s\nbacklight_path = %s\n"
"brightness = 160\nblank_timeout = 2\n" %
(root / "cover.sock", root / "fb1", root / "backlight"),
encoding="utf-8")
daemon = Cover(root, exe, config, main_cfg)
try:
if "pong" not in daemon.send("PING"):
sys.stderr.write("FAIL: cover daemon did not answer PING\n")
return 1
_, lit = daemon.frame()
if lit or daemon.backlight_value() != "0":
sys.stderr.write("FAIL: a boot-open flip must leave the cover fully off\n")
return 1
print("[ok] open flip: cover is fully off")
daemon.send("LID CLOSED")
if not wait_for(lambda: not daemon.frame()[1]):
sys.stderr.write("FAIL: closing the flip did not blank the cover\n")
return 1
if "visible=1" in daemon.send("STATUS"):
sys.stderr.write("FAIL: closing the flip lit the cover without a button\n")
return 1
print("[ok] closed flip: cover waits for an external button")
daemon.send("NETWORK 4G SIG75 WIFI")
daemon.send("BATTERY 82")
before, _ = daemon.frame()
daemon.send("BUTTON")
if not wait_for(lambda: daemon.frame()[1]):
sys.stderr.write("FAIL: BUTTON did not show the clock/indicators\n")
return 1
if daemon.backlight_value() != "160" or "visible=1" not in daemon.send("STATUS"):
sys.stderr.write("FAIL: BUTTON did not enable the backlight\n")
return 1
with_clock, _ = daemon.frame()
if before == with_clock:
sys.stderr.write("FAIL: no frame was drawn on BUTTON\n")
return 1
print("[ok] external button: clock, battery and backlight on")
daemon.send("NETWORK 3G SIG20")
if not wait_for(lambda: daemon.frame()[0] != with_clock):
sys.stderr.write("FAIL: network indicators are not rendered\n")
return 1
if "network=3G SIG20" not in daemon.send("STATUS"):
sys.stderr.write("FAIL: NETWORK command was not stored\n")
return 1
print("[ok] network indicators are republished on the cover")
if not wait_for(lambda: not daemon.frame()[1], timeout=5):
sys.stderr.write("FAIL: cover did not respect the blank timeout\n")
return 1
if daemon.backlight_value() != "0" or "visible=0" not in daemon.send("STATUS"):
sys.stderr.write("FAIL: blank timeout did not switch the cover fully off "
"(backlight=%r status=%r)\n" %
(daemon.backlight_value(), daemon.send("STATUS")))
return 1
print("[ok] blank timeout: cover blanks with no further button")
daemon.send("BUTTON")
wait_for(lambda: daemon.frame()[1])
daemon.send("LID OPEN")
if not wait_for(lambda: not daemon.frame()[1]):
sys.stderr.write("FAIL: opening the flip did not switch the cover off\n")
return 1
daemon.send("BUTTON")
time.sleep(0.3)
if daemon.frame()[1] or "visible=1" in daemon.send("STATUS"):
sys.stderr.write("FAIL: BUTTON was honoured while the flip was open\n")
return 1
print("[ok] open flip overrides BUTTON and keeps the cover off")
finally:
daemon.close()
# A second daemon follows Config -> Screen blank (auto); 0 = never blank.
sub = root / "auto"
sub.mkdir()
config2 = root / "cover-auto.conf"
config2.write_text(
"socket_path = %s\nfb_device = %s\nbacklight_path = %s\n"
"brightness = 160\nblank_timeout = auto\n" %
(sub / "cover.sock", sub / "fb1", sub / "backlight"),
encoding="utf-8")
main_cfg.write_text("0\n")
daemon2 = Cover(sub, exe, config2, main_cfg)
try:
daemon2.send("LID CLOSED")
daemon2.send("BUTTON")
if not wait_for(lambda: daemon2.frame()[1]):
sys.stderr.write("FAIL: auto timeout daemon did not light the cover\n")
return 1
time.sleep(2.5)
if not daemon2.frame()[1] or "visible=1" not in daemon2.send("STATUS"):
sys.stderr.write("FAIL: Screen blank = 0 should keep the cover on\n")
return 1
if "blank_ms=0" not in daemon2.send("STATUS"):
sys.stderr.write("FAIL: auto timeout did not read the main Screen blank config\n")
return 1
print("[ok] auto timeout follows Config -> Screen blank (0 = never)")
finally:
daemon2.close()
print("cover display behaviour: all checks passed")
return 0
if __name__ == "__main__":
sys.exit(main())
+196 -44
View File
@@ -1,7 +1,17 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
/* Compiled idle cover IPC/renderer for nokia-beatles. No Python in the idle path. */
/* Compiled idle cover IPC/renderer for nokia-beatles. No Python in the idle path.
*
* Behaviour contract for the 2720 Flip external panel:
* - flip open: the panel is fully off (black frame and backlight 0);
* - flip closed: the panel stays off until an external side button is pressed;
* - BUTTON shows the clock, date and the compact network/battery indicators;
* - the same Screen blank timeout as dwm (~/.config/sxmo/idle_blank_timeout,
* default 300 s, 0 = never) blanks the cover again when no button arrives;
* - all other events (network, SMS, battery, calls, theme) only update the
* frame while the cover is visible, so an idle daemon stays at 0% CPU.
*/
#include <ctype.h>
#include <poll.h>
#include <strings.h>
@@ -13,6 +23,9 @@
#define COVER_LOCK "/run/bananarchy-cover-idle.lock"
#define DEFAULT_SOCKET "/run/bananarchy/cover.sock"
#define DEFAULT_FB "/dev/fb1"
#define MAIN_BLANK_CFG "/home/user/.config/sxmo/idle_blank_timeout"
#define DEFAULT_BLANK_SECS 300
#define CLOCK_REDRAW_MS 30000
struct glyph {
char ch;
@@ -40,6 +53,7 @@ static const struct glyph font[] = {
{'8', {0x36, 0x49, 0x49, 0x49, 0x36}}, {'9', {0x06, 0x49, 0x49, 0x29, 0x1e}},
{':', {0x00, 0x36, 0x36, 0x00, 0x00}}, {'-', {0x08, 0x08, 0x08, 0x08, 0x08}},
{'.', {0x00, 0x60, 0x60, 0x00, 0x00}}, {'/', {0x20, 0x10, 0x08, 0x04, 0x02}},
{'%', {0x23, 0x13, 0x08, 0x64, 0x62}}, {'|', {0x00, 0x00, 0x7f, 0x00, 0x00}},
{' ', {0x00, 0x00, 0x00, 0x00, 0x00}},
};
@@ -143,6 +157,12 @@ static int fb_geometry(const char *fb_path, unsigned int *width,
FILE *handle;
const char *p = strstr(fb_path, "fb");
unsigned int bytes_per_pixel;
const char *sim = getenv("BANANARCHY_COVER_FB_GEOM");
if(sim && sscanf(sim, "%u,%u,%u", width, height, bpp) == 3 &&
*width > 0 && *height > 0 && (*bpp == 16 || *bpp == 32)) {
*stride = *width * (*bpp / 8);
return 1;
}
if(p)
index = atoi(p + 2);
snprintf(sysfs, sizeof(sysfs),
@@ -185,7 +205,44 @@ static int write_all(int fd, const unsigned char *buffer, size_t length)
return 1;
}
static int draw_frame(const char *fb_path, const char *message, int test)
struct state {
char lid[16];
char backend[16];
char call[64];
char message[128];
char network[96];
int enabled;
int battery;
int sms;
int test;
int visible;
long long last_input_ms;
long long blank_ms;
char backlight_path[128];
int backlight_level;
};
/* Fully off means both a black framebuffer and a zeroed backlight. A missing
* backlight node is normal while the cover panel DT overlay is hardware-gated;
* the black frame still leaves nothing visible on the panel. */
static void set_backlight(const struct state *state, int on)
{
char value[32];
int fd;
if(!state->backlight_path[0])
return;
snprintf(value, sizeof(value), "%d", on ? state->backlight_level : 0);
/* O_TRUNC matters for regular files (host tests and future sysfs shims):
* a shorter "0" must not leave the tail of the previous "160" behind. */
fd = open(state->backlight_path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC,
0644);
if(fd < 0)
return;
(void)!write(fd, value, strlen(value));
close(fd);
}
static int draw_frame(const char *fb_path, const struct state *state)
{
int fd = open(fb_path, O_RDWR | O_CLOEXEC);
unsigned int width = 0;
@@ -197,6 +254,7 @@ static int draw_frame(const char *fb_path, const char *message, int test)
struct frame fb;
char clock[16];
char date[32];
char battery[32];
time_t now = time(NULL);
struct tm tm;
if(fd < 0)
@@ -219,7 +277,7 @@ static int draw_frame(const char *fb_path, const char *message, int test)
localtime_r(&now, &tm);
strftime(clock, sizeof(clock), "%H:%M", &tm);
strftime(date, sizeof(date), "%d.%m.%Y", &tm);
if(test == 2) {
if(state->test == 2) {
frame_rect(&fb, 0, 0, (int)width / 4, (int)height,
rgb888(250, 40, 40));
frame_rect(&fb, (int)width / 4, 0, (int)width / 2, (int)height,
@@ -228,10 +286,11 @@ static int draw_frame(const char *fb_path, const char *message, int test)
rgb888(60, 110, 250));
frame_rect(&fb, (int)width * 3 / 4, 0, (int)width, (int)height,
rgb888(245, 245, 245));
} else if(test == 3) {
} else if(state->test == 3) {
frame_rect(&fb, 0, 0, (int)width, (int)height,
rgb888(245, 245, 245));
} else if(test == 4) {
} else if(state->test == 4 ||
strcmp(state->lid, "open") == 0 || !state->visible) {
frame_rect(&fb, 0, 0, (int)width, (int)height, rgb888(0, 0, 0));
} else {
frame_rect(&fb, 0, 0, (int)width, (int)height, rgb888(8, 12, 26));
@@ -241,8 +300,17 @@ static int draw_frame(const char *fb_path, const char *message, int test)
width >= 220 ? 5 : 3, rgb888(235, 240, 248));
frame_text(&fb, date, 30, (int)height / 2 + 40, 2,
rgb888(90, 150, 240));
if(message && message[0])
frame_text(&fb, message, 6, (int)height - 30, 2,
/* Compact network / battery indicators, pushed by the event bridge. */
if(state->network[0])
frame_text(&fb, state->network, 6, (int)height - 44, 1,
rgb888(120, 230, 160));
if(state->battery >= 0) {
snprintf(battery, sizeof(battery), "BAT %d%%", state->battery);
frame_text(&fb, battery, 6, (int)height - 26, 1,
rgb888(250, 210, 60));
}
if(state->message[0])
frame_text(&fb, state->message, 6, (int)height - 12, 1,
rgb888(235, 240, 248));
}
if(lseek(fd, 0, SEEK_SET) < 0 || !write_all(fd, mem, size)) {
@@ -282,15 +350,50 @@ static void trim(char *value)
}
}
static long long blank_timeout_ms(const char *configured)
{
const char *path = getenv("BANANARCHY_COVER_MAIN_BLANK_CFG");
char buf[32];
long secs = DEFAULT_BLANK_SECS;
long value;
if(!path || !path[0])
path = MAIN_BLANK_CFG;
if(configured && strcasecmp(configured, "auto") != 0 && configured[0]) {
value = strtol(configured, NULL, 10);
if(value < 0)
value = 0;
if(value > 86400)
value = 86400;
return (long long)value * 1000LL;
}
/* "auto" (the default) follows Config -> Screen blank exactly. */
FILE *handle = fopen(path, "r");
if(handle) {
if(fscanf(handle, "%31s", buf) == 1) {
value = strtol(buf, NULL, 10);
if(value >= 0 && value <= 86400)
secs = value;
}
fclose(handle);
}
return (long long)secs * 1000LL;
}
static void read_config(const char *path, char *socket_path, size_t splen,
char *fb_path, size_t fblen)
char *fb_path, size_t fblen, struct state *state)
{
char line[256];
char blank[32];
FILE *handle = fopen(path, "r");
safe_copy(socket_path, splen, DEFAULT_SOCKET);
safe_copy(fb_path, fblen, DEFAULT_FB);
if(!handle)
snprintf(blank, sizeof(blank), "auto");
state->backlight_path[0] = '\0';
state->backlight_level = 160;
if(!handle) {
state->blank_ms = blank_timeout_ms(blank);
return;
}
while(fgets(line, sizeof(line), handle)) {
char *comment = strchr(line, '#');
char *eq;
@@ -310,8 +413,17 @@ static void read_config(const char *path, char *socket_path, size_t splen,
safe_copy(socket_path, splen, value);
else if(strcmp(key, "fb_device") == 0)
safe_copy(fb_path, fblen, value);
else if(strcmp(key, "backlight_path") == 0)
safe_copy(state->backlight_path, sizeof(state->backlight_path), value);
else if(strcmp(key, "brightness") == 0) {
long v = strtol(value, NULL, 10);
if(v > 0 && v <= 255)
state->backlight_level = (int)v;
} else if(strcmp(key, "blank_timeout") == 0)
safe_copy(blank, sizeof(blank), value);
}
fclose(handle);
state->blank_ms = blank_timeout_ms(blank);
}
static void lower_string(char *value)
@@ -330,17 +442,6 @@ static void upper_string(char *value)
}
}
struct state {
char lid[16];
char backend[16];
char call[64];
char message[128];
int enabled;
int battery;
int sms;
int test;
};
static int test_value(const char *mode)
{
if(!mode)
@@ -369,14 +470,33 @@ static void handle_command(char *buffer, struct state *state, int *redraw)
char *value = strtok_r(NULL, " \t\r\n", &save);
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;
state->last_input_ms = now_ms();
*redraw = 1;
}
} else if(strcmp(command, "NETWORK") == 0) {
char *rest = save;
while(rest && (*rest == ' ' || *rest == '\t'))
rest++;
safe_copy(state->network, sizeof(state->network), rest ? rest : "");
trim(state->network);
if(state->visible)
*redraw = 1;
} else if(strcmp(command, "NOTIFY") == 0) {
char *rest = save;
while(rest && (*rest == ' ' || *rest == '\t'))
rest++;
safe_copy(state->message, sizeof(state->message), rest ? rest : "");
trim(state->message);
*redraw = 1;
if(state->visible)
*redraw = 1;
} else if(strcmp(command, "CALL") == 0) {
char *value = strtok_r(NULL, " \t\r\n", &save);
if(value) {
@@ -391,6 +511,8 @@ static void handle_command(char *buffer, struct state *state, int *redraw)
char *value = strtok_r(NULL, " \t\r\n", &save);
if(value)
state->battery = (int)strtol(value, NULL, 10);
if(state->visible)
*redraw = 1;
} else if(strcmp(command, "SET") == 0) {
char *key = strtok_r(NULL, " \t\r\n", &save);
char *value = strtok_r(NULL, " \t\r\n", &save);
@@ -403,14 +525,18 @@ static void handle_command(char *buffer, struct state *state, int *redraw)
state->test = test_value(mode);
*redraw = 1;
} else if(strcmp(command, "BLANK") == 0) {
state->test = 4;
state->visible = 0;
*redraw = 1;
} else if(strcmp(command, "UNBLANK") == 0) {
state->test = 0;
if(strcmp(state->lid, "closed") == 0) {
state->visible = 1;
state->last_input_ms = now_ms();
}
*redraw = 1;
} else if(strcmp(command, "REFRESH") == 0 ||
strcmp(command, "RELOAD_THEME") == 0) {
*redraw = 1;
if(state->visible)
*redraw = 1;
}
}
@@ -430,9 +556,11 @@ static void reply_for(char *buffer, const struct state *state,
snprintf(reply, len, "OK pong\n");
} else if(strcmp(command, "STATUS") == 0) {
snprintf(reply, len,
"OK lid=%s backend=%s enabled=%d battery=%d call=%s sms=%d\n",
state->lid, state->backend, state->enabled, state->battery,
state->call, state->sms);
"OK lid=%s backend=%s enabled=%d visible=%d blank_ms=%lld "
"battery=%d call=%s sms=%d network=%s\n",
state->lid, state->backend, state->enabled, state->visible,
state->blank_ms, state->battery, state->call, state->sms,
state->network);
} else if(strcmp(command, "LID") == 0) {
snprintf(reply, len, "OK lid=%s\n", state->lid);
} else if(strcmp(command, "TEST") == 0) {
@@ -452,13 +580,22 @@ int main(int argc, char **argv)
struct sockaddr_un local;
int server;
struct state state;
time_t last_draw = 0;
long long last_draw = 0;
int redraw = 1;
if(lock_fd < 0)
return 1;
(void)lock_fd;
install_reaper();
if(argc > 2 && strcmp(argv[1], "--config") == 0)
config = argv[2];
memset(&state, 0, sizeof(state));
snprintf(state.lid, sizeof(state.lid), "open");
snprintf(state.backend, sizeof(state.backend), "none");
snprintf(state.call, sizeof(state.call), "none");
state.enabled = 1;
state.battery = -1;
read_config(config, socket_path, sizeof(socket_path),
fb_path, sizeof(fb_path));
fb_path, sizeof(fb_path), &state);
mkdir_p(socket_path);
unlink(socket_path);
server = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
@@ -473,12 +610,6 @@ int main(int argc, char **argv)
return 1;
chmod(socket_path, 0660);
chown(socket_path, 0, SESSION_GID);
memset(&state, 0, sizeof(state));
snprintf(state.lid, sizeof(state.lid), "open");
snprintf(state.backend, sizeof(state.backend), "none");
snprintf(state.call, sizeof(state.call), "none");
state.enabled = 1;
state.battery = -1;
while(1) {
struct pollfd pfd;
char buffer[512];
@@ -487,34 +618,55 @@ int main(int argc, char **argv)
struct sockaddr_un peer;
socklen_t peer_len = sizeof(peer);
ssize_t nread;
long long now = now_ms();
/* With the cover off there is no timer at all: poll blocks until IPC. */
int timeout_ms = -1;
if(state.visible) {
long long next = CLOCK_REDRAW_MS - (now - last_draw);
if(next < 1)
next = 1;
if(state.blank_ms > 0) {
long long remaining = state.blank_ms - (now - state.last_input_ms);
if(remaining <= 0) {
state.visible = 0;
redraw = 1;
} else if(remaining < next) {
next = remaining;
}
}
timeout_ms = (int)(next > 1000000 ? 1000000 : next);
if(state.visible && now - last_draw >= CLOCK_REDRAW_MS)
redraw = 1;
}
if(redraw) {
set_backlight(&state, state.visible || state.test == 2 ||
state.test == 3 || state.test == 1);
snprintf(state.backend, sizeof(state.backend), "%s",
draw_frame(fb_path, &state) ? "fb" : "none");
last_draw = now;
redraw = 0;
}
pfd.fd = server;
pfd.events = POLLIN;
pfd.revents = 0;
if(poll(&pfd, 1, 1000) > 0 && (pfd.revents & POLLIN)) {
if(poll(&pfd, 1, timeout_ms) > 0 && (pfd.revents & POLLIN)) {
nread = recvfrom(server, buffer, sizeof(buffer) - 1, 0,
(struct sockaddr *)&peer, &peer_len);
if(nread > 0) {
int redraw = 0;
buffer[nread] = '\0';
snprintf(original, sizeof(original), "%s", buffer);
handle_command(buffer, &state, &redraw);
reply_for(original, &state, reply, sizeof(reply));
sendto(server, reply, strlen(reply), 0,
(struct sockaddr *)&peer, peer_len);
if(redraw)
last_draw = 0;
if(strncasecmp(original, "QUIT", 4) == 0) {
set_backlight(&state, 0);
close(server);
unlink(socket_path);
return 0;
}
}
}
if(state.enabled && time(NULL) - last_draw > 30) {
last_draw = time(NULL);
snprintf(state.backend, sizeof(state.backend), "%s",
draw_frame(fb_path, state.message, state.test) ? "fb" : "none");
}
}
return 0;
}
@@ -3,10 +3,15 @@
#endif
/* Compiled side-volume-key reader for nokia-beatles. No Python in the idle path. */
#include <poll.h>
#include <sys/socket.h>
#include <sys/un.h>
#include "common.h"
#define VOLUME_LOCK "/run/bananarchy-volume-keys.lock"
#define LID_STATE_FILE "/run/bananarchy/lid-state"
#define LID_CLIENT_SOCKET "/run/bananarchy/volume-lid-client.sock"
#define COVER_SOCKET "/run/bananarchy/cover.sock"
#ifndef EV_KEY
#define EV_KEY 0x01
@@ -18,6 +23,10 @@
#define KEY_VOLUMEUP 115
#endif
#ifndef KEY_POWER
#define KEY_POWER 116
#endif
static char *const session_env[] = {
(char *)"PATH=/home/user/.local/bin:/home/user/.config/sxmo/hooks:/usr/share/sxmo/default_hooks:/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin",
(char *)"HOME=/home/user",
@@ -28,6 +37,45 @@ static char *const session_env[] = {
NULL
};
static int lid_is_closed(void)
{
char buf[32] = "";
FILE *handle = fopen(LID_STATE_FILE, "r");
if(!handle)
return 0;
if(!fgets(buf, sizeof(buf), handle))
buf[0] = '\0';
fclose(handle);
return strncmp(buf, "closed", 6) == 0;
}
/* While the flip is closed the external side keys are cover-display wake
* buttons, not volume controls. The cover daemon is a 0%-CPU datagram
* server; a failed send just means it is not running on this target. */
static void cover_button(void)
{
int fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
struct sockaddr_un local;
struct sockaddr_un remote;
if(fd < 0)
return;
mkdir("/run/bananarchy", 0755);
unlink(LID_CLIENT_SOCKET);
memset(&local, 0, sizeof(local));
local.sun_family = AF_UNIX;
snprintf(local.sun_path, sizeof(local.sun_path), "%s", LID_CLIENT_SOCKET);
if(bind(fd, (struct sockaddr *)&local, sizeof(local)) < 0) {
close(fd);
return;
}
memset(&remote, 0, sizeof(remote));
remote.sun_family = AF_UNIX;
snprintf(remote.sun_path, sizeof(remote.sun_path), "%s", COVER_SOCKET);
sendto(fd, "BUTTON\n", 7, 0, (struct sockaddr *)&remote, sizeof(remote));
close(fd);
unlink(LID_CLIENT_SOCKET);
}
static void apply_volume(const char *action)
{
char *const argv[] = {
@@ -58,6 +106,13 @@ static void read_ready(struct watch_list *list, struct pollfd *fds, int nfds)
while((nread = read(fds[i].fd, &ev, sizeof(ev))) == (ssize_t)sizeof(ev)) {
if(ev.type != EV_KEY || ev.value != 1)
continue;
if(ev.code != KEY_VOLUMEUP && ev.code != KEY_VOLUMEDOWN &&
ev.code != KEY_POWER)
continue;
if(lid_is_closed()) {
cover_button();
continue;
}
if(ev.code == KEY_VOLUMEUP)
apply_volume("up");
else if(ev.code == KEY_VOLUMEDOWN)