From aaef150f8a9a9f352bca68229d14ba65a089e1e0 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Fri, 22 Sep 2017 00:29:31 -0400 Subject: [PATCH] Begin microswitch test logic --- tests/gpio.js | 100 +++++++++++++++++++++++++++++++------------------- 1 file changed, 63 insertions(+), 37 deletions(-) diff --git a/tests/gpio.js b/tests/gpio.js index ac46e7c..ccd8e5c 100644 --- a/tests/gpio.js +++ b/tests/gpio.js @@ -6,44 +6,70 @@ const btn = Gpio(5, 'in', 'both') console.log('Watching input on GPIO 05') -let saveTime = 0 -let active = false -btn.watch((err, val) => { - const NOW = +new Date() - /* Button + 10K ohm resistor */ - /* 1 = open */ - /* 0 = closed */ - if (err) { - return console.error(err) - } - console.log(`Release switch val: ${val}`) - if (val === 1) { - //console.log('open') - } else if (val === 0) { - //console.log('closed') - } - if (val === 0) { - if ((!active && saveTime === 0) || (active && NOW - saveTime > 10 * 1000)) { - saveTime = NOW - active = true //maybe unncecessary - } else { - //saveTime = 0 - //active = false +function releaseTest () { + let saveTime = 0 + let active = false + btn.watch((err, val) => { + const NOW = +new Date() + /* Button + 10K ohm resistor */ + /* 1 = open */ + /* 0 = closed */ + if (err) { + return console.error(err) } - } else if (val === 1) { - if (active) { - if (NOW - saveTime > 50 && NOW - saveTime < 1000) { - console.log('Started Frame') - } else if (NOW - saveTime >= 1000) { - console.log('Started Sequence') + console.log(`Release switch val: ${val}`) + if (val === 0) { + //console.log('closed') + } else if (val === 1) { + //console.log('open') + } + if (val === 0) { + //closed + if ((!active && saveTime === 0) || (active && NOW - saveTime > 10 * 1000)) { + saveTime = NOW + active = true //maybe unncecessary + } else { + //saveTime = 0 + //active = false + } + } else if (val === 1) { + //open + if (active) { + if (NOW - saveTime > 50 && NOW - saveTime < 1000) { + console.log('Started Frame') + } else if (NOW - saveTime >= 1000) { + console.log('Started Sequence') + } + console.log(`Release closed for ${NOW - saveTime}`) + saveTime = 0 + active = false } - console.log(`Release closed for ${NOW - saveTime}`) - saveTime = 0 - active = false } - } -}) + }) +} -/*setInterval(() => { - console.log(btn.readSync()) -}, 1000)*/ \ No newline at end of file +function microTest () { + let saveTime = 0 + let active = false //this._state.active + let primed = false //this._state.primed + btn.watch((err, val) => { + const NOW = +new Date() + if (err) { + return console.error(err) + } + console.log(`Micro switch val: ${val}`) + if (val === 0) { + //console.log('closed') + } else if (val === 1) { + //console.log('open') + } + if (val === 0) { + //console.log('closed') + } else if (val === 1) { + //console.log('open') + } + }) +} + +//releaseTest() +microTest() \ No newline at end of file