supla-device
Loading...
Searching...
No Matches
temperature_drop_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
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_TEMPERATURE_DROP_SENSOR_H_
20#define SRC_SUPLA_SENSOR_TEMPERATURE_DROP_SENSOR_H_
21
22#include <supla/element.h>
23
24#include "virtual_binary.h"
25#include "therm_hygro_meter.h"
26
27namespace Supla {
28namespace Sensor {
29
30#define MAX_TEMPERATURE_MEASUREMENTS 60
31
32class TemperatureDropSensor : public Supla::Element {
33 public:
34 explicit TemperatureDropSensor(ThermHygroMeter *thermometer);
35
36 void onInit() override;
37 void iterateAlways() override;
38
39 bool isDropDetected() const;
40 int getBinarySensorChannelNo() const;
41
47 void setTemperatureDropThreshold(int16_t threshold);
48
55 void setDropDetectionDelayMs(uint32_t delayMs);
56
57 private:
58 Supla::Sensor::VirtualBinary virtualBinary;
59 ThermHygroMeter *thermometer = nullptr;
60
61 int16_t getAverage(int fromIndex, int toIndex) const;
62 bool detectTemperatureDrop(int16_t temperature, int16_t *average) const;
63
64 uint32_t lastTemperatureUpdate = 0;
65 uint32_t filteringTimestamp = 0;
66 uint32_t dropDetectionTimestamp = 0;
67 uint32_t probeIntervalMs = 30000;
68 uint32_t dropDetectionDelayMs = 0;
69
70 int16_t measurements[MAX_TEMPERATURE_MEASUREMENTS] = {};
71 int measurementIndex = 0;
72 int16_t temperatureDropThreshold = -200; // -2 degree
73 int16_t averageAtDropDetection = INT16_MIN;
74};
75
76} // namespace Sensor
77} // namespace Supla
78
79#endif // SRC_SUPLA_SENSOR_TEMPERATURE_DROP_SENSOR_H_
Base class for all elements of SuplaDevice.
Definition element.h:33
void setTemperatureDropThreshold(int16_t threshold)
Set temperature drop threshold detection.
Definition temperature_drop_sensor.cpp:137
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition temperature_drop_sensor.cpp:39
void onInit() override
Third method called on element in SuplaDevice.begin()
Definition temperature_drop_sensor.cpp:36
void setDropDetectionDelayMs(uint32_t delayMs)
Set drop detection delay.
Definition temperature_drop_sensor.cpp:141
Definition therm_hygro_meter.h:29
Definition virtual_binary.h:28