diff --git a/app/www/index.html b/app/www/index.html index f9832ec..5967fb9 100644 --- a/app/www/index.html +++ b/app/www/index.html @@ -322,7 +322,13 @@ null==d?void 0:d))},attrHooks:{type:{set:function(a,b){if(!o.radioValue&&"radio" }; web.getStateSuccess = function (res) { 'use strict'; - console.dir(res); + if (res.frame.dir !== true) { + $('#dir').prop('checked', true); + setDirLabel(false); + } + $('#counter').val(res.counter); + $('#exposure').val(res.frame.exposure); + $('#delay').val(res.frame.delay); }; web.init = function () { 'use strict'; @@ -330,6 +336,7 @@ null==d?void 0:d))},attrHooks:{type:{set:function(a,b){if(!o.radioValue&&"radio" getState = web.getState; setDir = web.setDir; setExposure = web.setExposure; + web.getState(); }; web.init(); diff --git a/index.js b/index.js index 019cb99..34b68f9 100644 --- a/index.js +++ b/index.js @@ -25,6 +25,8 @@ function createServer () { app.post('/dir', rDir) app.get( '/exposure', rExposure) app.post('/exposure', rExposure) + app.get( '/counter', rCounter) + app.post('/counter', rCounter) app.get( '/frame', rFrame) app.post('/frame', rFrame) app.get( '/sequence', () => {}) @@ -119,6 +121,35 @@ function rDelay (req, res, next) { return next() } +function rCounter (req, res, next) { + let counter = 0 + let set = false + if (req.query && typeof req.query.counter !== 'undefined') { + if (typeof req.query.counter === 'string') { + counter = parseInt(req.query.counter) + } else { + counter = req.query.counter + } + set = true + } + if (req.body && typeof req.body.counter !== 'undefined') { + if (typeof req.body.counter !== 'string') { + counter = parseInt(req.body.counter) + } else { + counter = req.body.counter + } + set = true + } + if (set) { + intval.setCounter(counter) + } else { + counter = intval._state.counter + } + log.info('/counter', { method : req.method, set : set, counter : counter }) + req.send({ counter : counter }) + return next() +} + function rFrame (req, res, next) { let dir = true let exposure = 0 diff --git a/lib/intval/index.js b/lib/intval/index.js index 3b9d54c..772a6cc 100644 --- a/lib/intval/index.js +++ b/lib/intval/index.js @@ -54,7 +54,8 @@ intval.init = function () { micro : { time : 0, primed : false //is ready to stop frame - } + }, + counter : 0 } intval._frame = { open : 250, //delay before pausing frame in open state @@ -264,6 +265,10 @@ intval.setDelay = function (val = 0) { intval._state.frame.delay = val log.info('setDelay', { delay : val }) } +intval.setCounter = function (val = 0) { + intval._state.counter = val + log.info('setCounter', { counter : val }) +} /** * Begin a single frame with set variables or defaults * @@ -313,8 +318,16 @@ intval.frame = function (dir = null, time = null, cb = () => {}) { }, time + intval._frame.closed) } } - intval._state.frame.cb = (len) => { - cb(len) + if (dir) { + intval._state.frame.cb = (len) => { + intval._state.counter++ + cb(len) + } + } else { + intval._state.frame.cb = (len) => { + intval._state.counter-- + cb(len) + } } } /**