diff options
author | Sergiusz Bazański <q3k@q3k.org> | 2012-11-11 17:10:40 +0100 |
---|---|---|
committer | Sergiusz Bazański <q3k@q3k.org> | 2012-11-11 17:10:40 +0100 |
commit | f4a74ec7dcd0faf3fcbd2134c28a4c6cfd623f09 (patch) | |
tree | 5f59e14d863dc01722e998fe99d50dd848465286 | |
parent | b045831c1e3b8d6158ab963ad1de93410007c116 (diff) | |
parent | 8bd6089f9aa2657939db9f794f43e9f89978cb8e (diff) | |
download | laserz_und_stuff-f4a74ec7dcd0faf3fcbd2134c28a4c6cfd623f09.tar.gz laserz_und_stuff-f4a74ec7dcd0faf3fcbd2134c28a4c6cfd623f09.tar.bz2 laserz_und_stuff-f4a74ec7dcd0faf3fcbd2134c28a4c6cfd623f09.tar.xz laserz_und_stuff-f4a74ec7dcd0faf3fcbd2134c28a4c6cfd623f09.zip |
Merge branch 'master' of ssh://hackerspace.pl/attero/laserz_und_stuff
-rw-r--r-- | Lasers_und_stuff/main.py | 38 | ||||
-rw-r--r-- | Lasers_und_stuff/main.pyc | bin | 9032 -> 9997 bytes | |||
-rw-r--r-- | Lasers_und_stuff/templates/status.html | 64 |
3 files changed, 85 insertions, 17 deletions
diff --git a/Lasers_und_stuff/main.py b/Lasers_und_stuff/main.py index dce13e1..1115a0a 100644 --- a/Lasers_und_stuff/main.py +++ b/Lasers_und_stuff/main.py @@ -15,10 +15,15 @@ import traceback from pygame.locals import * from Cannon import HackWAWCannonController from Cannon import Gunpoint +import pygame.camera app = flask.Flask(__name__) app.debug = True pygame.init() +pygame.camera.init() + +CAMERA_X = 400 +CAMERA_Y = 30 cannon = None @@ -42,17 +47,32 @@ def move_down(amount): cannon.move_down(amount) return "OK" +@app.route("/fire/", methods=["POST"]) +def fire(): + cannon.fire(); + +@app.route("/stop_fire/", methods=["POST"]) +def stop_fire(): + cannon.fired = False; + @app.route("/status") def status(): return json.dumps(cannon.get_data()) @app.route("/") def root(): - return flask.render_template("status.html", data=cannon.get_data()) + + +#Camera stuff + +camera = pygame.camera.Camera("/dev/video0", (640, 480)) +camera.start() + + def main(): #create the screen - window = pygame.display.set_mode((800, 600)) + window = pygame.display.set_mode((1200, 800)) GRAY = ( 182, 182, 182) VIOLET = (150, 100, 190) @@ -72,6 +92,7 @@ def main(): gunpoint = Gunpoint((5, 4), (200, 4), (5, 210)) + keep_running = True while keep_running: screen.draw_surface(cannon) @@ -112,6 +133,14 @@ def main(): cannon.send_data() elif event.type == MOUSEBUTTONUP: + mousex, mousey = pygame.mouse.get_pos() + print mousex, mousey + x = (mousex - CAMERA_X)/640.0 + y = (CAMERA_Y + 480 - mousey)/480.0 + print x, y + position = gunpoint.aim((x, y)) + print position + cannon.position = position screen.change_color() print "Pygame thread exited." os.kill(os.getpid(), signal.SIGINT) @@ -196,7 +225,10 @@ class Screen: for i, text in enumerate(self.communicates): self.print_text(text, 20, 20 + i*20, (0, 0, 0), 30, self.window) - self.print_text([str(x) for x in cannon.get_data()].__str__(), 20, 300, (0, 0, 0), 30, self.window) + self.print_text([str(x) for x in cannon.get_data()].__str__(), 20, 300, (0, 0, 0), 30, self.window) + image = camera.get_image() + self.window.blit(image, (CAMERA_X, CAMERA_Y)) + pygame.display.flip() def print_text(self, text,xx,yy,color,text_size, screen): diff --git a/Lasers_und_stuff/main.pyc b/Lasers_und_stuff/main.pyc Binary files differindex 223d4cb..5cec598 100644 --- a/Lasers_und_stuff/main.pyc +++ b/Lasers_und_stuff/main.pyc diff --git a/Lasers_und_stuff/templates/status.html b/Lasers_und_stuff/templates/status.html index 233476b..0b1b24d 100644 --- a/Lasers_und_stuff/templates/status.html +++ b/Lasers_und_stuff/templates/status.html @@ -2,33 +2,69 @@ {% block body %} <script type=text/javascript src="{{url_for('static', filename='jquery.min.js') }}"> </script> <script type=text/javascript> - $(document).ready(function(){ - // - $('#dupa').text("I like bananas"); - }); - function pop_banana() { - $('#banana').html('<a href="http://ranchochilamate.com/wp/wp-content/uploads/2010/10/banana.jpg">Click</a>'); + function update() { + update_status(); + window.setTimeout(update, 100000000); } + $("document").ready(function(data) { + update(); + }); + + function move_right() { $.post("/right/20", function(data) { - $('#dupa').html(data); + update_status(); + }); + } + + function move_left() { + $.post("/left/20", function(data) { + update_status(); }); + } + + function move_down() { + $.post("/down/20", function(data) { + update_status(); + }); + } function move_up() { $.post("{{url_for('move_up', amount="20")}}", function(data) { - $('#dupa').html(data); + update_status(); }); } + + function fire() { + $.post("/fire", function(data) { + + }); + } + + function stop_fire() { + $.post("/stop_fire", function(data) { + + }); + } + + function update_status() { + $.get("/status", function(data) { + $('#status').html(data); + }); + } + </script> <div style="width: 400px; height: 400px; margin-top: -200px; margin-left: -200px; position: absolute; top: 50%; left: 50%;"> + <h2>Hello in cannon controller, adjust angles!</h2> + <p>Angles can be in range 0:255</p> <a onclick="move_up()">Up</a> - <a href="/down/20">Down</a> - <a href="/left/20">Left</a> - <a href ="/right/20"" onclick="move_right()">Right</a> - <p id="dupa" onclick="move_right()"></p> - <p id="banana"></p> - <h2>Status</h2> <p>{{data}}</p></div> + <a onclick="move_down()">Down</a> + <a onclick="move_left()">Left</a> + <a onclick="move_right()">Right</a> + <p><a onclick="fire()">Fire!</a> <a onclick="stop_fire()">Stop</a></p> + + <h2>Status: </h2> <p id="status">{{data}}</p></div> </body> {% endblock %}
\ No newline at end of file |