2 releases
Uses new Rust 2024
| new 0.1.7 | Dec 16, 2025 |
|---|---|
| 0.1.6 |
|
| 0.1.5 |
|
| 0.1.3 | Dec 11, 2025 |
#292 in Hardware support
78KB
1.5K
SLoC
uconsole-sleep
This is a Rust port of uConsole-sleep. It provides a power key monitor that toggles between normal and power-saving modes. Passed tests on uConsole cm4 with RPI Trixie OS.
Binary:
- Monitor the power key and toggle power-saving mode on short press.
Power-saving mode includes:
- Display off (backlight control via sysfs)
- Reduced CPU frequency (configurable via
SAVING_CPU_FREQ) - Future extensibility: WiFi control, Bluetooth control, etc.
Environment variables:
SAVING_CPU_FREQ— set tomin,maxin MHz (e.g.100,600) to apply when in power-saving modeHOLD_TRIGGER_SEC— float seconds to treat as a long press (default 0.7)
Build:
cargo build --release
Usage (run as root to write sysfs, grab input device, and manage power):
sudo ./target/release/uconsole-sleep
To override the configuration location
default /etc/uconsole-sleep/config or repo ./etc/uconsole-sleep/config.default
sudo ./target/release/uconsole-sleep --config /path/to/config
- Use
RUST_LOGenvironment variable to control logging level (e.g.RUST_LOG=debug) or CLI flags-v(info),-vv(debug),-vvv(trace). - Run
uconsole-sleep -horuconsole-sleep --helpto print usage and available options such as--dry-run,--toggle-wifi,--toggle-bt, and--config.
Examples:
# Dry run (no writes)
sudo ./target/release/uconsole-sleep --dry-run
# Show help
sudo ./target/release/uconsole-sleep --help
How it works:
- Press power key (short press < 0.7s): toggle between normal and power-saving mode
- Power-saving mode: turns off display, reduces CPU frequency
- Normal mode: turns on display, restores default CPU frequency
- The program grabs exclusive access to the power key device to prevent LXDE from triggering shutdown dialogs
Notes:
- This implementation uses sysfs writes to toggle display and CPU frequency
- The power key device is grabbed (EVIOCGRAB) to prevent desktop environment conflicts
- Tests cover hardware detection helpers
Dependencies
~2MB
~42K SLoC