diff options
author | xengineering <mail2xengineering@protonmail.com> | 2021-06-19 11:08:57 +0200 |
---|---|---|
committer | xengineering <mail2xengineering@protonmail.com> | 2021-06-20 13:57:58 +0200 |
commit | 963b86e49fad07a3722646b9d7f4b1c09d199eb1 (patch) | |
tree | 5ccb6b66bf9ce1c53e3e97fa7057e44b66512295 /src/camera.go | |
parent | 198023be0f62ef6bb35cdd5ae78f90ab0a6f187e (diff) | |
download | birdscan-963b86e49fad07a3722646b9d7f4b1c09d199eb1.tar birdscan-963b86e49fad07a3722646b9d7f4b1c09d199eb1.tar.zst birdscan-963b86e49fad07a3722646b9d7f4b1c09d199eb1.zip |
Implement continuous Python Daemon
Diffstat (limited to 'src/camera.go')
-rw-r--r-- | src/camera.go | 63 |
1 files changed, 1 insertions, 62 deletions
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, ) { - -} |