hg
Dependents: Example_DS3231_test
Adafruit_SGP30.h@0:41a622cdd86d, 2018-07-23 (annotated)
- Committer:
- ndrs_cwt
- Date:
- Mon Jul 23 09:51:43 2018 +0000
- Revision:
- 0:41a622cdd86d
Port from Adafruit_SGP30 arduino lib(https://github.com/adafruit/Adafruit_SGP30) to use Mbed API
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ndrs_cwt | 0:41a622cdd86d | 1 | /*! |
ndrs_cwt | 0:41a622cdd86d | 2 | * @file Adafruit_SGP30.h |
ndrs_cwt | 0:41a622cdd86d | 3 | * |
ndrs_cwt | 0:41a622cdd86d | 4 | * This is the documentation for Adafruit's SGP30 driver for the |
ndrs_cwt | 0:41a622cdd86d | 5 | * Arduino platform. It is designed specifically to work with the |
ndrs_cwt | 0:41a622cdd86d | 6 | * Adafruit SGP30 breakout: http://www.adafruit.com/products/3709 |
ndrs_cwt | 0:41a622cdd86d | 7 | * |
ndrs_cwt | 0:41a622cdd86d | 8 | * These sensors use I2C to communicate, 2 pins (SCL+SDA) are required |
ndrs_cwt | 0:41a622cdd86d | 9 | * to interface with the breakout. |
ndrs_cwt | 0:41a622cdd86d | 10 | * |
ndrs_cwt | 0:41a622cdd86d | 11 | * Adafruit invests time and resources providing this open source code, |
ndrs_cwt | 0:41a622cdd86d | 12 | * please support Adafruit and open-source hardware by purchasing |
ndrs_cwt | 0:41a622cdd86d | 13 | * products from Adafruit! |
ndrs_cwt | 0:41a622cdd86d | 14 | * |
ndrs_cwt | 0:41a622cdd86d | 15 | * Written by Ladyada for Adafruit Industries. |
ndrs_cwt | 0:41a622cdd86d | 16 | * |
ndrs_cwt | 0:41a622cdd86d | 17 | * BSD license, all text here must be included in any redistribution. |
ndrs_cwt | 0:41a622cdd86d | 18 | * |
ndrs_cwt | 0:41a622cdd86d | 19 | */ |
ndrs_cwt | 0:41a622cdd86d | 20 | |
ndrs_cwt | 0:41a622cdd86d | 21 | #include "mbed.h" |
ndrs_cwt | 0:41a622cdd86d | 22 | |
ndrs_cwt | 0:41a622cdd86d | 23 | // the i2c address |
ndrs_cwt | 0:41a622cdd86d | 24 | #define SGP30_I2CADDR_DEFAULT 0x58 ///< SGP30 has only one I2C address |
ndrs_cwt | 0:41a622cdd86d | 25 | |
ndrs_cwt | 0:41a622cdd86d | 26 | // commands and constants |
ndrs_cwt | 0:41a622cdd86d | 27 | #define SGP30_FEATURESET 0x0020 ///< The required set for this library |
ndrs_cwt | 0:41a622cdd86d | 28 | #define SGP30_CRC8_POLYNOMIAL 0x31 ///< Seed for SGP30's CRC polynomial |
ndrs_cwt | 0:41a622cdd86d | 29 | #define SGP30_CRC8_INIT 0xFF ///< Init value for CRC |
ndrs_cwt | 0:41a622cdd86d | 30 | #define SGP30_WORD_LEN 2 ///< 2 bytes per word |
ndrs_cwt | 0:41a622cdd86d | 31 | |
ndrs_cwt | 0:41a622cdd86d | 32 | /**************************************************************************/ |
ndrs_cwt | 0:41a622cdd86d | 33 | /*! Class that stores state and functions for interacting with SGP30 Gas Sensor */ |
ndrs_cwt | 0:41a622cdd86d | 34 | /**************************************************************************/ |
ndrs_cwt | 0:41a622cdd86d | 35 | class Adafruit_SGP30 { |
ndrs_cwt | 0:41a622cdd86d | 36 | public: |
ndrs_cwt | 0:41a622cdd86d | 37 | Adafruit_SGP30(PinName sda, PinName scl); |
ndrs_cwt | 0:41a622cdd86d | 38 | bool begin(); |
ndrs_cwt | 0:41a622cdd86d | 39 | bool IAQinit(void); |
ndrs_cwt | 0:41a622cdd86d | 40 | bool IAQmeasure(void); |
ndrs_cwt | 0:41a622cdd86d | 41 | |
ndrs_cwt | 0:41a622cdd86d | 42 | bool getIAQBaseline(uint16_t *eco2_base, uint16_t *tvoc_base); |
ndrs_cwt | 0:41a622cdd86d | 43 | bool setIAQBaseline(uint16_t eco2_base, uint16_t tvoc_base); |
ndrs_cwt | 0:41a622cdd86d | 44 | bool getIAQRaw(uint16_t *H2_raw, uint16_t *Eth_raw); |
ndrs_cwt | 0:41a622cdd86d | 45 | |
ndrs_cwt | 0:41a622cdd86d | 46 | /** |
ndrs_cwt | 0:41a622cdd86d | 47 | * The last measurement of the IAQ-calculated Total Volatile Organic Compounds in ppb. This value is set when you call {@link IAQmeasure()} |
ndrs_cwt | 0:41a622cdd86d | 48 | */ |
ndrs_cwt | 0:41a622cdd86d | 49 | uint16_t TVOC; |
ndrs_cwt | 0:41a622cdd86d | 50 | |
ndrs_cwt | 0:41a622cdd86d | 51 | /** |
ndrs_cwt | 0:41a622cdd86d | 52 | * The last measurement of the IAQ-calculated equivalent CO2 in ppm. This value is set when you call {@link IAQmeasure()} |
ndrs_cwt | 0:41a622cdd86d | 53 | */ |
ndrs_cwt | 0:41a622cdd86d | 54 | uint16_t eCO2; |
ndrs_cwt | 0:41a622cdd86d | 55 | |
ndrs_cwt | 0:41a622cdd86d | 56 | /** |
ndrs_cwt | 0:41a622cdd86d | 57 | * The 48-bit serial number, this value is set when you call {@link begin()} |
ndrs_cwt | 0:41a622cdd86d | 58 | */ |
ndrs_cwt | 0:41a622cdd86d | 59 | uint16_t serialnumber[3]; |
ndrs_cwt | 0:41a622cdd86d | 60 | private: |
ndrs_cwt | 0:41a622cdd86d | 61 | I2C _i2c; |
ndrs_cwt | 0:41a622cdd86d | 62 | int _i2caddr; |
ndrs_cwt | 0:41a622cdd86d | 63 | |
ndrs_cwt | 0:41a622cdd86d | 64 | void write(uint8_t address, uint8_t *data, uint8_t n); |
ndrs_cwt | 0:41a622cdd86d | 65 | void read(uint8_t address, uint8_t *data, uint8_t n); |
ndrs_cwt | 0:41a622cdd86d | 66 | bool readWordFromCommand(uint8_t command[], uint8_t commandLength, uint16_t delay, uint16_t *readdata = NULL, uint8_t readlen = 0); |
ndrs_cwt | 0:41a622cdd86d | 67 | uint8_t generateCRC(uint8_t data[], uint8_t datalen); |
ndrs_cwt | 0:41a622cdd86d | 68 | }; |