Created
July 19, 2019 14:15
-
-
Save manekinekko/2da533f0e1909e33a86b06766001d3d2 to your computer and use it in GitHub Desktop.
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/ash | |
# set the input pin | |
IN_PIN=19 | |
WEBHOOK=https://my-awesome-endpoint.dev/build-id | |
LOCK_FILE=/tmp/yolo.lock | |
# set the state direction of the pin | |
fast-gpio set-input $IN_PIN | |
while true | |
do | |
# get the state value '0' or '1' from the pin | |
# - '0': means the button is pressed | |
# - '1': means the button is relased | |
# NOTE: make sure the 'GPI19' string matches the $PIN number | |
state=$(fast-gpio read $IN_PIN | awk '/Read GPI19:/ {print $4}') | |
# if the pin state is '0', this means the button is being pressed | |
if [ "$state" = "0" ]; then | |
echo "YOLO Button Engaged..." | |
if [ -f "$LOCK_FILE" ]; then | |
# check if the button is already in lock mode (the button is pressed and locked) | |
# in this case, we just show the followingg message and skip. | |
echo "Command Loaded & Locked!" | |
echo ">Release Button to Cancel." | |
else | |
# when the button is pressed and not in lock mode, | |
# we go ahead and ping the $WEBHOOK url AND create a lock file. | |
curl -X POST -d {} $WEBHOOK | |
touch $LOCK_FILE | |
echo "Engaging Command..." | |
fi | |
else | |
# if the pin state is '1', this means the button is being released | |
# we delete the lock file to clear the state | |
[ -f $LOCK_FILE ] && rm $LOCK_FILE | |
echo "YOLO Button ready!" | |
fi | |
sleep 1 | |
clear | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment