Skip to content

Commit 33c7030

Browse files
committed
v1.0.5 - adding SGP30_ as a prefix to SGP30ERR. THIS BREAKS BACKWARD COMPATIBILITY
To avoid compilation errors (conflicts) with other libraries which also use SUCCESS as an enumerated value, it was necessary to prefix the SGP30ERR enum values with SGP30_. SUCCESS becomes SGP30_SUCCESS etc.. Unfortunately this breaks backward compatibility. If you start to see errors along the lines of SUCCESS is undefined, please use the library manager to select version 1.0.4 of this library. Sorry about that...
1 parent f30cd2e commit 33c7030

File tree

6 files changed

+45
-45
lines changed

6 files changed

+45
-45
lines changed

examples/Example4_ErrorChecking/Example4_ErrorChecking.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ void loop() {
4444
{
4545
t1 = t2; //measure CO2 and TVOC levels
4646
error = mySensor.measureAirQuality();
47-
if (error == SUCCESS) {
47+
if (error == SGP30_SUCCESS) {
4848
Serial.print("CO2: ");
4949
Serial.print(mySensor.CO2);
5050
Serial.print(" ppm\tTVOC: ");
5151
Serial.print(mySensor.TVOC);
5252
Serial.println(" ppb");
5353
}
54-
else if (error == ERR_BAD_CRC) {
54+
else if (error == SGP30_ERR_BAD_CRC) {
5555
Serial.println("CRC Failed");
5656
}
57-
else if (error == ERR_I2C_TIMEOUT) {
57+
else if (error == SGP30_ERR_I2C_TIMEOUT) {
5858
Serial.println("I2C Timed out");
5959
}
6060
}

examples/Example9_UnitTest/Example9_UnitTest.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ void setup() {
2828
}
2929
//measureTest() should not be called after a call to initAirQuality()
3030
error = mySensor.measureTest();
31-
if (error == SUCCESS) {
31+
if (error == SGP30_SUCCESS) {
3232
Serial.println("Success!");
3333
}
34-
else if (error == ERR_BAD_CRC) {
34+
else if (error == SGP30_ERR_BAD_CRC) {
3535
Serial.println("CRC Failed");
3636
}
37-
else if (error == ERR_I2C_TIMEOUT) {
37+
else if (error == SGP30_ERR_I2C_TIMEOUT) {
3838
Serial.println("I2C Timed out");
3939
}
40-
else if (error == SELF_TEST_FAIL) {
40+
else if (error == SGP30_SELF_TEST_FAIL) {
4141
Serial.println("Self Test Failed");
4242
}
4343
}

keywords.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ serialID KEYWORD2
3434
#######################################
3535
# Constants (LITERAL1)
3636
#######################################
37-
SUCCESS LITERAL1
38-
ERR_BAD_CRC LITERAL1
39-
ERR_I2C_TIMEOUT LITERAL1
40-
SELF_TEST_FAIL LITERAL1
37+
SGP30_SUCCESS LITERAL1
38+
SGP30_ERR_BAD_CRC LITERAL1
39+
SGP30_ERR_I2C_TIMEOUT LITERAL1
40+
SGP30_SELF_TEST_FAIL LITERAL1
4141
SparkFun_SGP30_Arduino_Library_h LITERAL1
4242
SparkFun_SGP30_Arduino_Library.h LITERAL1
4343
init_air_quality LITERAL1

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun SGP30 Arduino Library
2-
version=1.0.4
2+
version=1.0.5
33
author=SparkFun Electronics
44
maintainer=SparkFun Electronics
55
sentence=Library for the Sensirion SGP30 air quality sensor

src/SparkFun_SGP30_Arduino_Library.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void SGP30::initAirQuality(void)
7575
//Call in regular intervals of 1 second to maintain synamic baseline calculations
7676
//CO2 returned in ppm, Total Volatile Organic Compounds (TVOC) returned in ppb
7777
//Will give fixed values of CO2=400 and TVOC=0 for first 15 seconds after init
78-
//Returns SUCCESS if successful or other error code if unsuccessful
78+
//Returns SGP30_SUCCESS if successful or other error code if unsuccessful
7979
SGP30ERR SGP30::measureAirQuality(void)
8080
{
8181
_i2cPort->beginTransmission(_SGP30Address);
@@ -87,28 +87,28 @@ SGP30ERR SGP30::measureAirQuality(void)
8787
uint8_t toRead;
8888
toRead = _i2cPort->requestFrom(_SGP30Address, (uint8_t)6);
8989
if (toRead != 6)
90-
return ERR_I2C_TIMEOUT; //Error out
90+
return SGP30_ERR_I2C_TIMEOUT; //Error out
9191
uint16_t _CO2 = _i2cPort->read() << 8; //store MSB in CO2
9292
_CO2 |= _i2cPort->read(); //store LSB in CO2
9393
uint8_t checkSum = _i2cPort->read(); //verify checksum
9494
if (checkSum != _CRC8(_CO2))
95-
return ERR_BAD_CRC; //checksum failed
95+
return SGP30_ERR_BAD_CRC; //checksum failed
9696
uint16_t _TVOC = _i2cPort->read() << 8; //store MSB in TVOC
9797
_TVOC |= _i2cPort->read(); //store LSB in TVOC
9898
checkSum = _i2cPort->read(); //verify checksum
9999
if (checkSum != _CRC8(_TVOC))
100-
return ERR_BAD_CRC; //checksum failed
100+
return SGP30_ERR_BAD_CRC; //checksum failed
101101
CO2 = _CO2; //publish valid data
102102
TVOC = _TVOC; //publish valid data
103-
return SUCCESS;
103+
return SGP30_SUCCESS;
104104
}
105105

106106
//Returns the current calculated baseline from
107107
//the sensor's dynamic baseline calculations
108108
//Save baseline periodically to non volatile memory
109109
//(like EEPROM) to restore after new power up or
110110
//after soft reset using setBaseline();
111-
//Returns SUCCESS if successful or other error code if unsuccessful
111+
//Returns SGP30_SUCCESS if successful or other error code if unsuccessful
112112
SGP30ERR SGP30::getBaseline(void)
113113
{
114114
_i2cPort->beginTransmission(_SGP30Address);
@@ -120,20 +120,20 @@ SGP30ERR SGP30::getBaseline(void)
120120
//Comes back in 6 bytes, baselineCO2 data(MSB) / data(LSB) / Checksum / baselineTVOC data(MSB) / data(LSB) / Checksum
121121
toRead = _i2cPort->requestFrom(_SGP30Address, (uint8_t)6);
122122
if (toRead != 6)
123-
return ERR_I2C_TIMEOUT; //Error out
123+
return SGP30_ERR_I2C_TIMEOUT; //Error out
124124
uint16_t _baselineCO2 = _i2cPort->read() << 8; //store MSB in _baselineCO2
125125
_baselineCO2 |= _i2cPort->read(); //store LSB in _baselineCO2
126126
uint8_t checkSum = _i2cPort->read(); //verify checksum
127127
if (checkSum != _CRC8(_baselineCO2))
128-
return ERR_BAD_CRC; //checksum failed
128+
return SGP30_ERR_BAD_CRC; //checksum failed
129129
uint16_t _baselineTVOC = _i2cPort->read() << 8; //store MSB in _baselineTVOC
130130
_baselineTVOC |= _i2cPort->read(); //store LSB in _baselineTVOC
131131
checkSum = _i2cPort->read(); //verify checksum
132132
if (checkSum != _CRC8(_baselineTVOC))
133-
return ERR_BAD_CRC; //checksum failed
133+
return SGP30_ERR_BAD_CRC; //checksum failed
134134
baselineCO2 = _baselineCO2; //publish valid data
135135
baselineTVOC = _baselineTVOC; //publish valid data
136-
return SUCCESS;
136+
return SGP30_SUCCESS;
137137
}
138138

139139
//Updates the baseline to a previous baseline
@@ -170,7 +170,7 @@ void SGP30::setHumidity(uint16_t humidity)
170170
}
171171

172172
//gives feature set version number (see data sheet)
173-
//Returns SUCCESS if successful or other error code if unsuccessful
173+
//Returns SGP30_SUCCESS if successful or other error code if unsuccessful
174174
SGP30ERR SGP30::getFeatureSetVersion(void)
175175
{
176176
_i2cPort->beginTransmission(_SGP30Address);
@@ -182,14 +182,14 @@ SGP30ERR SGP30::getFeatureSetVersion(void)
182182
//Comes back in 3 bytes, data(MSB) / data(LSB) / Checksum
183183
toRead = _i2cPort->requestFrom(_SGP30Address, (uint8_t)3);
184184
if (toRead != 3)
185-
return ERR_I2C_TIMEOUT; //Error out
185+
return SGP30_ERR_I2C_TIMEOUT; //Error out
186186
uint16_t _featureSetVersion = _i2cPort->read() << 8; //store MSB in featureSetVerison
187187
_featureSetVersion |= _i2cPort->read(); //store LSB in featureSetVersion
188188
uint8_t checkSum = _i2cPort->read(); //verify checksum
189189
if (checkSum != _CRC8(_featureSetVersion))
190-
return ERR_BAD_CRC; //checksum failed
190+
return SGP30_ERR_BAD_CRC; //checksum failed
191191
featureSetVersion = _featureSetVersion; //publish valid data
192-
return SUCCESS;
192+
return SGP30_SUCCESS;
193193
}
194194

195195
//Intended for part verification and testing
@@ -206,20 +206,20 @@ SGP30ERR SGP30::measureRawSignals(void)
206206
//Comes back in 6 bytes, H2 data(MSB) / data(LSB) / Checksum / ethanol data(MSB) / data(LSB) / Checksum
207207
toRead = _i2cPort->requestFrom(_SGP30Address, (uint8_t)6);
208208
if (toRead != 6)
209-
return ERR_I2C_TIMEOUT; //Error out
209+
return SGP30_ERR_I2C_TIMEOUT; //Error out
210210
uint16_t _H2 = _i2cPort->read() << 8; //store MSB in _H2
211211
_H2 |= _i2cPort->read(); //store LSB in _H2
212212
uint8_t checkSum = _i2cPort->read(); //verify checksum
213213
if (checkSum != _CRC8(_H2))
214-
return ERR_BAD_CRC; //checksumfailed
214+
return SGP30_ERR_BAD_CRC; //checksumfailed
215215
uint16_t _ethanol = _i2cPort->read() << 8; //store MSB in ethanol
216216
_ethanol |= _i2cPort->read(); //store LSB in ethanol
217217
checkSum = _i2cPort->read(); //verify checksum
218218
if (checkSum != _CRC8(_ethanol))
219-
return ERR_BAD_CRC; //checksum failed
219+
return SGP30_ERR_BAD_CRC; //checksum failed
220220
H2 = _H2; //publish valid data
221221
ethanol = _ethanol; //publish valid data
222-
return SUCCESS;
222+
return SGP30_SUCCESS;
223223
}
224224

225225
//Soft reset - not device specific
@@ -232,7 +232,7 @@ void SGP30::generalCallReset(void)
232232
}
233233

234234
//readout of serial ID register can identify chip and verify sensor presence
235-
//Returns SUCCESS if successful or other error code if unsuccessful
235+
//Returns SGP30_SUCCESS if successful or other error code if unsuccessful
236236
SGP30ERR SGP30::getSerialID(void)
237237
{
238238
_i2cPort->beginTransmission(_SGP30Address);
@@ -244,28 +244,28 @@ SGP30ERR SGP30::getSerialID(void)
244244
//Comes back in 9 bytes, H2 data(MSB) / data(LSB) / Checksum / ethanol data(MSB) / data(LSB) / Checksum
245245
toRead = _i2cPort->requestFrom(_SGP30Address, (uint8_t)9);
246246
if (toRead != 9)
247-
return ERR_I2C_TIMEOUT; //Error out
247+
return SGP30_ERR_I2C_TIMEOUT; //Error out
248248
uint16_t _serialID1 = _i2cPort->read() << 8; //store MSB to top of _serialID1
249249
_serialID1 |= _i2cPort->read(); //store next byte in _serialID1
250250
uint8_t checkSum1 = _i2cPort->read(); //verify checksum
251251
if (checkSum1 != _CRC8(_serialID1))
252-
return ERR_BAD_CRC; //checksum failed
252+
return SGP30_ERR_BAD_CRC; //checksum failed
253253
uint16_t _serialID2 = _i2cPort->read() << 8; //store next byte to top of _serialID2
254254
_serialID2 |= _i2cPort->read(); //store next byte in _serialID2
255255
uint8_t checkSum2 = _i2cPort->read(); //verify checksum
256256
if (checkSum2 != _CRC8(_serialID2))
257-
return ERR_BAD_CRC; //checksum failed
257+
return SGP30_ERR_BAD_CRC; //checksum failed
258258
uint16_t _serialID3 = _i2cPort->read() << 8; //store next byte to top of _serialID3
259259
_serialID3 |= _i2cPort->read(); //store LSB in _serialID3
260260
uint8_t checkSum3 = _i2cPort->read(); //verify checksum
261261
if (checkSum3 != _CRC8(_serialID3))
262-
return ERR_BAD_CRC; //checksum failed
262+
return SGP30_ERR_BAD_CRC; //checksum failed
263263
serialID = ((uint64_t)_serialID1 << 32) + ((uint64_t)_serialID2 << 16) + ((uint64_t)_serialID3); //publish valid data
264-
return SUCCESS;
264+
return SGP30_SUCCESS;
265265
}
266266

267267
//Sensor runs on chip self test
268-
//Returns SUCCESS if successful or other error code if unsuccessful
268+
//Returns SGP30_SUCCESS if successful or other error code if unsuccessful
269269
SGP30ERR SGP30::measureTest(void)
270270
{
271271
_i2cPort->beginTransmission(_SGP30Address);
@@ -277,15 +277,15 @@ SGP30ERR SGP30::measureTest(void)
277277
//Comes back in 3 bytes, data(MSB) / data(LSB) / Checksum
278278
toRead = _i2cPort->requestFrom(_SGP30Address, (uint8_t)3);
279279
if (toRead != 3)
280-
return ERR_I2C_TIMEOUT; //Error out
280+
return SGP30_ERR_I2C_TIMEOUT; //Error out
281281
uint16_t results = _i2cPort->read() << 8; //store MSB in results
282282
results |= _i2cPort->read(); //store LSB in results
283283
uint8_t checkSum = _i2cPort->read(); //verify checksum
284284
if (checkSum != _CRC8(results))
285-
return ERR_BAD_CRC; //checksum failed
285+
return SGP30_ERR_BAD_CRC; //checksum failed
286286
if (results != 0xD400)
287-
return SELF_TEST_FAIL; //self test results incorrect
288-
return SUCCESS;
287+
return SGP30_SELF_TEST_FAIL; //self test results incorrect
288+
return SGP30_SUCCESS;
289289
}
290290

291291
#ifndef SGP30_LOOKUP_TABLE

src/SparkFun_SGP30_Arduino_Library.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
#include <Wire.h>
4444
typedef enum
4545
{
46-
SUCCESS = 0,
47-
ERR_BAD_CRC,
48-
ERR_I2C_TIMEOUT,
49-
SELF_TEST_FAIL
46+
SGP30_SUCCESS = 0,
47+
SGP30_ERR_BAD_CRC,
48+
SGP30_ERR_I2C_TIMEOUT,
49+
SGP30_SELF_TEST_FAIL
5050
} SGP30ERR;
5151

5252
const uint8_t init_air_quality[2] = {0x20, 0x03};

0 commit comments

Comments
 (0)