Skip to content

Commit

Permalink
v1.0.20 Add useStaleData
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulZC committed Oct 7, 2022
1 parent 7e911f7 commit 10468a1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ sendCommand KEYWORD2
readRegister KEYWORD2
computeCRC8 KEYWORD2

useStaleData KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SparkFun SCD30 Arduino Library
version=1.0.19
version=1.0.20
author=SparkFun Electronics
maintainer=SparkFun Electronics <sparkfun.com>
sentence=Library for the Sensirion SCD30 CO2 Sensor
Expand Down
9 changes: 6 additions & 3 deletions src/SparkFun_SCD30_Arduino_Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ uint16_t SCD30::getCO2(void)
if (co2HasBeenReported == true) // Trigger a new read
{
if (readMeasurement() == false) // Pull in new co2, humidity, and temp into global vars
co2 = 0; // Failed to read sensor
if (!_useStaleData)
co2 = 0; // Failed to read sensor
}

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

humidityHasBeenReported = true;

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

temperatureHasBeenReported = true;

Expand Down
3 changes: 3 additions & 0 deletions src/SparkFun_SCD30_Arduino_Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ class SCD30

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

void useStaleData(bool enable) { _useStaleData = enable; }

private:
// Variables
#ifdef USE_TEENSY3_I2C_LIB
Expand All @@ -131,6 +133,7 @@ class SCD30
float co2 = 0;
float temperature = 0;
float humidity = 0;
bool _useStaleData = false; // If true, stale data is returned instead of zeros

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

0 comments on commit 10468a1

Please sign in to comment.