Address conflict between SpanButton and certain Adafruit Boards

Change enum from BUTTON and TOGGLE to HS_BUTTON and HS_TOGGLE to avoid conflict with #define BUTTON in certain Adafruit boards
This commit is contained in:
HomeSpan 2023-04-20 21:56:55 -04:00
parent 5853989651
commit 889a326e02
2 changed files with 8 additions and 8 deletions

View File

@ -969,7 +969,7 @@ void Span::processSerialCommand(const char *c){
for(auto button=PushButtons.begin(); button!=PushButtons.end(); button++){ for(auto button=PushButtons.begin(); button!=PushButtons.end(); button++){
if((*button)->service==(*svc)){ if((*button)->service==(*svc)){
if((*button)->buttonType==SpanButton::BUTTON) if((*button)->buttonType==SpanButton::HS_BUTTON)
Serial.printf(" \u25bc SpanButton: Pin=%d, Single=%ums, Double=%ums, Long=%ums, Type=",(*button)->pin,(*button)->singleTime,(*button)->doubleTime,(*button)->longTime); Serial.printf(" \u25bc SpanButton: Pin=%d, Single=%ums, Double=%ums, Long=%ums, Type=",(*button)->pin,(*button)->singleTime,(*button)->doubleTime,(*button)->longTime);
else else
Serial.printf(" \u25bc SpanToggle: Pin=%d, Toggle=%ums, Type=",(*button)->pin,(*button)->longTime); Serial.printf(" \u25bc SpanToggle: Pin=%d, Toggle=%ums, Type=",(*button)->pin,(*button)->longTime);
@ -2118,7 +2118,7 @@ SpanRange::SpanRange(int min, int max, int step){
SpanButton::SpanButton(int pin, uint16_t longTime, uint16_t singleTime, uint16_t doubleTime, triggerType_t triggerType) : PushButton(pin, triggerType){ SpanButton::SpanButton(int pin, uint16_t longTime, uint16_t singleTime, uint16_t doubleTime, triggerType_t triggerType) : PushButton(pin, triggerType){
if(homeSpan.Accessories.empty() || homeSpan.Accessories.back()->Services.empty()){ if(homeSpan.Accessories.empty() || homeSpan.Accessories.back()->Services.empty()){
if(buttonType==BUTTON) if(buttonType==HS_BUTTON)
Serial.printf("\nFATAL ERROR! Can't create new SpanButton(%d,%u,%u,%u) without a defined Service ***\n",pin,longTime,singleTime,doubleTime); Serial.printf("\nFATAL ERROR! Can't create new SpanButton(%d,%u,%u,%u) without a defined Service ***\n",pin,longTime,singleTime,doubleTime);
else else
Serial.printf("\nFATAL ERROR! Can't create new SpanToggle(%d,%u) without a defined Service ***\n",pin,longTime); Serial.printf("\nFATAL ERROR! Can't create new SpanToggle(%d,%u) without a defined Service ***\n",pin,longTime);
@ -2139,8 +2139,8 @@ SpanButton::SpanButton(int pin, uint16_t longTime, uint16_t singleTime, uint16_t
void SpanButton::check(){ void SpanButton::check(){
if( (buttonType==BUTTON && triggered(singleTime,longTime,doubleTime)) || if( (buttonType==HS_BUTTON && triggered(singleTime,longTime,doubleTime)) ||
(buttonType==TOGGLE && toggled(longTime)) ) // if the underlying PushButton is triggered/toggled (buttonType==HS_TOGGLE && toggled(longTime)) ) // if the underlying PushButton is triggered/toggled
service->button(pin,type()); // call the Service's button() routine with pin and type as parameters service->button(pin,type()); // call the Service's button() routine with pin and type as parameters
} }

View File

@ -814,11 +814,11 @@ class SpanButton : public PushButton {
protected: protected:
enum buttonType_t { enum buttonType_t {
BUTTON, HS_BUTTON,
TOGGLE HS_TOGGLE
}; };
buttonType_t buttonType=BUTTON; // type of SpanButton buttonType_t buttonType=HS_BUTTON; // type of SpanButton
public: public:
@ -842,7 +842,7 @@ class SpanToggle : public SpanButton {
public: public:
SpanToggle(int pin, triggerType_t triggerType=TRIGGER_ON_LOW, uint16_t toggleTime=5) : SpanButton(pin,triggerType,toggleTime){buttonType=TOGGLE;}; SpanToggle(int pin, triggerType_t triggerType=TRIGGER_ON_LOW, uint16_t toggleTime=5) : SpanButton(pin,triggerType,toggleTime){buttonType=HS_TOGGLE;};
int position(){return(pressType);} int position(){return(pressType);}
}; };