Mbed library for SPS30 i2c communication

Revision:
6:83ed80f27fff
Parent:
5:147de21156cf
Child:
8:f6b216228067
--- a/sps30.cpp	Fri Mar 08 01:33:37 2019 +0000
+++ b/sps30.cpp	Tue Mar 12 03:26:29 2019 +0000
@@ -26,8 +26,8 @@
     i2cbuff[3] = SPS30_STRT_MEAS_WRITE_DATA & 255;
     i2cbuff[4] = sps30::CalcCrc2b(SPS30_STRT_MEAS_WRITE_DATA);
     int res = _i2c.write(SPS30_I2C_ADDR, i2cbuff, 5, false);
-    if(res) return SPSnoAckERROR;
-    return SPSnoERROR;
+    if(res) return SPSNOACKERROR;
+    return SPSNOERROR;
 }
 
 //-----------------------------------------------------------------------------
@@ -38,8 +38,8 @@
     i2cbuff[0] = SPS30_CMMD_STOP_MEAS >> 8;
     i2cbuff[1] = SPS30_CMMD_STOP_MEAS & 255;
     int res = _i2c.write(SPS30_I2C_ADDR, i2cbuff, 2, false);
-    if(res) return SPSnoAckERROR;
-    return SPSnoERROR;
+    if(res) return SPSNOACKERROR;
+    return SPSNOERROR;
 }
 
 //-----------------------------------------------------------------------------
@@ -50,15 +50,15 @@
     i2cbuff[0] = SPS30_CMMD_GET_READY_STAT >> 8;
     i2cbuff[1] = SPS30_CMMD_GET_READY_STAT & 255;
     int res = _i2c.write(SPS30_I2C_ADDR, i2cbuff, 2, false);
-    if(res) return SPSnoAckERROR;
+    if(res) return SPSNOACKERROR;
     
     _i2c.read(SPS30_I2C_ADDR | 1, i2cbuff, 3, false);
     uint16_t stat = (i2cbuff[0] << 8) | i2cbuff[1];
     ready = stat;
     uint8_t dat = sps30::CheckCrc2b(stat, i2cbuff[2]);
     
-    if(dat == SPScrcERROR) return SPScrcERROR;
-    return SPSnoERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
+    return SPSNOERROR;
 }
 
 //-----------------------------------------------------------------------------
@@ -69,124 +69,124 @@
     i2cbuff[0] = SPS30_CMMD_READ_MEAS >> 8;
     i2cbuff[1] = SPS30_CMMD_READ_MEAS & 255;
     int res = _i2c.write(SPS30_I2C_ADDR, i2cbuff, 2, false);
