#Commands:
#r = start recording
#p = take picture
#0-8 = ISO modes 100-800, 0 is auto
#a = auto exposure
#n = night exposure


#Exposure Modes:
#- off
#- auto
#- night
#- nightpreview
#- backlight
#- spotlight
#- sports
#- snow
#- beach
#- verylong
#- fixedfps
#- antishake
#- fireworks

#White Balance Modes:
#- off
#- auto
#- sunlight
#- cloudy
#- shade
#- tungsten
#- flourescent
#- incandescent
#- flash
#- horizon

import time
import keyboard
from time import sleep
from picamera import PiCamera

camera = PiCamera()
camera.resolution = (1920, 1080)
camera.exposure_mode = 'auto'
camera.awb_mode = 'auto'
camera.start_preview()

print("PiCorder V1.4")
		
			
def record_start():
	camera.resolution = (1920, 1080)
	sleep(2)
	camera.start_recording('/home/pi/Documents/test_files/button.h264')
	print("Recording Started")
	while True:
		if keyboard.is_pressed('r'):
			record_stop()
			print("stop")
			time.sleep(1)
			break
		
def record_stop():
	camera.stop_recording()
	print("Recording Stopped")
	
	
def end():
	camera.stop_preview()
	camera.close()
	print("Killing Program")
	time.sleep(2)
			

while True:
	try:
		if keyboard.is_pressed('r'):
			record_start()
			
		if keyboard.is_pressed('x'):
			end()
			break
	except:
		pass
