supla-device
Loading...
Searching...
No Matches
button.h
1/*
2 Copyright (C) AC SOFTWARE SP. Z O.O.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15*/
16
17#ifndef SRC_SUPLA_CONTROL_BUTTON_H_
18#define SRC_SUPLA_CONTROL_BUTTON_H_
19
20#include <stdint.h>
21#include <supla/action_handler.h>
22#include "action_trigger.h"
23#include "simple_button.h"
24
26
27namespace Supla {
28namespace Control {
29
30class Button : public SimpleButton, public ActionHandler {
31 public:
32 friend class ActionTrigger;
33 enum class ButtonType : uint8_t {
34 MONOSTABLE,
35 BISTABLE,
36 MOTION_SENSOR,
37 CENTRAL_CONTROL
38 };
39
40 enum class OnLoadConfigType : uint8_t {
41 LOAD_FULL_CONFIG,
42 LOAD_BUTTON_SETUP_ONLY,
43 DONT_LOAD_CONFIG
44 };
45
46 explicit Button(Supla::Io *io,
47 int pin,
48 bool pullUp = false,
49 bool invertLogic = false);
50 explicit Button(int pin, bool pullUp = false, bool invertLogic = false);
51
52 void onTimer() override;
53 void onLoadConfig(SuplaDeviceClass *) override;
54 void onInit() override;
55 void addAction(uint16_t action, ActionHandler &client, uint16_t event,
56 bool alwaysEnabled = false) override;
57 void addAction(uint16_t action, ActionHandler *client, uint16_t event,
58 bool alwaysEnabled = false) override;
59 void disableAction(int32_t action,
60 ActionHandler *client,
61 int32_t event) override;
62 void enableAction(int32_t action,
63 ActionHandler *client,
64 int32_t event) override;
65
66 void setHoldTime(unsigned int timeMs);
67 void repeatOnHoldEvery(unsigned int timeMs);
68
69 // setting of bistableButton is for backward compatiblity.
70 // Use setButtonType instaed.
71 void setMulticlickTime(unsigned int timeMs, bool bistableButton = false);
72
73 void setButtonType(const ButtonType type);
74 bool isBistable() const;
75 bool isMonostable() const;
76 bool isMotionSensor() const;
77 bool isCentral() const;
78
79 virtual void configureAsConfigButton(SuplaDeviceClass *sdc);
80 bool disableActionsInConfigMode() override;
81 void dontUseOnLoadConfig();
82 void setOnLoadConfigType(OnLoadConfigType type);
83
84 uint8_t getMaxMulticlickValue();
85 int8_t getButtonNumber() const override;
86 void setButtonNumber(int8_t number);
87
88 void handleAction(int event, int action) override;
89
90 void disableButton();
91 void enableButton();
92 void waitForRelease();
93
94 uint32_t getLastStateChange() const;
95
96 void setAllowHoldOnPowerOn(bool allow) { allowHoldOnPowerOn = allow; }
97
98 protected:
99 void evaluateMaxMulticlickValue();
100 // disbles repeating "on hold" if repeat time is lower than threshold
101 // threshold 0 disables always
102 void disableRepeatOnHold(uint32_t threshold = 0);
103 void enableRepeatOnHold();
104 const char *getButtonTypeName(ButtonType type) const;
105 uint32_t lastStateChangeMs = 0;
106 uint16_t repeatOnHoldMs = 0;
107 uint16_t holdSend = 0;
108 uint16_t holdTimeMs = 0;
109 uint16_t multiclickTimeMs = 0;
110 ButtonType buttonType = ButtonType::MONOSTABLE;
111 enum OnLoadConfigType onLoadConfigType = OnLoadConfigType::LOAD_FULL_CONFIG;
112
113 uint8_t clickCounter = 0;
114 uint8_t maxMulticlickValueConfigured = 0;
115 bool repeatOnHoldEnabled = false;
116 bool configButton = false;
117 int8_t buttonNumber = -1;
118 bool disabled = false;
119 bool allowHoldOnPowerOn = false;
120 bool waitingForRelease = false;
121
122 static int buttonCounter;
123};
124
125}; // namespace Control
126}; // namespace Supla
127
128#endif // SRC_SUPLA_CONTROL_BUTTON_H_
Definition SuplaDevice.h:96
void onInit() override
Third method called on element in SuplaDevice.begin()
Definition button.cpp:48
void onTimer() override
Method called on timer interupt.
Definition button.cpp:52
void onLoadConfig(SuplaDeviceClass *) override
First method called on element in SuplaDevice.begin().
Definition button.cpp:361
Definition io.h:33