Commit 3b88970e authored by Kristian Tan's avatar Kristian Tan

Removed unneccesary on/off parameter

parent d52c0ff8
...@@ -30,21 +30,26 @@ def main(): ...@@ -30,21 +30,26 @@ def main():
# The function below is executed when someone requests a URL with the pin number and action in it: # The function below is executed when someone requests a URL with the pin number and action in it:
@app.route("/<change_pin>/<action>") @app.route("/<change_pin>")
def action(change_pin, action): def action(change_pin, action):
change_pin = int(change_pin) change_pin = int(change_pin)
device_name = pins[change_pin]['name'] device_name = pins[change_pin]['name']
print("Input value before change: " + str(GPIO.input(change_pin))) print("Input value before change: " + str(GPIO.input(change_pin)))
if action == "on": # if action == "on":
GPIO.output(change_pin, GPIO.HIGH) # GPIO.output(change_pin, GPIO.HIGH)
message = "Turned " + device_name + " on." # message = "Turned " + device_name + " on."
if action == "off": # if action == "off":
GPIO.output(change_pin, GPIO.LOW) # GPIO.output(change_pin, GPIO.LOW)
message = "Turned " + device_name + " off." # message = "Turned " + device_name + " off."
if action == "toggle": # if action == "toggle":
GPIO.output(change_pin, not GPIO.input(change_pin)) GPIO.output(change_pin, not GPIO.input(change_pin))
message = "Toggled " + device_name + "."
message = "Turned " + device_name
if GPIO.input(change_pin) == 0:
message += "off."
else:
message += "on."
for pin in pins: for pin in pins:
pins[pin]['state'] = GPIO.input(pin) pins[pin]['state'] = GPIO.input(pin)
......
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
{% for pin in pins %} {% for pin in pins %}
<p>The {{ pins[pin].name }} <p>The {{ pins[pin].name }}
{% if pins[pin].state == true %} {% if pins[pin].state == true %}
is currently on (<a href="/{{pin}}/off">turn off</a>) is currently on (<a href="/{{pin}}">turn off</a>)
{% else %} {% else %}
is currently off (<a href="/{{pin}}/on">turn on</a>) is currently off (<a href="/{{pin}}">turn on</a>)
{% endif %} {% endif %}
</p> </p>
{% endfor %} {% endfor %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment