implement invert
This commit is contained in:
parent
f2e6289330
commit
5b66d34d58
|
@ -1,12 +1,13 @@
|
||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
|
|
||||||
Button::Button(DigitalInputCard *inputCard, uint8_t inputPin)
|
Button::Button(DigitalInputCard *inputCard, uint8_t inputPin, bool invert)
|
||||||
{
|
{
|
||||||
this->inputCard = inputCard;
|
this->inputCard = inputCard;
|
||||||
this->inputPin = inputPin;
|
this->inputPin = inputPin;
|
||||||
this->input_handler_id = -1; // initialize to MAX_UINT16
|
this->input_handler_id = -1; // initialize to MAX_UINT16
|
||||||
this->shortPressTime = 100; // default short press time
|
this->shortPressTime = 100; // default short press time
|
||||||
this->longPressTime = 2000; // default long press time
|
this->longPressTime = 2000; // default long press time
|
||||||
|
this->invert = invert;
|
||||||
}
|
}
|
||||||
|
|
||||||
Button::~Button()
|
Button::~Button()
|
||||||
|
@ -48,6 +49,8 @@ void Button::buttonChangedCallback(uint8_t pin, uint8_t value)
|
||||||
if (pin != this->inputPin)
|
if (pin != this->inputPin)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
value = this->invert ? !value : value;
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
// button pressed
|
// button pressed
|
||||||
this->buttonState = true;
|
this->buttonState = true;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
class Button {
|
class Button {
|
||||||
public:
|
public:
|
||||||
Button(DigitalInputCard* inputCard, uint8_t inputPin);
|
Button(DigitalInputCard* inputCard, uint8_t inputPin, bool invert = false);
|
||||||
~Button();
|
~Button();
|
||||||
void setMinLongPressTime(uint32_t time);
|
void setMinLongPressTime(uint32_t time);
|
||||||
void setMinShortPressTime(uint32_t time);
|
void setMinShortPressTime(uint32_t time);
|
||||||
|
@ -19,6 +19,7 @@ class Button {
|
||||||
std::function<void()> longPressCallback;
|
std::function<void()> longPressCallback;
|
||||||
std::function<void()> shortPressCallback;
|
std::function<void()> shortPressCallback;
|
||||||
uint32_t pressedTime;
|
uint32_t pressedTime;
|
||||||
|
bool invert;
|
||||||
bool buttonState;
|
bool buttonState;
|
||||||
bool longPressTriggered;
|
bool longPressTriggered;
|
||||||
void buttonChangedCallback(uint8_t pin, uint8_t value);
|
void buttonChangedCallback(uint8_t pin, uint8_t value);
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
ESPMegaPRO espmega = ESPMegaPRO();
|
ESPMegaPRO espmega = ESPMegaPRO();
|
||||||
ESPMegaDisplayOTA internalDisplayOTA = ESPMegaDisplayOTA();
|
ESPMegaDisplayOTA internalDisplayOTA = ESPMegaDisplayOTA();
|
||||||
Button rightOnButton(&espmega.inputs, RIGHT_ON_BUTTON_PIN);
|
Button rightOnButton(&espmega.inputs, RIGHT_ON_BUTTON_PIN);
|
||||||
Button rightOffButton(&espmega.inputs, RIGHT_OFF_BUTTON_PIN);
|
Button rightOffButton(&espmega.inputs, RIGHT_OFF_BUTTON_PIN, true);
|
||||||
Button leftOnButton(&espmega.inputs, LEFT_ON_BUTTON_PIN);
|
Button leftOnButton(&espmega.inputs, LEFT_ON_BUTTON_PIN);
|
||||||
Button leftOffButton(&espmega.inputs, LEFT_OFF_BUTTON_PIN);
|
Button leftOffButton(&espmega.inputs, LEFT_OFF_BUTTON_PIN, true);
|
||||||
SmartVariable toiletLightsLock;
|
SmartVariable toiletLightsLock;
|
||||||
SmartVariable gymLightsLock;
|
SmartVariable gymLightsLock;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue