diff options
Diffstat (limited to 'src/camera.go')
-rw-r--r-- | src/camera.go | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/src/camera.go b/src/camera.go index 197aa21..cc29f54 100644 --- a/src/camera.go +++ b/src/camera.go @@ -3,7 +3,9 @@ package main import ( - "time" + "log" + "os/exec" + "io" ) type Camera struct { @@ -38,15 +40,46 @@ func NewCamera() Camera { } } -func runCameraHooks(last string, next string) { - +func runCameraHooks(last string, next string, m *Machine) { if last == "idle" && next == "single_picture" { - // TODO implement launch of python subprocess here - go func() { - time.Sleep(1 * time.Second) - camera.statemachine.SendEvent("single_picture_taken") - }() + go singlePicture(m) + } +} + +func singlePicture(m *Machine) { + + // create command + var cmd *exec.Cmd + if !debug { + cmd = exec.Command("python3", "/usr/lib/python3.9/site-packages/birdscan/") + } else { + cmd = exec.Command("python3", "../python/birdscan", "--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) } + data,err := io.ReadAll(stdout) + if err != nil { + log.Print(err) + } + err = cmd.Wait() // wait until command execution and io is complete + if err != nil { + log.Print(err) + } + + // process result + log.Println(string(data)) + m.SendEvent("single_picture_taken") } func (cam *Camera) run() { |