Basic web control.

master
q3k 2012-11-11 13:35:07 +01:00
parent 318fe0a909
commit 1ab422118c
2 changed files with 50 additions and 2 deletions

View File

@ -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

View File

@ -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()