diff options
author | xengineering <mail2xengineering@protonmail.com> | 2021-06-19 10:23:29 +0200 |
---|---|---|
committer | xengineering <mail2xengineering@protonmail.com> | 2021-06-19 10:23:29 +0200 |
commit | 198023be0f62ef6bb35cdd5ae78f90ab0a6f187e (patch) | |
tree | f207e6c7e2e6d07c262b3fb5f761300bafc3c65f /src/camera.go | |
parent | 955b242b815024545385ee216b20dac78276b16d (diff) | |
download | birdscan-198023be0f62ef6bb35cdd5ae78f90ab0a6f187e.tar birdscan-198023be0f62ef6bb35cdd5ae78f90ab0a6f187e.tar.zst birdscan-198023be0f62ef6bb35cdd5ae78f90ab0a6f187e.zip |
Update Python / Golang Interface
Diffstat (limited to 'src/camera.go')
-rw-r--r-- | src/camera.go | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/camera.go b/src/camera.go index 86c0fb1..519cc65 100644 --- a/src/camera.go +++ b/src/camera.go @@ -5,7 +5,9 @@ package main import ( "log" "os/exec" - "io" + "os" + "path/filepath" + "bufio" ) type Camera struct { @@ -51,9 +53,16 @@ func singlePicture(m *Machine) { // create command var cmd *exec.Cmd if !config.Flag.Debug { - cmd = exec.Command("python3", "/usr/lib/python3.9/site-packages/birdscan/") - } else { - cmd = exec.Command("python3", "../python/birdscan", "--debug") // FIXME relative paths do not work in exec.Command! + 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 @@ -68,10 +77,16 @@ func singlePicture(m *Machine) { if err != nil { log.Print(err) } - _,err = io.ReadAll(stdout) - 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) @@ -84,3 +99,8 @@ func singlePicture(m *Machine) { func (cam *Camera) run() { cam.statemachine.Run() } + +// read until '\n' +func readLine(buff *[]byte, ) { + +} |