supla-device
Loading...
Searching...
No Matches
multi_ds_sensor.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_SENSOR_MULTI_DS_SENSOR_H_
18#define SRC_SUPLA_SENSOR_MULTI_DS_SENSOR_H_
19
20#include <supla/sensor/thermometer.h>
21#include <supla/storage/storage.h>
22#include <supla/storage/config.h>
23
24#include <stdint.h>
25
26#include <DallasTemperature.h>
27#include <OneWire.h>
28
29namespace Supla {
30namespace Sensor {
31
33
34#pragma pack(push, 1)
36 uint8_t channelNumber = 0;
37 uint8_t address[8] = {};
38};
39#pragma pack(pop)
40
41class MultiDsSensor : public Thermometer {
42 public:
43 explicit MultiDsSensor(int subDeviceId,
44 uint8_t *deviceAddress, bool useSubDevices,
46 subDeviceId(subDeviceId), handler(handler) {
47 if (useSubDevices) {
48 channel.setSubDeviceId(subDeviceId);
49 }
50 memcpy(address, deviceAddress, 8);
51 }
52
53 void onInit() override;
54 void iterateAlways() override;
55 double getValue() override;
56
57 void saveSensorConfig();
58 void purgeConfig();
59
60 uint8_t *getAddress() {
61 return address;
62 }
63
64 int getSubDeviceId() {
65 return subDeviceId;
66 }
67
68 bool isOwnerOfSubDeviceId(int subDeviceId) const override {
69 return channel.getSubDeviceId() == subDeviceId;
70 }
71
72 void setDetailsSend(bool send) { detailsSend = send; }
73 bool getDetailsSend() { return detailsSend; }
74
75 protected:
77 DeviceAddress address;
78
79 private:
80 int subDeviceId = -1;
81 int8_t retryCounter = 0;
82 double lastValidValue = TEMPERATURE_NOT_AVAILABLE;
83 bool detailsSend = false;
84};
85
86}; // namespace Sensor
87}; // namespace Supla
88
89#endif // SRC_SUPLA_SENSOR_MULTI_DS_SENSOR_H_
Definition multi_ds_handler_base.h:44
void purgeConfig()
Removes all configration data related to the element from Storage::Config.
Definition multi_ds_sensor.cpp:84
void onInit() override
Third method called on element in SuplaDevice.begin().
Definition multi_ds_sensor.cpp:25
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition multi_ds_sensor.cpp:29
bool isOwnerOfSubDeviceId(int subDeviceId) const override
Returns true if element is owner of subDeviceId.
Definition multi_ds_sensor.h:68
Definition multi_ds_sensor.h:35