Skip to content

Commit bb1cea5

Browse files
empejedogi
authored andcommitted
update treehouses button (fixes #193) (#194)
1 parent b13dfcd commit bb1cea5

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@treehouses/cli",
3-
"version": "1.2.3",
3+
"version": "1.2.4",
44
"description": "Thin command-line interface for Raspberry Pi low level configuration.",
55
"main": "cli.sh",
66
"bin": {

templates/gpio-button.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,33 @@
55
import time
66
import subprocess
77

8+
ESTIMATED_STATE_DIFF_DURATION = 1
9+
ESTIMATED_PIN_CALLBACK_DURATION = 15
10+
811
GPIO.cleanup()
912
GPIO.setmode(GPIO.BOARD)
1013
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
1114

1215
prevState = None
1316
while True:
1417
state = GPIO.input(18)
18+
# sleep in the loop is related to how fast the command in the block run
1519
if prevState == state:
20+
time.sleep(ESTIMATED_STATE_DIFF_DURATION)
1621
continue
1722
elif state == 1:
1823
print "Pin is on"
1924
try:
2025
subprocess.check_output(['bash', '/etc/gpio-button-action-on.sh'])
2126
except:
2227
pass
23-
time.sleep(15)
28+
time.sleep(ESTIMATED_PIN_CALLBACK_DURATION)
2429
else:
2530
print "Pin is off"
2631
try:
2732
subprocess.check_output(['bash', '/etc/gpio-button-action-off.sh'])
2833
except:
2934
pass
30-
time.sleep(15)
35+
time.sleep(ESTIMATED_PIN_CALLBACK_DURATION)
3136

3237
prevState = state

0 commit comments

Comments
 (0)