-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera_manager.go
81 lines (69 loc) · 1.59 KB
/
camera_manager.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"errors"
"log"
"github.com/urlgrey/canon-eos-go/eos"
)
type CameraCommand int
const (
TAKE_PICTURE CameraCommand = iota
LIVE_VIEW_ENABLED
LIVE_VIEW_DISABLED
)
type CameraManager struct {
commandChannel chan CameraCommand
stopChannel chan bool
stopped bool
eosClient *eos.EOSClient
camera eos.CameraModel
}
func NewCameraManager() *CameraManager {
return &CameraManager{commandChannel: make(chan CameraCommand), stopChannel: make(chan bool)}
}
func (c *CameraManager) Initialize() error {
c.eosClient = eos.NewEOSClient()
if err := c.eosClient.Initialize(); err != nil {
return err
}
models, _ := c.eosClient.GetCameraModels()
if len(models) == 0 {
return errors.New("No cameras connected")
}
c.camera = models[0]
return nil
}
func (c *CameraManager) GetCommandChannel() chan CameraCommand {
return c.commandChannel
}
func (c *CameraManager) Run() {
defer c.eosClient.Release()
defer c.camera.Release()
c.camera.OpenSession()
defer c.camera.CloseSession()
var cmd CameraCommand
for {
select {
case c.stopped = <-c.stopChannel:
log.Println("Camera Manager returning")
return
case cmd = <-c.commandChannel:
switch cmd {
case TAKE_PICTURE:
c.camera.TakePicture()
case LIVE_VIEW_ENABLED:
c.camera.SetLiveViewOutputDevice(eos.TFT)
c.camera.StartLiveView()
case LIVE_VIEW_DISABLED:
c.camera.StopLiveView()
default:
log.Printf("Unrecognized command: %d\n", cmd)
}
}
}
}
func (c *CameraManager) IsStopped() bool {
return c.stopped
}
func (c *CameraManager) Stop() {
c.stopChannel <- true
}