only: ButtonDebounce inverted API

This commit is contained in:
rusefi 2024-04-12 00:28:13 -04:00
parent 80c2e3c4f2
commit 93b3759a42
2 changed files with 5 additions and 3 deletions

View File

@ -20,7 +20,7 @@ ButtonDebounce::ButtonDebounce(const char *name)
/**
We need to have a separate init function because we do not have the pin or mode in the context in which the class is originally created
*/
void ButtonDebounce::init (efitimems_t threshold, brain_pin_e &pin, pin_input_mode_e &mode) {
void ButtonDebounce::init (efitimems_t threshold, brain_pin_e &pin, pin_input_mode_e &mode, bool inverted) {
// we need to keep track of whether we have already been initialized due to the way unit tests run.
if (!isInstanceRegisteredInGlobalList) {
// Link us to the list that is used to track ButtonDebounce instances, so that when the configuration changes,
@ -31,6 +31,7 @@ void ButtonDebounce::init (efitimems_t threshold, brain_pin_e &pin, pin_input_mo
m_threshold = MS2NT(threshold);
m_pin = &pin;
m_mode = &mode;
m_inverted = inverted;
startConfiguration();
isInstanceRegisteredInGlobalList = true;
}
@ -86,7 +87,7 @@ bool ButtonDebounce::readPinEvent() {
bool ButtonDebounce::getPhysicalState() {
#if EFI_PROD_CODE || EFI_UNIT_TEST
return efiReadPin(active_pin);
return efiReadPin(active_pin) ^ m_inverted;
#else
return false;
#endif

View File

@ -15,7 +15,7 @@
class ButtonDebounce {
public:
explicit ButtonDebounce(const char* name);
void init(efitimems_t threshold, brain_pin_e &pin, pin_input_mode_e &mode);
void init(efitimems_t threshold, brain_pin_e &pin, pin_input_mode_e &mode, bool inverted = false);
void stopConfiguration();
void startConfiguration();
bool readPinEvent();
@ -34,6 +34,7 @@ private:
pin_input_mode_e *m_mode;
pin_input_mode_e active_mode = PI_DEFAULT;
bool storedValue = false;
bool m_inverted = false;
bool isInstanceRegisteredInGlobalList = false;
bool needsPinInitialization = true;
ButtonDebounce *nextDebounce = nullptr;