supla-device
Loading...
Searching...
No Matches
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#include <supla/log_wrapper.h>
27
28#include "therm_hygro_meter.h"
29
30namespace Supla {
31namespace Sensor {
32class Si7021 : public ThermHygroMeter {
33 public:
34 Si7021() {
35 }
36
37 double getTemp() {
38 float value = TEMPERATURE_NOT_AVAILABLE;
39 value = sensor.readTemperature();
40
41 if (isnan(value)) {
42 value = TEMPERATURE_NOT_AVAILABLE;
43 }
44
45 return value;
46 }
47
48 double getHumi() {
49 float value = HUMIDITY_NOT_AVAILABLE;
50 value = sensor.readHumidity();
51
52 if (isnan(value)) {
53 value = HUMIDITY_NOT_AVAILABLE;
54 }
55
56 return value;
57 }
58
59 void onInit() {
60 sensor.begin();
61
62 switch (sensor.getModel()) {
63 case SI_Engineering_Samples:
64 SUPLA_LOG_INFO("Found model: SI engineering samples");
65 break;
66 case SI_7013:
67 SUPLA_LOG_INFO("Found model: Si7013");
68 break;
69 case SI_7020:
70 SUPLA_LOG_INFO("Found model: Si7020");
71 break;
72 case SI_7021:
73 SUPLA_LOG_INFO("Found model: Si7021");
74 break;
75 case SI_UNKNOWN:
76 default:
77 SUPLA_LOG_INFO("Unknown model");
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_
void onInit()
Third method called on element in SuplaDevice.begin().
Definition Si7021.h:59