Adafruit_SGP30.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // @file Adafruit_SGP30.h
  2. #ifndef ADAFRUIT_SGP30_H
  3. #define ADAFRUIT_SGP30_H
  4. #include "Arduino.h"
  5. #include <Wire.h>
  6. // the i2c address
  7. #define SGP30_I2CADDR_DEFAULT 0x58 ///< SGP30 has only one I2C address
  8. // commands and constants
  9. #define SGP30_FEATURESET 0x0020 ///< The required set for this library
  10. #define SGP30_CRC8_POLYNOMIAL 0x31 ///< Seed for SGP30's CRC polynomial
  11. #define SGP30_CRC8_INIT 0xFF ///< Init value for CRC
  12. #define SGP30_WORD_LEN 2 ///< 2 bytes per word
  13. /*!
  14. * @brief Class that stores state and functions for interacting with
  15. * SGP30 Gas Sensor
  16. */
  17. class Adafruit_SGP30 {
  18. public:
  19. Adafruit_SGP30();
  20. boolean begin(TwoWire *theWire = &Wire, boolean initSensor = true);
  21. boolean softReset();
  22. boolean IAQinit();
  23. boolean IAQmeasure();
  24. boolean IAQmeasureRaw();
  25. boolean getIAQBaseline(uint16_t *eco2_base, uint16_t *tvoc_base);
  26. boolean setIAQBaseline(uint16_t eco2_base, uint16_t tvoc_base);
  27. boolean setHumidity(uint32_t absolute_humidity);
  28. /** The last measurement of the IAQ-calculated Total Volatile Organic
  29. * Compounds in ppb. This value is set when you call {@link IAQmeasure()} **/
  30. uint16_t TVOC;
  31. /** The last measurement of the IAQ-calculated equivalent CO2 in ppm. This
  32. * value is set when you call {@link IAQmeasure()} **/
  33. uint16_t eCO2;
  34. /** The last measurement of the IAQ-calculated equivalent CO2 in ppm. This
  35. * value is set when you call {@link IAQmeasureRaw()} **/
  36. uint16_t rawH2;
  37. /** The last measurement of the IAQ-calculated equivalent CO2 in ppm. This
  38. * value is set when you call {@link IAQmeasureRaw()} **/
  39. uint16_t rawEthanol;
  40. /** The 48-bit serial number, this value is set when you call {@link begin()}
  41. * **/
  42. uint16_t serialnumber[3];
  43. private:
  44. TwoWire *_i2c;
  45. uint8_t _i2caddr;
  46. void write(uint8_t address, uint8_t *data, uint8_t n);
  47. void read(uint8_t address, uint8_t *data, uint8_t n);
  48. boolean readWordFromCommand(uint8_t command[], uint8_t commandLength,
  49. uint16_t delay, uint16_t *readdata = NULL,
  50. uint8_t readlen = 0);
  51. uint8_t generateCRC(uint8_t data[], uint8_t datalen);
  52. };
  53. #endif // ndef ADAFRUIT_SGP30_H