supla-device
Loading...
Searching...
No Matches
button.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_CONTROL_BUTTON_H_
5#define SRC_SUPLA_CONTROL_BUTTON_H_
6
7#include <stdint.h>
8#include <supla/action_handler.h>
9#include "action_trigger.h"
10#include "simple_button.h"
11
13
14namespace Supla {
15namespace Io {
16class Base;
17} // namespace Io
18
19namespace Control {
20
21class Button : public SimpleButton, public ActionHandler {
22 public:
23 friend class ActionTrigger;
24 enum class ButtonType : uint8_t {
25 MONOSTABLE,
26 BISTABLE,
27 MOTION_SENSOR,
28 CENTRAL_CONTROL
29 };
30
31 enum class OnLoadConfigType : uint8_t {
32 LOAD_FULL_CONFIG,
33 LOAD_BUTTON_SETUP_ONLY,
34 DONT_LOAD_CONFIG
35 };
36
37 explicit Button(Supla::Io::IoPin inputPin);
38 explicit Button(Supla::Io::Base *io,
39 int pin,
40 bool pullUp = false,
41 bool invertLogic = false);
42 explicit Button(int pin, bool pullUp = false, bool invertLogic = false);
43
44 void onTimer() override;
45 void onLoadConfig(SuplaDeviceClass *) override;
46 void onInit() override;
47 void addAction(uint16_t action, ActionHandler &client, uint16_t event,
48 bool alwaysEnabled = false) override;
49 void addAction(uint16_t action, ActionHandler *client, uint16_t event,
50 bool alwaysEnabled = false) override;
51 void disableAction(int32_t action,
52 ActionHandler *client,
53 int32_t event) override;
54 void enableAction(int32_t action,
55 ActionHandler *client,
56 int32_t event) override;
57
58 void setHoldTime(unsigned int timeMs);
59 void repeatOnHoldEvery(unsigned int timeMs);
60
61 // setting of bistableButton is for backward compatiblity.
62 // Use setButtonType instaed.
63 void setMulticlickTime(unsigned int timeMs, bool bistableButton = false);
64
65 void setButtonType(const ButtonType type);
66 bool isBistable() const;
67 bool isMonostable() const;
68 bool isMotionSensor() const;
69 bool isCentral() const;
70
71 virtual void configureAsConfigButton(SuplaDeviceClass *sdc);
72 bool disableActionsInConfigMode() override;
73 void dontUseOnLoadConfig();
74 void setOnLoadConfigType(OnLoadConfigType type);
75
76 uint8_t getMaxMulticlickValue();
77 int8_t getButtonNumber() const override;
78 void setButtonNumber(int8_t number);
79
80 void handleAction(int event, int action) override;
81
82 void disableButton();
83 void enableButton();
84 void waitForRelease();
85
86 uint32_t getLastStateChange() const;
87
88 void setAllowHoldOnPowerOn(bool allow) { allowHoldOnPowerOn = allow; }
89
90 protected:
91 void evaluateMaxMulticlickValue();
92 // disbles repeating "on hold" if repeat time is lower than threshold
93 // threshold 0 disables always
94 void disableRepeatOnHold(uint32_t threshold = 0);
95 void enableRepeatOnHold();
96 const char *getButtonTypeName(ButtonType type) const;
97 uint32_t lastStateChangeMs = 0;
98 uint16_t repeatOnHoldMs = 0;
99 uint16_t holdSend = 0;
100 uint16_t holdTimeMs = 0;
101 uint16_t multiclickTimeMs = 0;
102 ButtonType buttonType = ButtonType::MONOSTABLE;
103 enum OnLoadConfigType onLoadConfigType = OnLoadConfigType::LOAD_FULL_CONFIG;
104
105 uint8_t clickCounter = 0;
106 uint8_t maxMulticlickValueConfigured = 0;
107 bool repeatOnHoldEnabled = false;
108 bool configButton = false;
109 int8_t buttonNumber = -1;
110 bool disabled = false;
111 bool allowHoldOnPowerOn = false;
112 bool waitingForRelease = false;
113
114 static int buttonCounter;
115};
116
117}; // namespace Control
118}; // namespace Supla
119
120#endif // SRC_SUPLA_CONTROL_BUTTON_H_
Definition SuplaDevice.h:167
Definition action_handler.h:8
Definition action_trigger.h:30
Definition button.h:21
void onInit() override
Third method called on element in SuplaDevice.begin()
Definition button.cpp:44
void onTimer() override
Method called on timer interupt.
Definition button.cpp:48
void onLoadConfig(SuplaDeviceClass *) override
First method called on element in SuplaDevice.begin().
Definition button.cpp:371
Definition simple_button.h:47
Definition io.h:23
Definition io_pin.h:14