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,44 +6,70 @@ const btn = Gpio(5, 'in', 'both')
console.log('Watching input on GPIO 05') console.log('Watching input on GPIO 05')
let saveTime = 0 function releaseTest () {
let active = false let saveTime = 0
btn.watch((err, val) => { let active = false
const NOW = +new Date() btn.watch((err, val) => {
/* Button + 10K ohm resistor */ const NOW = +new Date()
/* 1 = open */ /* Button + 10K ohm resistor */
/* 0 = closed */ /* 1 = open */
if (err) { /* 0 = closed */
return console.error(err) 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
} }
} else if (val === 1) { console.log(`Release switch val: ${val}`)
if (active) { if (val === 0) {
if (NOW - saveTime > 50 && NOW - saveTime < 1000) { //console.log('closed')
console.log('Started Frame') } else if (val === 1) {
} else if (NOW - saveTime >= 1000) { //console.log('open')
console.log('Started Sequence') }
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(() => { 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()