Refactor releaseWatch to use a seperate function to determine close state for the release switch

This commit is contained in:
mmcw-dev 2017-10-19 21:30:07 -04:00
parent 2b06eb3b3c
commit e27add8da7
1 changed files with 15 additions and 6 deletions

View File

@ -172,7 +172,7 @@ class Intval {
*
* 1) If closed, start timer.
* 2) If opened, check timer AND
* 3) If `press` (`NOW - this._state.release.time`) greater than minimum and less than `this._releaseSequence`, start frame
* 3) If `press` (`now - this._state.release.time`) greater than minimum and less than `this._releaseSequence`, start frame
* 4) If `press` greater than `this._releaseSequence`, start sequence
*
* Button + 10K ohm resistor
@ -184,7 +184,7 @@ class Intval {
*
*/
_watchRelease (err, val) {
const NOW = +new Date()
const now = +new Date()
let press = 0
if (err) {
return log.error(err)
@ -192,15 +192,14 @@ class Intval {
log.info(`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
if (this._releaseClosedState(now)) {
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
press = now - this._state.release.time
if (press > this._releaseMin && press < this._releaseSequence) {
this.frame()
} else if (press >= this._releaseSequence) {
@ -213,6 +212,16 @@ class Intval {
}
log.info('completed if statement')
}
_releaseClosedState (now) {
if (!this._state.release.active && this._state.release.time === 0) {
return true
}
if (this._state.release.active && (now - this._state.release.time) > (this._releaseSequence * 10)) {
return true
}
return false
}
/**
* Set the default direction of the camera.
* * forward = true