From 32affb1b72b7b7adc667f9311bb90bd43c8f08a4 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Tue, 19 Sep 2017 15:06:34 -0400 Subject: [PATCH] Use PINS configuration object to initialize pins TODO: Separate into file, automatically switching out for different models --- lib/intval/index.js | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/lib/intval/index.js b/lib/intval/index.js index 3edb38e..35481b6 100644 --- a/lib/intval/index.js +++ b/lib/intval/index.js @@ -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