Skip to content

Sudo password prompt, cz-battery-saver features, per-service toggles and scrolling settings - #2

Merged
baltamir1978 merged 9 commits into
baltamir1978:mainfrom
Z3R0C1PH3R:battery-saver-features
Nov 25, 2026
Merged

baltamir1978 merged 9 commits into
baltamir1978:mainfrom
Z3R0C1PH3R:battery-saver-features

Conversation

@Z3R0C1PH3R

Copy link
Copy Markdown
Contributor

Supersedes #1 (closed while I fixed some layout issues). Everything was tested on a Cardputer Zero by driving the keyboard and checking the screen.

Sudo password on screen

  • If sudo -n needs a password, the settings screen asks for it on top of the list instead of saying passwordless sudo is required. A wrong password shows an error and asks again; ESC cancels ("Not changed").
  • The password goes to sudo -S -p "" on stdin only. It is never stored, logged or put on the command line, and it is wiped after use (SecretInput, wipe). classify_sudo handles the different sudo messages, with LC_ALL=C.
  • Typing: linux_input handles Shift and the Cardputer's Sym layer (it reads the tca8418 keymap). T types a letter instead of switching the theme while the prompt is open.
  • Simulator: ZEROPOWER_SIMULATE_SUDO=<password>.

English messages

  • The "hold ESC to exit" and screenshot toasts and the help popup were in Spanish; they are in English now.

From cz-battery-saver, and more

  • Power saving: "Sleep sound card" and "Pause launcher" are two separate switches (idle_audio, idle_launcher), plus a "Saver delay" (3–60 s). The old idle_saver key is still read.
  • Hardware:
    • CPU max speed (1000/800/600 MHz): set in cpufreq right away and as arm_freq in config.txt for boot.
    • Status LED.
    • Grove 5V and GPIO 5V outputs, kept at boot with a udev rule (70-zeropower-leds.rules). On uninstall, restore removes the rule and leaves the outputs as they are.
    • With Desk Mode installed, "Desk Mode unplug" closes its HDMI desktop once HDMI has been unplugged for 1–30 min (the row is hidden without Desk Mode).
  • Services: one switch per service instead of "Background extras": NFS client (rpcbind, nfs-blkmap), Avahi, daily apt updates, man-db and e2scrub. extra_services is still accepted, and uninstall still undoes it for anyone who changed it with 0.1.3.
  • Measured with the screen off: status LED ~4 mA, each 5 V output ~3 mA with nothing plugged in, 600 MHz ~5 mA at idle. The hints say so.

UI

  • The lists scroll, with a scrollbar, when a group has more than 5 rows, instead of shrinking the rows (which made the text overlap).
  • Settings that only apply after a reboot (GPU memory) say "Needs restart" in the hint line.

Tests

  • power_model_test: sudo outcome classification, SecretInput, the split saver keys and the legacy key, UnplugTimer, and the group sizes.
  • Tools/compilar.sh todo passes in the Tools/Dockerfile image on a clean checkout (tests and .deb).

Z3R0C1PH3R and others added 7 commits November 24, 2026 23:45
Si `sudo -n` dice que hace falta contraseña, la lista de ajustes la pide encima
(«Password required») y repite el cambio con `sudo -S -p ""`. La contraseña va por
la entrada estándar (run_process admite ahora entrada), nunca en la línea de
órdenes; no se guarda y se borra de la memoria al acabar (SecretInput, wipe). Si
no vale, se vuelve a pedir con el aviso en rojo. Sudo la recuerda unos minutos.

- model/sudo_password: classify_sudo (mensajes de sudo con LC_ALL=C) y SecretInput,
  con pruebas en power_model_test.
- linux_input: Shift (mayúsculas y signos de un teclado de PC) y la capa Sym del
  Cardputer, leída de su mapa de teclas; al soltar sale la misma tecla que al pulsar.
- La T no cambia el tema mientras se escribe la contraseña.
- Simulador: ZEROPOWER_SIMULATE_SUDO=<clave> para probar la pantalla.
El resto de la interfaz ya estaba en inglés: «Mantén ESC para salir», «Guardada en» y
«No se pudo capturar» se habían quedado en español.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
…pantalla apagada, su retardo y cerrar Desk Mode al desconectar el HDMI

- Screen-off saver: Both / Sound card / Launcher / Off (idle_saver=on|audio|launcher|off;
  «on» sigue siendo las dos cosas, así que los power.conf de antes valen igual).
- Saver delay: 3, 5, 10, 30 o 60 s con la pantalla apagada antes de empezar (antes, 5 fijos).
- Desk Mode unplug (Hardware): con cz-desk-mode instalado, zeropowerd para su escritorio HDMI
  (unidad de usuario cz-desk-mode-desktop.service) tras 1, 5, 15 o 30 min con el HDMI
  desconectado. Por defecto Keep desktop, porque se pierde lo no guardado. Sin Desk Mode sale
  como «not installed».
- UnplugTimer en power_logic, con pruebas; IdleTracker::set_delay.
- Con 6 filas (Hardware) las filas miden 15 px para que la pista no tape la línea de estado.

Co-authored-by: Cursor <cursoragent@cursor.com>
- La pista va justo debajo de la última fila y con las líneas un poco más juntas: con dos
  líneas rozaba la línea de estado.
