Skip to content

Commit

Permalink
update treehouses button (fixes #193) (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
empeje authored and dogi committed Nov 20, 2018
1 parent b13dfcd commit bb1cea5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@treehouses/cli",
"version": "1.2.3",
"version": "1.2.4",
"description": "Thin command-line interface for Raspberry Pi low level configuration.",
"main": "cli.sh",
"bin": {
Expand Down
9 changes: 7 additions & 2 deletions templates/gpio-button.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,33 @@
import time
import subprocess

ESTIMATED_STATE_DIFF_DURATION = 1
ESTIMATED_PIN_CALLBACK_DURATION = 15

GPIO.cleanup()
GPIO.setmode(GPIO.BOARD)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

prevState = None
while True:
state = GPIO.input(18)
# sleep in the loop is related to how fast the command in the block run
if prevState == state:
time.sleep(ESTIMATED_STATE_DIFF_DURATION)
continue
elif state == 1:
print "Pin is on"
try:
subprocess.check_output(['bash', '/etc/gpio-button-action-on.sh'])
except:
pass
time.sleep(15)
time.sleep(ESTIMATED_PIN_CALLBACK_DURATION)
else:
print "Pin is off"
try:
subprocess.check_output(['bash', '/etc/gpio-button-action-off.sh'])
except:
pass
time.sleep(15)
time.sleep(ESTIMATED_PIN_CALLBACK_DURATION)

prevState = state

0 comments on commit bb1cea5

Please sign in to comment.