Add beginnings of the arbitrary exposure time logic. Test with /tests/index.js file

This commit is contained in:
mmcw-dev 2017-10-20 19:36:23 -04:00
parent 429441137e
commit 7e989eeadf
2 changed files with 27 additions and 6 deletions

View File

@ -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

View File

@ -2,4 +2,6 @@
const intval = require('../lib/intval')
intval.init()
intval.init()
intval.setDir(false)
intval.setTime(1000)