From 963b86e49fad07a3722646b9d7f4b1c09d199eb1 Mon Sep 17 00:00:00 2001 From: xengineering Date: Sat, 19 Jun 2021 11:08:57 +0200 Subject: Implement continuous Python Daemon --- src/camera.go | 63 +---------------------------------------------------------- 1 file changed, 1 insertion(+), 62 deletions(-) (limited to 'src/camera.go') diff --git a/src/camera.go b/src/camera.go index 519cc65..fe1140e 100644 --- a/src/camera.go +++ b/src/camera.go @@ -2,14 +2,6 @@ package main -import ( - "log" - "os/exec" - "os" - "path/filepath" - "bufio" -) - type Camera struct { statemachine Machine } @@ -44,63 +36,10 @@ func NewCamera() Camera { func runCameraHooks(last string, next string, m *Machine) { if last == "idle" && next == "single_picture" { - go singlePicture(m) + ipc.WriteLineTo("picamera", "single_picture\n") } } -func singlePicture(m *Machine) { - - // create command - var cmd *exec.Cmd - if !config.Flag.Debug { - cmd = exec.Command("/usr/bin/python3", "/usr/lib/python3.9/site-packages/birdscan/") - } else { // debug mode - pwd,err := os.Getwd() - if err != nil { - log.Fatal(err) - } - repoDir := filepath.Dir(pwd) - log.Printf("Repository path is assumed to be = '%s'", repoDir) - pythonPackage := repoDir + "/python/birdscan" - cmd = exec.Command("/usr/bin/python3", pythonPackage, "--debug") - } - - // connect stdout of python process - stdout,err := cmd.StdoutPipe() - if err != nil { - log.Print(err) - } - defer stdout.Close() - - // run command - err = cmd.Start() - if err != nil { - log.Print(err) - } - - scanner := bufio.NewScanner(stdout) - for scanner.Scan() { - text := scanner.Text() - log.Printf("Python returned '%s'", text) - if text == "ok" { - break - } - } - - err = cmd.Wait() // wait until command execution and io is complete - if err != nil { - log.Print(err) - } - - // process result - m.SendEvent("single_picture_taken") -} - func (cam *Camera) run() { cam.statemachine.Run() } - -// read until '\n' -func readLine(buff *[]byte, ) { - -} -- cgit v1.2.3-70-g09d2