Start intval logic in module

This commit is contained in:
mmcwilliams 2017-08-29 08:23:52 -04:00
parent e264dc8343
commit ddf89cf6aa
1 changed files with 27 additions and 4 deletions

View File

@ -33,7 +33,11 @@ const PINS = {
class Intval { class Intval {
constructor () { constructor () {
this._pin = {} this._pin = {}
this._startFrame = 0 this._state = {
dir : true, //forward
running : false,
startFrame : 0
}
this._declarePins() this._declarePins()
} }
_declarePins () { _declarePins () {
@ -53,12 +57,25 @@ class Intval {
this._pin.fwd.set(0) this._pin.fwd.set(0)
this._pin.bwd.set(1) this._pin.bwd.set(1)
} }
_watchMicro (err, val) {
if (err) {
console.error(err)
}
}
_watchRelease (err, val) { _watchRelease (err, val) {
if (err) { if (err) {
console.error(err); console.error(err)
} }
} }
setDir (val = true) {
if (typeof val !== 'boolean') {
return console.warn('Direction must be represented as either true or false')
}
this._state.dir = val
}
frame (dir = true, time = 0, delay = 0) { frame (dir = true, time = 0, delay = 0) {
this._state.running = true
this._pin.micro.watch(this._watchMicro)
if (delay !== 0) { if (delay !== 0) {
setTimeout(function () { setTimeout(function () {
if (dir) { if (dir) {
@ -76,8 +93,14 @@ class Intval {
} }
} }
} }
_stop () {
this._pin.fwd.set(0)
this._pin.bwd.set(0)
this._pin.micro.unwatch()
this._state.running = false
}
status () { status () {
return {} return this._state
} }
} }