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 uint8_t alarmMuted; // 0 - not used, 1 - alarm is muted,
41 // 2 - alarm is not muted
42 };
43 };
44
45 BinarySensorConfig() : reserved{} {}
46};
47#pragma pack(pop)
48
49class BinaryBase : public ElementWithChannelActions {
50 public:
51 BinaryBase();
52 virtual ~BinaryBase();
53 virtual bool getValue() = 0;
54 void iterateAlways() override;
55 Channel *getChannel() override;
56 const Channel *getChannel() const override;
57 void onLoadConfig(SuplaDeviceClass *) override;
58 Supla::ApplyConfigResult applyChannelConfig(TSD_ChannelConfig *config,
59 bool local = false) override;
60
66 bool isServerInvertLogic() const;
67
77 bool setServerInvertLogic(bool invertLogic, bool local = true);
78
86 uint16_t getTimeoutDs() const;
87
99 bool setTimeoutDs(uint16_t timeoutDs, bool local = true);
100
107 uint16_t getFilteringTimeMs() const;
108
120 bool setFilteringTimeMs(uint16_t filteringTimeMs, bool local = true);
121
129 uint8_t getSensitivity() const;
130
142 bool setSensitivity(uint8_t sensitivity, bool local = true);
143
149 uint8_t getAlarmMuted() const;
150
161 bool setAlarmMuted(uint8_t alarmMuted, bool local = true);
162
169 void setReadIntervalMs(uint32_t intervalMs);
170
174 void purgeConfig() override;
175
183 void fillChannelConfig(void *channelConfig,
184 int *size,
185 uint8_t configType) override;
186
187 protected:
188 void saveConfig();
189 void printConfig();
190 void printConfig(const TChannelConfig_BinarySensor *serverConfig);
191 uint32_t lastReadTime = 0;
192 uint32_t readIntervalMs = 100;
193 BinarySensorChannel channel;
194 BinarySensorConfig config;
195};
196
197} // namespace Sensor
198} // namespace Supla
199
200
201#endif // SRC_SUPLA_SENSOR_BINARY_BASE_H_
Definition binary_sensor_channel.h:25
Definition channel.h:33
Definition SuplaDevice.h:162
bool setSensitivity(uint8_t sensitivity, bool local=true)
Set the sensitivity.
Definition binary_base.cpp:215
uint16_t getFilteringTimeMs() const
Get the filtering time in ms.
Definition binary_base.cpp:262
void purgeConfig() override
Purge the configuration.
Definition binary_base.cpp:104
bool isServerInvertLogic() const
Get the invert logic setting.
Definition binary_base.cpp:283
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition binary_base.cpp:188
void setReadIntervalMs(uint32_t intervalMs)
Set the read interval in ms.
Definition binary_base.cpp:287
uint8_t getSensitivity() const
Get the sensitivity.
Definition binary_base.cpp:228
bool setAlarmMuted(uint8_t alarmMuted, bool local=true)
Set the alarm muted state.
Definition binary_base.cpp:232
bool setServerInvertLogic(bool invertLogic, bool local=true)
Set the invert logic.
Definition binary_base.cpp:203
uint16_t getTimeoutDs() const
Get the timeout in deciseconds (1 == 0.1 s).
Definition binary_base.cpp:279
bool setFilteringTimeMs(uint16_t filteringTimeMs, bool local=true)
Set the filtering time in ms.
Definition binary_base.cpp:249
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:266
uint8_t getAlarmMuted() const
Get the alarm muted state.
Definition binary_base.cpp:245
const Channel * getChannel() const override
Returns pointer to main channel.
Definition binary_base.cpp:199
void fillChannelConfig(void *channelConfig, int *size, uint8_t configType) override
Fill the channel config.
Definition binary_base.cpp:294
Definition proto.h:3267
Definition proto.h:3116