19#ifndef SRC_SUPLA_CONTROL_SIMPLE_BUTTON_H_
20#define SRC_SUPLA_CONTROL_SIMPLE_BUTTON_H_
24#include "../element.h"
26#include "../local_action.h"
36enum StateResults { PRESSED, RELEASED, TO_PRESSED, TO_RELEASED };
40 ButtonState(
Supla::Io::Base *io,
int pin,
bool pullUp,
bool invertLogic);
41 ButtonState(
int pin,
bool pullUp,
bool invertLogic);
42 enum StateResults update();
43 enum StateResults getLastState()
const;
44 void init(
int buttonNumber);
46 void setSwNoiseFilterDelay(
unsigned int newDelayMs);
47 void setDebounceDelay(
unsigned int newDelayMs);
51 int valueOnPress()
const;
55 uint16_t debounceDelayMs = 50;
56 uint16_t swNoiseFilterDelayMs = 20;
57 uint32_t debounceTimestampMs = 0;
58 uint32_t filterTimestampMs = 0;
60 int8_t newStatusCandidate = 0;
61 int8_t prevState = -1;
63 bool invertLogic =
false;
66class SimpleButton :
public Element,
public LocalAction {
71 bool invertLogic =
false);
72 explicit SimpleButton(
int pin,
bool pullUp =
false,
bool invertLogic =
false);
76 void setSwNoiseFilterDelay(
unsigned int newDelayMs);
77 void setDebounceDelay(
unsigned int newDelayMs);
79 enum StateResults getLastState()
const;
84 virtual int8_t getButtonNumber()
const;