Permalink
Browse files

Added series example

  • Loading branch information...
1 parent b282076 commit 639ac3a23dde5d9376fa791284fbad44bf357182 @lwille committed Apr 7, 2013
Showing with 28 additions and 9 deletions.
  1. +20 −0 examples/series.coffee
  2. +8 −9 examples/server.coffee
View
20 examples/series.coffee
@@ -0,0 +1,20 @@
+# Capture 20 pictures and save them to disk.
+
+GPhoto = require "../build/Release/gphoto2"
+async = require "async"
+fs = require "fs"
+
+gphoto = new GPhoto.GPhoto2()
+
+gphoto.list (cameras)->
+ if cameras.length and camera = cameras[0]
+ async.forEachSeries [0 .. 20], (i, cb)->
+ camera.takePicture download:true, (er, data)->
+ return cb er if er
+ fs.writeFile "series_#{i}.jpg", data, "binary", (er)->
+ cb er
+ , (er)->
+ console.error er if er
+ console.log "done."
+ else
+ console.log "No camera found."
View
17 examples/server.coffee
@@ -1,14 +1,14 @@
process.title = 'node-gphoto2 test program'
+global[id] ?= require name for id, name of {
+ "fs"
+ "GPhoto":"../build/Release/gphoto2"
+ "express"
+ _: "underscore"
+}
-
-GPhoto = require "../build/Release/gphoto2"
-fs = require "fs"
gphoto = new GPhoto.GPhoto2()
-express = require 'express'
-_ = require 'underscore'
-
requests = {}
-preview_listeners = new Array()
+preview_listeners = []
camera = undefined
@@ -29,7 +29,6 @@ gphoto.list (cameras)->
app = express()
-console.log __dirname
app.use express.static __dirname + '/public'
app.use express.bodyParser()
@@ -114,4 +113,4 @@ app.get '/preview*', (req, res)->
listener.writeHead 500
listener.end()
-app.listen 1337, "0.0.0.0"
+app.listen process.env.PORT || 1337, "0.0.0.0"

0 comments on commit 639ac3a

Please sign in to comment.