diff options
author | Sergiusz Bazański <q3k@q3k.org> | 2012-11-11 13:35:07 +0100 |
---|---|---|
committer | Sergiusz Bazański <q3k@q3k.org> | 2012-11-11 13:35:07 +0100 |
commit | 1ab422118cfacee567725e0f1244a66f30350e6d (patch) | |
tree | e55b1c97c407385fefca70e770d46df640b719ba | |
parent | 318fe0a9094b2624761d2f6f8de8f491305145bc (diff) | |
download | laserz_und_stuff-1ab422118cfacee567725e0f1244a66f30350e6d.tar.gz laserz_und_stuff-1ab422118cfacee567725e0f1244a66f30350e6d.tar.bz2 laserz_und_stuff-1ab422118cfacee567725e0f1244a66f30350e6d.tar.xz laserz_und_stuff-1ab422118cfacee567725e0f1244a66f30350e6d.zip |
Basic web control.
-rw-r--r-- | Lasers_und_stuff/Cannon.py | 9 | ||||
-rw-r--r-- | Lasers_und_stuff/main.py | 43 |
2 files changed, 50 insertions, 2 deletions
diff --git a/Lasers_und_stuff/Cannon.py b/Lasers_und_stuff/Cannon.py index b997284..f124ce6 100644 --- a/Lasers_und_stuff/Cannon.py +++ b/Lasers_und_stuff/Cannon.py @@ -5,10 +5,19 @@ Created on Nov 11, 2012 ''' import serial import glob +import threading from math import ceil +def mutex(m): + def wrapper(self, *args, **kwargs): + self.s.acquire() + m() + self.s.release() + return wrapper + class CannonController : def __init__(self): + self.s = threading.Semaphore() print("cannon controller started") self.position = [0, 0] self.fired = False diff --git a/Lasers_und_stuff/main.py b/Lasers_und_stuff/main.py index 4869d96..15ab4e3 100644 --- a/Lasers_und_stuff/main.py +++ b/Lasers_und_stuff/main.py @@ -10,6 +10,7 @@ import flask import threading import os import signal +import json from pygame.locals import * from Cannon import CannonController from Cannon import Gunpoint @@ -18,9 +19,47 @@ app = flask.Flask(__name__) app.debug = True pygame.init() +cannon = None + +@app.route("/left/<int:amount>") +def move_left(amount): + cannon.move_left(amount) + return "OK" + +@app.route("/right/<int:amount>") +def move_right(amount): + cannon.move_right(amount) + return "OK" + +@app.route("/up/<int:amount>") +def move_up(amount): + cannon.move_up(amount) + return "OK" + +@app.route("/down/<int:amount>") +def move_down(amount): + cannon.move_down(amount) + return "OK" + +@app.route("/status") +def status(): + return json.dumps(cannon.get_data()) + @app.route("/") def root(): - return "COCKS" + return """<html> + <head> + <title>Turret!</title> + </head> + <body> + <div style="width: 400px; height: 400px; margin-top: -200px; margin-left: -200px; position: absolute; top: 50%; left: 50%;"> + <a href="/up/20">Up</a> + <a href="/down/20">Down</a> + <a href="/left/20">Left</a> + <a href="/right/20">Right</a> + </div> + </body> +</html>""" def main(): #create the screen @@ -35,7 +74,7 @@ def main(): colors = [GRAY, VIOLET, RED, GREEN, BLUE, VERYLIGHT] - + global cannon cannon = CannonController() |