Push dev work to master #2
|
@ -37,16 +37,20 @@ class Intval {
|
|||
this._state = {
|
||||
dir : true, //forward
|
||||
frame : {
|
||||
start : 0,
|
||||
active : false,
|
||||
time : 0,
|
||||
delay : 0,
|
||||
val : 0,
|
||||
expected : 0
|
||||
start : 0, //time frame started, timestamp
|
||||
active : false, //should frame be running
|
||||
time : 0, //length of frame, in ms
|
||||
delay : 0, //delay before start of frame, in ms
|
||||
|
||||
expected : 0 //expected length of frame, in ms
|
||||
},
|
||||
release : {
|
||||
time: 0,
|
||||
active : false
|
||||
active : false //is pressed
|
||||
},
|
||||
micro : {
|
||||
time : 0,
|
||||
primed : false //is ready to stop frame
|
||||
}
|
||||
}
|
||||
this._releaseMin = 50
|
||||
|
@ -110,6 +114,7 @@ class Intval {
|
|||
|
||||
this._pin.micro.unwatch()
|
||||
this._state.frame.active = false
|
||||
this._state.frame.start = 0
|
||||
}
|
||||
/**
|
||||
* Callback for watching relese switch state changes.
|
||||
|
@ -158,12 +163,14 @@ class Intval {
|
|||
}
|
||||
console.log(`Release switch val: ${val}`)
|
||||
if (val === 0) {
|
||||
//closed
|
||||
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 (val === 1) {
|
||||
//opened
|
||||
if (this._state.release.active) {
|
||||
press = NOW - this._state.release.time
|
||||
if (press > this._releaseMin && press < this._releaseSequence) {
|
||||
|
|
|
@ -2,11 +2,10 @@
|
|||
|
||||
const Gpio = require('onoff').Gpio
|
||||
|
||||
const btn = Gpio(5, 'in', 'both')
|
||||
|
||||
console.log('Watching input on GPIO 05')
|
||||
|
||||
function releaseTest () {
|
||||
const PIN = 5
|
||||
const btn = Gpio(PIN, 'in', 'both')
|
||||
console.log(`Watching input on GPIO 0${PIN}`)
|
||||
let saveTime = 0
|
||||
let active = false
|
||||
btn.watch((err, val) => {
|
||||
|
@ -49,8 +48,11 @@ function releaseTest () {
|
|||
}
|
||||
|
||||
function microTest () {
|
||||
const PIN = 5
|
||||
const btn = Gpio(PIN, 'in', 'both')
|
||||
console.log(`Watching input on GPIO 0${PIN}`)
|
||||
let saveTime = 0
|
||||
let active = false //this._state.active
|
||||
let frameActive = true //this._state.frame.active
|
||||
let primed = false //this._state.primed
|
||||
btn.watch((err, val) => {
|
||||
const NOW = +new Date()
|
||||
|
@ -63,10 +65,19 @@ function microTest () {
|
|||
} else if (val === 1) {
|
||||
//console.log('open')
|
||||
}
|
||||
if (val === 0) {
|
||||
//console.log('closed')
|
||||
} else if (val === 1) {
|
||||
//console.log('open')
|
||||
if (val === 0 && frameActive) {
|
||||
if (!primed) {
|
||||
primed = true
|
||||
saveTime = NOW
|
||||
console.log('Primed')
|
||||
}
|
||||
} else if (val === 1 && frameActive) {
|
||||
if (primed) {
|
||||
primed = false
|
||||
setTimeout( () => {
|
||||
console.log(`Stop Frame after ${NOW - saveTime}`)
|
||||
}, 10)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue