diff --git a/lib/intval/index.js b/lib/intval/index.js index 4c4dd49..e8a502d 100644 --- a/lib/intval/index.js +++ b/lib/intval/index.js @@ -42,6 +42,7 @@ intval.init = function () { frame : { start : 0, //time frame started, timestamp active : false, //should frame be running + paused : false, 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 @@ -121,6 +122,7 @@ intval._startBwd = function () { intval._pause = function () { intval._pin.fwd.writeSync(0) intval._pin.fwd.writeSync(0) + intval._state.micro.paused = true } /** * Stop motor by setting both motor pins to 0 (LOW) @@ -167,7 +169,7 @@ intval._watchMicro = function (err, val) { log.info('Microswitch primed to stop motor') } } else if (val === 1 && intval._state.frame.active) { - if (intval._state.micro.primed) { + if (intval._state.micro.primed && !intval._state.micro.paused) { intval._state.micro.primed = false intval._state.micro.time = 0 //setTimeout( () => { @@ -289,12 +291,15 @@ intval.frame = function (dir = null, time = null) { setTimeout(intval._pause, intval._state.frame.open) if (dir) { log.info('frame', { pausing : time - intval._state.frame.open }) - setTimeout(() => { - log.info('frame', 'restarting after pause') + setTimeout( () => { + intval._state.frame.paused = false intval._startFwd() }, time - intval._state.frame.open) } else { - setTimeout(intval._startBwd, time - intval._state.frame.open) + setTimeout( () => { + intval._state.frame.paused = false + intval._startBwd() + }, time - intval._state.frame.open) } } }