#!/usr/bin/python

# SciFiCam 
# Copyright (C) 2017  Mihails Delmans

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

import sys
from time import sleep
import subprocess

from scificam import *



print "Starting fbcp..."

try:
	subprocess.Popen(["fbcp"])
except Exception as e:
	print "Failed to start fbcp:\n{0}".format(e)
	sys.exit()

print "fbcp started succesully..."

camera = SciFiCam()
camera.addMode(AutoMode)
camera.addMode(ManualMode)
camera.addMode(TimelapseMode)
camera.addMode(VideoCaptureMode)
camera.addMode(ShutDownMode)
camera.start()

try:
	while True:
		sleep(1)
finally:
	camera.stop()
	sys.exit()