Push dev work to master #2
21
index.js
21
index.js
|
@ -20,16 +20,16 @@ let app = restify.createServer({
|
||||||
function createServer () {
|
function createServer () {
|
||||||
app.use(restify.plugins.queryParser())
|
app.use(restify.plugins.queryParser())
|
||||||
app.use(restify.plugins.bodyParser({ mapParams: false }))
|
app.use(restify.plugins.bodyParser({ mapParams: false }))
|
||||||
app.get('/', index)
|
app.get( '/', index)
|
||||||
app.get('/dir', rDir)
|
app.get( '/dir', rDir)
|
||||||
app.post('/dir', rDir)
|
app.post('/dir', rDir)
|
||||||
app.get('/exposure', rExposure)
|
app.get( '/exposure', rExposure)
|
||||||
app.post('/exposure', rExposure)
|
app.post('/exposure', rExposure)
|
||||||
app.get('/frame', rFrame)
|
app.get( '/frame', rFrame)
|
||||||
app.post('/frame', rFrame)
|
app.post('/frame', rFrame)
|
||||||
app.get('/sequence', () => {})
|
app.get( '/sequence', () => {})
|
||||||
app.post('/sequence', () => {})
|
app.post('/sequence', () => {})
|
||||||
app.get('/status', rStatus)
|
app.get( '/status', rStatus)
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
log.info('server', { name : APPNAME, port : PORT })
|
log.info('server', { name : APPNAME, port : PORT })
|
||||||
})
|
})
|
||||||
|
@ -58,6 +58,7 @@ function rDir (req, res, next) {
|
||||||
} else {
|
} else {
|
||||||
dir = intval._state.frame.dir
|
dir = intval._state.frame.dir
|
||||||
}
|
}
|
||||||
|
log.info('/dir', { method: req.method, set : set, dir : dir})
|
||||||
res.send({ dir : dir })
|
res.send({ dir : dir })
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
|
@ -85,7 +86,9 @@ function rExposure (req, res, next) {
|
||||||
} else {
|
} else {
|
||||||
exposure = intval._state.frame.exposure
|
exposure = intval._state.frame.exposure
|
||||||
}
|
}
|
||||||
|
log.info('/exposure', { method: req.method, set : set, exposure : exposure })
|
||||||
res.send({ exposure : exposure })
|
res.send({ exposure : exposure })
|
||||||
|
return next()
|
||||||
}
|
}
|
||||||
|
|
||||||
function rDelay (req, res, next) {
|
function rDelay (req, res, next) {
|
||||||
|
@ -111,11 +114,15 @@ function rDelay (req, res, next) {
|
||||||
} else {
|
} else {
|
||||||
delay = intval._state.frame.delay
|
delay = intval._state.frame.delay
|
||||||
}
|
}
|
||||||
|
log.info('/delay', { method: req.method, set : set, delay : delay })
|
||||||
res.send({ delay : delay })
|
res.send({ delay : delay })
|
||||||
|
return next()
|
||||||
}
|
}
|
||||||
|
|
||||||
function rFrame (req, res, next) {
|
function rFrame (req, res, next) {
|
||||||
intval.frame()
|
intval.frame(cb=()=>{
|
||||||
|
log.info('happened')
|
||||||
|
})
|
||||||
res.send({})
|
res.send({})
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,8 @@ intval.init = function () {
|
||||||
active : false, //should frame be running
|
active : false, //should frame be running
|
||||||
paused : false,
|
paused : false,
|
||||||
exposure : 0, //length of frame exposure, in ms
|
exposure : 0, //length of frame exposure, in ms
|
||||||
delay : 0 //delay before start of frame, in ms
|
delay : 0, //delay before start of frame, in ms
|
||||||
|
cb : () => {}
|
||||||
},
|
},
|
||||||
release : {
|
release : {
|
||||||
time: 0,
|
time: 0,
|
||||||
|
@ -142,6 +143,7 @@ intval._stop = function () {
|
||||||
|
|
||||||
intval._pin.micro.unwatch()
|
intval._pin.micro.unwatch()
|
||||||
intval._state.frame.active = false
|
intval._state.frame.active = false
|
||||||
|
if (intval._state.frame.cb) intval._state.frame.cb()
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Callback for watching relese switch state changes.
|
* Callback for watching relese switch state changes.
|
||||||
|
@ -269,7 +271,7 @@ intval.setDelay = function (val = 0) {
|
||||||
* @param {?integer} [time="null"] (optional) Exposure time, 0 = minimum
|
* @param {?integer} [time="null"] (optional) Exposure time, 0 = minimum
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
intval.frame = function (dir = null, time = null) {
|
intval.frame = function (dir = null, time = null, cb = () => {}) {
|
||||||
if (dir === true || (dir === null && intval._state.frame.dir === true) ) {
|
if (dir === true || (dir === null && intval._state.frame.dir === true) ) {
|
||||||
dir = true
|
dir = true
|
||||||
} else {
|
} else {
|
||||||
|
@ -286,7 +288,7 @@ intval.frame = function (dir = null, time = null) {
|
||||||
intval._state.frame.active = true
|
intval._state.frame.active = true
|
||||||
intval._pin.micro.watch(intval._watchMicro)
|
intval._pin.micro.watch(intval._watchMicro)
|
||||||
|
|
||||||
log.info('frame', {dir : dir, time : time})
|
log.info('frame', {dir : dir ? 'forward' : 'backward', time : time})
|
||||||
|
|
||||||
if (dir) {
|
if (dir) {
|
||||||
intval._startFwd()
|
intval._startFwd()
|
||||||
|
@ -312,6 +314,7 @@ intval.frame = function (dir = null, time = null) {
|
||||||
}, time + intval._frame.closed)
|
}, time + intval._frame.closed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
intval._state.frame.cb = cb
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Start a sequence of frames, using defaults or explicit instructions
|
* Start a sequence of frames, using defaults or explicit instructions
|
||||||
|
|
Loading…
Reference in New Issue