Driver for Sensirion SCD30, CO2 sensor module using I2C. The device also senses Temperature and Humidity.

Dependents:   scd30_HelloWorld scd30_HelloWorld

Files at this revision

API Documentation at this revision

Comitter:
loopsva
Date:
Thu Sep 13 17:38:26 2018 +0000
Parent:
0:2a16832400d0
Commit message:
Changed the way the data structure is handled

Changed in this revision

scd30.cpp Show annotated file Show diff for this revision Revisions of this file
scd30.h Show annotated file Show diff for this revision Revisions of this file
diff -r 2a16832400d0 -r 24bb922e179c scd30.cpp
--- a/scd30.cpp	Mon Sep 10 17:51:13 2018 +0000
+++ b/scd30.cpp	Thu Sep 13 17:38:26 2018 +0000
@@ -60,7 +60,7 @@
 //-----------------------------------------------------------------------------
 // Get ready status value
 
-uint8_t scd30::getReadyStatus(SCD30_str& sSTR)
+uint8_t scd30::getReadyStatus()
 {
     i2cBuff[0] = SCD30_CMMD_GET_READY_STAT >> 8;
     i2cBuff[1] = SCD30_CMMD_GET_READY_STAT & 255;
@@ -69,7 +69,7 @@
     
     _i2c.read(SCD30_I2C_ADDR | 1, i2cBuff, 3, false);
     uint16_t stat = (i2cBuff[0] << 8) | i2cBuff[1];
-    sSTR.ready = stat;
+    scdSTR.ready = stat;
     uint8_t dat = scd30::checkCrc2b(stat, i2cBuff[2]);
     
     if(dat == SCDcrcERROR) return SCDcrcERRORv1;
@@ -80,7 +80,7 @@
 //-----------------------------------------------------------------------------
 // Get all the measurement values, stick them into the array
 
-uint8_t scd30::readMeasurement(SCD30_str& sSTR)
+uint8_t scd30::readMeasurement()
 {
     i2cBuff[0] = SCD30_CMMD_READ_MEAS >> 8;
     i2cBuff[1] = SCD30_CMMD_READ_MEAS & 255;
@@ -90,42 +90,42 @@
     _i2c.read(SCD30_I2C_ADDR | 1, i2cBuff, 18, false);
     
     uint16_t stat = (i2cBuff[0] << 8) | i2cBuff[1];
-    sSTR.co2m = stat;
+    scdSTR.co2m = stat;
     uint8_t dat = scd30::checkCrc2b(stat, i2cBuff[2]);
     if(dat == SCDcrcERROR) return SCDcrcERRORv1;
     
     stat = (i2cBuff[3] << 8) | i2cBuff[4];
-    sSTR.co2l = stat;
+    scdSTR.co2l = stat;
     dat = scd30::checkCrc2b(stat, i2cBuff[5]);
     if(dat == SCDcrcERROR) return SCDcrcERRORv2;
     
     stat = (i2cBuff[6] << 8) | i2cBuff[7];
-    sSTR.tempm = stat;
+    scdSTR.tempm = stat;
     dat = scd30::checkCrc2b(stat, i2cBuff[8]);
     if(dat == SCDcrcERROR) return SCDcrcERRORv3;
     
     stat = (i2cBuff[9] << 8) | i2cBuff[10];
-    sSTR.templ = stat;
+    scdSTR.templ = stat;
     dat = scd30::checkCrc2b(stat, i2cBuff[11]);
     if(dat == SCDcrcERROR) return SCDcrcERRORv4;
     
     stat = (i2cBuff[12] << 8) | i2cBuff[13];
-    sSTR.humm = stat;
+    scdSTR.humm = stat;
     dat = scd30::checkCrc2b(stat, i2cBuff[14]);
     if(dat == SCDcrcERROR) return SCDcrcERRORv5;
     
     stat = (i2cBuff[15] << 8) | i2cBuff[16];
-    sSTR.huml = stat;
+    scdSTR.huml = stat;
     dat = scd30::checkCrc2b(stat, i2cBuff[17]);
     if(dat == SCDcrcERROR) return SCDcrcERRORv6;
     
-    sSTR.co2i = (sSTR.co2m << 16) | sSTR.co2l ;
-    sSTR.tempi = (sSTR.tempm << 16) | sSTR.templ ;
-    sSTR.humi = (sSTR.humm << 16) | sSTR.huml ;
+    scdSTR.co2i = (scdSTR.co2m << 16) | scdSTR.co2l ;
+    scdSTR.tempi = (scdSTR.tempm << 16) | scdSTR.templ ;
+    scdSTR.humi = (scdSTR.humm << 16) | scdSTR.huml ;
     
-    sSTR.co2f = *(float*)&sSTR.co2i;
-    sSTR.tempf = *(float*)&sSTR.tempi;
-    sSTR.humf = *(float*)&sSTR.humi;
+    scdSTR.co2f = *(float*)&scdSTR.co2i;
+    scdSTR.tempf = *(float*)&scdSTR.tempi;
+    scdSTR.humf = *(float*)&scdSTR.humi;
     
     return SCDnoERROR;
 }
@@ -229,7 +229,7 @@
 //-----------------------------------------------------------------------------
 // Get article code
 
-uint8_t scd30::getArticleCode(SCD30_str& sSTR)
+uint8_t scd30::getArticleCode()
 {
     i2cBuff[0] = SCD30_CMMD_READ_ARTICLECODE >> 8;
     i2cBuff[1] = SCD30_CMMD_READ_ARTICLECODE & 255;
@@ -238,7 +238,7 @@
     
     _i2c.read(SCD30_I2C_ADDR | 1, i2cBuff, 3, false);
     uint16_t stat = (i2cBuff[0] << 8) | i2cBuff[1];
-    sSTR.acode = stat;
+    scdSTR.acode = stat;
     uint8_t dat = scd30::checkCrc2b(stat, i2cBuff[2]);
     
     if(dat == SCDcrcERROR) return SCDcrcERRORv1;
@@ -248,7 +248,7 @@
 //-----------------------------------------------------------------------------
 // Get scd30 serial number
 
-uint8_t scd30::getSerialNumber(SCD30_str& sSTR)
+uint8_t scd30::getSerialNumber()
 {
     i2cBuff[0] = SCD30_CMMD_READ_SERIALNBR >> 8;
     i2cBuff[1] = SCD30_CMMD_READ_SERIALNBR & 255;
@@ -256,15 +256,15 @@
     if(res) return SCDnoAckERROR;
     
     int i = 0;
-    for(i = 0; i < sizeof(sSTR.sn); i++) sSTR.sn[i] = 0;
+    for(i = 0; i < sizeof(scdSTR.sn); i++) scdSTR.sn[i] = 0;
     for(i = 0; i < sizeof(i2cBuff); i++) i2cBuff[i] = 0;
     
     _i2c.read(SCD30_I2C_ADDR | 1, i2cBuff, SCD30_SN_SIZE, false);
     int t = 0;
     for(i = 0; i < SCD30_SN_SIZE; i +=3) {
         uint16_t stat = (i2cBuff[i] << 8) | i2cBuff[i + 1];
-        sSTR.sn[i - t] = stat >> 8;
-        sSTR.sn[i - t + 1] = stat & 255;
+        scdSTR.sn[i - t] = stat >> 8;
+        scdSTR.sn[i - t + 1] = stat & 255;
         uint8_t dat = scd30::checkCrc2b(stat, i2cBuff[i + 2]);
         t++;
         if(dat == SCDcrcERROR) return SCDcrcERRORv1;
diff -r 2a16832400d0 -r 24bb922e179c scd30.h
--- a/scd30.h	Mon Sep 10 17:51:13 2018 +0000
+++ b/scd30.h	Thu Sep 13 17:38:26 2018 +0000
@@ -49,7 +49,7 @@
      * Structure to access SCD30's raw and finished data
      *
      */    
-    typedef struct {
+    struct scdSTRuct {
         uint16_t co2m;          /**< High order 16 bit word of CO2 */
         uint16_t co2l;          /**< Low  order 16 bit word of CO2 */
         uint16_t tempm;         /**< High order 16 bit word of Temp */
@@ -69,7 +69,7 @@
         
         uint16_t acode;         /**< Article code number?? */
         uint8_t sn[24];         /**< ASCII Serial Number */
-    } SCD30_str;
+    } scdSTR;
     
     
     /** Create a SCD30 object using the specified I2C object
@@ -115,21 +115,21 @@
     
     /** Get Ready Status register 
      *
-     * @param Pointer to SCD30_str structure
-     * @see Ready Status result in SCD30_str structure
+     * @param --none--
+     * @see Ready Status result in scdSTR structure
      *
      * @return enum SCDerror
      */
-    uint8_t getReadyStatus(SCD30_str& sSTR);
+    uint8_t getReadyStatus();
     
     /** Get all environmental parameters (CO2, Temp and Hum) 
      *
-     * @param Pointer to SCD30_str structure
-     * @see Results in SCD30_str structure
+     * @param --none-
+     * @see Results in scdSTR structure
      *
      * @return enum SCDerror
      */
-    uint8_t readMeasurement(SCD30_str& sSTR);
+    uint8_t readMeasurement();
     
     /** Set Temperature offset
      *
@@ -182,21 +182,21 @@
     
     /** Get Article Code
      *
-     * @param Pointer to SCD30_str structure
+     * @param --none--
      * 
      *
      * @return enum SCDerror
      */
-    uint8_t getArticleCode(SCD30_str& sSTR);
+    uint8_t getArticleCode();
     
     /** Get Serial Number
      *
-     * @param Pointer to SCD30_str structure
-     * @see ASCII Serial Number in SCD30_str structure
+     * @param --none--
+     * @see ASCII Serial Number in scdSTR structure
      *
      * @return enum SCDerror
      */
-    uint8_t getSerialNumber(SCD30_str& sSTR);
+    uint8_t getSerialNumber();
  
 private:
     char i2cBuff[34];