supla-device
Loading...
Searching...
No Matches
Si7021.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_SENSOR_SI7021_H_
5#define SRC_SUPLA_SENSOR_SI7021_H_
6
7// Dependency: Adafruid Si7021 library - use library manager to install it
8// https://github.com/adafruit/Adafruit_Si7021
9
10#include <Adafruit_Si7021.h>
11#include <supla/log_wrapper.h>
12
13#include "therm_hygro_meter.h"
14
15namespace Supla {
16namespace Sensor {
17class Si7021 : public ThermHygroMeter {
18 public:
19 Si7021() {
20 }
21
22 double getTemp() {
23 float value = TEMPERATURE_NOT_AVAILABLE;
24 value = sensor.readTemperature();
25
26 if (isnan(value)) {
27 value = TEMPERATURE_NOT_AVAILABLE;
28 }
29
30 return value;
31 }
32
33 double getHumi() {
34 float value = HUMIDITY_NOT_AVAILABLE;
35 value = sensor.readHumidity();
36
37 if (isnan(value)) {
38 value = HUMIDITY_NOT_AVAILABLE;
39 }
40
41 return value;
42 }
43
44 void onInit() {
45 sensor.begin();
46
47 switch (sensor.getModel()) {
48 case SI_Engineering_Samples:
49 SUPLA_LOG_INFO("Found model: SI engineering samples");
50 break;
51 case SI_7013:
52 SUPLA_LOG_INFO("Found model: Si7013");
53 break;
54 case SI_7020:
55 SUPLA_LOG_INFO("Found model: Si7020");
56 break;
57 case SI_7021:
58 SUPLA_LOG_INFO("Found model: Si7021");
59 break;
60 case SI_UNKNOWN:
61 default:
62 SUPLA_LOG_INFO("Unknown model");
63 }
64
65 channel.setNewValue(getTemp(), getHumi());
66 }
67
68 protected:
69 ::Adafruit_Si7021 sensor; // I2C
70};
71
72}; // namespace Sensor
73}; // namespace Supla
74
75#endif // SRC_SUPLA_SENSOR_SI7021_H_
Definition Si7021.h:17
void onInit()
Third method called on element in SuplaDevice.begin()
Definition Si7021.h:44
Definition therm_hygro_meter.h:14