From a7bcb0a87bae76c453ab0f29686d452453795bc4 Mon Sep 17 00:00:00 2001 From: mmcw-dev Date: Wed, 20 Dec 2017 22:10:36 -0500 Subject: [PATCH] Combine sequence and intval functionality --- index.js | 40 ++++++++++++++++++++++++++++++++++++++++ lib/intval/index.js | 8 +------- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 78f6624..5fbf35b 100644 --- a/index.js +++ b/index.js @@ -287,6 +287,20 @@ function rSequence (req, res, next) { exposure = req.body.exposure } } + if (req.query && typeof req.query.delay !== 'undefined') { + if (typeof req.query.delay === 'string') { + delay = parseInt(req.query.delay) + } else { + delay = req.query.delay + } + } + if (req.body && typeof req.body.delay!== 'undefined') { + if (typeof req.body.delay === 'string') { + delay = parseInt(req.body.delay) + } else { + delay = req.body.delay + } + } if (intval._state.sequence && sequence._state.active) { return sequence.setStop(() => { intval._state.sequence = false @@ -465,6 +479,31 @@ function bReset (obj, cb) { setTimeout(cb, 10) } +function seq () { + if (intval._state.sequence && sequence._state.active) { + return sequence.setStop(() => { + intval._state.sequence = false + return cb() + }) + } else { + console.time('sequence time') + intval._state.sequence = true + sequence.start({ + loop : [ (next) => { + intval.frame(dir, exposure, (len) => { + next() + }) + }, (next) => { + setTimeout(() => { + next() + }, delay) + }] + }, (seq) => { + console.timeEnd('sequence time') + }) + } +} + function index (req, res, next) { fs.readFile(INDEXPATH, 'utf8', (err, data) => { if (err) { @@ -477,6 +516,7 @@ function index (req, res, next) { function init () { intval.init() + intval.sequence = seq createServer() createBLE() } diff --git a/lib/intval/index.js b/lib/intval/index.js index 6e2ea37..2d53e14 100644 --- a/lib/intval/index.js +++ b/lib/intval/index.js @@ -412,13 +412,7 @@ intval.frame = function (dir = null, exposure = null, cb = () => {}) { exposure: exposure } } -/** -* Start a sequence of frames, using defaults or explicit instructions -* -*/ -intval.sequence = function () { - log.info('sequence', `Started sequence`) -} + intval.status = function () { return intval._state }