flutter-pi icon indicating copy to clipboard operation
flutter-pi copied to clipboard

Turn off screen after certain time

Open danielkastberg opened this issue 11 months ago • 7 comments

I would like to turn off the screen after midnight. Is it possible since flutter pi runs without X11 or Wayland? I read online but all posts are mentioning something related to X11 or Wayland like "xset", "tvservice" or "xrandr" but no use since they require X11 or Wayland running.

Can this be done or do I have to turn the power off the PI during nighttime?

danielkastberg avatar Dec 25 '24 00:12 danielkastberg

You can take my example of turning the screen on and off on the Pi4 https://github.com/DisDis/dslideshow/tree/master/deb_factory/template_build_arm64/opt/dslideshow/scripts

DisDis avatar Dec 25 '24 08:12 DisDis

Thank you! I'm away from my PI but will test it when I get back. I used tvservice before and got "Can't find display" but then I know it should work for the flutter pi

danielkastberg avatar Dec 25 '24 23:12 danielkastberg

I had a similar case and thought I would share my solution. I am running a Pi 5 with the new Touch Screen Display 2 and I couldn't get any of the tools that people recommended (tvservice, xrandr etc.) but managed to find that I could change the brightness directly with the backlight class.

Under /sys/class/backlight/ I was able to find my display and then set the brightness to 0 or max_brightness. So In my case I can turn it off using echo 0 | sudo tee /sys/class/backlight/11-0045/brightness and turn it on with echo 20 | sudo tee /sys/class/backlight/11-0045/brightness

In my case I wanted "screensaver" functionality so changing the brightness worked wonderful since the display is on and reactive just no brightness. So I could just make a widget that lives at the top with a GestureDetector to trigger a timer. Your case might be a bit different though and brightness might not be enough.

tryy3 avatar Dec 31 '24 01:12 tryy3

You can take my example of turning the screen on and off on the Pi4 https://github.com/DisDis/dslideshow/tree/master/deb_factory/template_build_arm64/opt/dslideshow/scripts

tvservice doesn´t seem to be included anymore in Bookworm. Have been replaced with vcgencmd. Tried vcgencmd display_power 0 but vcgencmd only works with vc4-fkms-v3d.

I had a similar case and thought I would share my solution. I am running a Pi 5 with the new Touch Screen Display 2 and I couldn't get any of the tools that people recommended (tvservice, xrandr etc.) but managed to find that I could change the brightness directly with the backlight class.

Under /sys/class/backlight/ I was able to find my display and then set the brightness to 0 or max_brightness. So In my case I can turn it off using echo 0 | sudo tee /sys/class/backlight/11-0045/brightness and turn it on with echo 20 | sudo tee /sys/class/backlight/11-0045/brightness

In my case I wanted "screensaver" functionality so changing the brightness worked wonderful since the display is on and reactive just no brightness. So I could just make a widget that lives at the top with a GestureDetector to trigger a timer. Your case might be a bit different though and brightness might not be enough.

My display doesn´t show up in backlight, just an empty folder...

Also tried ddcutil but running ddcutil getvcp scan results in Display not found. I'm using the Wavesahre 11.9 inch touch display. https://www.waveshare.com/wiki/11.9inch_Touch_Monitor Maybe this screen just won´t work without X11...

danielkastberg avatar Jan 09 '25 19:01 danielkastberg

When running on a Raspberry Pi 3B+ with current Debian Bookworm, I would run kmsblank -c 0 to disable the display (which is connected via HDMI). But sadly this does not work:

Connector 0: blank
Failed to set DPMS: -13

When flutter-pi is not running, that command works and disables the display as expected (that tool waits for a keypress to resume the display). I assume because the way flutter-pi works, the command is "clashing" with my flutter app running.

Maybe this should be added into the docs somewhere, haven't found anything about this.

FibreFoX avatar Feb 02 '25 23:02 FibreFoX

I solved it with changing the display driver to fkms. dtoverlay=vc4-fkms-v3d and then I could control the power with vcgencmd vcgencmd display_power 0 && vcgencmd display_power 1 Not a sustainable solutions since the fkms has been deprecated but works for now. I'll try /sys/class/backlight/ and see if that can work with kms-driver

danielkastberg avatar Feb 03 '25 18:02 danielkastberg

@FibreFoX @danielkastberg I implemented first version. It works fine. https://github.com/ardera/flutter-pi/pull/478

DisDis avatar May 01 '25 19:05 DisDis