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