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

Removed unneccesary on/off parameter

parent d52c0ff8
......@@ -30,21 +30,26 @@ def main():
# 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):
change_pin = int(change_pin)
device_name = pins[change_pin]['name']
print("Input value before change: " + str(GPIO.input(change_pin)))
if action == "on":
GPIO.output(change_pin, GPIO.HIGH)
message = "Turned " + device_name + " on."
if action == "off":
GPIO.output(change_pin, GPIO.LOW)
message = "Turned " + device_name + " off."
if action == "toggle":
GPIO.output(change_pin, not GPIO.input(change_pin))
message = "Toggled " + device_name + "."
# if action == "on":
# GPIO.output(change_pin, GPIO.HIGH)
# message = "Turned " + device_name + " on."
# if action == "off":
# GPIO.output(change_pin, GPIO.LOW)
# message = "Turned " + device_name + " off."
# if action == "toggle":
GPIO.output(change_pin, not GPIO.input(change_pin))
message = "Turned " + device_name
if GPIO.input(change_pin) == 0:
message += "off."
else:
message += "on."
for pin in pins:
pins[pin]['state'] = GPIO.input(pin)
......
......@@ -9,9 +9,9 @@
{% for pin in pins %}
<p>The {{ pins[pin].name }}
{% 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 %}
is currently off (<a href="/{{pin}}/on">turn on</a>)
is currently off (<a href="/{{pin}}">turn on</a>)
{% endif %}
</p>
{% 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