Skip to content

Commit 10468a1

Browse files
committed
v1.0.20 Add useStaleData
1 parent 7e911f7 commit 10468a1

4 files changed

+12
-4
lines changed

keywords.txt

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ sendCommand KEYWORD2
4949
readRegister KEYWORD2
5050
computeCRC8 KEYWORD2
5151

52+
useStaleData KEYWORD2
53+
5254
#######################################
5355
# Constants (LITERAL1)
5456
#######################################

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun SCD30 Arduino Library
2-
version=1.0.19
2+
version=1.0.20
33
author=SparkFun Electronics
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Library for the Sensirion SCD30 CO2 Sensor

src/SparkFun_SCD30_Arduino_Library.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ uint16_t SCD30::getCO2(void)
107107
if (co2HasBeenReported == true) // Trigger a new read
108108
{
109109
if (readMeasurement() == false) // Pull in new co2, humidity, and temp into global vars
110-
co2 = 0; // Failed to read sensor
110+
if (!_useStaleData)
111+
co2 = 0; // Failed to read sensor
111112
}
112113

113114
co2HasBeenReported = true;
@@ -121,7 +122,8 @@ float SCD30::getHumidity(void)
121122
{
122123
if (humidityHasBeenReported == true) // Trigger a new read
123124
if (readMeasurement() == false) // Pull in new co2, humidity, and temp into global vars
124-
humidity = 0; // Failed to read sensor
125+
if (!_useStaleData)
126+
humidity = 0; // Failed to read sensor
125127

126128
humidityHasBeenReported = true;
127129

@@ -134,7 +136,8 @@ float SCD30::getTemperature(void)
134136
{
135137
if (temperatureHasBeenReported == true) // Trigger a new read
136138
if (readMeasurement() == false) // Pull in new co2, humidity, and temp into global vars
137-
temperature = 0; // Failed to read sensor
139+
if (!_useStaleData)
140+
temperature = 0; // Failed to read sensor
138141

139142
temperatureHasBeenReported = true;
140143

src/SparkFun_SCD30_Arduino_Library.h

+3
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ class SCD30
120120

121121
uint8_t computeCRC8(uint8_t data[], uint8_t len);
122122

123+
void useStaleData(bool enable) { _useStaleData = enable; }
124+
123125
private:
124126
// Variables
125127
#ifdef USE_TEENSY3_I2C_LIB
@@ -131,6 +133,7 @@ class SCD30
131133
float co2 = 0;
132134
float temperature = 0;
133135
float humidity = 0;
136+
bool _useStaleData = false; // If true, stale data is returned instead of zeros
134137

135138
// These track the staleness of the current data
136139
// This allows us to avoid calling readMeasurement() every time individual datums are requested

0 commit comments

Comments
 (0)