comparison Button.cpp @ 2:b76b999b88c7 default tip

fix flank detection
author ark
date 2017-01-31 00:07 +0100
parents 284066a427c8
children
comparison
equal deleted inserted replaced
1:284066a427c8 2:b76b999b88c7
30 30
31 31
32 void Button::update(unsigned long ms) { 32 void Button::update(unsigned long ms) {
33 bool s = this->readState(); 33 bool s = this->readState();
34 // process state change 34 // process state change
35 this->isPressed = false;
36 this->isReleased = false;
35 if(this->isOn != s) { 37 if(this->isOn != s) {
36 // if last state change is older than threshold, accept new state 38 // if last state change is older than threshold, accept new state
37 // change is not a bounce. 39 // change is not a bounce.
38 if(ms - this->lastChangeMs >= Button::BOUNCE_THRESHOLD) { 40 if(ms - this->lastChangeMs >= Button::BOUNCE_THRESHOLD) {
41 this->isOn = s;
39 this->isPressed = this->isOn; 42 this->isPressed = this->isOn;
40 this->isReleased = !this->isOn; 43 this->isReleased = !this->isOn;
41 this->isOn = s;
42 this->lastChangeMs = ms; 44 this->lastChangeMs = ms;
43 } 45 }
44 } else {
45 this->isPressed = false;
46 this->isReleased = false;
47 } 46 }
48 } 47 }
49 48
50 49
51 bool Button::readState() { 50 bool Button::readState() {