Screen blanking and Shutdownscript
-
Hi There!
Found a neat Script here: https://retropie.org.uk/forum/post/148439
Thanks @QuixoticDevI modified the Script to look for additional Controllers and to shut down the Pi after a customizeable Period.
Perhaps it is useable for anyone - so here is the Moified Script:
#!/bin/bash #============================================================= # Title : idle-screenoff.sh # # Description : Power off the display when idle # - Detects idle by monitoring joystick input # Base-Script: # Author : QuixoticDev # Version : v1.0 - 05/23/2018 # # Extended and modified by: Aut0mat3d # Version : v1.1e - 02/06/2024 #============================================================= #-------------------- # User Variables #-------------------- # inputDevice = Device to monitor for activity # - Tested with XBOX 360 Controller (first joystick js0) inputDevice1=/dev/input/js0 inputDevice2=/dev/input/js1 inputDevice3=/dev/input/js2 # inputWindow = Time window (s) to monitor the device for input # - Check for input in a 5 second window inputWindow=2 # inputCount = How many inputs constitute activity + 1 # - Add 1 to desired, might be XBOX 360 unique behavior inputCount=2 # inputInterval = Time interval (s) between input checks # - Wait 30 seconds between idle input checks inputInterval=12 # inactivityTimeout = Idle time before powering off screen idleTimeoutM=15 # Power Device off after n Minutes (in Total) powerOffTimeoutM=60 # The Command to run when powerOffTimeout is reached powerOffCommand="/opt/retroflag-picase/shutdown.sh power" #-------------------- # Script Variables #-------------------- # Dont change idleTimeoutS=$(( ${idleTimeoutM} * 60 )) PowerOffTimeoutS=$(( ${powerOffTimeoutM} * 60 )) idleFlag=0 #-------------------- # Loop Forever #-------------------- while true; do # Check if HDMI is ON # 1 = ON # 0 = OFF tvStatus=$(vcgencmd display_power | awk -F'=' '{print $2}' ) #echo "tvStatus" #echo $tvStatus if [ ${tvStatus} -eq 1 ]; then #------------------------------------------------------------------------- # HDMI Status = ON #------------------------------------------------------------------------- # - Query joystick for input with a timeout (inputWindow) # - Check if idle # - idle (first time) = start counter and set idle flag # - idle (subsequent) = Do nothing, keep looping # - Active = Reset idle flag # - Sleep between checks (inputInterval) # - Check if idle flag has been active for longer than the idleTimeoutM # - Longer = Shutdown Display # - Shorter = Keep looping #------------------------------------------------------------------------- # Check if joystick active # 0 = Joystick input detected, user active # 1 = Joystick device not available # 124 = No input received during inputWindow inputAcive1=$(timeout ${inputWindow} dd if=${inputDevice1} of=/dev/null count=${inputCount} >/dev/null 2>&1; echo $?) inputAcive2=$(timeout ${inputWindow} dd if=${inputDevice2} of=/dev/null count=${inputCount} >/dev/null 2>&1; echo $?) inputAcive3=$(timeout ${inputWindow} dd if=${inputDevice3} of=/dev/null count=${inputCount} >/dev/null 2>&1; echo $?) if [ ${inputAcive1} -eq 0 ] || [ ${inputAcive2} -eq 0 ] || [ ${inputAcive3} -eq 0 ]; then # Active - Clear idle flag #echo "Active" idleFlag=0 else # Not Active # Skip if already inactive if [ ${idleFlag} -eq 0 ]; then # Start timer SECONDS=0 # Set to state to inactive idleFlag=1 fi fi # Sleep sleep ${inputInterval} # Poweroff display if longer than timeout and idle if [ ${SECONDS} -ge ${idleTimeoutS} ] && [ ${idleFlag} -eq 1 ]; then vcgencmd display_power 0 fi else #------------------------------------------------------------------------- # HDMI Status = OFF #------------------------------------------------------------------------- # - Query joystick for input # - Block script until input is received # - If device is not valid return and keep checking # - If Activity is detected # - Yes = Power on display # - No = Sleep for a second and repeat #------------------------------------------------------------------------- # Check if joystick active # 0 = Joystick input detected, user active # 1 = Joystick device not available # 124 = No input received during inputWindow #inputAcive=$(dd if=${inputDevice} of=/dev/null count=${inputCount} >/dev/null 2>&1; echo $?) #if [ ${inputAcive} -eq 0 ]; then inputAcive1=$(timeout ${inputWindow} dd if=${inputDevice1} of=/dev/null count=${inputCount} >/dev/null 2>&1; echo $?) inputAcive2=$(timeout ${inputWindow} dd if=${inputDevice2} of=/dev/null count=${inputCount} >/dev/null 2>&1; echo $?) inputAcive3=$(timeout ${inputWindow} dd if=${inputDevice3} of=/dev/null count=${inputCount} >/dev/null 2>&1; echo $?) if [ ${inputAcive1} -eq 0 ] || [ ${inputAcive2} -eq 0 ] || [ ${inputAcive3} -eq 0 ]; then SECONDS=0 idleFlag=0 #echo "WakeDisplayUp" vcgencmd display_power 1 else #echo "Display off for " $SECONDS "Seconds" # Poweroff System if longer than timeout if [ ${SECONDS} -ge ${PowerOffTimeoutS} ]; then echo "CALL SHUTDOWN-SCRIPT:"$powerOffCommand; $powerOffCommand sleep 20 fi sleep 1 fi fi done;
Place it (as the originial) under /home/pi/idle-screenoff.sh
and make it executeable with chmod +xIn the Script you have to modify the Script which has to be run for powering off the Pi.
Modify this Line to your needs:powerOffCommand="/opt/retroflag-picase/shutdown.sh power"
I run the Script before ES starts.
Here is my /opt/retropie/configs/all/autostart.sh/home/pi/idle-screenoff.sh & emulationstation #auto
I hope someone does have a Use for that.
If you reply here, i cant guarantee to reply or react as i am chronically ill and disabled.All the Best, and Thanks for Retropie and ES
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.