| 26 | } |
| 27 | |
| 28 | void Button::_read_state() { |
| 29 | bool reading = digitalRead(_pin); |
| 30 | |
| 31 | //if (_inverted) reading = !reading; |
| 32 | reading = _inverted ^ reading; |
| 33 | |
| 34 | unsigned long now = millis(); |
| 35 | |
| 36 | if (!reading) { |
| 37 | if (_buttonState != RELEASED) { |
| 38 | button_service.write_state(RELEASED); |
| 39 | } |
| 40 | _buttonState = RELEASED; |
| 41 | _lastDebounceTime = now; |
| 42 | _pressStartTime = now; |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | if (now - _lastDebounceTime < _debounceDelay) return; |
| 47 | _buttonState = PRESSED; |
| 48 | button_service.write_state(_buttonState); |
| 49 | } |
| 50 | |
| 51 | ButtonState Button::getState() const { |
| 52 | return _buttonState; |
no test coverage detected