Push dev work to master #2

Merged
sixteenmillimeter merged 416 commits from dev into master 2018-07-19 15:29:02 +00:00
2 changed files with 27 additions and 6 deletions
Showing only changes of commit 7e989eeadf - Show all commits

View File

@ -40,12 +40,12 @@ intval.init = function () {
intval._state = { intval._state = {
dir : true, //forward dir : true, //forward
frame : { frame : {
start : 0, //time frame started, timestamp start : 0, //time frame started, timestamp
active : false, //should frame be running active : false, //should frame be running
time : 0, //length of frame, in ms time : 0, //length of frame, in ms
delay : 0, //delay before start of frame, in ms delay : 0, //delay before start of frame, in ms
open : 300, //delay before pausing frame in open state
expected : 1000 //expected length of frame, in ms expected : 630 //expected length of frame, in ms
}, },
release : { release : {
time: 0, time: 0,
@ -117,6 +117,11 @@ intval._startBwd = function () {
intval._pin.fwd.writeSync(0) intval._pin.fwd.writeSync(0)
intval._pin.bwd.writeSync(1) 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) * 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') return log.warn('Direction must be represented as either true or false')
} }
intval._state.dir = val 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 * Begin a single frame with set variables or defaults
* *
@ -270,6 +281,14 @@ intval.frame = function (dir = null, time = null) {
} else { } else {
intval._startBwd() 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 * Start a sequence of frames, using defaults or explicit instructions

View File

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