supla-device
Loading...
Searching...
No Matches
multi_ds_sensor.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_SENSOR_MULTI_DS_SENSOR_H_
5#define SRC_SUPLA_SENSOR_MULTI_DS_SENSOR_H_
6
7#include <supla/sensor/thermometer.h>
8#include <supla/storage/storage.h>
9#include <supla/storage/config.h>
10
11#include <stdint.h>
12#include <string.h>
13
14
15namespace Supla {
16namespace Sensor {
17
18class MultiDsHandlerBase;
19
20#pragma pack(push, 1)
22 uint8_t channelNumber = 0;
23 uint8_t address[8] = {};
24};
25#pragma pack(pop)
26
27class MultiDsSensor : public Thermometer {
28 public:
29 explicit MultiDsSensor(int subDeviceId,
30 uint8_t *deviceAddress, bool useSubDevices,
32 handler(handler), subDeviceId(subDeviceId) {
33 // Keep the persisted ID separately because useSubDevices=false must leave
34 // the protocol Channel::SubDeviceId at 0 for backward compatibility.
35 if (useSubDevices) {
36 channel.setSubDeviceId(static_cast<uint8_t>(subDeviceId));
37 }
38 memcpy(address, deviceAddress, 8);
39 }
40
41 void onInit() override;
42 void iterateAlways() override;
43 double getValue() override;
44
45 void saveSensorConfig();
46 void purgeConfig() override;
47
48 uint8_t *getAddress() {
49 return address;
50 }
51
52 int getSubDeviceId() const {
53 return subDeviceId;
54 }
55
56 bool isOwnerOfSubDeviceId(int subDeviceId) const override {
57 return this->subDeviceId == subDeviceId;
58 }
59
60 void setDetailsSend(bool send) { detailsSend = send; }
61 bool getDetailsSend() { return detailsSend; }
62
63 protected:
65 uint8_t address[8] = {};
66
67 private:
68 int subDeviceId = -1;
69 int8_t retryCounter = 0;
70 double lastValidValue = TEMPERATURE_NOT_AVAILABLE;
71 bool detailsSend = false;
72};
73
74}; // namespace Sensor
75}; // namespace Supla
76
77#endif // SRC_SUPLA_SENSOR_MULTI_DS_SENSOR_H_
Definition multi_ds_handler_base.h:31
Definition multi_ds_sensor.h:27
void onInit() override
Third method called on element in SuplaDevice.begin()
Definition multi_ds_sensor.cpp:13
void purgeConfig() override
Removes all configration data related to the element from Storage::Config.
Definition multi_ds_sensor.cpp:75
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition multi_ds_sensor.cpp:17
bool isOwnerOfSubDeviceId(int subDeviceId) const override
Returns true if element is owner of subDeviceId.
Definition multi_ds_sensor.h:56
Definition thermometer.h:13
Definition multi_ds_sensor.h:21