summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <mail2xengineering@protonmail.com>2021-06-19 10:23:29 +0200
committerxengineering <mail2xengineering@protonmail.com>2021-06-19 10:23:29 +0200
commit198023be0f62ef6bb35cdd5ae78f90ab0a6f187e (patch)
treef207e6c7e2e6d07c262b3fb5f761300bafc3c65f
parent955b242b815024545385ee216b20dac78276b16d (diff)
downloadbirdscan-198023be0f62ef6bb35cdd5ae78f90ab0a6f187e.tar
birdscan-198023be0f62ef6bb35cdd5ae78f90ab0a6f187e.tar.zst
birdscan-198023be0f62ef6bb35cdd5ae78f90ab0a6f187e.zip
Update Python / Golang Interface
-rw-r--r--python/birdscan/__main__.py4
-rw-r--r--src/camera.go34
2 files changed, 29 insertions, 9 deletions
diff --git a/python/birdscan/__main__.py b/python/birdscan/__main__.py
index 77fae73..71ba294 100644
--- a/python/birdscan/__main__.py
+++ b/python/birdscan/__main__.py
@@ -17,7 +17,7 @@ def main():
if len(sys.argv) == 2: # check if argument is given (--debug)
time.sleep(1)
- sys.stdout.write("ok")
+ sys.stdout.write("ok\n")
else:
from picamera import PiCamera
camera = PiCamera()
@@ -28,7 +28,7 @@ def main():
camera.capture("/var/lib/birdscan/{}.jpg".format(
time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime()))
)
- sys.stdout.write("ok")
+ sys.stdout.write("ok\n")
if __name__ == "__main__":
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, ) {
+
+}