Skip to content

Commit

Permalink
add support for different monitor turn off tools in raspi-monitor.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
sdetweil committed Apr 1, 2021
1 parent 1ab0f08 commit 46dda93
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 44 deletions.
1 change: 1 addition & 0 deletions motion.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ if (
// "calibrated" occurs once, at the beginning of a session,
motion.on("calibrated", function () {
console.log("!c:", "calibrated")
console.log("!e:", "motionend")
})

// "motionstart" events are fired when the "calibrated"
Expand Down
79 changes: 41 additions & 38 deletions plugins/autosleep/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,31 @@
};

service.wake = function () {
if(config.autoTimer.mode!=='disabled'){
if(config.autoTimer.mode!=='disabled'){
// only wake up if sleeping
if (Focus.get() === 'sleep') {
service.woke = true;
if (config.autoTimer.mode == "monitor") {
service.exec(config.autoTimer.wakeCmd, service.puts);
Focus.change('default');
} else if (config.autoTimer.mode == "tv") {
Focus.change('default');
} else if (config.autoTimer.mode == "energy") {
Focus.change('default')
// if the timer was running
if (energyStarTimer != null) {
// stop it
$interval.cancel(energyStarTimer)
energyStarTimer = null;
}
// if the dummy wake up delay is running, stop it too
if (energyStarTimerStop != null) {
$interval.cancel(energyStarTimerStop)
}
switch(config.autoTimer.mode){
case "monitor":
case "tv":
service.exec(config.autoTimer.wakeCmd, service.puts);
Focus.change('default');
break;
case "energy":
Focus.change('default')
// if the timer was running
if (energyStarTimer != null) {
// stop it
$interval.cancel(energyStarTimer)
energyStarTimer = null;
}
// if the dummy wake up delay is running, stop it too
if (energyStarTimerStop != null) {
$interval.cancel(energyStarTimerStop)
}
break;
default:
Focus.change('default')
}
}
}
Expand All @@ -74,7 +78,7 @@
$interval.cancel(energyStarTimerStop)
// cancel to long timer
$interval.cancel(energyStarTimer)
// restart it, so we don't drift towards 0 delay
// restart it, so we don't drift towards 0 delay
energyStarTimer = $interval(bleep, energyStarDelay);
// restart the main sleep timer
service.startAutoSleepTimer();
Expand All @@ -88,27 +92,26 @@
}

service.sleep = function () {
if(config.autoTimer.mode!=='disabled'){
if(config.autoTimer.mode!=='disabled'){
service.woke = false;
if (config.autoTimer.mode == "monitor") {
service.exec(config.autoTimer.sleepCmd, service.puts);
Focus.change("sleep")
} else if (config.autoTimer.mode == "tv") {
Focus.change('sleep')
} else if (config.autoTimer.mode == "energy") {
Focus.change("sleep");
if (energyStarTimer == null) {
energyStarTimer = $interval(bleep, energyStarDelay);
} else {
$interval.cancel(energyStarTimer)
energyStarTimer = $interval(bleep, energyStarDelay);
}
} else {
Focus.change("default");
switch(config.autoTimer.mode){
case "monitor":
case "tv":
service.exec(config.autoTimer.sleepCmd, service.puts);
Focus.change("sleep")
break;
case "energy":
Focus.change("sleep");
if (energyStarTimer == null) {
energyStarTimer = $interval(bleep, energyStarDelay);
} else {
$interval.cancel(energyStarTimer)
energyStarTimer = $interval(bleep, energyStarDelay);
}
break;
default:
Focus.change("default");
}
} else {
Focus.change("default");
}
};

service.puts = function (error, stdout, stderr) {
Expand Down
35 changes: 29 additions & 6 deletions scripts/raspi-monitor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,42 @@
# Script to enable and disable the HDMI signal of the Raspberry PI

CMD="$1"
type=cec-utils

function on {
/opt/vc/bin/tvservice --preferred

# Hack to enable virtual terminal nr 7 again:
chvt 6
chvt 7
case $type
'tvservice')
tvservice -p && sudo chvt 6 && sudo chvt 7
;;
'dpms')
DISPLAY=:0 xset dpms force on
;;
'vcgencmd')
/usr/bin/vcgencmd display_power 1
;;
'cec-utils')
echo 'on 0' | cec-client -s
;;
esac
}

function off {
/opt/vc/bin/tvservice --off
case $type
'tvservice')
tvservice -o
;;
'dpms')
DISPLAY=:0 xset dpms force off
;;
'vcgencmd')
/usr/bin/vcgencmd display_power 0
;;
'cec-utils')
echo 'standby 0' | cec-client -s
;;
}


function must_be_root {
if [ $USER != root ]; then
echo "ERROR: Script must be executed as the root user"
Expand Down

0 comments on commit 46dda93

Please sign in to comment.