Debounce pin state function (#1780)

* add readpinstate

* wrong var name
This commit is contained in:
David Holdeman 2020-09-09 16:18:54 -05:00 committed by GitHub
parent 7d7acc3e5f
commit e7af7cd391
2 changed files with 7 additions and 1 deletions

View File

@ -68,13 +68,18 @@ void ButtonDebounce::updateConfiguration () {
@returns true if the button is pressed, and will not return true again within the set timeout
*/
bool ButtonDebounce::readPinEvent() {
readValue = false;
return readPinState();
}
bool ButtonDebounce::readPinState() {
if (!pin) {
return false;
}
efitick_t timeNow = getTimeNowNt();
// If it's been less than the threshold since we were last called
if ((timeNow - timeLast) < threshold) {
return false;
return readValue;
}
// readValue is a class variable, so it needs to be reset.
// We don't actually need it to be a class variable in this method,

View File

@ -16,6 +16,7 @@ public:
void init(int t, brain_pin_e *p, pin_input_mode_e *m);
void updateConfiguration();
bool readPinEvent();
bool readPinState();
static void updateConfigurationList();
private:
int threshold;