Beta
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Fork of X_NUCLEO_IKS01A2 by
Components/HTS221Sensor/HTS221Sensor.h@11:8f4e5789b6b3, 2017-11-02 (annotated)
- Committer:
- Qksalo
- Date:
- Thu Nov 02 10:58:12 2017 +0000
- Revision:
- 11:8f4e5789b6b3
- Parent:
- 9:038121268b07
Beta
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nikapov | 0:cad5dab2b21d | 1 | /** |
nikapov | 0:cad5dab2b21d | 2 | ****************************************************************************** |
nikapov | 0:cad5dab2b21d | 3 | * @file HTS221Sensor.h |
cparata | 1:bd2a01e81e6f | 4 | * @author CLab |
nikapov | 0:cad5dab2b21d | 5 | * @version V1.0.0 |
nikapov | 0:cad5dab2b21d | 6 | * @date 5 August 2016 |
nikapov | 0:cad5dab2b21d | 7 | * @brief Abstract class of an HTS221 Humidity and Temperature sensor. |
nikapov | 0:cad5dab2b21d | 8 | ****************************************************************************** |
nikapov | 0:cad5dab2b21d | 9 | * @attention |
nikapov | 0:cad5dab2b21d | 10 | * |
nikapov | 0:cad5dab2b21d | 11 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
nikapov | 0:cad5dab2b21d | 12 | * |
nikapov | 0:cad5dab2b21d | 13 | * Redistribution and use in source and binary forms, with or without modification, |
nikapov | 0:cad5dab2b21d | 14 | * are permitted provided that the following conditions are met: |
nikapov | 0:cad5dab2b21d | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
nikapov | 0:cad5dab2b21d | 16 | * this list of conditions and the following disclaimer. |
nikapov | 0:cad5dab2b21d | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
nikapov | 0:cad5dab2b21d | 18 | * this list of conditions and the following disclaimer in the documentation |
nikapov | 0:cad5dab2b21d | 19 | * and/or other materials provided with the distribution. |
nikapov | 0:cad5dab2b21d | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
nikapov | 0:cad5dab2b21d | 21 | * may be used to endorse or promote products derived from this software |
nikapov | 0:cad5dab2b21d | 22 | * without specific prior written permission. |
nikapov | 0:cad5dab2b21d | 23 | * |
nikapov | 0:cad5dab2b21d | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
nikapov | 0:cad5dab2b21d | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
nikapov | 0:cad5dab2b21d | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
nikapov | 0:cad5dab2b21d | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
nikapov | 0:cad5dab2b21d | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
nikapov | 0:cad5dab2b21d | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
nikapov | 0:cad5dab2b21d | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
nikapov | 0:cad5dab2b21d | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
nikapov | 0:cad5dab2b21d | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
nikapov | 0:cad5dab2b21d | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
nikapov | 0:cad5dab2b21d | 34 | * |
nikapov | 0:cad5dab2b21d | 35 | ****************************************************************************** |
nikapov | 0:cad5dab2b21d | 36 | */ |
nikapov | 0:cad5dab2b21d | 37 | |
nikapov | 0:cad5dab2b21d | 38 | |
nikapov | 0:cad5dab2b21d | 39 | /* Prevent recursive inclusion -----------------------------------------------*/ |
nikapov | 0:cad5dab2b21d | 40 | |
nikapov | 0:cad5dab2b21d | 41 | #ifndef __HTS221Sensor_H__ |
nikapov | 0:cad5dab2b21d | 42 | #define __HTS221Sensor_H__ |
nikapov | 0:cad5dab2b21d | 43 | |
nikapov | 0:cad5dab2b21d | 44 | |
nikapov | 0:cad5dab2b21d | 45 | /* Includes ------------------------------------------------------------------*/ |
nikapov | 0:cad5dab2b21d | 46 | |
nikapov | 0:cad5dab2b21d | 47 | #include "DevI2C.h" |
davide.aliprandi@st.com | 6:671fd10a51b7 | 48 | #include "HTS221_driver.h" |
nikapov | 0:cad5dab2b21d | 49 | #include "HumiditySensor.h" |
nikapov | 0:cad5dab2b21d | 50 | #include "TempSensor.h" |
nikapov | 0:cad5dab2b21d | 51 | |
nikapov | 0:cad5dab2b21d | 52 | |
nikapov | 0:cad5dab2b21d | 53 | /* Class Declaration ---------------------------------------------------------*/ |
nikapov | 0:cad5dab2b21d | 54 | |
nikapov | 0:cad5dab2b21d | 55 | /** |
nikapov | 0:cad5dab2b21d | 56 | * Abstract class of an HTS221 Humidity and Temperature sensor. |
nikapov | 0:cad5dab2b21d | 57 | */ |
nikapov | 0:cad5dab2b21d | 58 | class HTS221Sensor : public HumiditySensor, public TempSensor |
nikapov | 0:cad5dab2b21d | 59 | { |
nikapov | 0:cad5dab2b21d | 60 | public: |
nikapov | 0:cad5dab2b21d | 61 | |
nikapov | 0:cad5dab2b21d | 62 | HTS221Sensor(DevI2C &i2c); |
nikapov | 0:cad5dab2b21d | 63 | HTS221Sensor(DevI2C &i2c, uint8_t address); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 64 | virtual int init(void *init); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 65 | virtual int read_id(uint8_t *id); |
Davidroid | 9:038121268b07 | 66 | virtual int get_humidity(float *pfData); |
Davidroid | 9:038121268b07 | 67 | virtual int get_temperature(float *pfData); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 68 | int enable(void); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 69 | int disable(void); |
Davidroid | 9:038121268b07 | 70 | int reset(void); |
Davidroid | 9:038121268b07 | 71 | int get_odr(float *odr); |
Davidroid | 9:038121268b07 | 72 | int set_odr(float odr); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 73 | int read_reg(uint8_t reg, uint8_t *data); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 74 | int write_reg(uint8_t reg, uint8_t data); |
nikapov | 0:cad5dab2b21d | 75 | /** |
nikapov | 0:cad5dab2b21d | 76 | * @brief Utility function to read data. |
nikapov | 0:cad5dab2b21d | 77 | * @param pBuffer: pointer to data to be read. |
nikapov | 0:cad5dab2b21d | 78 | * @param RegisterAddr: specifies internal address register to be read. |
nikapov | 0:cad5dab2b21d | 79 | * @param NumByteToRead: number of bytes to be read. |
nikapov | 0:cad5dab2b21d | 80 | * @retval 0 if ok, an error code otherwise. |
nikapov | 0:cad5dab2b21d | 81 | */ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 82 | uint8_t io_read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead) |
nikapov | 0:cad5dab2b21d | 83 | { |
Davidroid | 9:038121268b07 | 84 | return (uint8_t) _dev_i2c.i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead); |
nikapov | 0:cad5dab2b21d | 85 | } |
nikapov | 0:cad5dab2b21d | 86 | |
nikapov | 0:cad5dab2b21d | 87 | /** |
nikapov | 0:cad5dab2b21d | 88 | * @brief Utility function to write data. |
nikapov | 0:cad5dab2b21d | 89 | * @param pBuffer: pointer to data to be written. |
nikapov | 0:cad5dab2b21d | 90 | * @param RegisterAddr: specifies internal address register to be written. |
nikapov | 0:cad5dab2b21d | 91 | * @param NumByteToWrite: number of bytes to write. |
nikapov | 0:cad5dab2b21d | 92 | * @retval 0 if ok, an error code otherwise. |
nikapov | 0:cad5dab2b21d | 93 | */ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 94 | uint8_t io_write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite) |
nikapov | 0:cad5dab2b21d | 95 | { |
Davidroid | 9:038121268b07 | 96 | return (uint8_t) _dev_i2c.i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite); |
nikapov | 0:cad5dab2b21d | 97 | } |
nikapov | 0:cad5dab2b21d | 98 | |
nikapov | 0:cad5dab2b21d | 99 | private: |
nikapov | 0:cad5dab2b21d | 100 | |
nikapov | 0:cad5dab2b21d | 101 | /* Helper classes. */ |
Davidroid | 9:038121268b07 | 102 | DevI2C &_dev_i2c; |
nikapov | 0:cad5dab2b21d | 103 | |
nikapov | 0:cad5dab2b21d | 104 | /* Configuration */ |
Davidroid | 9:038121268b07 | 105 | uint8_t _address; |
nikapov | 0:cad5dab2b21d | 106 | |
nikapov | 0:cad5dab2b21d | 107 | }; |
nikapov | 0:cad5dab2b21d | 108 | |
nikapov | 0:cad5dab2b21d | 109 | #ifdef __cplusplus |
nikapov | 0:cad5dab2b21d | 110 | extern "C" { |
nikapov | 0:cad5dab2b21d | 111 | #endif |
davide.aliprandi@st.com | 6:671fd10a51b7 | 112 | uint8_t HTS221_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 113 | uint8_t HTS221_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ); |
nikapov | 0:cad5dab2b21d | 114 | #ifdef __cplusplus |
nikapov | 0:cad5dab2b21d | 115 | } |
nikapov | 0:cad5dab2b21d | 116 | #endif |
nikapov | 0:cad5dab2b21d | 117 | |
nikapov | 0:cad5dab2b21d | 118 | #endif |