Use PINS configuration object to initialize pins

TODO: Separate into file, automatically switching out for different
models
This commit is contained in:
mmcwilliams 2017-09-19 15:06:34 -04:00
parent 332399cfd7
commit 32affb1b72
1 changed files with 33 additions and 9 deletions

View File

@ -11,20 +11,20 @@ try {
const PINS = { const PINS = {
fwd : { fwd : {
pin : 4, pin : 13,
dir : 'out' dir : 'out'
}, },
bwd : { bwd : {
pin : 5, pin : 19,
dir : 'out' dir : 'out'
}, },
micro : { micro : {
pin : 6, pin : 6,
dir : 'in', dir : 'in',
edge : 'rising' edge : 'both'
}, },
release : { release : {
pin : 7, pin : 5,
dir : 'in', dir : 'in',
edge : 'both' edge : 'both'
} }
@ -60,11 +60,13 @@ class Intval {
* *
*/ */
_declarePins () { _declarePins () {
this._pin.fwd = Gpio(13, 'out') let pin
this._pin.bwd = Gpio(19, 'out') for (let p in PINS) {
this._pin.micro = Gpio(5, 'in', 'rising') // pin = PINS[p]
this._pin.release = Gpio(6, 'in', 'both') if (pin.edge) this._pin[p] = Gpio(pin.pin, pin.dir, pin.edge)
if (!pin.edge) this._pin[p] = Gpio(pin.pin, pin.dir)
}
console.dir(this._pin)
this._pin.release.watch(this._watchRelease) this._pin.release.watch(this._watchRelease)
} }
/** /**
@ -114,6 +116,15 @@ class Intval {
this._pin.micro.unwatch() this._pin.micro.unwatch()
this._state.frame.active = false this._state.frame.active = false
} }
/**
* Intval._watchMicro() -
* Callback for watching microswitch state changes
* Using GPIO 06 on raspberry pi zero w
*
* @param {object} err Error object present if problem reading pin
* @param {integer} val Current value of the pin
*
*/
_watchMicro (err, val) { _watchMicro (err, val) {
/* Microswitch + 10K ohm resistor */ /* Microswitch + 10K ohm resistor */
/* 1 = open */ /* 1 = open */
@ -124,6 +135,19 @@ class Intval {
this._state.frame.val = val this._state.frame.val = val
//determine when to stop //determine when to stop
} }
/**
* Intval._watchRelease() -
* Callback for watching relese switch state changes
* Using GPIO 05 on raspberry pi zero w
* * If closed, start timer.
* * If opened, check timer AND
* * If time closed longer than minimum and less than `this._releaseSequence`, start frame
* * If time closed longer than `this._releaseSequence`, start sequence
*
* @param {object} err Error object present if problem reading pin
* @param {integer} val Current value of the pin
*
*/
_watchRelease (err, val) { _watchRelease (err, val) {
const NOW = +new Date() const NOW = +new Date()
let press = 0 let press = 0