From 591097e5a3741432e2acd9c41fadd4eb10678674 Mon Sep 17 00:00:00 2001 From: xengineering Date: Tue, 15 Jun 2021 16:44:15 +0200 Subject: Refactoring: Make Statemachine reusable --- src/camera.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/camera.go') diff --git a/src/camera.go b/src/camera.go index 12a9d54..197aa21 100644 --- a/src/camera.go +++ b/src/camera.go @@ -2,6 +2,10 @@ package main +import ( + "time" +) + type Camera struct { statemachine Machine } @@ -29,10 +33,22 @@ func NewCamera() Camera { }, api: make(chan string), state_listeners: make([]*(chan string), 0), + hook: runCameraHooks, }, } } +func runCameraHooks(last string, next string) { + + 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") + }() + } +} + func (cam *Camera) run() { cam.statemachine.Run() } -- cgit v1.2.3-70-g09d2