Mbed library for SPS30 i2c communication (Configured to be interfaced with TresidderOS) Inherits members and methods from SensorDriver class
Diff: sps30.h
- Revision:
- 8:f6b216228067
- Parent:
- 7:4152825938bf
- Child:
- 9:a5fe43e183e2
--- a/sps30.h Tue Mar 12 08:25:10 2019 +0000 +++ b/sps30.h Fri Mar 15 06:52:32 2019 +0000 @@ -29,24 +29,33 @@ #define SPS30_CRC_INIT 0xff #define SPS30_SN_SIZE 33 // size of the s/n ascii string + CRC values -#define SPS30_ACODE_SIZE 33 // size of the article code ascii string + CRC values + +#define MASS_MAX 1000.00f +#define MASS_MIN 0.00f +#define NUM_MAX 3000.00f +#define NUM_MIN 0.00f + +#define I2C_FREQUENCY_STD 100000 // SPS30 uses 100MHz for I2C communication /** Create SPS30 controller class * * @param sps30 class * */ -class sps30 { +class Sps30 { public: - enum SPSError { - SPSNOERROR, //all ok - SPSISREADY, //ready status register - SPSNOACKERROR, //no I2C ACK error - SPSCRCERROR, //CRC error, any - }; + enum SPSStatus { + DISCONNECTED, + CONNECTED, + DATANOTREADY, + DATAREADY, + DATAERROR, + DATAOOR, + DATAOK, + } SPSStatus; - uint16_t ready; /**< 1 = ready, 0 = busy */ + uint16_t sps_ready; /**< 1 = ready, 0 = busy */ uint32_t clean_interval_i; /** 32 unsigned bit in seconds */ float mass_1p0_f; /**< float of Mass Conc of PM1.0 */ @@ -62,7 +71,6 @@ float typ_pm_size_f; /**< float of Typical Particle Size */ - uint8_t acode[33]; /**< Article code number */ uint8_t sn[33]; /**< ASCII Serial Number */ @@ -74,7 +82,7 @@ * * @return none */ - sps30(PinName sda, PinName scl, int i2c_frequency); + Sps30(PinName sda, PinName scl, int i2c_frequency); /** Destructor * @@ -82,7 +90,75 @@ * * @return none */ - ~sps30(); + ~Sps30(); + + + /** Initialise SPS30 + * + * @param --none-- + * + * @return enum SPSStatus + */ + uint8_t InitSPS30(); + + /** Poll SPS30 Data + * + * @param --none-- + * + * @return enum SPSStatus + */ + uint8_t PollSPS30(); + + +private: + + enum SPSError { + SPSNOERROR, //all ok + SPSISREADY, //ready status register + SPSNOACKERROR, //no I2C ACK error + SPSCRCERROR, //CRC error, any + }; + + char i2cbuff[60]; + + uint16_t clean_interval_m; /**< High order 16 bit word of Auto Clean Interval */ + uint16_t clean_interval_l; /**< High order 16 bit word of Auto Clean Interval */ + + uint16_t mass_1p0_m; /**< High order 16 bit word of Mass Conc of PM1.0 */ + uint16_t mass_1p0_l; /**< Low order 16 bit word of Mass Conc of PM1.0 */ + uint16_t mass_2p5_m; /**< High order 16 bit word of Mass Conc of PM2.5 */ + uint16_t mass_2p5_l; /**< Low order 16 bit word of Mass Conc of PM2.5 */ + uint16_t mass_4p0_m; /**< High order 16 bit word of Mass Conc of PM4.0 */ + uint16_t mass_4p0_l; /**< Low order 16 bit word of Mass Conc of PM4.0 */ + uint16_t mass_10p0_m; /**< High order 16 bit word of Mass Conc of PM10 */ + uint16_t mass_10p0_l; /**< Low order 16 bit word of Mass Conc of PM10 */ + + uint16_t num_0p5_m; /**< High order 16 bit word of Number Conc of PM0.5 */ + uint16_t num_0p5_l; /**< Low order 16 bit word of Number Conc of PM0.5 */ + uint16_t num_1p0_m; /**< High order 16 bit word of Number Conc of PM1.0 */ + uint16_t num_1p0_l; /**< Low order 16 bit word of Number Conc of PM1.0 */ + uint16_t num_2p5_m; /**< High order 16 bit word of Number Conc of PM2.5 */ + uint16_t num_2p5_l; /**< Low order 16 bit word of Number Conc of PM2.5 */ + uint16_t num_4p0_m; /**< High order 16 bit word of Number Conc of PM4.0 */ + uint16_t num_4p0_l; /**< Low order 16 bit word of Number Conc of PM4.0 */ + uint16_t num_10p0_m; /**< High order 16 bit word of Number Conc of PM10 */ + uint16_t num_10p0_l; /**< Low order 16 bit word of Number Conc of PM10 */ + + uint16_t typ_pm_size_m; /**< High order 16 bit word of Typical Particle Size */ + uint16_t typ_pm_size_l; /**< Low order 16 bit word of Typical Particle Size */ + + uint32_t mass_1p0_i; /**< 32 bit int of Mass Conc of PM1.0 */ + uint32_t mass_2p5_i; /**< 32 bit int of Mass Conc of PM2.5 */ + uint32_t mass_4p0_i; /**< 32 bit int of Mass Conc of PM4.0 */ + uint32_t mass_10p0_i; /**< 32 bit int of Mass Conc of PM10 */ + + uint32_t num_0p5_i; /**< 32 bit int of Number Conc of PM0.5 */ + uint32_t num_1p0_i; /**< 32 bit int of Number Conc of PM1.0 */ + uint32_t num_2p5_i; /**< 32 bit int of Number Conc of PM2.5 */ + uint32_t num_4p0_i; /**< 32 bit int of Number Conc of PM4.0 */ + uint32_t num_10p0_i; /**< 32 bit int of Number Conc of PM10 */ + + uint32_t typ_pm_size_i; /**< 32 bit int of Typical Particle Size */ /** Start Auto-Measurement * @@ -135,15 +211,6 @@ */ uint8_t CheckCrc2b(uint16_t seed, uint8_t crc_in); - /** Get Article Code - * - * @param --none-- - * @see ASCII Article Code as acode[33] (returns all 0) - * - * @return enum SPSerror - */ - uint8_t GetArticleCode(); - /** Get Serial Number * * @param --none-- @@ -188,48 +255,6 @@ */ uint8_t SoftReset(); -private: - char i2cbuff[60]; - - uint16_t clean_interval_m; /**< High order 16 bit word of Auto Clean Interval */ - uint16_t clean_interval_l; /**< High order 16 bit word of Auto Clean Interval */ - - uint16_t mass_1p0_m; /**< High order 16 bit word of Mass Conc of PM1.0 */ - uint16_t mass_1p0_l; /**< Low order 16 bit word of Mass Conc of PM1.0 */ - uint16_t mass_2p5_m; /**< High order 16 bit word of Mass Conc of PM2.5 */ - uint16_t mass_2p5_l; /**< Low order 16 bit word of Mass Conc of PM2.5 */ - uint16_t mass_4p0_m; /**< High order 16 bit word of Mass Conc of PM4.0 */ - uint16_t mass_4p0_l; /**< Low order 16 bit word of Mass Conc of PM4.0 */ - uint16_t mass_10p0_m; /**< High order 16 bit word of Mass Conc of PM10 */ - uint16_t mass_10p0_l; /**< Low order 16 bit word of Mass Conc of PM10 */ - - uint16_t num_0p5_m; /**< High order 16 bit word of Number Conc of PM0.5 */ - uint16_t num_0p5_l; /**< Low order 16 bit word of Number Conc of PM0.5 */ - uint16_t num_1p0_m; /**< High order 16 bit word of Number Conc of PM1.0 */ - uint16_t num_1p0_l; /**< Low order 16 bit word of Number Conc of PM1.0 */ - uint16_t num_2p5_m; /**< High order 16 bit word of Number Conc of PM2.5 */ - uint16_t num_2p5_l; /**< Low order 16 bit word of Number Conc of PM2.5 */ - uint16_t num_4p0_m; /**< High order 16 bit word of Number Conc of PM4.0 */ - uint16_t num_4p0_l; /**< Low order 16 bit word of Number Conc of PM4.0 */ - uint16_t num_10p0_m; /**< High order 16 bit word of Number Conc of PM10 */ - uint16_t num_10p0_l; /**< Low order 16 bit word of Number Conc of PM10 */ - - uint16_t typ_pm_size_m; /**< High order 16 bit word of Typical Particle Size */ - uint16_t typ_pm_size_l; /**< Low order 16 bit word of Typical Particle Size */ - - uint32_t mass_1p0_i; /**< 32 bit int of Mass Conc of PM1.0 */ - uint32_t mass_2p5_i; /**< 32 bit int of Mass Conc of PM2.5 */ - uint32_t mass_4p0_i; /**< 32 bit int of Mass Conc of PM4.0 */ - uint32_t mass_10p0_i; /**< 32 bit int of Mass Conc of PM10 */ - - uint32_t num_0p5_i; /**< 32 bit int of Number Conc of PM0.5 */ - uint32_t num_1p0_i; /**< 32 bit int of Number Conc of PM1.0 */ - uint32_t num_2p5_i; /**< 32 bit int of Number Conc of PM2.5 */ - uint32_t num_4p0_i; /**< 32 bit int of Number Conc of PM4.0 */ - uint32_t num_10p0_i; /**< 32 bit int of Number Conc of PM10 */ - - uint32_t typ_pm_size_i; /**< 32 bit int of Typical Particle Size */ - protected: I2C _i2c;