supla-device
Toggle main menu visibility
Loading...
Searching...
No Matches
src
supla
sensor
SCD4x.h
1
/*
2
Copyright (C) malarz
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_SCD4X_H_
20
#define SRC_SUPLA_SENSOR_SCD4X_H_
21
22
// Dependency: SparkFun_SCD4x_Arduino_Library
23
// use library manager to install it
24
// https://github.com/sparkfun/SparkFun_SCD4x_Arduino_Library
25
26
#include "SparkFun_SCD4x_Arduino_Library.h"
27
28
#include "therm_hygro_meter.h"
29
#include "general_purpose_measurement.h"
30
31
namespace
Supla {
32
namespace
Sensor {
33
class
SCD4x :
public
ThermHygroMeter {
34
public
:
35
SCD4x() {
36
co2channel =
new
GeneralPurposeMeasurement
();
37
co2channel->setDefaultUnitAfterValue(
"ppm"
);
38
co2channel->setInitialCaption(
"CO₂"
);
39
co2channel->getChannel()->setDefaultIcon(8);
40
co2channel->setDefaultValuePrecision(1);
41
}
42
43
double
getTemp()
override
{
44
readValuesFromDevice();
45
return
temperature;
46
}
47
48
double
getHumi()
override
{
49
return
humidity;
50
}
51
52
double
getCO2() {
53
return
co2;
54
}
55
56
void
onInit
()
override
{
57
if
(scd.begin() ==
false
) {
58
SUPLA_LOG_DEBUG(
"SCD4x Sensor not detected. Please check wiring."
);
59
}
else
{
60
SUPLA_LOG_DEBUG(
"SCD4x Sensor detected."
);
61
}
62
}
63
64
GeneralPurposeMeasurement
* getCO2channel() {
65
return
co2channel;
66
}
67
68
private
:
69
void
readValuesFromDevice() {
70
if
(scd.readMeasurement()) {
71
retryCount = 0;
72
temperature = scd.getTemperature();
73
humidity = scd.getHumidity();
74
co2 = scd.getCO2();
75
co2channel->
setValue
(co2);
76
}
else
{
77
SUPLA_LOG_DEBUG(
"SCD4x read error"
);
78
retryCount++;
79
if
(retryCount > 3) {
80
retryCount = 0;
81
temperature = TEMPERATURE_NOT_AVAILABLE;
82
humidity = HUMIDITY_NOT_AVAILABLE;
83
co2 = NAN;
84
}
85
}
86
}
87
88
protected
:
89
double
temperature = TEMPERATURE_NOT_AVAILABLE;
90
double
humidity = HUMIDITY_NOT_AVAILABLE;
91
double
co2 = NAN;
92
int8_t retryCount = 0;
93
::SCD4x scd;
94
GeneralPurposeMeasurement *co2channel =
nullptr
;
95
};
96
97
};
// namespace Sensor
98
};
// namespace Supla
99
100
#endif
// SRC_SUPLA_SENSOR_SCD4X_H_
Supla::Sensor::GeneralPurposeChannelBase::setValue
virtual void setValue(const double &value)
Method used to set new value for channel with driver which accepts MeasurementDriver::setValue() meth...
Definition
general_purpose_channel_base.cpp:575
Supla::Sensor::GeneralPurposeMeasurement
Definition
general_purpose_measurement.h:26
Supla::Sensor::SCD4x::onInit
void onInit() override
Third method called on element in SuplaDevice.begin().
Definition
SCD4x.h:56
Generated by
1.17.0