Library for Sensirion Environmental Sensor Shield for SGP30 & SHTC1

Dependents:   example-sensirion-ublox-c030

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sensirion_ess.h Source File

sensirion_ess.h

00001 /*
00002  * Copyright (c) 2017-2018, Sensirion AG
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  * * Redistributions of source code must retain the above copyright notice, this
00009  *   list of conditions and the following disclaimer.
00010  *
00011  * * Redistributions in binary form must reproduce the above copyright notice,
00012  *   this list of conditions and the following disclaimer in the documentation
00013  *   and/or other materials provided with the distribution.
00014  *
00015  * * Neither the name of Sensirion AG nor the names of its
00016  *   contributors may be used to endorse or promote products derived from
00017  *   this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00020  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00023  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00024  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00025  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00026  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00027  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00028  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  */
00030 
00031 #ifndef SENSIRION_ESS
00032 #define SENSIRION_ESS
00033 #include "mbed.h"
00034 #define LED_RED D9
00035 #define LED_YEL D10
00036 #define LED_GRN D11
00037 class SensirionESS
00038 {
00039 public:
00040     SensirionESS(void *interface);
00041 
00042     int initSensors();
00043 
00044     int measureRHT();
00045     int measureIAQ();
00046 
00047     bool isInitialized();
00048 
00049     float getTemperature() const;
00050     float getHumidity() const;
00051 
00052     int getProductType() const;
00053     int getFeatureSetVersion() const;
00054 
00055     float getTVOC() const;
00056     float getECO2() const; // SGP30 only
00057 
00058     const char* getError() const;
00059 
00060     void setLedRYG(int r, int y, int g);
00061 
00062     int remainingWaitTimeMS();
00063 
00064     const static int PRODUCT_TYPE_SGP30    = 0;
00065     const static int PRODUCT_TYPE_SGPC3    = 1;
00066 
00067 private:
00068     int8_t i2c_write(uint8_t addr, const uint8_t* data, uint16_t count);
00069     int8_t i2c_read(uint8_t addr, uint8_t* data, uint16_t count);
00070     static uint8_t crc8(const uint8_t* data, uint8_t len);
00071 
00072     inline void setError(const char* error);
00073     int readFeatureSetInt();
00074     int measureRHTInt();
00075     int initSGP();
00076     void setLedRYGInt(int r, int y, int g);
00077 
00078     const static int ERROR_BUF_LENGTH       = 255;
00079     const static int CMD_LENGTH             = 2;
00080 
00081     const static int SHT_DATA_LENGTH        = 6;
00082     const static int SHT_I2C_ADDR           = 0x70;
00083     const static int SHT_MEASURE_DELAY      = 15;   // SHTC1 worst case
00084 
00085     const static int SGP30_DATA_LENGTH      = 6;
00086     const static int SGPC3_DATA_LENGTH      = 3;
00087     const static int SGP_I2C_ADDR           = 0x58;
00088     const static int SGP_MEASURE_DELAY      = 50;
00089 
00090     const static int SGP_RED_THRESHOLD     = 150;
00091     const static int SGP_YEL_THRESHOLD     = 125;
00092 
00093     const static int SGPC3_INTERMEASURE_DELAY = 2000;
00094     const static int SGP30_INTERMEASURE_DELAY = 1000;
00095 
00096     int SGP_INTERMEASURE_DELAY                = SGP30_INTERMEASURE_DELAY;
00097     int SGP_DATA_LENGTH                       = SGP30_DATA_LENGTH;
00098 
00099     float mTemperature = -250;
00100     float mHumidity    = -1;
00101     float mTVOC        = -1;
00102     float mECO2        = -1;
00103 
00104     int mProductType       = 0;
00105     int mFeatureSetVersion = 0;
00106 
00107     unsigned long mSGPMeasurementTimestamp = 0;
00108 
00109     bool mInitialized = false;
00110     char mErrorBuf[ERROR_BUF_LENGTH];
00111     uint8_t mDataBuf[SHT_DATA_LENGTH]; // max(SHT_DATA_LENGTH, SGP_DATA_LENGTH)
00112     I2C *i2c_connection;
00113     Timer *t;
00114 
00115 
00116 };
00117 
00118 #endif /* SENSIRION_ESS */