2017-08-22 03:52:27 +00:00
|
|
|
'use strict'
|
|
|
|
|
2017-08-28 12:49:47 +00:00
|
|
|
let Gpio
|
|
|
|
try {
|
|
|
|
Gpio = require('onoff').Gpio
|
|
|
|
} catch (e) {
|
|
|
|
console.warn('Failed including Gpio, using sim')
|
|
|
|
Gpio = require('../../lib/onoffsim').Gpio
|
|
|
|
}
|
|
|
|
|
2017-08-26 23:26:30 +00:00
|
|
|
|
2017-08-22 05:31:27 +00:00
|
|
|
const PINS = {
|
|
|
|
fwd : {
|
|
|
|
pin : 4,
|
|
|
|
dir : 'out'
|
|
|
|
},
|
|
|
|
bwd : {
|
|
|
|
pin : 5,
|
|
|
|
dir : 'out'
|
|
|
|
},
|
|
|
|
micro : {
|
|
|
|
pin : 6,
|
|
|
|
dir : 'in',
|
|
|
|
edge : 'rising'
|
|
|
|
},
|
|
|
|
release : {
|
|
|
|
pin : 7,
|
|
|
|
dir : 'in',
|
|
|
|
edge : 'both'
|
|
|
|
}
|
|
|
|
}
|
2017-08-22 03:52:27 +00:00
|
|
|
|
|
|
|
class Intval {
|
|
|
|
constructor () {
|
|
|
|
this._pin = {}
|
2017-08-22 04:30:17 +00:00
|
|
|
this._startFrame = 0
|
2017-08-22 03:52:27 +00:00
|
|
|
this._declarePins()
|
|
|
|
}
|
|
|
|
_declarePins () {
|
2017-08-22 05:31:27 +00:00
|
|
|
this._pin.fwd = Gpio(4, 'out')
|
|
|
|
this._pin.bwd = Gpio(5, 'out')
|
|
|
|
this._pin.micro = Gpio(6, 'in', 'rising')
|
|
|
|
this._pin.release = Gpio(7, 'in', 'both')
|
2017-08-28 12:49:47 +00:00
|
|
|
|
|
|
|
this._pin.release.watch(this._watchRelease)
|
2017-08-22 04:49:08 +00:00
|
|
|
}
|
|
|
|
_startFwd () {
|
|
|
|
this._pin.fwd.set(1)
|
|
|
|
this._pin.bwd.set(0)
|
2017-08-28 12:49:47 +00:00
|
|
|
//start high-cpu watch
|
2017-08-22 04:49:08 +00:00
|
|
|
}
|
|
|
|
_startBwd () {
|
|
|
|
this._pin.fwd.set(0)
|
|
|
|
this._pin.bwd.set(1)
|
|
|
|
}
|
2017-08-28 12:49:47 +00:00
|
|
|
_watchRelease (err, val) {
|
|
|
|
if (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
}
|
2017-08-22 04:49:08 +00:00
|
|
|
frame (dir = true, time = 0, delay = 0) {
|
|
|
|
if (delay !== 0) {
|
|
|
|
setTimeout(function () {
|
|
|
|
if (dir) {
|
|
|
|
this._startFwd()
|
|
|
|
} else {
|
|
|
|
this._startBwd()
|
|
|
|
}
|
|
|
|
|
|
|
|
}, delay)
|
|
|
|
} else {
|
|
|
|
if (dir) {
|
|
|
|
this._startFwd()
|
|
|
|
} else {
|
|
|
|
this._startBwd()
|
|
|
|
}
|
|
|
|
}
|
2017-08-22 03:52:27 +00:00
|
|
|
}
|
2017-08-22 04:00:24 +00:00
|
|
|
status () {
|
|
|
|
return {}
|
|
|
|
}
|
2017-08-22 03:52:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = new Intval()
|