Fix initialization bug

This commit is contained in:
Steven Polley 2020-10-29 03:17:11 +00:00
parent 3b038c2515
commit f457299f50

10
main.go
View File

@ -56,6 +56,14 @@ func main() {
fmt.Printf("Start reading device: %v\n", deviceID)
// This is a warm up ladies and gentlemen.
for i := 0; i < 20; i++ {
if ok := webcam.Read(&img); !ok {
fmt.Printf("Device closed: %v\n", deviceID)
return
}
}
// main loop
for {
if ok := webcam.Read(&img); !ok {
@ -88,7 +96,7 @@ func main() {
currentRecording.Write(img)
// Determine if we should stop recording
if lastMotionDetectedTime.Add(time.Second * recordLengthAfterMotion).After(time.Now()) {
if lastMotionDetectedTime.Add(time.Second * recordLengthAfterMotion).Before(time.Now()) {
log.Printf("motion has not been detected for the last %d seconds stopping recording to file", recordLengthAfterMotion)
err = currentRecording.Close()
if err != nil {