supla-device
Toggle main menu visibility
Loading...
Searching...
No Matches
src
supla
sensor
AHT.h
1
/*
2
Copyright (C) AC SOFTWARE SP. Z O.O.
3
This program is free software; you can redistribute it and/or
4
modify it under the terms of the GNU General Public License
5
as published by the Free Software Foundation; either version 2
6
of the License, or (at your option) any later version.
7
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
13
You should have received a copy of the GNU General Public License
14
along with this program; if not, write to the Free Software
15
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
*/
17
18
#ifndef SRC_SUPLA_SENSOR_AHT_H_
19
#define SRC_SUPLA_SENSOR_AHT_H_
20
21
#include <Adafruit_AHTX0.h>
22
23
#include "therm_hygro_meter.h"
24
25
namespace
Supla {
26
namespace
Sensor {
27
class
AHT
:
public
ThermHygroMeter {
28
public
:
29
void
onInit
() {
30
aht.begin();
31
}
32
33
double
getTemp() {
34
double
value = TEMPERATURE_NOT_AVAILABLE;
35
aht.getEvent(&humidity, &temp);
36
value = temp.temperature;
37
if
(isnan(value)) {
38
value = TEMPERATURE_NOT_AVAILABLE;
39
}
40
if
(value == TEMPERATURE_NOT_AVAILABLE) {
41
retryCountTemp++;
42
if
(retryCountTemp > 3) {
43
retryCountTemp = 0;
44
}
else
{
45
value = lastValidTemp;
46
}
47
}
else
{
48
retryCountTemp = 0;
49
}
50
lastValidTemp = value;
51
return
value;
52
}
53
54
double
getHumi() {
55
double
value = HUMIDITY_NOT_AVAILABLE;
56
value = humidity.relative_humidity;
57
if
(isnan(value)) {
58
value = HUMIDITY_NOT_AVAILABLE;
59
}
60
if
(value == HUMIDITY_NOT_AVAILABLE) {
61
retryCountHumi++;
62
if
(retryCountHumi > 3) {
63
retryCountHumi = 0;
64
}
else
{
65
value = lastValidHumi;
66
}
67
}
else
{
68
retryCountHumi = 0;
69
}
70
lastValidHumi = value;
71
return
value;
72
}
73
74
protected
:
75
Adafruit_AHTX0 aht;
76
double
lastValidTemp = TEMPERATURE_NOT_AVAILABLE;
77
double
lastValidHumi = HUMIDITY_NOT_AVAILABLE;
78
int8_t retryCountTemp = 0;
79
int8_t retryCountHumi = 0;
80
sensors_event_t temp;
81
sensors_event_t humidity;
82
};
83
};
// namespace Sensor
84
};
// namespace Supla
85
#endif
// SRC_SUPLA_SENSOR_AHT_H_
Supla::Sensor::AHT
Definition
AHT.h:27
Supla::Sensor::AHT::onInit
void onInit()
Third method called on element in SuplaDevice.begin().
Definition
AHT.h:29
Generated by
1.17.0