supla-device
Loading...
Searching...
No Matches
thermometer_group.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_SUPLET_THERMOMETER_GROUP_H_
20#define SRC_SUPLA_SUPLET_THERMOMETER_GROUP_H_
21
22#include <stdint.h>
23#include <supla/suplet/virtual_channel.h>
24
25#ifndef SUPLA_SUPLET_THERMOMETER_GROUP_MAX_SOURCES
26#define SUPLA_SUPLET_THERMOMETER_GROUP_MAX_SOURCES 8
27#endif
28
29namespace Supla {
30namespace Suplet {
31
32enum class ThermometerGroupMode : uint8_t {
33 Avg = 1,
34 Min = 2,
35 Max = 3,
36};
37
39 uint8_t version = 1;
40 ThermometerGroupMode mode = ThermometerGroupMode::Avg;
41 uint16_t refreshIntervalMs = 1000;
42 uint8_t sourceCount = 0;
43 int16_t sourceChannels[SUPLA_SUPLET_THERMOMETER_GROUP_MAX_SOURCES] = {};
44};
45
46class ThermometerGroup : public VirtualThermometer {
47 public:
48 ThermometerGroup(uint8_t subDeviceId,
49 int channelNumber,
50 const ThermometerGroupConfig &config);
51
52 void iterateAlways() override;
53 double calculateValue() const;
54 const ThermometerGroupConfig &getConfig() const;
55
56 private:
57 struct GroupValue {
58 bool hasOnlineSource = false;
59 bool hasValidValue = false;
60 double value = TEMPERATURE_NOT_AVAILABLE;
61 };
62
63 static bool isValidTemperature(double value);
64 GroupValue calculateGroupValue() const;
65
66 ThermometerGroupConfig config = {};
67 uint32_t lastRefreshMs = 0;
68};
69
70bool parseThermometerGroupConfig(const uint8_t *data,
71 uint16_t dataSize,
72 ThermometerGroupConfig *config);
73bool serializeThermometerGroupConfig(const ThermometerGroupConfig &config,
74 uint8_t *data,
75 uint16_t dataSize,
76 uint16_t *writtenSize = nullptr);
77
78} // namespace Suplet
79} // namespace Supla
80
81#endif // SRC_SUPLA_SUPLET_THERMOMETER_GROUP_H_
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition thermometer_group.h:38