replay.py 1.06 KB
Newer Older
1 2 3 4 5 6 7 8
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 18 18:34:40 2018

@author: Antoine Lima, Leo Reynaert, Domitille Jehenne
"""

9 10 11 12 13 14 15 16
import os
from settings import Settings

onRasp = os.uname()[1] == 'raspberrypi'

if onRasp:
	import picamera

17 18 19

class Replay():
	def __init__(self):
20 21 22 23 24 25 26 27 28
		if onRasp:
			self.cam = picamera.PiCamera()
			self.cam.resolution = Settings['picam.resolution']
			self.cam.framerate = Settings['picam.fps']
			self.cam.hflip = Settings['picam.hflip']
			self.cam.vflip = Settings['picam.vflip']
			self.format = Settings['picam.format']
			self.continue_recording = False
			self.stream = picamera.PiCameraCircularIO(self.cam, seconds=Settings['replay.duration'])
29 30
	
	def capture(self, fileToSave):
31 32 33
		if onRasp:
			self.cam.start_recording(self.stream, self.format)
			self.continue_recording = True
34
			
35 36 37 38 39 40 41 42 43
			try:
				while self.continue_recording:
					self.cam.wait_recording(1)
			finally:
				self.cam.stop_recording()
				
			self.stream.copy_to(fileToSave)
			self.cam.close()
			self.stream.close()
44 45 46

	def stop():
		self.continue_recording = False