From 7e989eeadfaaf010dfdd6f13f42a5d30dc4f799c Mon Sep 17 00:00:00 2001 From: mmcw-dev Date: Fri, 20 Oct 2017 19:36:23 -0400 Subject: [PATCH] Add beginnings of the arbitrary exposure time logic. Test with /tests/index.js file --- lib/intval/index.js | 29 ++++++++++++++++++++++++----- tests/index.js | 4 +++- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/lib/intval/index.js b/lib/intval/index.js index 6b1015a..bc69ef3 100644 --- a/lib/intval/index.js +++ b/lib/intval/index.js @@ -40,12 +40,12 @@ intval.init = function () { intval._state = { dir : true, //forward frame : { - start : 0, //time frame started, timestamp + start : 0, //time frame started, timestamp active : false, //should frame be running - time : 0, //length of frame, in ms - delay : 0, //delay before start of frame, in ms - - expected : 1000 //expected length of frame, in ms + time : 0, //length of frame, in ms + delay : 0, //delay before start of frame, in ms + open : 300, //delay before pausing frame in open state + expected : 630 //expected length of frame, in ms }, release : { time: 0, @@ -117,6 +117,11 @@ intval._startBwd = function () { intval._pin.fwd.writeSync(0) intval._pin.bwd.writeSync(1) } + +intval._pause = function () { + intval._pin.fwd.writeSync(0) + intval._pin.fwd.writeSync(0) +} /** * Stop motor by setting both motor pins to 0 (LOW) * @@ -238,7 +243,13 @@ intval.setDir = function (val = true) { return log.warn('Direction must be represented as either true or false') } intval._state.dir = val +} +intval.setTime = function (val = 0) { + intval._state.frame.time = val } +intval.setDelay = function (val = 0) { + intval._state.frame.delay = val +} /** * Begin a single frame with set variables or defaults * @@ -270,6 +281,14 @@ intval.frame = function (dir = null, time = null) { } else { intval._startBwd() } + if (time !== null && time !== 0) { + setTimeout(intval._pause, intval._state.frame.open) + if (dir) { + setTimeout(intval._startFwd, 1000) + } else { + setTimeout(intval._startBwd, 1000) + } + } } /** * Start a sequence of frames, using defaults or explicit instructions diff --git a/tests/index.js b/tests/index.js index 657e5f7..47fbadb 100644 --- a/tests/index.js +++ b/tests/index.js @@ -2,4 +2,6 @@ const intval = require('../lib/intval') -intval.init() \ No newline at end of file +intval.init() +intval.setDir(false) +intval.setTime(1000) \ No newline at end of file