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