From 0848d5bfc0d766d57b51ee3de537b943eb8c1c19 Mon Sep 17 00:00:00 2001 From: mmcw-dev Date: Sat, 21 Oct 2017 12:08:12 -0400 Subject: [PATCH] Add logging to webapp and callback to frame function in intval --- index.js | 21 ++++++++++++++------- lib/intval/index.js | 9 ++++++--- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index be29495..6c1f975 100644 --- a/index.js +++ b/index.js @@ -20,16 +20,16 @@ let app = restify.createServer({ function createServer () { app.use(restify.plugins.queryParser()) app.use(restify.plugins.bodyParser({ mapParams: false })) - app.get('/', index) - app.get('/dir', rDir) + app.get( '/', index) + app.get( '/dir', rDir) app.post('/dir', rDir) - app.get('/exposure', rExposure) + app.get( '/exposure', rExposure) app.post('/exposure', rExposure) - app.get('/frame', rFrame) + app.get( '/frame', rFrame) app.post('/frame', rFrame) - app.get('/sequence', () => {}) + app.get( '/sequence', () => {}) app.post('/sequence', () => {}) - app.get('/status', rStatus) + app.get( '/status', rStatus) app.listen(PORT, () => { log.info('server', { name : APPNAME, port : PORT }) }) @@ -58,6 +58,7 @@ function rDir (req, res, next) { } else { dir = intval._state.frame.dir } + log.info('/dir', { method: req.method, set : set, dir : dir}) res.send({ dir : dir }) return next() } @@ -85,7 +86,9 @@ function rExposure (req, res, next) { } else { exposure = intval._state.frame.exposure } + log.info('/exposure', { method: req.method, set : set, exposure : exposure }) res.send({ exposure : exposure }) + return next() } function rDelay (req, res, next) { @@ -111,11 +114,15 @@ function rDelay (req, res, next) { } else { delay = intval._state.frame.delay } + log.info('/delay', { method: req.method, set : set, delay : delay }) res.send({ delay : delay }) + return next() } function rFrame (req, res, next) { - intval.frame() + intval.frame(cb=()=>{ + log.info('happened') + }) res.send({}) return next() } diff --git a/lib/intval/index.js b/lib/intval/index.js index 1974015..20b9dae 100644 --- a/lib/intval/index.js +++ b/lib/intval/index.js @@ -44,7 +44,8 @@ intval.init = function () { active : false, //should frame be running paused : false, 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 : { time: 0, @@ -142,6 +143,7 @@ intval._stop = function () { intval._pin.micro.unwatch() intval._state.frame.active = false + if (intval._state.frame.cb) intval._state.frame.cb() } /** * 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 * */ -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) ) { dir = true } else { @@ -286,7 +288,7 @@ intval.frame = function (dir = null, time = null) { intval._state.frame.active = true intval._pin.micro.watch(intval._watchMicro) - log.info('frame', {dir : dir, time : time}) + log.info('frame', {dir : dir ? 'forward' : 'backward', time : time}) if (dir) { intval._startFwd() @@ -312,6 +314,7 @@ intval.frame = function (dir = null, time = null) { }, time + intval._frame.closed) } } + intval._state.frame.cb = cb } /** * Start a sequence of frames, using defaults or explicit instructions