-    if(res) return SPSnoAckERROR;
+    if(res) return SPSNOACKERROR;
     
     _i2c.read(SPS30_I2C_ADDR | 1, i2cbuff, 60, false);
     
     uint16_t stat = (i2cbuff[0] << 8) | i2cbuff[1];
     mass_1p0_m = stat;
     uint8_t dat = sps30::CheckCrc2b(stat, i2cbuff[2]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
     
     stat = (i2cbuff[3] << 8) | i2cbuff[4];
     mass_1p0_l = stat;
     dat = sps30::CheckCrc2b(stat, i2cbuff[5]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
 
 
     
     stat = (i2cbuff[6] << 8) | i2cbuff[7];
     mass_2p5_m = stat;
     dat = sps30::CheckCrc2b(stat, i2cbuff[8]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
     
     stat = (i2cbuff[9] << 8) | i2cbuff[10];
     mass_2p5_l = stat;
     dat = sps30::CheckCrc2b(stat, i2cbuff[11]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
 
 
     
     stat = (i2cbuff[12] << 8) | i2cbuff[13];
     mass_4p0_m = stat;
     dat = sps30::CheckCrc2b(stat, i2cbuff[14]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
     
     stat = (i2cbuff[15] << 8) | i2cbuff[16];
     mass_4p0_l = stat;
     dat = sps30::CheckCrc2b(stat, i2cbuff[17]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
 
 
 
     stat = (i2cbuff[18] << 8) | i2cbuff[19];
     mass_10p0_m = stat;
     dat = sps30::CheckCrc2b(stat, i2cbuff[20]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
     
     stat = (i2cbuff[21] << 8) | i2cbuff[22];
     mass_10p0_l = stat;
     dat = sps30::CheckCrc2b(stat, i2cbuff[23]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
 
 
 
     stat = (i2cbuff[24] << 8) | i2cbuff[25];
     num_0p5_m = stat;
     dat = sps30::CheckCrc2b(stat, i2cbuff[26]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
     
     stat = (i2cbuff[27] << 8) | i2cbuff[28];
     num_0p5_l = stat;
     dat = sps30::CheckCrc2b(stat, i2cbuff[29]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
 
 
     stat = (i2cbuff[30] << 8) | i2cbuff[31];
     num_1p0_m = stat;
     dat = sps30::CheckCrc2b(stat, i2cbuff[32]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
     
     stat = (i2cbuff[33] << 8) | i2cbuff[34];
     num_1p0_l = stat;
     dat = sps30::CheckCrc2b(stat, i2cbuff[35]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
 
 
     
     stat = (i2cbuff[36] << 8) | i2cbuff[37];
     num_2p5_m = stat;
     dat = sps30::CheckCrc2b(stat, i2cbuff[38]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
     
     stat = (i2cbuff[39] << 8) | i2cbuff[40];
     num_2p5_l = stat;
     dat = sps30::CheckCrc2b(stat, i2cbuff[41]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
 
 
     
     stat = (i2cbuff[42] << 8) | i2cbuff[43];
     num_4p0_m = stat;
     dat = sps30::CheckCrc2b(stat, i2cbuff[44]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
     
     stat = (i2cbuff[45] << 8) | i2cbuff[46];
     num_4p0_l = stat;
     dat = sps30::CheckCrc2b(stat, i2cbuff[47]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
 
 
     stat = (i2cbuff[48] << 8) | i2cbuff[49];
     num_10p0_m = stat;
     dat = sps30::CheckCrc2b(stat, i2cbuff[50]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
     
     stat = (i2cbuff[51] << 8) | i2cbuff[52];
     num_10p0_l = stat;
     dat = sps30::CheckCrc2b(stat, i2cbuff[53]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
 
 
     stat = (i2cbuff[54] << 8) | i2cbuff[55];
     typ_pm_size_m = stat;
     dat = sps30::CheckCrc2b(stat, i2cbuff[56]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
     
     stat = (i2cbuff[57] << 8) | i2cbuff[58];
     typ_pm_size_l = stat;
     dat = sps30::CheckCrc2b(stat, i2cbuff[59]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
     
     mass_1p0_i = (mass_1p0_m << 16) | mass_1p0_l;
     mass_2p5_i = (mass_2p5_m << 16) | mass_2p5_l;
@@ -214,7 +214,7 @@
 
     typ_pm_size_f = *(float*)&typ_pm_size_i;
     
-    return SPSnoERROR;
+    return SPSNOERROR;
 }
     
 //-----------------------------------------------------------------------------
@@ -250,8 +250,8 @@
 uint8_t sps30::CheckCrc2b(uint16_t seed, uint8_t crc_in)
 {
     uint8_t crc_calc = sps30::CalcCrc2b(seed);
-    if(crc_calc != crc_in) return SPScrcERROR;
-    return SPSnoERROR;
+    if(crc_calc != crc_in) return SPSCRCERROR;
+    return SPSNOERROR;
 }
 
 //-----------------------------------------------------------------------------
@@ -262,7 +262,7 @@
     i2cbuff[0] = SPS30_CMMD_READ_ARTICLECODE >> 8;
     i2cbuff[1] = SPS30_CMMD_READ_ARTICLECODE & 255;
     int res = _i2c.write(SPS30_I2C_ADDR, i2cbuff, 2, false);
-    if(res) return SPSnoAckERROR;
+    if(res) return SPSNOACKERROR;
     
     int i = 0;
     for(i = 0; i < sizeof(acode); i++) acode[i] = 0;
@@ -276,11 +276,11 @@
         acode[i - t + 1] = stat & 255;
         uint8_t dat = sps30::CheckCrc2b(stat, i2cbuff[i + 2]);
         t++;
-        if(dat == SPScrcERROR) return SPScrcERROR;
+        if(dat == SPSCRCERROR) return SPSCRCERROR;
         if(stat == 0) break;
     }
 
-    return SPSnoERROR;
+    return SPSNOERROR;
 }
 
 //-----------------------------------------------------------------------------
@@ -291,7 +291,7 @@
     i2cbuff[0] = SPS30_CMMD_READ_SERIALNBR >> 8;
     i2cbuff[1] = SPS30_CMMD_READ_SERIALNBR & 255;
     int res = _i2c.write(SPS30_I2C_ADDR, i2cbuff, 2, false);
-    if(res) return SPSnoAckERROR;
+    if(res) return SPSNOACKERROR;
     
     int i = 0;
     for(i = 0; i < sizeof(sn); i++) sn[i] = 0;
@@ -305,11 +305,11 @@
         sn[i - t + 1] = stat & 255;
         uint8_t dat = sps30::CheckCrc2b(stat, i2cbuff[i + 2]);
         t++;
-        if(dat == SPScrcERROR) return SPScrcERROR;
+        if(dat == SPSCRCERROR) return SPSCRCERROR;
         if(stat == 0) break;
     }
 
-    return SPSnoERROR;
+    return SPSNOERROR;
 }
 
 //-----------------------------------------------------------------------------
@@ -321,23 +321,23 @@
     i2cbuff[1] = SPS30_CMMD_AUTO_CLEAN_INTV & 255;
     
     int res = _i2c.write(SPS30_I2C_ADDR, i2cbuff, 2, false);
-    if(res) return SPSnoAckERROR;
+    if(res) return SPSNOACKERROR;
     
     _i2c.read(SPS30_I2C_ADDR | 1, i2cbuff, 6, false);
     
     uint16_t stat = (i2cbuff[0] << 8) | i2cbuff[1];
     clean_interval_m = stat;
     uint8_t dat = sps30::CheckCrc2b(stat, i2cbuff[2]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
     
     stat = (i2cbuff[3] << 8) | i2cbuff[4];
     clean_interval_l = stat;
     dat = sps30::CheckCrc2b(stat, i2cbuff[5]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
     
     clean_interval_i = (clean_interval_m << 16) | clean_interval_l;
     
-    return SPSnoERROR;
+    return SPSNOERROR;
 }
 
 //-----------------------------------------------------------------------------
@@ -360,23 +360,23 @@
     i2cbuff[7] = sps30::CalcCrc2b(set_interval_l);
     
     int res = _i2c.write(SPS30_I2C_ADDR, i2cbuff, 8, false);
-    if(res) return SPSnoAckERROR;
+    if(res) return SPSNOACKERROR;
     
     _i2c.read(SPS30_I2C_ADDR | 1, i2cbuff, 6, false);
     
     uint16_t stat = (i2cbuff[0] << 8) | i2cbuff[1];
     clean_interval_m = stat;
     uint8_t dat = sps30::CheckCrc2b(stat, i2cbuff[2]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
     
     stat = (i2cbuff[3] << 8) | i2cbuff[4];
     clean_interval_l = stat;
     dat = sps30::CheckCrc2b(stat, i2cbuff[5]);
-    if(dat == SPScrcERROR) return SPScrcERROR;
+    if(dat == SPSCRCERROR) return SPSCRCERROR;
     
     clean_interval_i = (clean_interval_m << 16) | clean_interval_l;
     
-    return SPSnoERROR;
+    return SPSNOERROR;
 }
 
 //-----------------------------------------------------------------------------
@@ -387,8 +387,8 @@
     i2cbuff[0] = SPS30_CMMD_START_FAN_CLEAN >> 8;
     i2cbuff[1] = SPS30_CMMD_START_FAN_CLEAN & 255;
     int res = _i2c.write(SPS30_I2C_ADDR, i2cbuff, 2, false);
-    if(res) return SPSnoAckERROR;
-    return SPSnoERROR;
+    if(res) return SPSNOACKERROR;
+    return SPSNOERROR;
 }
 
 //-----------------------------------------------------------------------------
@@ -399,6 +399,6 @@
     i2cbuff[0] = SPS30_CMMD_SOFT_RESET >> 8;
     i2cbuff[1] = SPS30_CMMD_SOFT_RESET & 255;
     int res = _i2c.write(SPS30_I2C_ADDR, i2cbuff, 2, false);
-    if(res) return SPSnoAckERROR;
-    return SPSnoERROR;
+    if(res) return SPSNOACKERROR;
+    return SPSNOERROR;
 }
\ No newline at end of file