Demo application for using the AT&T IoT Starter Kit Powered by AWS.

Dependencies:   SDFileSystem

Fork of ATT_AWS_IoT_demo by Anthony Phillips

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HTS221.h Source File

HTS221.h

00001 
00002 #ifndef HTS221_H_
00003 #define HTS221_H_
00004 
00005 class HTS221 {
00006 public:
00007     HTS221(void);
00008     int begin(void);
00009     int activate(void);
00010     int deactivate(void);
00011 
00012     int bduActivate(void);
00013     int bduDeactivate(void);
00014 
00015     int readHumidity(void);
00016     double readTemperature(void);
00017 private:
00018     int storeCalibration(void);
00019     unsigned char _h0_rH, _h1_rH;
00020     unsigned int  _T0_degC, _T1_degC;
00021     unsigned int  _H0_T0, _H1_T0;
00022     unsigned int  _T0_OUT, _T1_OUT;
00023     double _temperature;
00024     int _humidity;
00025     unsigned char _address;
00026 
00027     unsigned char readRegister(unsigned char slaveAddress, unsigned char regToRead);
00028     int writeRegister(unsigned char slaveAddress, unsigned char regToWrite, unsigned char dataToWrite);
00029 };
00030 
00031 #define HTS221_ADDRESS     0xBF
00032 
00033 //Define a few of the registers that we will be accessing on the HTS221
00034 #define WHO_AM_I           0x0F
00035 #define WHO_AM_I_RETURN    0xBC //This read-only register contains the device identifier, set to BCh
00036 
00037 #define AVERAGE_REG        0x10 // To configure humidity/temperature average.
00038 #define AVERAGE_DEFAULT    0x1B
00039 
00040 /*
00041  * [7] PD: power down control
00042  * (0: power-down mode; 1: active mode)
00043  *
00044  * [6:3] Reserved
00045  *
00046  * [2] BDU: block data update
00047  * (0: continuous update; 1: output registers not updated until MSB and LSB reading)
00048 The BDU bit is used to inhibit the output register update between the reading of the upper
00049 and lower register parts. In default mode (BDU = ?0?), the lower and upper register parts are
00050 updated continuously. If it is not certain whether the read will be faster than output data rate,
00051 it is recommended to set the BDU bit to ?1?. In this way, after the reading of the lower (upper)
00052 register part, the content of that output register is not updated until the upper (lower) part is
00053 read also.
00054  *
00055  * [1:0] ODR1, ODR0: output data rate selection (see table 17)
00056  */
00057 #define CTRL_REG1          0x20
00058 #define POWER_UP           0x80
00059 #define BDU_SET            0x4
00060 #define ODR0_SET           0x1   // setting sensor reading period 1Hz
00061 
00062 #define CTRL_REG2          0x21
00063 #define CTRL_REG3          0x22
00064 #define REG_DEFAULT        0x00
00065 
00066 #define STATUS_REG         0x27
00067 #define TEMPERATURE_READY  0x1
00068 #define HUMIDITY_READY     0x2
00069 
00070 #define HUMIDITY_L_REG     0x28
00071 #define HUMIDITY_H_REG     0x29
00072 #define TEMP_L_REG         0x2A
00073 #define TEMP_H_REG         0x2B
00074 /*
00075  * calibration registry should be read for temperature and humidity calculation.
00076  * Before the first calculation of temperature and humidity,
00077  * the master reads out the calibration coefficients.
00078  * will do at init phase
00079  */
00080 #define CALIB_START        0x30
00081 #define CALIB_END          0x3F
00082 /*
00083 #define CALIB_T0_DEGC_X8   0x32
00084 #define CALIB_T1_DEGC_X8   0x33
00085 #define CALIB_T1_T0_MSB    0x35
00086 #define CALIB_T0_OUT_L     0x3C
00087 #define CALIB_T0_OUT_H     0x3D
00088 #define CALIB_T1_OUT_L     0x3E
00089 #define CALIB_T1_OUT_H     0x3F
00090  */
00091  
00092 #endif
00093