Begin microswitch test logic

This commit is contained in:
mmcwilliams 2017-09-22 00:29:31 -04:00
parent bc077a24a1
commit aaef150f8a
1 changed files with 63 additions and 37 deletions

View File

@ -6,6 +6,7 @@ const btn = Gpio(5, 'in', 'both')
console.log('Watching input on GPIO 05') console.log('Watching input on GPIO 05')
function releaseTest () {
let saveTime = 0 let saveTime = 0
let active = false let active = false
btn.watch((err, val) => { btn.watch((err, val) => {
@ -17,12 +18,13 @@ btn.watch((err, val) => {
return console.error(err) return console.error(err)
} }
console.log(`Release switch val: ${val}`) console.log(`Release switch val: ${val}`)
if (val === 1) { if (val === 0) {
//console.log('open')
} else if (val === 0) {
//console.log('closed') //console.log('closed')
} else if (val === 1) {
//console.log('open')
} }
if (val === 0) { if (val === 0) {
//closed
if ((!active && saveTime === 0) || (active && NOW - saveTime > 10 * 1000)) { if ((!active && saveTime === 0) || (active && NOW - saveTime > 10 * 1000)) {
saveTime = NOW saveTime = NOW
active = true //maybe unncecessary active = true //maybe unncecessary
@ -31,6 +33,7 @@ btn.watch((err, val) => {
//active = false //active = false
} }
} else if (val === 1) { } else if (val === 1) {
//open
if (active) { if (active) {
if (NOW - saveTime > 50 && NOW - saveTime < 1000) { if (NOW - saveTime > 50 && NOW - saveTime < 1000) {
console.log('Started Frame') console.log('Started Frame')
@ -43,7 +46,30 @@ btn.watch((err, val) => {
} }
} }
}) })
}
/*setInterval(() => { function microTest () {
console.log(btn.readSync()) let saveTime = 0
}, 1000)*/ 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()