supla-device
Loading...
Searching...
No Matches
binary_base.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
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#ifndef SRC_SUPLA_SENSOR_BINARY_BASE_H_
20#define SRC_SUPLA_SENSOR_BINARY_BASE_H_
21
22#include <supla/channels/binary_sensor_channel.h>
23#include <supla/element_with_channel_actions.h>
24
26
27namespace Supla {
28
29namespace Sensor {
30
31#pragma pack(push, 1)
32struct BinarySensorConfig {
33 union {
34 uint8_t reserved[32];
35 struct {
36 uint16_t timeoutDs; // 1 ds -> 0.1 s; 0 - not used; range 1..36000
37 uint16_t filteringTimeMs; // 0 - not used; > 0 - filtering time
38 uint8_t sensitivity; // 0 - not used; 1..101 -> 0..100 %;
39 // value 1 is 0% -> off
40 };
41 };
42
43 BinarySensorConfig() : reserved{} {}
44};
45
46#pragma pack(pop)
47class BinaryBase : public ElementWithChannelActions {
48 public:
49 BinaryBase();
50 virtual ~BinaryBase();
51 virtual bool getValue() = 0;
52 void iterateAlways() override;
53 Channel *getChannel() override;
54 const Channel *getChannel() const override;
55 void onLoadConfig(SuplaDeviceClass *) override;
56 Supla::ApplyConfigResult applyChannelConfig(TSD_ChannelConfig *config,
57 bool local = false) override;
58
64 bool isServerInvertLogic() const;
65
75 bool setServerInvertLogic(bool invertLogic, bool local = true);
76
84 uint16_t getTimeoutDs() const;
85
97 bool setTimeoutDs(uint16_t timeoutDs, bool local = true);
98
105 uint16_t getFilteringTimeMs() const;
106
118 bool setFilteringTimeMs(uint16_t filteringTimeMs, bool local = true);
119
127 uint8_t getSensitivity() const;
128
140 bool setSensitivity(uint8_t sensitivity, bool local = true);
141
148 void setReadIntervalMs(uint32_t intervalMs);
149
153 void purgeConfig() override;
154
162 void fillChannelConfig(void *channelConfig,
163 int *size,
164 uint8_t configType) override;
165
166 protected:
167 void saveConfig();
168 void printConfig();
169 uint32_t lastReadTime = 0;
170 uint32_t readIntervalMs = 100;
171 BinarySensorChannel channel;
172 BinarySensorConfig config;
173};
174
175} // namespace Sensor
176} // namespace Supla
177
178
179#endif // SRC_SUPLA_SENSOR_BINARY_BASE_H_
Definition binary_sensor_channel.h:25
Definition channel.h:33
Definition SuplaDevice.h:97
bool setSensitivity(uint8_t sensitivity, bool local=true)
Set the sensitivity.
Definition binary_base.cpp:200
uint16_t getFilteringTimeMs() const
Get the filtering time in ms.
Definition binary_base.cpp:230
void purgeConfig() override
Purge the configuration.
Definition binary_base.cpp:97
bool isServerInvertLogic() const
Get the invert logic setting.
Definition binary_base.cpp:251
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition binary_base.cpp:173
void setReadIntervalMs(uint32_t intervalMs)
Set the read interval in ms.
Definition binary_base.cpp:255
uint8_t getSensitivity() const
Get the sensitivity.
Definition binary_base.cpp:213
bool setServerInvertLogic(bool invertLogic, bool local=true)
Set the invert logic.
Definition binary_base.cpp:188
uint16_t getTimeoutDs() const
Get the timeout in deciseconds (1 == 0.1 s).
Definition binary_base.cpp:247
bool setFilteringTimeMs(uint16_t filteringTimeMs, bool local=true)
Set the filtering time in ms.
Definition binary_base.cpp:217
void onLoadConfig(SuplaDeviceClass *) override
First method called on element in SuplaDevice.begin().
Definition binary_base.cpp:42
bool setTimeoutDs(uint16_t timeoutDs, bool local=true)
Set the timeout in deciseconds (1 == 0.1 s).
Definition binary_base.cpp:234
void fillChannelConfig(void *channelConfig, int *size, uint8_t configType) override
Fill the channel config.
Definition binary_base.cpp:262
Definition proto.h:3041