From f457299f50df3d7ba090684bae2550f29e9b45e4 Mon Sep 17 00:00:00 2001 From: Steven Polley Date: Thu, 29 Oct 2020 03:17:11 +0000 Subject: [PATCH] Fix initialization bug --- main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 5928771..d6adbe1 100644 --- a/main.go +++ b/main.go @@ -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 {