-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #376 from MiczFlor/develop
GPIO sample scripts (alongside wiki changes)
- Loading branch information
Showing
8 changed files
with
137 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/python3 | ||
from gpiozero import Button | ||
from signal import pause | ||
from subprocess import check_call | ||
|
||
# This script is compatible with any I2S DAC e.g. from Hifiberry, Justboom, ES9023, PCM5102A | ||
# Only Buttons that have dissimilar functions as the two encoder are enabled | ||
|
||
# 2018-10-15 | ||
# this script has the `pull_up=True` for all pins. See the following link for additional info: | ||
# https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/259#issuecomment-430007446 | ||
# | ||
# 2017-12-12 | ||
# This script was copied from the following RPi forum post: | ||
# https://forum-raspberrypi.de/forum/thread/13144-projekt-jukebox4kids-jukebox-fuer-kinder/?postID=312257#post312257 | ||
# I have not yet had the time to test is, so I placed it in the misc folder. | ||
# If anybody has ideas or tests or experience regarding this solution, please create pull requests or contact me. | ||
|
||
def def_shutdown(): | ||
check_call("./scripts/playout_controls.sh -c=shutdown", shell=True) | ||
|
||
def def_halt(): | ||
check_call("./scripts/playout_controls.sh -c=playerpause", shell=True) | ||
|
||
shut = Button(3, hold_time=2) | ||
halt = Button(24,pull_up=True) | ||
|
||
shut.when_held = def_shutdown | ||
halt.when_pressed = def_halt | ||
|
||
pause() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
misc/sampleconfigs/phoniebox-idle-watchdog-countdown.service.sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[Unit] | ||
Description=Phoniebox Idle Watchdog Countdown Service | ||
|
||
[Service] | ||
User=pi | ||
Group=pi | ||
Type=simple | ||
WorkingDirectory=/home/pi/RPi-Jukebox-RFID | ||
ExecStart=/home/pi/RPi-Jukebox-RFID/scripts/idle-watchdog-countdown.sh | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/bash | ||
|
||
# This is a mpd idle watchdog to shutdown the box. | ||
# | ||
# Phonieboxes without reliable system time can use this idle-watchdog-script to | ||
# shutdown the box after a pre defined number of minutes. | ||
# This script checks every 60 seconds if mpd is paying music with volume set to | ||
# greater than 0. If not it decreases the pre-defined number of minutes and shut | ||
# down the box if it reaches zero. | ||
# Be aware that playing lots of short sequences (less than 60 seconds) could be | ||
# undetected by this script and lead to an unwanted shutdown. | ||
|
||
# Check for idle time settings. Assume to disable automatic shudown if not set. | ||
if [ ! -r ./settings/Idle_Time_Before_Shutdown ]; then | ||
logger "Idle_Time_Before_Shutdown is not set. Disable idle watchdog!" | ||
exit 0 | ||
else | ||
SHUTDOWNAFTER=$(cat ./settings/Idle_Time_Before_Shutdown | head -n 1) | ||
fi | ||
|
||
# Check if setting is a numeric value; else warn and disable watchdog. | ||
[ "$SHUTDOWNAFTER" -eq "$SHUTDOWNAFTER" ] 2>/dev/null | ||
if [ $? -ne 0 ]; then | ||
logger "Invalid settings for Idle_Time_Before_Shutdown (not numeric). Disable idle watchdog!" | ||
exit 0 | ||
fi | ||
|
||
COUNTDOWN=$SHUTDOWNAFTER # initialize countdown value | ||
|
||
# start the continuous loop | ||
while [ $SHUTDOWNAFTER -gt 0 ]; do | ||
# check if mpd is playing and volume is not 0 | ||
if [ $(mpc | egrep -c '^\[playing\]') -eq 1 ] && [ $(mpc | egrep -c '^volume:\s+0%') -eq 0 ]; then | ||
if [ $COUNTDOWN -ne $SHUTDOWNAFTER ]; then | ||
logger "mpd is playing audible again. Stop countdown to shutdown." | ||
fi | ||
COUNTDOWN=$SHUTDOWNAFTER # re-init countdown | ||
else | ||
if [ $COUNTDOWN -gt 0 ]; then | ||
logger "mpd is NOT playing audible. Shutdown in $COUNTDOWN minutes." | ||
else | ||
logger "mpd was NOT playing audible for $SHUTDOWNAFTER minutes. Shutdown system!" | ||
./scripts/playout_controls.sh -c=shutdownsilent | ||
exit 0 | ||
fi | ||
COUNTDOWN=$(expr $COUNTDOWN - 1) | ||
fi | ||
sleep 60 | ||
done | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters