SLEEP support development for CM4

I had a play around with this too for KDE Wayland and didn’t get too much further.

  • I bound the sleep.sh to a custom keyboard shortcut instead of the power button. For note I would ssh the scripts just to confirm it was not keyboard shortcut affecting the tests below.
  • I did get kscreen-doctor to turn off the screen but the call never exits, despite my best efforts, and thus I couldn’t get the screen back on without rebooting. I have read this is a known issue and is fixed in Plasma 6 (I think)
  • I opted for the dim/undim screen route, turn Bluetooth off/on, switch to powersave and was using that for a while
  • I couldn’t get the killing processes to work as again despite my best efforts I must have always been killing something vital as once invoked I had to reboot to recover.

Since my latest install though I haven’t bothered with the sleep because despite everything i did I didn’t notice and real change in battery usage over stock KDE management

I would be interested to see what results people are getting from custom sleep over stock, if anyone has any data to share.

1 Like

Interesting, I suppose there is no workaround (for the time being) if you use KDE.

I decided to switch to X11 instead of Wayfire because the scaling on X11 is way better and uniform and it helps me read stuff better (I have Presbyopia. )
I was determined to use Wayland because I’ve read a bit about it and it seemed to be theoretically more efficient, based on its architecture, but I couldn’t really benchmark it so it was just a hunch.

In any case, without knowing how to map the Shellscript to the power button and without being able to exit the qsleep state through keyboard, this specific script is unusable in KDE. I’ll try to replicate your script (in KDE) based on what you mentioned you did

  • Turn off screen
  • Turn off WiFi
  • Turn off BlueTooth
  • Enter powersave

Not only because I want to save battery life, but because I want to be able to “turn off the device” in a quick way and still save the state of my work and avoid a rise of temperature if I have to put the uConsole inside a backpack.

This scenario is common for me. I’m fiddling with the uConsole, I have terminals and browsers open, maybe emacs, and my wife tells me she’s ready to go, so I would like to “turn off” and “turn it on” on a whim.

Wait, but it is my understanding that hibernate is not supported on the CM4, and that’s why this script was created.

Sources:
Supespend and battery life - uConsole - clockworkpi

Also, I decided to try sudo systemctl hibernate. I got this error: Call to Hibernate failed: Sleep verb "hibernate" not supported. I also tried the suspend variant and got the same error.

I tried to map a shortcut to the Hibernate action in Settings → Workspace → Shortcuts → Power Management, but I only got the screen to “turn off” (Mouse was still visible) and the behaviour was funky overall (Ctrl + Alt would return the screen back to normal, pressing the power button would bring the shutdown menu) so yeah… hibernate doesn’t really seem to be implemented.

I went back and looked at my last code and what I did was link power saving to lockscreen. I set up a listener for change in state of lockscreen and then ran powersave settings on lock, and return to normal on unlock. I wasn’t doing anything to turn off the screen, just relying on the power settings for the lockscreen to take care of this.

I ended up using 2 scripts, a python one for the listener and bash for the power saving. I couldn’t get the power savings to be noticeably different to just locking screen but here is my code if it is of nay use

lockread.sh

#!/usr/bin/env python3

import dbus
from dbus.mainloop.glib import DBusGMainLoop
import os

powersave_on = False

def screensaver_changed(state):
    global powersave_on
    """This method is called when the screensaver starts/stops (for some reason gets called twice for each change)"""
    screensaver = session_bus.get_object('org.freedesktop.ScreenSaver', '/ScreenSaver')
    active = screensaver.GetActive()
    print("ScreenSaver is " + ("on" if active else "off"))
    if active and not powersave_on:
        os.system("~/.config/myscripts/powersave.sh on")
        powersave_on = True
    elif not active and powersave_on:
        os.system("~/.config/myscripts/powersave.sh off")
        powersave_on = False

DBusGMainLoop(set_as_default=True)
session_bus = dbus.SessionBus()
session_bus.add_signal_receiver(screensaver_changed, 'ActiveChanged', 'org.freedesktop.ScreenSaver')

from gi.repository import GLib
loop = GLib.MainLoop()
loop.run()

powersave.sh you could add WiFi off and on here

#!/bin/bash

if [ $1 = "on" ]; then
    echo "powersave" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
    bluetoothctl power off
elif [ $1 = "off" ]; then
    echo "ondemand" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
    bluetoothctl power on
fi
1 Like

I might try it… when I fix the disaster I made hahaha.
I changed the behaviour of the power button through KDE settings and linked it to a shutdown now shellscript.
As soon as I did that, the uConsole turned off and now, whenever gdm finishes loading … I think the button event is called? I can’t get to the desktop because the uConsole turns off itself hahaha. ( suspect the shell is called)

I am currently looking for a way to interupt the load of GDM or maybe jump directly into TTY os that I can modify the script and comment the command, but I haven’t found a way to do so. If I can’t find a way to do it, then I will try to read the filesystem with my fedora laptop at home and edit the script.
If even that laptop can’t read the filesystem (I tried on my phone but I couldn’t see any file per se) then I will just wipe out the card with Rex’s image again… I mean, it’s no big deal but I want to learn how to boot into terminal in cases of emergency where you can’t or should not load the UI at all despite having one.

But I think I will open a new thread and stop chnaging the subject of this topic even more.

You will be able to read the file system, either the uSD or eMMC, on your Fedora laptop and modify the script

1 Like

wow, i’m sorry, I couldn’t imagined that something can doesn’t support event hibernating in modern times.

my fault.

I know right! haha, but it’s part of the fun I guess. :joy:

1 Like
1 Like

I have some questions

  • What’s the right way to go? using scaling_governor or scaling_max_freq?
  • Also, should I use only cpu0 and cpu1 or cpu* (seeing my cpu folder has 4 cpu subfolders 0 …3)
  • In which section should one write the over_voltage_min, arm_freq_min and gpu_freq_min lines.
  • When do those values (previous line) go back to normal? Does the OS know they’re just for idle?

I’m trying to make my custom sh jus because, but I am curious as to why people uses different files and configs.

because they want to write their own custom shell scripts :joy: :rofl: :grin:

Hahaha seems like it’s a common practice :rofl: