Line data Source code
1 : #include "IncrementButton.hpp" 2 : 3 : BEGIN_CS_NAMESPACE 4 : 5 12 : IncrementButton::State IncrementButton::updateImplementation() { 6 12 : Button::State incrState = button.update(); 7 : 8 12 : if (incrState == Button::Released) { 9 : // Button released, don't do anything 10 : // This one is first to minimize overhead 11 : // because most of the time, the button will 12 : // be released 13 12 : } else if (incrState == Button::Rising) { 14 4 : longPressState = Initial; 15 10 : } else if (incrState == Button::Falling) { 16 6 : return Increment; 17 : } else { // if (incrState == Button::Pressed) 18 0 : if (longPressState == LongPress) { 19 : // still long pressed 20 0 : if (millis() - longPressRepeat >= LONG_PRESS_REPEAT_DELAY) { 21 0 : longPressRepeat += LONG_PRESS_REPEAT_DELAY; 22 0 : return Increment; 23 : } 24 0 : } else if (button.stableTime() >= LONG_PRESS_DELAY) { 25 : // long press starts 26 0 : longPressState = LongPress; 27 0 : longPressRepeat = millis(); 28 0 : return Increment; 29 : } 30 : } 31 6 : return Nothing; 32 12 : } 33 : 34 : END_CS_NAMESPACE