Skip to content

Commit

Permalink
Improve hardware tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Callum committed Mar 26, 2014
1 parent 07415e2 commit b56dc43
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
7 changes: 3 additions & 4 deletions client.py
Expand Up @@ -12,7 +12,7 @@

GPIO.setmode(GPIO.BOARD)

INTERVAL = 3
INTERVAL = 2
HMAC_KEY = open(os.path.join(os.path.dirname(__file__),
".hmac_key")).read().strip()

Expand All @@ -38,7 +38,7 @@ def has_changed_state(self):

def call_server(url_params):
data = json.dumps(url_params)
requests.post(os.getenv("ITTF_API_URL"), params={
requests.post(os.getenv("ITTF_SERVER_URL"), params={
"data": data,
"token": hmac.new(HMAC_KEY, data, hashlib.sha256).hexdigest()
})
Expand All @@ -49,8 +49,7 @@ def call_server(url_params):

for c, p in leds.iteritems():
GPIO.setup(p, GPIO.OUT)

GPIO.output(leds["b"], False)
GPIO.output(p, False)

try:
while True:
Expand Down
11 changes: 6 additions & 5 deletions hardware_tests/leds.py
@@ -1,7 +1,7 @@
#!/usr/env/bin python

from RPi import GPIO
import time
from time import sleep

GPIO.setmode(GPIO.BOARD)

Expand All @@ -11,17 +11,18 @@
GPIO.setup(p, GPIO.OUT)
GPIO.output(p, False)

r, g, b = PINS

try:
r, g, b = PINS
while True:
GPIO.output(b, False)
GPIO.output(r, True)
time.sleep(1)
sleep(1)
GPIO.output(r, False)
GPIO.output(g, True)
time.sleep(1)
sleep(1)
GPIO.output(g, False)
GPIO.output(b, True)
time.sleep(1)
sleep(1)
except KeyboardInterrupt:
pass
17 changes: 13 additions & 4 deletions hardware_tests/switches.py
@@ -1,15 +1,24 @@
#!/usr/env/bin python

from RPi import GPIO
from time import sleep

GPIO.setmode(GPIO.BOARD)

PINS = (22, 24, 26)

latest_states = {}
for p in PINS:
GPIO.setup(p, GPIO.IN)
latest_states[p] = GPIO.input(p)

while True:
for p in PINS:
if GPIO.input(p):
print "%s on" % p
try:
while True:
for p in PINS:
state = GPIO.input(p)
if state and state != latest_states[p]:
print "%s on" % p
latest_states[p] = state
sleep(0.5)
except KeyboardInterrupt:
pass
2 changes: 1 addition & 1 deletion start
Expand Up @@ -6,4 +6,4 @@ if [ "$1" == "dev" ]; then
fi

echo $url
sudo ITTF_API_URL=$url python client.py
sudo ITTF_SERVER_URL=$url python client.py

0 comments on commit b56dc43

Please sign in to comment.