Created
December 6, 2022 21:38
-
-
Save joshwlewis/e0b24b14ec74552d42372634184a767b to your computer and use it in GitHub Desktop.
Falcon Player GPIO DO_NOT_PRESS Button Scripts
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
#!/bin/bash | |
# do-not-press-down.sh runs when the physical DO NOT PRESS button is depressed. | |
# This is designed to provide feedback as to whether or not the button release | |
# will activate a sequence. If the $PREFIX is not already playing, this runs | |
# an ok sound + effect. If $PREFIX is already playing (somebody is spamming | |
# the button), this runs an err sound + effect. Either way, the sound + effect | |
# will play in the background without interrupting anything already playing. | |
# For this reason, use short sounds and sequences with this script (under 1 | |
# second). | |
shopt -s nullglob | |
PREFIX="do-not-press" | |
if [[ $(fpp -s | cut -d ',' -f 4) == "$PREFIX"* ]]; then | |
echo "Already playing $PREFIX. Selecting err media." | |
EFFECTS=("$MEDIADIR/sequences/$PREFIX-err"*) | |
SOUNDS=("$MEDIADIR/music/$PREFIX-err"*) | |
else | |
echo "Not playing $PREFIX. Selecting ok media." | |
EFFECTS=("$MEDIADIR/sequences/$PREFIX-ok"*) | |
SOUNDS=("$MEDIADIR/music/$PREFIX-ok"*) | |
fi | |
COUNT=$((${#EFFECTS[@]} < ${#SOUNDS[@]} ? ${#EFFECTS[@]} : ${#SOUNDS[@]})) | |
RAND_IDX=$(($RANDOM % $COUNT)) | |
SOUND=${SOUNDS[$RAND_IDX]} | |
if [ -n "${SOUND}" ]; then | |
echo "Playing $SOUND" | |
fpp -C "Play Media" "$SOUND" 1 0 | |
fi | |
EFFECT=${EFFECTS[$RAND_IDX]} | |
EFFECT_NAME=$(basename "$EFFECT" | cut -d "." -f1) | |
if [ -n "${EFFECT_NAME}" ]; then | |
echo "Playing $EFFECT_NAME" | |
fpp -C "FSEQ Effect Start" "$EFFECT_NAME" 0 1 | |
fi |
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
#!/bin/bash | |
# do-not-press-up.sh runs when the physical DO NOT PRESS button is released. | |
# This script is designed to trigger only one $PLAYLIST item per push. Each | |
# successive run of this script should play the next $PLAYLIST item or cycle | |
# back to the beginning. If a $PLAYLIST item is already playing (probably from | |
# a previous button push), this script will stop that item, returning to | |
# whatever was running prior to starting the last $PLAYLIST item. | |
shopt -s nullglob | |
PLAYLIST="do-not-press" | |
if [[ $(fpp -s | cut -d ',' -f 4) == *"$PLAYLIST"* ]]; then | |
echo "Already playing $PLAYLIST. Stopping Now." | |
fpp -C "Stop Now" | |
exit 0; | |
fi | |
COUNTER_FILE="$MEDIADIR/$PLAYLIST-count.txt" | |
if [ -f $COUNTER_FILE ]; then | |
PLAY_COUNT=$(<$COUNTER_FILE) | |
else | |
PLAY_COUNT="0" | |
fi | |
echo "PLAY_COUNT: $PLAY_COUNT" | |
echo -n "$(($PLAY_COUNT+1))" > $COUNTER_FILE | |
ITEM_COUNT=$(grep "total_items" "$MEDIADIR/playlists/$PLAYLIST.json" | cut -d ':' -f 2 | xargs) | |
NEXT_IDX=$(($PLAY_COUNT % $ITEM_COUNT)) | |
START_IDX=$(($NEXT_IDX + 1)) | |
END_IDX=$(($START_IDX + 1)) | |
echo "Playing $PLAYLIST from $START_IDX to $END_IDX" | |
fpp -C "Insert Playlist Immediate" $PLAYLIST $START_IDX $END_IDX 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment