supla-device
Toggle main menu visibility
Loading...
Searching...
No Matches
src
supla
sensor
Si7021.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_SI7021_H_
20
#define SRC_SUPLA_SENSOR_SI7021_H_
21
22
// Dependency: Adafruid Si7021 library - use library manager to install it
23
// https://github.com/adafruit/Adafruit_Si7021
24
25
#include <Adafruit_Si7021.h>
26
27
#include "therm_hygro_meter.h"
28
29
namespace
Supla {
30
namespace
Sensor {
31
class
Si7021 :
public
ThermHygroMeter {
32
public
:
33
Si7021() {
34
}
35
36
double
getTemp() {
37
float
value = TEMPERATURE_NOT_AVAILABLE;
38
value = sensor.readTemperature();
39
40
if
(isnan(value)) {
41
value = TEMPERATURE_NOT_AVAILABLE;
42
}
43
44
return
value;
45
}
46
47
double
getHumi() {
48
float
value = HUMIDITY_NOT_AVAILABLE;
49
value = sensor.readHumidity();
50
51
if
(isnan(value)) {
52
value = HUMIDITY_NOT_AVAILABLE;
53
}
54
55
return
value;
56
}
57
58
void
onInit
() {
59
sensor.begin();
60
61
Serial.print(F(
"Found model "
));
62
switch
(sensor.getModel()) {
63
case
SI_Engineering_Samples:
64
Serial.print(F(
"SI engineering samples"
));
65
break
;
66
case
SI_7013:
67
Serial.print(F(
"Si7013"
));
68
break
;
69
case
SI_7020:
70
Serial.print(F(
"Si7020"
));
71
break
;
72
case
SI_7021:
73
Serial.print(F(
"Si7021"
));
74
break
;
75
case
SI_UNKNOWN:
76
default
:
77
Serial.print(F(
"Unknown"
));
78
}
79
80
channel.setNewValue(getTemp(), getHumi());
81
}
82
83
protected
:
84
::Adafruit_Si7021 sensor;
// I2C
85
};
86
87
};
// namespace Sensor
88
};
// namespace Supla
89
90
#endif
// SRC_SUPLA_SENSOR_SI7021_H_
Supla::Sensor::Si7021::onInit
void onInit()
Third method called on element in SuplaDevice.begin().
Definition
Si7021.h:58
Generated by
1.17.0