Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save manekinekko/2da533f0e1909e33a86b06766001d3d2 to your computer and use it in GitHub Desktop.

Select an option

Save manekinekko/2da533f0e1909e33a86b06766001d3d2 to your computer and use it in GitHub Desktop.

Revisions

  1. manekinekko created this gist Jul 19, 2019.
    47 changes: 47 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    #!/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