summaryrefslogtreecommitdiff
path: root/src/camera.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/camera.go')
-rw-r--r--src/camera.go34
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, ) {
+
+}