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 = {
fwd : {
pin : 4,
pin : 13,
dir : 'out'
},
bwd : {
pin : 5,
pin : 19,
dir : 'out'
},
micro : {
pin : 6,
dir : 'in',
edge : 'rising'
edge : 'both'
},
release : {
pin : 7,
pin : 5,
dir : 'in',
edge : 'both'
}
@ -60,11 +60,13 @@ class Intval {
*
*/
_declarePins () {
this._pin.fwd = Gpio(13, 'out')
this._pin.bwd = Gpio(19, 'out')
this._pin.micro = Gpio(5, 'in', 'rising') //
this._pin.release = Gpio(6, 'in', 'both')
let pin
for (let p in PINS) {
pin = PINS[p]
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)
}
/**
@ -114,6 +116,15 @@ class Intval {
this._pin.micro.unwatch()
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) {
/* Microswitch + 10K ohm resistor */
/* 1 = open */
@ -124,6 +135,19 @@ class Intval {
this._state.frame.val = val
//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) {
const NOW = +new Date()
let press = 0