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"
34enum StateResults { PRESSED, RELEASED, TO_PRESSED, TO_RELEASED };
38 ButtonState(
Supla::Io *io,
int pin,
bool pullUp,
bool invertLogic);
39 ButtonState(
int pin,
bool pullUp,
bool invertLogic);
40 enum StateResults update();
41 enum StateResults getLastState()
const;
42 void init(
int buttonNumber);
44 void setSwNoiseFilterDelay(
unsigned int newDelayMs);
45 void setDebounceDelay(
unsigned int newDelayMs);
49 int valueOnPress()
const;
53 uint16_t debounceDelayMs = 50;
54 uint16_t swNoiseFilterDelayMs = 20;
55 uint32_t debounceTimestampMs = 0;
56 uint32_t filterTimestampMs = 0;
58 int8_t newStatusCandidate = 0;
59 int8_t prevState = -1;
61 bool invertLogic =
false;
64class SimpleButton :
public Element,
public LocalAction {
69 bool invertLogic =
false);
70 explicit SimpleButton(
int pin,
bool pullUp =
false,
bool invertLogic =
false);
74 void setSwNoiseFilterDelay(
unsigned int newDelayMs);
75 void setDebounceDelay(
unsigned int newDelayMs);
77 enum StateResults getLastState()
const;
82 virtual int8_t getButtonNumber()
const;