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 index 223d4cb..5cec598 100644 Binary files a/Lasers_und_stuff/main.pyc and b/Lasers_und_stuff/main.pyc differ 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 %}
+

Hello in cannon controller, adjust angles!

+

Angles can be in range 0:255

Up - Down - Left - Right -

-

-

Status

{{data}}

+ Down + Left + Right +

Fire! Stop

+ +

Status:

{{data}}

{% endblock %} \ No newline at end of file