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 Io {
29class Base;
30} // namespace Io
31
32namespace Control {
33
34class Button : public SimpleButton, public ActionHandler {
35 public:
36 friend class ActionTrigger;
37 enum class ButtonType : uint8_t {
38 MONOSTABLE,
39 BISTABLE,
40 MOTION_SENSOR,
41 CENTRAL_CONTROL
42 };
43
44 enum class OnLoadConfigType : uint8_t {
45 LOAD_FULL_CONFIG,
46 LOAD_BUTTON_SETUP_ONLY,
47 DONT_LOAD_CONFIG
48 };
49
50 explicit Button(Supla::Io::Base *io,
51 int pin,
52 bool pullUp = false,
53 bool invertLogic = false);
54 explicit Button(int pin, bool pullUp = false, bool invertLogic = false);
55
56 void onTimer() override;
57 void onLoadConfig(SuplaDeviceClass *) override;
58 void onInit() override;
59 void addAction(uint16_t action, ActionHandler &client, uint16_t event,
60 bool alwaysEnabled = false) override;
61 void addAction(uint16_t action, ActionHandler *client, uint16_t event,
62 bool alwaysEnabled = false) override;
63 void disableAction(int32_t action,
64 ActionHandler *client,
65 int32_t event) override;
66 void enableAction(int32_t action,
67 ActionHandler *client,
68 int32_t event) override;
69
70 void setHoldTime(unsigned int timeMs);
71 void repeatOnHoldEvery(unsigned int timeMs);
72
73 // setting of bistableButton is for backward compatiblity.
74 // Use setButtonType instaed.
75 void setMulticlickTime(unsigned int timeMs, bool bistableButton = false);
76
77 void setButtonType(const ButtonType type);
78 bool isBistable() const;
79 bool isMonostable() const;
80 bool isMotionSensor() const;
81 bool isCentral() const;
82
83 virtual void configureAsConfigButton(SuplaDeviceClass *sdc);
84 bool disableActionsInConfigMode() override;
85 void dontUseOnLoadConfig();
86 void setOnLoadConfigType(OnLoadConfigType type);
87
88 uint8_t getMaxMulticlickValue();
89 int8_t getButtonNumber() const override;
90 void setButtonNumber(int8_t number);
91
92 void handleAction(int event, int action) override;
93
94 void disableButton();
95 void enableButton();
96 void waitForRelease();
97
98 uint32_t getLastStateChange() const;
99
100 void setAllowHoldOnPowerOn(bool allow) { allowHoldOnPowerOn = allow; }
101
102 protected:
103 void evaluateMaxMulticlickValue();
104 // disbles repeating "on hold" if repeat time is lower than threshold
105 // threshold 0 disables always
106 void disableRepeatOnHold(uint32_t threshold = 0);
107 void enableRepeatOnHold();
108 const char *getButtonTypeName(ButtonType type) const;
109 uint32_t lastStateChangeMs = 0;
110 uint16_t repeatOnHoldMs = 0;
111 uint16_t holdSend = 0;
112 uint16_t holdTimeMs = 0;
113 uint16_t multiclickTimeMs = 0;
114 ButtonType buttonType = ButtonType::MONOSTABLE;
115 enum OnLoadConfigType onLoadConfigType = OnLoadConfigType::LOAD_FULL_CONFIG;
116
117 uint8_t clickCounter = 0;
118 uint8_t maxMulticlickValueConfigured = 0;
119 bool repeatOnHoldEnabled = false;
120 bool configButton = false;
121 int8_t buttonNumber = -1;
122 bool disabled = false;
123 bool allowHoldOnPowerOn = false;
124 bool waitingForRelease = false;
125
126 static int buttonCounter;
127};
128
129}; // namespace Control
130}; // namespace Supla
131
132#endif // SRC_SUPLA_CONTROL_BUTTON_H_
Definition SuplaDevice.h:97
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:35