Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # Suspends and Resumes XBMC based on Monitor status
- # By Ari Asulin ([email protected])
- # */15 * * * * /etc/init.d/sleeptest.sh
- if [ $(pidof -x sleeptest.sh| wc -w) -gt 2 ]; then
- echo "Script currently running. Exiting..."
- exit
- fi
- cmdMonitor="/opt/vc/bin/tvservice -s" # command to check monitor status
- cmdWake="/sbin/initctl start xbmc" # command to resume xbmc
- cmdSleep="/sbin/initctl stop xbmc" # command to suspend xbmc
- evtSleep="HPD low" # change this based on the signals your monitor sends
- evtWake="HPD high" # when turned on and off
- sleepDelay=30 # Waiting period after monitor off. Must be < 60
- checkDelay=5 # 5 Seconds = average of 2.5 second response
- echo "Starting XBMC HDMI Monitor..."
- echo " If this hangs with no output, most likely tvservice is broken and you'll need to restart it"
- while true; do # Forever loop
- # Get XBMC PID if its running
- PID=`ps -A | grep xbmc.bin | awk '{print $1}'`
- # Check for Monitor Off Signal
- if $cmdMonitor | grep "$evtSleep" > /dev/null; then
- # Monitor is Off, check to see if XBMC is running
- echo "HDMI Monitor is Off"
- if [ $PID ]; then
- # XBMC is running with monitor off, so wait a bit
- echo "XBMC is running [$PID]. Waiting $sleepDelay Seconds..."
- sleep $sleepDelay
- # Check to see if the monitor is still off
- if $cmdMonitor | grep "$evtSleep" > /dev/null; then
- # The monitor didn't come back on, so suspend
- echo "HDMI Monitor is still off. Suspending XBMC..."
- $cmdSleep
- else
- # Looks like the monitor came back on while we were waiting, so do nothing.
- echo "HDMI Monitor came back on during waiting period. Doing nothing..."
- fi
- else
- # XBMC is not running and the monitor is off, so do nothing.
- echo "XBMC is not running"
- fi
- # Check for Monitor On Signal
- elif $cmdMonitor | grep "$evtWake" > /dev/null; then
- # Monitor is On, check to see if XBMC is running
- echo "HDMI Monitor is On"
- if [ $PID ]; then
- # XBMC is running, so we can exit
- echo "XBMC is running [$PID]. Exiting..."
- sleep 60 # We're done, so sleep for a while
- else
- # XBMC is not running, but the monitor is on, so resume xbmc
- echo "XBMC is not running. Resuming..."
- $cmdWake
- sleep 60 # We're done, so sleep for a while
- fi
- else
- # If you get this status, run tvservice -s with the monitor on and off
- # to figure out what strings to look for
- echo "HDMI Monitor Status Unknown"
- fi
- # If nothing else is going on, sleep
- echo "Sleeping $checkDelay Seconds..."
- sleep $checkDelay
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement