diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 2b20cf5..b07b858 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -976,7 +976,12 @@ void Span::processSerialCommand(const char *c){ for(auto button=PushButtons.begin(); button!=PushButtons.end(); button++){ if((*button)->service==(*svc)){ - Serial.printf(" \u25bc SpanButton: Pin=%d, Single=%ums, Double=%ums, Long=%ums, Type=",(*button)->pin,(*button)->singleTime,(*button)->doubleTime,(*button)->longTime); + + if((*button)->buttonType==SpanButton::BUTTON) + Serial.printf(" \u25bc SpanButton: Pin=%d, Single=%ums, Double=%ums, Long=%ums, Type=",(*button)->pin,(*button)->singleTime,(*button)->doubleTime,(*button)->longTime); + else + Serial.printf(" \u25bc SpanToggle: Pin=%d, Toggle=%ums, Type=",(*button)->pin,(*button)->longTime); + if((*button)->triggerType==PushButton::TRIGGER_ON_LOW) Serial.printf("TRIGGER_ON_LOW\n"); else if((*button)->triggerType==PushButton::TRIGGER_ON_HIGH) diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 9c37a49..34438d9 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -794,24 +794,35 @@ struct [[deprecated("Please use Characteristic::setRange() method instead.")]] S /////////////////////////////// -class SpanButton : PushButton { +class SpanButton : public PushButton { friend class Span; friend class SpanService; - + uint16_t singleTime; // minimum time (in millis) required to register a single press uint16_t longTime; // minimum time (in millis) required to register a long press uint16_t doubleTime; // maximum time (in millis) between single presses to register a double press instead - SpanService *service; // Service to which this PushButton is attached + SpanService *service; // Service to which this PushButton is attached - void check(); // check PushButton and call button() if pressed + void check(); // check PushButton and call button() if "pressed" + protected: + + enum buttonType_t { + BUTTON, + TOGGLE + }; + + buttonType_t buttonType=BUTTON; // type of SpanButton + public: enum { SINGLE=0, DOUBLE=1, - LONG=2 + LONG=2, + ON=3, + OFF=4 }; static constexpr triggerType_t TRIGGER_ON_LOW=PushButton::TRIGGER_ON_LOW; @@ -830,6 +841,15 @@ class SpanButton : PushButton { /////////////////////////////// +class SpanToggle : SpanButton { + + public: + + SpanToggle(int pin, triggerType_t triggerType=TRIGGER_ON_LOW, uint16_t toggleTime=5) : SpanButton(pin,triggerType,toggleTime){buttonType=TOGGLE;}; +}; + +/////////////////////////////// + class SpanUserCommand { friend class Span;