- Desk Mode unplug sólo sale con Desk Mode instalado (si no, Hardware se queda en 5 filas).
- Con 6 filas: filas de 16 px (a 15 los interruptores se tocaban) y la pista y el estado
  comparten el sitio; el estado sólo se enseña si tiene algo que decir y, al moverse, se
  quita el resultado del último cambio para que se vea la pista de la fila nueva.

Probado en el aparato pulsando teclas y leyendo /dev/fb0, también con 6 filas (Desk Mode
simulado) y en tema claro.

Co-authored-by: Cursor <cursoragent@cursor.com>
…e de CPU

- Power saving: «Sleep sound card» y «Pause launcher» por separado (idle_audio,
  idle_launcher); el antiguo idle_saver se sigue leyendo.
- Hardware: CPU max speed (cpufreq ya y arm_freq al arrancar), Status LED y las salidas
  de 5 V del puerto Grove y de los pines GPIO, con regla de udev para el arranque.
  Medido con la pantalla apagada: LED ~4 mA, cada salida de 5 V ~3 mA sin nada
  enchufado, 600 MHz ~5 mA en reposo.
- La lista se desplaza: 5 filas a la vista y barra a la derecha, en vez de encoger.
- La pista de los ajustes que piden reiniciar (GPU memory) dice «Needs restart».

Co-authored-by: Cursor <cursoragent@cursor.com>
NFS client (rpcbind, nfs-blkmap), Avahi, actualizaciones diarias de apt, índice de man y
e2scrub, cada uno con sus unidades. extra_services se sigue aceptando y deshaciendo al
desinstalar, para quien lo cambió con la 0.1.3.

Co-authored-by: Cursor <cursoragent@cursor.com>
@baltamir1978

Copy link
Copy Markdown
Owner

Thanks a lot, this is a big and careful piece of work. I went through the helper and the sudo part in detail, and the simulator build + power_model_test pass on this branch.

Looks good:

  • The password only goes to sudo -S -p "" on stdin, it is wiped afterwards, and SIGPIPE is handled in run_process.
  • The new helper keys only accept values from a closed list; restore still undoes the old extra_services, and the legacy idle_saver key is still read.

Needed before merging:

Minor, up to you:

  • GPIO 5V: turning it off here cuts power to the Caps (RF/NFC, GPS…) until their app turns it back on. The hint could say that more clearly than "Cap apps may turn it on".
  • CPU max speed: after restore, config.txt keeps a # ZeroPower / [all] / arm_freq=1000 block. It's harmless, but it would be cleaner to remove the block when going back to 1000, or to restore from config.txt.orig.
  • Desk Mode unplug: the daemon calls systemctl --user from a system service. It should work because the unit sets XDG_RUNTIME_DIR, but I couldn't test it without Desk Mode.

baltamir1978 and others added 2 commits November 25, 2026 22:17
# Conflicts:
#	tests/power_model_test.cpp
…sa de los Caps

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

Copy link
Copy Markdown
Owner

I merged current main (0.1.4) into your branch and resolved the test conflict. I also added one small commit: going back to 1000 MHz now removes the config.txt block ZeroPower added, and the GPIO 5V hint now warns that turning it off cuts power to a plugged-in Cap. The build and tests pass. Merging. Thank you very much for this, it's a great contribution! 🙏

@baltamir1978
baltamir1978 merged commit 70fbeea into baltamir1978:main Nov 25, 2026
baltamir1978 added a commit that referenced this pull request Nov 26, 2026
… limpio al volver a 1000 MHz

Con el PR #2 de Z3R0C1PH3R ya fusionado. Al apagar por batería baja, el CM0 se detiene pero
la placa sigue con corriente y la pantalla quedaba congelada: parecía colgado. Ahora
zeropowerd pausa el lanzador y la app abierta, enciende la pantalla si estaba apagada y copia
al framebuffer una imagen ya hecha (Tools/generar_pantallas.py, RGB565 en crudo: sin LVGL ni
fuentes en el servicio). Espera 10 s y apaga; si en ese rato se enchufa el cargador, lo deja
todo como estaba. ZEROPOWERD_BATTERY_DIR permite probarlo con una batería falsa.

El bloque «# ZeroPower» de arm_freq se añadía con una línea en blanco delante y al quitarlo
se quedaba: cada vuelta a 1000 MHz dejaba otra. Ahora se quita entero (perl, de perl-base).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HuWQ2dt8pyL4xeMBn7Bj5q
@Z3R0C1PH3R

Copy link
Copy Markdown
Contributor Author

Thanks for merging and for the fixes! I tested Desk Mode unplug on a Cardputer Zero with 0.1.6: a stand-in user unit cz-desk-mode-desktop.service, /usr/lib/cz-desk-mode present, HDMI disconnected and desktop_unplug=1. After about 90 s zeropowerd logged "HDMI unplugged for 1 min: closing the Desk Mode desktop" and the unit was stopped, so systemctl --user from the system service works with the XDG_RUNTIME_DIR the unit sets.

About the failed CI runs on the fork PRs (#1, #2, #3): none of them had any jobs. They were waiting for approval to run workflows from a fork and were marked as failed when the PR was closed or merged, so there was no real build error.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants