2017-09-16 18:47:33 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const Gpio = require('onoff').Gpio
|
|
|
|
|
2017-09-16 19:07:34 +00:00
|
|
|
const btn = Gpio(5, 'in', 'both')
|
2017-09-16 18:47:33 +00:00
|
|
|
|
2017-09-16 19:07:34 +00:00
|
|
|
console.log('Watching input on GPIO 05')
|
2017-09-16 18:54:40 +00:00
|
|
|
|
2017-09-17 23:51:33 +00:00
|
|
|
let saveTime = 0
|
|
|
|
let active = false
|
2017-09-16 19:09:29 +00:00
|
|
|
btn.watch((err, val) => {
|
2017-09-17 23:51:33 +00:00
|
|
|
const NOW = +new Date()
|
|
|
|
/* Button + 10K ohm resistor */
|
|
|
|
/* 1 = open */
|
|
|
|
/* 0 = closed */
|
2017-09-16 18:47:33 +00:00
|
|
|
if (err) {
|
|
|
|
return console.error(err)
|
|
|
|
}
|
2017-09-18 00:27:51 +00:00
|
|
|
console.log(`Release switch val: ${val}`)
|
2017-09-17 23:55:35 +00:00
|
|
|
if (val === 1) {
|
2017-09-18 00:00:26 +00:00
|
|
|
//console.log('open')
|
2017-09-17 23:55:35 +00:00
|
|
|
} else if (val === 0) {
|
2017-09-18 00:00:26 +00:00
|
|
|
//console.log('closed')
|
2017-09-17 23:55:35 +00:00
|
|
|
}
|
2017-09-17 23:51:33 +00:00
|
|
|
if (val === 0) {
|
2017-09-18 00:25:21 +00:00
|
|
|
if ((!active && saveTime === 0) || (active && NOW - saveTime > 10 * 1000)) {
|
2017-09-17 23:51:33 +00:00
|
|
|
saveTime = NOW
|
|
|
|
active = true //maybe unncecessary
|
2017-09-18 00:00:26 +00:00
|
|
|
} else {
|
|
|
|
//saveTime = 0
|
|
|
|
//active = false
|
2017-09-17 23:55:35 +00:00
|
|
|
}
|
|
|
|
} else if (val === 1) {
|
|
|
|
if (active) {
|
2017-09-17 23:57:38 +00:00
|
|
|
if (NOW - saveTime > 50 && NOW - saveTime < 1000) {
|
2017-09-17 23:51:33 +00:00
|
|
|
console.log('Started Frame')
|
2017-09-17 23:57:38 +00:00
|
|
|
} else if (NOW - saveTime >= 1000) {
|
2017-09-17 23:51:33 +00:00
|
|
|
console.log('Started Sequence')
|
|
|
|
}
|
|
|
|
console.log(`Release closed for ${NOW - saveTime}`)
|
|
|
|
saveTime = 0
|
|
|
|
active = false
|
|
|
|
}
|
|
|
|
}
|
2017-09-16 19:09:29 +00:00
|
|
|
})
|
2017-09-16 18:54:40 +00:00
|
|
|
|
2017-09-16 19:09:29 +00:00
|
|
|
/*setInterval(() => {
|
2017-09-16 18:54:40 +00:00
|
|
|
console.log(btn.readSync())
|
2017-09-16 19:09:29 +00:00
|
|
|
}, 1000)*/
|