-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
61 lines (51 loc) · 1.66 KB
/
main.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
package main
import (
"flag"
"fmt"
"sync"
"github.com/jonmol/gphoto2"
)
var (
snap bool = false
preview bool = false
previewSnap bool = false
printSettings bool = false
snapFile string = "/tmp/snap_test.jpeg"
previewDir string = "/tmp/gphoto2_preview"
shutterSpeed string
previewAmount int = 10
)
var cameraLock sync.Mutex // we need to lock the camera so we're not trying two operations at the same time
func init() {
flag.IntVar(&previewAmount, "preview-shots", previewAmount, "Amount of shots to take in preview mode")
flag.BoolVar(&snap, "snap", snap, "Take a picture and write to -snap-file")
flag.BoolVar(&printSettings, "print-settings", printSettings, "Print camera settings")
flag.BoolVar(&preview, "preview", preview, "Enter preview mode")
flag.BoolVar(&previewSnap, "preview-snap", previewSnap, "Take -preview-shots amount of pictures in preview mode and write them to --preview-dir")
flag.StringVar(&shutterSpeed, "shutter-speed", shutterSpeed, "Set shutter speed")
flag.StringVar(&snapFile, "snap-file", snapFile, "File to write to when taking a picture")
flag.StringVar(&previewDir, "preview-dir", previewDir, "Directory to write to when taking a series of preview pictures")
}
func main() {
flag.Parse()
camera, err := gphoto2.NewCamera("")
if err != nil {
panic(fmt.Sprintf("%s: %s", "Failed to connect to camera, make sure it's around!", err))
}
printInfo(camera)
pFinished := make(chan bool)
if preview {
go previewMode(camera, pFinished)
}
if shutterSpeed != "" {
setShutterSpeed("shutterspeed", camera)
}
if snap {
snapPhoto(camera)
}
if preview {
<-pFinished
}
camera.Exit()
camera.Free()
}