Jurica Resetar / Si7006A20

Dependents:   acd52832_Humidity_Temp_Example iBeacon acnsensa acnSENSA

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Si7006A20.h Source File

Si7006A20.h

00001 /*******************************************************************************
00002  * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved.
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included
00012  * in all copies or substantial portions of the Software.
00013  *
00014  *
00015  * The library is modified to suite Si7006A20 Humidity and Temperature Sesor
00016  * Made by Jurica Resetar @ aconno
00017  * More info and contact: aconno.de
00018  *
00019  *******************************************************************************
00020  */
00021 
00022 #ifndef _Si70006A20_H_
00023 #define _Si70006A20_H_
00024 
00025 #include "mbed.h"
00026 #include "aconno_i2c.h"
00027 
00028 /***** Definitions *****/
00029 #define I2C_ADDR    (0x80)  // 1000000x
00030 #define POLYVAL     (0x131)
00031 
00032 
00033 class Si7006{
00034     public:
00035     
00036         /**
00037          * @brief   Measurement resolution.
00038          * @details Controls the resolution of the humidity and temperarure readings.
00039          */
00040         typedef enum {
00041             RH_12b_TEMP_14b = 0x0, ///< 12 bits for RH, 14 bits for Temp
00042             RH_8b_TEMP_12b = 0x1,  ///< 8 bits for RH, 12 bits for Temp
00043             RH_10b_TEMP_13b = 0x2, ///< 10 bits for RH, 13 bits for Temp
00044             RH_11b_TEMP_11b = 0x3, ///< 11 bits for RH, 11 bits for Temp
00045         } resolution_t;
00046             
00047         /**
00048          * Si7006 constructor
00049          *
00050          */
00051          Si7006(I2C *ic2);
00052     
00053         /**
00054          * @brief   Get Electronic ID.
00055          * @details Gets the Electronic ID of the connected device. Verifies the 
00056          *          ID with an 8-bit CRC.
00057          *
00058          * @param   Character buffer to store the id. Needs to be at least 8 bytes.
00059          * @returns 0 if no errors, -1 if error.
00060          */
00061         uint8_t getElectronicId(char *id);
00062     
00063         /**
00064          * @brief   Configure sample resolution.
00065          * @details Sets the number of bits used for humidity and temperature readings.
00066          * @param   resolution Enum for the resolution setting.
00067          * @returns 0 if no errors, -1 if error.
00068          */
00069         int configResolution(Si7006::resolution_t resolution);
00070     
00071         /**
00072          * @brief   Get temperature reading.
00073          * @details Initiates a temperature reading and blocks until reading has
00074          *          been calculated. 
00075          * 
00076          * @note    Will hold the I2C bus until reading is complete. Refer to datasheet
00077          *          for timing specifications.
00078          * 
00079          * @param   tempC Pointer for temperature reading. Unit is degree Celcius.
00080          * @returns 0 if no errors, -1 if error.
00081          */
00082         float getTemperature();
00083     
00084         /**
00085          * @brief   Check temperature reading.
00086          * @details Checks to see if the temperature reading has been completed.
00087                     Returns temperature if reading complete.
00088          * @note    Must call startTemperature() prior to calling this function. 
00089          * @param   tempC Pointer for temperature reading. Unit is degree Celcius.
00090          * @returns 0 if reading taken, -1 if reading pending.
00091          */
00092         float calculateTemperature(char *rawTemp);
00093     
00094         /**
00095          * @brief   Get humidity reading.
00096          * @details Initiates a humidity reading and blocks until reading has
00097          *          been calculated.
00098          *
00099          * @note    Will hold the I2C bus until reading is complete. Refer to datasheet
00100          *          for timing specifications.
00101          * 
00102          * @param   humidx10 Pointer for humidity reading. Unit is 1/10th percent.
00103          * @returns 0 if no errors, -1 if error.
00104          */
00105         float getHumidity();
00106     
00107         /**
00108          * @brief   Get humidity reading.
00109          * @details Initiates a humidity reading and blocks until reading has
00110          *          been calculated.
00111          *
00112          * @note    Will hold the I2C bus until reading is complete. Refer to datasheet
00113          *          for timing specifications.
00114          * 
00115          * @param   humid Pointer for humidity reading. Unit is percent.
00116          * @returns 0 if no errors, -1 if error.
00117          */
00118         float checkHumidity(char *rawHumidity);
00119 
00120         /**
00121          * @brief   Get temperature from humidity reading.
00122          * @details Gets temperature reading from previous humidity reading.
00123          * @note    Must call startHumidity() prior to calling this function. 
00124          * @param   tempC Pointer for temperature reading. Unit is degree Celcius.
00125          * @returns 0 if reading taken, -1 if reading pending.
00126          */
00127         int getPrevTemperature(float* tempC);
00128     
00129         /**
00130          * @brief   Get temperature from humidity reading.
00131          * @details Gets temperature reading from previous humidity reading.
00132          * @note    Must call startHumidity() prior to calling this function. 
00133          * @param   tempCx10 Pointer for temperature reading. Unit is 1/10th degree Celcius.
00134          * @returns 0 if reading taken, -1 if reading pending.
00135          */
00136         int getPrevTemperature(int16_t *tempCx10);
00137     
00138         /**
00139          * @brief   Get firmware revision.
00140          * @details Reads the firmware revision, refer to datasheet for codes.
00141          * @param   rev Pointer to store firmware revision.
00142          * @returns 0 if no errors, -1 if error.
00143          */
00144         int getRev(char *rev);
00145     
00146         /**
00147          * @brief   Control heater.
00148          * @details Enable or disable the heater.
00149          * @param   enable True to enable heater, false to disable.
00150          * @returns 0 if no errors, -1 if error.
00151          */
00152         int heater(bool enable);
00153         
00154     private:
00155     
00156         char crc8(char value, char seed);
00157         aconno_i2c i2c;
00158         bool i2c_owner;
00159 };
00160 
00161 #endif /* _Si7006_H_ */