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 };
38
39 enum class OnLoadConfigType : uint8_t {
40 LOAD_FULL_CONFIG,
41 LOAD_BUTTON_SETUP_ONLY,
42 DONT_LOAD_CONFIG
43 };
44
45 explicit Button(Supla::Io *io,
46 int pin,
47 bool pullUp = false,
48 bool invertLogic = false);
49 explicit Button(int pin, bool pullUp = false, bool invertLogic = false);
50
51 void onTimer() override;
52 void onLoadConfig(SuplaDeviceClass *) override;
53 void onInit() override;
54 void addAction(uint16_t action, ActionHandler &client, uint16_t event,
55 bool alwaysEnabled = false) override;
56 void addAction(uint16_t action, ActionHandler *client, uint16_t event,
57 bool alwaysEnabled = false) override;
58 void disableAction(int32_t action,
59 ActionHandler *client,
60 int32_t event) override;
61 void enableAction(int32_t action,
62 ActionHandler *client,
63 int32_t event) override;
64
65 void setHoldTime(unsigned int timeMs);
66 void repeatOnHoldEvery(unsigned int timeMs);
67
68 // setting of bistableButton is for backward compatiblity.
69 // Use setButtonType instaed.
70 void setMulticlickTime(unsigned int timeMs, bool bistableButton = false);
71
72 void setButtonType(const ButtonType type);
73 bool isBistable() const;
74 bool isMonostable() const;
75 bool isMotionSensor() const;
76
77 virtual void configureAsConfigButton(SuplaDeviceClass *sdc);
78 bool disableActionsInConfigMode() override;
79 void dontUseOnLoadConfig();
80 void setOnLoadConfigType(OnLoadConfigType type);
81
82 uint8_t getMaxMulticlickValue();
83 int8_t getButtonNumber() const override;
84 void setButtonNumber(int8_t number);
85
86 void handleAction(int event, int action) override;
87
88 void disableButton();
89 void enableButton();
90
91 uint32_t getLastStateChange() const;
92
93 protected:
94 void evaluateMaxMulticlickValue();
95 // disbles repeating "on hold" if repeat time is lower than threshold
96 // threshold 0 disables always
97 void disableRepeatOnHold(uint32_t threshold = 0);
98 void enableRepeatOnHold();
99 uint32_t multiclickTimeMs = 0;
100 uint32_t lastStateChangeMs = 0;
101 uint16_t repeatOnHoldMs = 0;
102 uint16_t holdSend = 0;
103 uint16_t holdTimeMs = 0;
104 ButtonType buttonType = ButtonType::MONOSTABLE;
105 enum OnLoadConfigType onLoadConfigType = OnLoadConfigType::LOAD_FULL_CONFIG;
106
107 uint8_t clickCounter = 0;
108 uint8_t maxMulticlickValueConfigured = 0;
109 bool repeatOnHoldEnabled = false;
110 bool configButton = false;
111 int8_t buttonNumber = -1;
112 bool disabled = 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:93
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:325
Definition io.h:33