More complex logic to prevent errant closed events from breaking
This commit is contained in:
parent
2d0aaaca8c
commit
78135c4e77
|
@ -49,6 +49,8 @@ class Intval {
|
|||
active : false
|
||||
}
|
||||
}
|
||||
this._releaseMin = 50
|
||||
this._releaseSequence = 1000
|
||||
this._declarePins()
|
||||
process.on('SIGINT', this._undeclarePins)
|
||||
}
|
||||
|
@ -98,6 +100,7 @@ class Intval {
|
|||
}
|
||||
_watchRelease (err, val) {
|
||||
const NOW = +new Date()
|
||||
let press = 0
|
||||
/* Button + 10K ohm resistor */
|
||||
/* 1 = open */
|
||||
/* 0 = closed */
|
||||
|
@ -106,16 +109,20 @@ class Intval {
|
|||
}
|
||||
console.log(`Release switch val: ${val}`)
|
||||
if (val === 0) {
|
||||
if (this._state.release.time === 0) {
|
||||
if ((!this._state.release.active && this._state.release.time === 0) || (this._state.release.active && (NOW - this._state.release.time) > (this._releaseSequence * 10))
|
||||
) {
|
||||
this._state.release.time = NOW
|
||||
this._state.release.active = true //maybe unncecessary
|
||||
} else if (this._state.release.active) {
|
||||
if (NOW - this._state.release.time > 100) {
|
||||
}
|
||||
} else if (val === 1) {
|
||||
if (this._state.release.active) {
|
||||
press = NOW - this._state.release.time
|
||||
if (press > this._releaseMin && press < this._releaseSequence) {
|
||||
this.frame()
|
||||
} else if (NOW - this._state.release.time > 1000) {
|
||||
} else if (press >= this._releaseSequence) {
|
||||
this.sequence()
|
||||
}
|
||||
console.log(`Release closed for ${NOW - this._state.release.time}`)
|
||||
console.log(`Release closed for ${press}`)
|
||||
this._state.release.time = 0
|
||||
this._state.release.active = false
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ btn.watch((err, val) => {
|
|||
//console.log('closed')
|
||||
}
|
||||
if (val === 0) {
|
||||
if (saveTime === 0) {
|
||||
if ((!active && saveTime === 0) || (active && NOW - saveTime > 10 * 1000)) {
|
||||
saveTime = NOW
|
||||
active = true //maybe unncecessary
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue