uConsole-Sleep v1.2

Hello,

I’ve coded a simple screen lock and power-saving service for uConsole.

TL;DR

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.
8 Likes

Feature

  • Re-map Power key, Shutdown to Screen-off
  • Hold power key to show power interactive menu
  • Turn off Screen (Backlight and LCD, not blank)
  • Turn off keyboard power
  • CPU max freq set to min freq on screen-off
  • Feature Customization

Tested on

Known issues

Details
  • In some cases, User input (mouse, keyboard) is required after pressing the power key in any S2Idle state. - fixed in v0.3
  • Keyboard turn-off only works with QMK custom firmware. - fixed in v1.0 (not confirmed)
  • Sometimes, sleep-power-control unable to detect the screen off of the desktop environment - fixed in v1.0
  • The display mode does not recover when the screen is turned off and on, on specific distribution. - fixed in v1.2 (disable turn off drm feature in /etc/uconsole-sleep/config)

Releases

Details

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

Configuration

$ sudo nano /etc/uconsole-sleep/config

$ sudo systemctl restart sleep-remap-powerkey.service
$ sudo systemctl restart sleep-power-control.service

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
2 Likes
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.

1 Like

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!)

Release v1.0

Full Changelog: Comparing v0.3…v1.0 · qkdxorjs1002/uConsole-sleep · GitHub

  • Official keyboard firmware detection
  • Apply timeout poll for desktop sleep mode detection
  • Use the detect flag instead of on forcing LCD turned on.

Release v1.1

Full Changelog: Comparing v1.0…v1.1 · qkdxorjs1002/uConsole-sleep · GitHub

  • Add feature hold power key to trigger KEY_POWER (interactive power menu)
1 Like

Sorry for asking the same thing, but is there any way to fix the screen going 90 when coming back from sleep in the Xfce environment? I really want to use your program, but I can’t because the screen rotating problem. Thanks.

Hi, I will release feature user can customize config (disable or set value/feature) in v1.2.
or, You can try to set fbcon=rotate:? proper value in /boot/firmware/cmdline.txt

2 Likes

Ok, I’ll give it a try and let you know. I’m outside now. Really appreciated :smiley:

Hi, I tried it myself. The line in my cmdline.txt was fbcon=rotate:1 and I changed the number according to this, but it doesn’t work.


My display setting in Xfce environment is the screenshot above.

When my uconsole wakes up, the screen rotates back, and the Rotation setting in the Display setting goes back to ‘none’ state, but fbcon=rotate is still ‘1’.

Do you think fbcon=rotate is related to the screen rotation setting in Xfce?
Thanks again! :grin:

When the DRM panel power is forcibly turned off and detected again, compositor the desktop environment will initialize to draw the screen.
If you have the default rotation setting at the initialization stage, it will remain in the original state even if you turn off and on the screen.
You can try taking reference to the following and search for relevant information.

1 Like

Release v1.2

Full Changelog: v1.1…v1.2

  • Feature customization
    $ sudo nano /etc/uconsole-sleep/config
    $ sudo systemctl restart sleep-remap-powerkey.service
    $ sudo systemctl restart sleep-power-control.service
    
  • Power saving CPU freq now follows a user-specified value, not available value.
4 Likes

OMG, it fianlly works!! Thanks for your working!! :heart_eyes:

2 Likes