Library for Silicon Labs Si7006 digital temperature and humidity chip.
Dependents: acd52832_Humidity_Temp_Example iBeacon acnsensa acnSENSA
Diff: Si7006A20.h
- Revision:
- 1:155934570c14
- Parent:
- 0:cc2c5d49fe63
- Child:
- 2:7c3c7db34528
--- a/Si7006A20.h Mon Jul 10 17:14:44 2017 +0000 +++ b/Si7006A20.h Mon Sep 25 10:21:52 2017 +0000 @@ -23,40 +23,13 @@ #define _Si70006A20_H_ #include "mbed.h" +#include "aconno_i2c.h" -/** - * Silicon Labs Si7006 Humidity and Temperature Sensor - * - * @code - * #include <stdio.h> - * #include "mbed.h" - * #include "Si7006A20.h" - * - * I2C i2c(I2C_SDA, I2C_SCL); - * Si7006 si(&i2c); - * - * int main() - * { - * while(1) { - * - * float humid; - * if(si.getHumidity(&humid) != 0) { - * printf("Error getting humidity\n"); - * humid = -1; - * } - * - * float temp; - * if(si.getTemperature(&temp) != 0) { - * printf("Error getting temperature"); - * temp = -1; - * } - * printf("Humidity = %f%% Temperature = %fC\n", humid, temp); - * - * wait(1); - * } - * } - * @endcode - */ +/***** Definitions *****/ +#define I2C_ADDR (0x80) // 1000000x +#define POLYVAL (0x131) + + class Si7006{ public: @@ -80,25 +53,6 @@ Si7006(PinName sda, PinName scl); /** - * Si7006 constructor. - * - * @param i2c I2C object to use - */ - Si7006(I2C *i2c); - - /** - * Si7006 destructor. - */ - ~Si7006(); - - /** - * @brief Reset. - * @details Sends the rest command. - * @returns 0 if no errors, -1 if error. - */ - int reset(void); - - /** * @brief Get Electronic ID. * @details Gets the Electronic ID of the connected device. Verifies the * ID with an 8-bit CRC. @@ -106,7 +60,7 @@ * @param Character buffer to store the id. Needs to be at least 8 bytes. * @returns 0 if no errors, -1 if error. */ - int getElectronicId(char *id); + uint8_t getElectronicId(char *id); /** * @brief Configure sample resolution. @@ -124,40 +78,10 @@ * @note Will hold the I2C bus until reading is complete. Refer to datasheet * for timing specifications. * - * @param tempCx10 Pointer for temperature reading. Unit is 1/10th degree Celcius. - * @returns 0 if no errors, -1 if error. - */ - int getTemperature(int16_t *tempCx10); - - /** - * @brief Get temperature reading. - * @details Initiates a temperature reading and blocks until reading has - * been calculated. - * - * @note Will hold the I2C bus until reading is complete. Refer to datasheet - * for timing specifications. - * * @param tempC Pointer for temperature reading. Unit is degree Celcius. * @returns 0 if no errors, -1 if error. */ - int getTemperature(float *tempC); - - /** - * @brief Start temperature reading. - * @details Initiates a temperature reading. Will not hold the bus or block. - * @returns 0 if no errors, -1 if error. - */ - int startTemperature(void); - - /** - * @brief Check temperature reading. - * @details Checks to see if the temperature reading has been completed. - Returns temperature if reading complete. - * @note Must call startTemperature() prior to calling this function. - * @param tempCx10 Pointer for temperature reading. Unit is 1/10th degree Celcius. - * @returns 0 if reading taken, -1 if reading pending. - */ - int checkTemperature(int16_t *tempCx10); + float getTemperature(); /** * @brief Check temperature reading. @@ -167,7 +91,7 @@ * @param tempC Pointer for temperature reading. Unit is degree Celcius. * @returns 0 if reading taken, -1 if reading pending. */ - int checkTemperature(float *tempC); + float calculateTemperature(char *rawTemp); /** * @brief Get humidity reading. @@ -180,7 +104,7 @@ * @param humidx10 Pointer for humidity reading. Unit is 1/10th percent. * @returns 0 if no errors, -1 if error. */ - int getHumidity(int16_t *humidx10); + float getHumidity(); /** * @brief Get humidity reading. @@ -193,37 +117,8 @@ * @param humid Pointer for humidity reading. Unit is percent. * @returns 0 if no errors, -1 if error. */ - int getHumidity(float *humid); - - /** - * @brief Start humidity reading. - * @details Initiates a humidity reading. Will not hold the bus or block. - * @returns 0 if no errors, -1 if error. - */ - int startHumidity(void); - - /** - * @brief Check humidity reading. - * @details Checks to see if the humidity reading has been completed. - Returns humidity if reading complete. - - * @note Must call startHumidity() prior to calling this function. - * @param humidCx10 Pointer for humidity reading. Unit is 1/10th percent. - * @returns 0 if reading taken, -1 if reading pending. - */ - int checkHumidity(int16_t *humidx10); - - /** - * @brief Check humidity reading. - * @details Checks to see if the humidity reading has been completed. - Returns humidity if reading complete. - - * @note Must call startHumidity() prior to calling this function. - * @param humid Pointer for humidity reading. Unit is percent. - * @returns 0 if reading taken, -1 if reading pending. - */ - int checkHumidity(float *humid); - + float checkHumidity(char *rawHumidity); + /** * @brief Get temperature from humidity reading. * @details Gets temperature reading from previous humidity reading. @@ -257,11 +152,11 @@ * @returns 0 if no errors, -1 if error. */ int heater(bool enable); - + private: char crc8(char value, char seed); - I2C *i2c_; + aconno_i2c i2c; bool i2c_owner; };