Hello,
I’ve coded a simple screen lock and power-saving service for uConsole.
This service is built on Ubuntu 22.04 and Python.
It detects power key events to turn the screen on and off. Initially, I used a polling loop for event detection, but to reduce CPU load, I switched to using epoll.
Whenever the screen turns off for any reason (e.g., screensaver, desktop lock, sleep mode),
the service detects the screen-off state and lowers the CPU’s maximum frequency to the minimum while also turning off the built-in keyboard’s power and wakeup trigger.
(I also tried changing the CPU governor to powersave
, but I noticed a slight delay when switching.)
Similarly, I initially used a polling loop to detect screen-off events, but to reduce CPU load, I switched to using inotify.
The service consists of two background processes:
- sleep-remap-powerkey
/usr/local/bin/sleep_remap_powerkey
Detects power key events and controls the screen power.
- sleep-power-control
/usr/local/bin/sleep_power_control
Manages power-saving operations based on screen status.
4 Likes
Feature
- Re-map Power key, Shutdown to Screen-off
- Turn off Screen (Backlight and LCD, not blank)
- Turn off keyboard power
- CPU max freq set to min freq on screen-off
Known issues
In some cases, User input (mouse, keyboard) is required after pressing the power key in any S2Idle state. - v0.3 fixed
- Keyboard turn-off only works with QMK custom firmware.
- Sometimes, sleep-power-control unable to detect the screen off of the desktop environment
- The display mode does not recover when the screen is turned off and on, on specific distribution.
Releases
CAUTION - If you are installing for the first time, keep the ssh connection open as a fallback against malfunctions until you check the operation.
Source and package build script
Deb Package
Installation
$ sudo dpkg -i uconsole-sleep.deb
# Uninstall
$ sudo dpkg -r uconsole-sleep
Build own package
# Dependency: python3, (venv)
$ sudo apt update
$ sudo apt install python3-full
$ wget https://raw.githubusercontent.com/qkdxorjs1002/uConsole-sleep/refs/heads/main/make_uconsole-sleep_package.sh
$ sudo chmod +x make_uconsole-sleep_package.sh
$ ./make_uconsole-sleep_package.sh
1 Like
Release v0.3
Full Changelog: Comparing v0.2...v0.3 · qkdxorjs1002/uConsole-sleep · GitHub
- Emit WakeUp Event after turn on screen
- Add DRM control to turn off screen(BL,LCD) (not blank)
Thanks for your nice program.
I’m using @Rex’s bookworm lite image with Xfce.
When I installed the image and turned on uConsole, the screen rotated, so I had to rotate it 90 degrees using the display setting.
Similarly, when I use your program and wake up my uConsole, the screen rotated with the display setting pops up.
Is there anything I should check before using your program? Because every time uConsole wakes up, the same thing happens.
Thanks again and any advice would be appreciated.
I’ll try to restore the display mode as it is before the screen turns off.
1 Like
Can you test this command?
This will turn off the screen for 3 seconds and turn it on again.
echo off | sudo tee /sys/class/drm/card1-DSI-1/status; sleep 3; echo detect | sudo tee /sys/class/drm/card1-DSI-1/status
Is the screen the same display mode as before?
1 Like
Yeah, still…
(Thanks! What a swift respond!)