summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergiusz Bazański <q3k@q3k.org>2012-11-11 17:25:06 +0100
committerSergiusz Bazański <q3k@q3k.org>2012-11-11 17:25:06 +0100
commitdab79a6a803a90a086cc3f82a4485d83ff90676e (patch)
tree81b511b899e41c97d26d848c8c034ddb3aa09a1a
parentf4a74ec7dcd0faf3fcbd2134c28a4c6cfd623f09 (diff)
downloadlaserz_und_stuff-dab79a6a803a90a086cc3f82a4485d83ff90676e.tar.gz
laserz_und_stuff-dab79a6a803a90a086cc3f82a4485d83ff90676e.tar.bz2
laserz_und_stuff-dab79a6a803a90a086cc3f82a4485d83ff90676e.zip
New fire code.
-rw-r--r--Lasers_und_stuff/main.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/Lasers_und_stuff/main.py b/Lasers_und_stuff/main.py
index 1115a0a..3b3851c 100644
--- a/Lasers_und_stuff/main.py
+++ b/Lasers_und_stuff/main.py
@@ -30,31 +30,36 @@ cannon = None
@app.route("/left/<int:amount>", methods=["POST"])
def move_left(amount):
cannon.move_left(amount)
+ cannon.send_data()
return "OK"
@app.route("/right/<int:amount>", methods=["POST"])
def move_right(amount):
cannon.move_right(amount)
+ cannon.send_data()
return "OK"
@app.route("/up/<int:amount>", methods=["POST"])
def move_up(amount):
cannon.move_up(amount)
+ cannon.send_data()
return "OK"
@app.route("/down/<int:amount>", methods=["POST"])
def move_down(amount):
cannon.move_down(amount)
+ cannon.send_data()
return "OK"
-@app.route("/fire/", methods=["POST"])
+@app.route("/fire", methods=["POST"])
def fire():
- cannon.fire();
+ cannon.fire()
+ cannon.send_data()
@app.route("/stop_fire/", methods=["POST"])
def stop_fire():
- cannon.fired = False;
-
+ pass
+
@app.route("/status")
def status():
return json.dumps(cannon.get_data())
@@ -66,8 +71,11 @@ def root():
#Camera stuff
-camera = pygame.camera.Camera("/dev/video0", (640, 480))
-camera.start()
+try:
+ camera = pygame.camera.Camera("/dev/video0", (640, 480))
+ camera.start()
+except:
+ camera = None
def main():
@@ -226,8 +234,9 @@ class Screen:
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)
- image = camera.get_image()
- self.window.blit(image, (CAMERA_X, CAMERA_Y))
+ if camera:
+ image = camera.get_image()
+ self.window.blit(image, (CAMERA_X, CAMERA_Y))
pygame.display.flip()