supla-device
Toggle main menu visibility
Loading...
Searching...
No Matches
src
supla
sensor
SHT10.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_SHT10_H_
20
#define SRC_SUPLA_SENSOR_SHT10_H_
21
22
#include <Arduino.h>
23
#include <supla/sensor/therm_hygro_meter.h>
24
#include <SHT1x-ESP.h>
// https://github.com/beegee-tokyo/SHT1x-ESP
25
// data pin pulled up with 10k resistor
26
27
namespace
Supla {
28
namespace
Sensor {
29
class
SHT10 :
public
ThermHygroMeter {
30
public
:
31
explicit
SHT10(
int
data_pin_,
int
clock_pin_)
32
: sht1x(data_pin_, clock_pin_, SHT1x::Voltage::DC_3_3v) {
33
}
34
35
double
getTemp() {
36
temperature = sht1x.readTemperatureC();
37
if
(isnan(temperature) || temperature < -30) {
38
temperature = TEMPERATURE_NOT_AVAILABLE;
39
}
40
return
temperature;
41
}
42
43
double
getHumi() {
44
humidity = sht1x.readHumidity();
45
if
(isnan(humidity) || humidity < 0) {
46
humidity = HUMIDITY_NOT_AVAILABLE;
47
}
48
return
humidity;
49
}
50
51
private
:
52
void
iterateAlways
() {
53
if
(millis() - lastReadTime > 10000) {
54
lastReadTime = millis();
55
channel.setNewValue(getTemp(), getHumi());
56
}
57
}
58
59
void
onInit
() {
60
channel.setNewValue(getTemp(), getHumi());
61
}
62
63
protected
:
64
::SHT1x sht1x;
65
double
temperature = TEMPERATURE_NOT_AVAILABLE;
66
double
humidity = HUMIDITY_NOT_AVAILABLE;
67
};
68
};
// namespace Sensor
69
};
// namespace Supla
70
71
#endif
// SRC_SUPLA_SENSOR_SHT10_H_
Supla::Sensor::ThermHygroMeter::iterateAlways
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition
therm_hygro_meter.cpp:82
Supla::Sensor::ThermHygroMeter::onInit
void onInit() override
Third method called on element in SuplaDevice.begin().
Definition
therm_hygro_meter.cpp:34
Generated by
1.17.0