Last active
November 1, 2025 15:36
-
-
Save joshwlewis/e0b24b14ec74552d42372634184a767b to your computer and use it in GitHub Desktop.
Falcon Player GPIO DO_NOT_PRESS Button Scripts
This file contains hidden or 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 $TARGET_PLAYLIST is not already playing, this runs | |
| # an ok sound + effect. If $TARGET_PLAYLIST 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 | |
| PRIMARY_PLAYLIST="show" | |
| TARGET_PLAYLIST="do-not-press" | |
| REMOTE_PLAYLIST="remote" | |
| TMPDIR=/var/tmp | |
| DOWN_FILE="$TMPDIR/$TARGET_PLAYLIST-down.txt" | |
| INT_FILE="$TMPDIR/$PRIMARY_PLAYLIST-interrupt.txt" | |
| CURRENT_PLAYLIST=$(curl -s http://fpp.local/api/fppd/status | jq -r '.current_playlist.playlist') | |
| NEXT_INT_AT=$(<"$INT_FILE") | |
| DOWN_AT=$(date +%s.%N) | |
| echo -n "$DOWN_AT" >"$DOWN_FILE" & | |
| if [[ $CURRENT_PLAYLIST == "$TARGET_PLAYLIST" || | |
| $CURRENT_PLAYLIST == "$REMOTE_PLAYLIST" || | |
| ($CURRENT_PLAYLIST == "$PRIMARY_PLAYLIST" && $(echo "$DOWN_AT < $NEXT_INT_AT" | bc -l) -eq 1) ]]; then | |
| echo "Selecting err media." | |
| EFFECTS=("$MEDIADIR/sequences/$TARGET_PLAYLIST-err"*) | |
| SOUNDS=("$MEDIADIR/music/$TARGET_PLAYLIST-err"*) | |
| else | |
| echo "Selecting ok media." | |
| EFFECTS=("$MEDIADIR/sequences/$TARGET_PLAYLIST-ok"*) | |
| SOUNDS=("$MEDIADIR/music/$TARGET_PLAYLIST-ok"*) | |
| fi | |
| COUNT=$((${#EFFECTS[@]} < ${#SOUNDS[@]} ? ${#EFFECTS[@]} : ${#SOUNDS[@]})) | |
| RAND_IDX=$(($RANDOM % $COUNT)) | |
| SOUND=${SOUNDS[$RAND_IDX]} | |
| if [ -n "${SOUND}" ]; then | |
| SOUND_NAME=$(basename "$SOUND") | |
| echo "Playing sound $SOUND_NAME" | |
| curl "http://fpp.local/api/command/Play%20Media/${SOUND_NAME}/1/0" | |
| echo | |
| fi | |
| EFFECT=${EFFECTS[$RAND_IDX]} | |
| if [ -n "${EFFECT}" ]; then | |
| EFFECT_NAME=$(basename "$EFFECT" | cut -d "." -f1) | |
| echo "Playing effect $EFFECT_NAME" | |
| curl "http://fpp.local/api/command/FSEQ%20Effect%20Start/${EFFECT_NAME}/false/true" | |
| echo | |
| fi |
This file contains hidden or 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 $TARGET_PLAYLIST item per push. Each | |
| # successive run of this script should play the next $TARGET_PLAYLIST item or cycle | |
| # back to the beginning. | |
| # If $TARGET_PLAYLIST is already playing (probably from a previous button push), | |
| # it won't enqueue another $TARGET_PLAYLIST item. | |
| # If $TARGET_PLAYLIST is running and a long press is detected, that item will be | |
| # stopped and normally scheduled programming will resume. | |
| # This script will only interrupt the $PRIMARY_PLAYLIST every $MIN_INT_FREQUENCY. | |
| shopt -s nullglob | |
| TARGET_PLAYLIST="do-not-press" | |
| PRIMARY_PLAYLIST="show" | |
| REMOTE_PLAYLIST="remote" | |
| TMPDIR=/var/tmp | |
| LONG_PRESS_LENGTH=1500 | |
| MIN_INT_FREQUENCY="${1:-300000}" | |
| DOWN_FILE="$TMPDIR/$TARGET_PLAYLIST-down.txt" | |
| INT_FILE="$TMPDIR/$PRIMARY_PLAYLIST-interrupt.txt" | |
| UP_AT=$(date +%s.%N) | |
| CURRENT_PLAYLIST=$(curl -s http://fpp.local/api/fppd/status | jq -r '.current_playlist.playlist') | |
| NEXT_INT_AT=$(<"$INT_FILE") | |
| if [[ "$CURRENT_PLAYLIST" == "$TARGET_PLAYLIST" ]]; then | |
| echo "Already playing $TARGET_PLAYLIST." | |
| DOWN_AT=$(<"$DOWN_FILE") | |
| PRESS_LENGTH=$(echo "(${UP_AT} * 1000) - (${DOWN_AT} * 1000)" | bc | cut -f1 -d\.) | |
| if (($PRESS_LENGTH > $LONG_PRESS_LENGTH)); then | |
| echo "Stopping $TARGET_PLAYLIST playlist now" | |
| curl "http://fpp.local/api/command/Stop%20Now" | |
| fi | |
| exit 0 | |
| elif [[ "$CURRENT_PLAYLIST" == "$REMOTE_PLAYLIST" ]]; then | |
| echo "Not interrupting $REMOTE_PLAYLIST playlist requests" | |
| exit 0 | |
| elif [[ "$CURRENT_PLAYLIST" == "$PRIMARY_PLAYLIST" ]]; then | |
| if [[ $(echo "$UP_AT < $NEXT_INT_AT" | bc -l) -eq 1 ]]; then | |
| echo "Not interrupting $PRIMARY_PLAYLIST playlist. It's happened recently." | |
| exit 0 | |
| fi | |
| fi | |
| COUNTER_FILE="$TMPDIR/$TARGET_PLAYLIST-count.txt" | |
| if [ -f $COUNTER_FILE ]; then | |
| PLAY_COUNT=$(<$COUNTER_FILE) | |
| else | |
| PLAY_COUNT="0" | |
| fi | |
| PLAY_COUNT=$(($PLAY_COUNT + 1)) | |
| echo -n "$PLAY_COUNT" >$COUNTER_FILE & | |
| ITEM_COUNT=$(grep "total_items" "$MEDIADIR/playlists/$TARGET_PLAYLIST.json" | cut -d ':' -f 2 | xargs) | |
| IDX=$((($PLAY_COUNT % $ITEM_COUNT) + 1)) | |
| echo "Playing $TARGET_PLAYLIST item $IDX" | |
| curl "http://fpp.local/api/command/Insert%20Playlist%20Immediate/${TARGET_PLAYLIST}/${IDX}/${IDX}/0" | |
| # Store the timestamp at which the next interrupt can happen | |
| printf %s "$(date --date="+$((MIN_INT_FREQUENCY / 1000)) seconds" +%s.%N)" >$INT_FILE & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment