diff options
author | xengineering <mail2xengineering@protonmail.com> | 2021-06-17 09:00:07 +0200 |
---|---|---|
committer | xengineering <mail2xengineering@protonmail.com> | 2021-06-17 11:27:05 +0200 |
commit | 52972b810a9a42cef5c88f9947d64a0705f243ac (patch) | |
tree | 6ce0307a030bb5279a695506868a424f6ab6599c /src/camera.go | |
parent | 591097e5a3741432e2acd9c41fadd4eb10678674 (diff) | |
download | birdscan-52972b810a9a42cef5c88f9947d64a0705f243ac.tar birdscan-52972b810a9a42cef5c88f9947d64a0705f243ac.tar.zst birdscan-52972b810a9a42cef5c88f9947d64a0705f243ac.zip |
Implement single Picture Mode
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() { |