ensuring camera is connected before trying to capture

This commit is contained in:
langolierz
2018-04-20 00:49:45 +00:00
parent 1ff6d89b1f
commit d41647d417
3 changed files with 21 additions and 7 deletions

View File

@@ -165,8 +165,8 @@ class Actions(object):
if self.video_driver.current_player.status == 'PAUSED': if self.video_driver.current_player.status == 'PAUSED':
self.toggle_pause_on_player() self.toggle_pause_on_player()
else: else:
self.capture.start_preview() is_successful = self.capture.start_preview()
if self.video_driver.current_player.status != 'PAUSED': if is_successful and self.video_driver.current_player.status != 'PAUSED':
self.toggle_pause_on_player() self.toggle_pause_on_player()
def toggle_capture_recording(self): def toggle_capture_recording(self):

View File

@@ -167,7 +167,9 @@ class Display(object):
def _generate_capture_status(self): def _generate_capture_status(self):
is_previewing = self.capture.is_previewing is_previewing = self.capture.is_previewing
is_recording = self.capture.is_recording is_recording = self.capture.is_recording
rec_time = self.capture.get_recording_time() rec_time = -1
if is_recording == True:
rec_time = self.capture.get_recording_time()
capture_status = '' capture_status = ''
if is_previewing and is_recording == True: if is_previewing and is_recording == True:
capture_status = '<{}>'.format('REC'+ self.format_time_value(rec_time)) capture_status = '<{}>'.format('REC'+ self.format_time_value(rec_time))

View File

@@ -1,7 +1,7 @@
import os import os
import subprocess import subprocess
import datetime import datetime
from picamera import PiCamera import picamera
class Capture(object): class Capture(object):
def __init__(self, root, message_handler, data): def __init__(self, root, message_handler, data):
@@ -17,14 +17,23 @@ class Capture(object):
def create_capture_device(self): def create_capture_device(self):
if self.use_capture: if self.use_capture:
self.device = PiCamera() try:
self.device = picamera.PiCamera()
except picamera.exc.PiCameraError as e:
self.use_capture = False
print('camera exception is {}'.format(e))
self.message_handler.set_message('INFO', 'no capture device attached')
def start_preview(self): def start_preview(self):
if self.use_capture == False:
self.message_handler.set_message('INFO', 'capture not enabled')
return False
if self.device.closed: if self.device.closed:
self.create_capture_device() self.create_capture_device()
self.is_previewing = True self.is_previewing = True
self.device.start_preview() self.device.start_preview()
self.set_preview_screen_size() self.set_preview_screen_size()
return True
def set_preview_screen_size(self): def set_preview_screen_size(self):
if self.data.get_screen_size_setting() == 'dev_mode': if self.data.get_screen_size_setting() == 'dev_mode':
@@ -40,6 +49,9 @@ class Capture(object):
self.device.close() self.device.close()
def start_recording(self): def start_recording(self):
if self.use_capture == False:
self.message_handler.set_message('INFO', 'capture not enabled')
return
if self.device.closed: if self.device.closed:
self.create_capture_device() self.create_capture_device()
# need to check the space in destination (or check in a main loop somewhere ?) # need to check the space in destination (or check in a main loop somewhere ?)
@@ -98,7 +110,7 @@ class Capture(object):
return '{}/{}'.format(rec_dir,name), name return '{}/{}'.format(rec_dir,name), name
def get_recording_time(self): def get_recording_time(self):
if not self.device.recording or self.device.frame.timestamp == None: if not self.device or not self.device.recording or self.device.frame.timestamp == None:
return -1 return -1
else: else:
return self.device.frame.timestamp / 1000000 return self.device.frame.timestamp / 1000000