timer + capture
[imago.git] / timer.py
index 916d578..587b436 100755 (executable)
--- a/timer.py
+++ b/timer.py
@@ -6,6 +6,7 @@ import os
 import sys
 import time
 import argparse
+import subprocess
 
 import pygame
 
@@ -45,6 +46,12 @@ class Timer:
 parser = argparse.ArgumentParser(description=__doc__)
 parser.add_argument('-m', type=int, default=45,
                     help="main time in minutes")
+parser.add_argument('-c', '--camera', dest='cam', action='store_true',
+                    help="camera on")
+parser.add_argument('-d', type=int, default=0,
+                    help="video device id")
+parser.add_argument('-r', type=int, nargs=2, default=[640, 480],
+                    help="set camera resolution")
 args = parser.parse_args()
 
 
@@ -64,6 +71,11 @@ main_time = args.m * 60
 
 timers = (Timer(main_time), Timer(main_time))
 
+if args.cam:
+    capture = subprocess.Popen(['python', 'capture.py', '-c', '-d', str(args.d), '-r',
+                      str(args.r[0]),
+                      str(args.r[1])], stdin=subprocess.PIPE)
+
 while not done:
 
     for event in pygame.event.get():
@@ -73,7 +85,12 @@ while not done:
             if first:
                 timers[0].start()
                 first = False
+                if args.cam:
+                    print >> capture.stdin, "stop"
+                    print >> capture.stdin, "take"
                 continue
+            if args.cam:
+                print >> capture.stdin, "take"
             for timer in timers:
                 if timer.is_running():
                     timer.stop()
@@ -87,3 +104,6 @@ while not done:
     screen.blit(text2, [300, 10])
     pygame.display.flip()
     clock.tick(15)
+
+
+print >> capture.stdin, "exit"