Thundersoft
/
HTU21D_for_TT_Mxx
Creating a project for TT_Mxx
HTU21D/HTU21D.h@2:2186c624272f, 2019-04-26 (annotated)
- Committer:
- ThunderSoft
- Date:
- Fri Apr 26 09:48:41 2019 +0000
- Revision:
- 2:2186c624272f
- Parent:
- 0:1159c687a20f
"Update the mbed-os code to support TT_M4G9"
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ThunderSoft | 0:1159c687a20f | 1 | #ifndef HTU21D_H |
ThunderSoft | 0:1159c687a20f | 2 | #define HTU21D_H |
ThunderSoft | 0:1159c687a20f | 3 | |
ThunderSoft | 0:1159c687a20f | 4 | /** |
ThunderSoft | 0:1159c687a20f | 5 | * Includes |
ThunderSoft | 0:1159c687a20f | 6 | */ |
ThunderSoft | 0:1159c687a20f | 7 | #include "mbed.h" |
ThunderSoft | 0:1159c687a20f | 8 | |
ThunderSoft | 0:1159c687a20f | 9 | /** |
ThunderSoft | 0:1159c687a20f | 10 | * Defines |
ThunderSoft | 0:1159c687a20f | 11 | */ |
ThunderSoft | 0:1159c687a20f | 12 | // Acquired from Datasheet. |
ThunderSoft | 0:1159c687a20f | 13 | |
ThunderSoft | 0:1159c687a20f | 14 | #define HTU21D_I2C_ADDRESS 0x40 |
ThunderSoft | 0:1159c687a20f | 15 | #define TRIGGER_TEMP_MEASURE 0xE3 |
ThunderSoft | 0:1159c687a20f | 16 | #define TRIGGER_HUMD_MEASURE 0xE5 |
ThunderSoft | 0:1159c687a20f | 17 | |
ThunderSoft | 0:1159c687a20f | 18 | |
ThunderSoft | 0:1159c687a20f | 19 | //Commands. |
ThunderSoft | 0:1159c687a20f | 20 | #define HTU21D_EEPROM_WRITE 0x80 |
ThunderSoft | 0:1159c687a20f | 21 | #define HTU21D_EEPROM_READ 0x81 |
ThunderSoft | 0:1159c687a20f | 22 | |
ThunderSoft | 0:1159c687a20f | 23 | |
ThunderSoft | 0:1159c687a20f | 24 | /** |
ThunderSoft | 0:1159c687a20f | 25 | * Honeywell HTU21D digital humidity and temperature sensor. |
ThunderSoft | 0:1159c687a20f | 26 | */ |
ThunderSoft | 0:1159c687a20f | 27 | class HTU21D { |
ThunderSoft | 0:1159c687a20f | 28 | |
ThunderSoft | 0:1159c687a20f | 29 | public: |
ThunderSoft | 0:1159c687a20f | 30 | |
ThunderSoft | 0:1159c687a20f | 31 | HTU21D(); |
ThunderSoft | 0:1159c687a20f | 32 | /** |
ThunderSoft | 0:1159c687a20f | 33 | * Constructor. |
ThunderSoft | 0:1159c687a20f | 34 | * |
ThunderSoft | 0:1159c687a20f | 35 | * @param sda mbed pin to use for SDA line of I2C interface. |
ThunderSoft | 0:1159c687a20f | 36 | * @param scl mbed pin to use for SCL line of I2C interface. |
ThunderSoft | 0:1159c687a20f | 37 | */ |
ThunderSoft | 0:1159c687a20f | 38 | HTU21D(PinName sda, PinName scl); |
ThunderSoft | 0:1159c687a20f | 39 | |
ThunderSoft | 0:1159c687a20f | 40 | |
ThunderSoft | 0:1159c687a20f | 41 | /** |
ThunderSoft | 0:1159c687a20f | 42 | * @brief Samples the temperature, input void, outputs an int in celcius. |
ThunderSoft | 0:1159c687a20f | 43 | * @return [description] |
ThunderSoft | 0:1159c687a20f | 44 | */ |
ThunderSoft | 0:1159c687a20f | 45 | int sample_ctemp(void); |
ThunderSoft | 0:1159c687a20f | 46 | |
ThunderSoft | 0:1159c687a20f | 47 | /** |
ThunderSoft | 0:1159c687a20f | 48 | * @brief Samples the temperature, input void, outputs an int in fahrenheit. |
ThunderSoft | 0:1159c687a20f | 49 | * @return [description] |
ThunderSoft | 0:1159c687a20f | 50 | */ |
ThunderSoft | 0:1159c687a20f | 51 | int sample_ftemp(void); |
ThunderSoft | 0:1159c687a20f | 52 | |
ThunderSoft | 0:1159c687a20f | 53 | /** |
ThunderSoft | 0:1159c687a20f | 54 | * @brief Samples the temperature, input void, outputs an int in kelvin. |
ThunderSoft | 0:1159c687a20f | 55 | * @return [description] |
ThunderSoft | 0:1159c687a20f | 56 | */ |
ThunderSoft | 0:1159c687a20f | 57 | int sample_ktemp(void); |
ThunderSoft | 0:1159c687a20f | 58 | |
ThunderSoft | 0:1159c687a20f | 59 | /** |
ThunderSoft | 0:1159c687a20f | 60 | * @brief Samples the humidity, input void, outputs and int. |
ThunderSoft | 0:1159c687a20f | 61 | * @return [description] |
ThunderSoft | 0:1159c687a20f | 62 | */ |
ThunderSoft | 0:1159c687a20f | 63 | int sample_humid(void); |
ThunderSoft | 0:1159c687a20f | 64 | |
ThunderSoft | 0:1159c687a20f | 65 | |
ThunderSoft | 0:1159c687a20f | 66 | |
ThunderSoft | 0:1159c687a20f | 67 | private: |
ThunderSoft | 0:1159c687a20f | 68 | |
ThunderSoft | 0:1159c687a20f | 69 | I2C* i2c_; |
ThunderSoft | 0:1159c687a20f | 70 | |
ThunderSoft | 0:1159c687a20f | 71 | /** |
ThunderSoft | 0:1159c687a20f | 72 | * Write to EEPROM or RAM on the device. |
ThunderSoft | 0:1159c687a20f | 73 | * |
ThunderSoft | 0:1159c687a20f | 74 | * @param EepromOrRam 0x80 -> Writing to EEPROM |
ThunderSoft | 0:1159c687a20f | 75 | * @param address Address to write to. |
ThunderSoft | 0:1159c687a20f | 76 | * @param data Data to write. |
ThunderSoft | 0:1159c687a20f | 77 | */ |
ThunderSoft | 0:1159c687a20f | 78 | void write(int EepromOrRam, int address, int data); |
ThunderSoft | 0:1159c687a20f | 79 | |
ThunderSoft | 0:1159c687a20f | 80 | /** |
ThunderSoft | 0:1159c687a20f | 81 | * Read EEPROM or RAM on the device. |
ThunderSoft | 0:1159c687a20f | 82 | * |
ThunderSoft | 0:1159c687a20f | 83 | * @param EepromOrRam 0x81 -> Reading from EEPROM |
ThunderSoft | 0:1159c687a20f | 84 | * @param address Address to read from. |
ThunderSoft | 0:1159c687a20f | 85 | * @return The contents of the memory address. |
ThunderSoft | 0:1159c687a20f | 86 | */ |
ThunderSoft | 0:1159c687a20f | 87 | int read(int EepromOrRam, int address); |
ThunderSoft | 0:1159c687a20f | 88 | |
ThunderSoft | 0:1159c687a20f | 89 | }; |
ThunderSoft | 0:1159c687a20f | 90 | |
ThunderSoft | 0:1159c687a20f | 91 | |
ThunderSoft | 0:1159c687a20f | 92 | #endif |