func handleCaptureEvent(camera *gphoto2go.Camera, folder string, fileName string) { path := path.Join(viper.GetString("photos.path"), fileName) reader := camera.FileReader(folder, fileName) fWriter, _ := os.Create(path) io.Copy(fWriter, reader) fWriter.Close() reader.Close() bus.Publish("photo:saved", path) }
func initCameraEventSource(camera *gphoto2go.Camera) { go func() { for { eventChan := camera.AsyncWaitForEvent(1000) evt := <-eventChan if evt.Type == gphoto2go.EVENT_FILE_ADDED { bus.Publish("photo:capture", camera, evt.Folder, evt.File) } } }() }
func initCamera() *gphoto2go.Camera { camera := new(gphoto2go.Camera) err := camera.Init() if err < 0 { log.Fatalf("No camera found. Exiting.\n") } else { bus.Publish("camera:init", camera) } return camera }