Created SpanToggle()

Derived from SpanButton()
This commit is contained in:
Gregg 2023-01-31 22:55:43 -06:00
parent 232362c807
commit c3d0c98e04
2 changed files with 31 additions and 6 deletions

View File

@ -976,7 +976,12 @@ void Span::processSerialCommand(const char *c){
for(auto button=PushButtons.begin(); button!=PushButtons.end(); button++){
if((*button)->service==(*svc)){
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)

View File

@ -794,7 +794,7 @@ struct [[deprecated("Please use Characteristic::setRange() method instead.")]] S
///////////////////////////////
class SpanButton : PushButton {
class SpanButton : public PushButton {
friend class Span;
friend class SpanService;
@ -804,14 +804,25 @@ class SpanButton : PushButton {
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
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;