Beta
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Fork of X_NUCLEO_IKS01A2 by
Components/LPS22HBSensor/LPS22HBSensor.h@0:cad5dab2b21d, 2016-11-28 (annotated)
- Committer:
- nikapov
- Date:
- Mon Nov 28 13:16:22 2016 +0000
- Revision:
- 0:cad5dab2b21d
- Child:
- 1:bd2a01e81e6f
X_NUCLEO_IKS01A2 lib created.
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 LPS22HBSensor.h |
nikapov | 0:cad5dab2b21d | 4 | * @author AST |
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 LPS22HB Pressure 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 __LPS22HBSensor_H__ |
nikapov | 0:cad5dab2b21d | 42 | #define __LPS22HBSensor_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" |
nikapov | 0:cad5dab2b21d | 48 | #include "LPS22HB_Driver.h" |
nikapov | 0:cad5dab2b21d | 49 | #include "PressureSensor.h" |
nikapov | 0:cad5dab2b21d | 50 | #include "TempSensor.h" |
nikapov | 0:cad5dab2b21d | 51 | |
nikapov | 0:cad5dab2b21d | 52 | /* Class Declaration ---------------------------------------------------------*/ |
nikapov | 0:cad5dab2b21d | 53 | |
nikapov | 0:cad5dab2b21d | 54 | /** |
nikapov | 0:cad5dab2b21d | 55 | * Abstract class of an LPS22HB Pressure sensor. |
nikapov | 0:cad5dab2b21d | 56 | */ |
nikapov | 0:cad5dab2b21d | 57 | class LPS22HBSensor : public PressureSensor, public TempSensor |
nikapov | 0:cad5dab2b21d | 58 | { |
nikapov | 0:cad5dab2b21d | 59 | public: |
nikapov | 0:cad5dab2b21d | 60 | LPS22HBSensor(DevI2C &i2c); |
nikapov | 0:cad5dab2b21d | 61 | LPS22HBSensor(DevI2C &i2c, uint8_t address); |
nikapov | 0:cad5dab2b21d | 62 | virtual int Init(void *init); |
nikapov | 0:cad5dab2b21d | 63 | virtual int ReadID(uint8_t *id); |
nikapov | 0:cad5dab2b21d | 64 | virtual int GetPressure(float *pfData); |
nikapov | 0:cad5dab2b21d | 65 | virtual int GetTemperature(float *pfData); |
nikapov | 0:cad5dab2b21d | 66 | int Enable(void); |
nikapov | 0:cad5dab2b21d | 67 | int Disable(void); |
nikapov | 0:cad5dab2b21d | 68 | int Reset(void); |
nikapov | 0:cad5dab2b21d | 69 | int Get_ODR(float *odr); |
nikapov | 0:cad5dab2b21d | 70 | int Set_ODR(float odr); |
nikapov | 0:cad5dab2b21d | 71 | int ReadReg(uint8_t reg, uint8_t *data); |
nikapov | 0:cad5dab2b21d | 72 | int WriteReg(uint8_t reg, uint8_t data); |
nikapov | 0:cad5dab2b21d | 73 | |
nikapov | 0:cad5dab2b21d | 74 | /** |
nikapov | 0:cad5dab2b21d | 75 | * @brief Utility function to read data. |
nikapov | 0:cad5dab2b21d | 76 | * @param pBuffer: pointer to data to be read. |
nikapov | 0:cad5dab2b21d | 77 | * @param RegisterAddr: specifies internal address register to be read. |
nikapov | 0:cad5dab2b21d | 78 | * @param NumByteToRead: number of bytes to be read. |
nikapov | 0:cad5dab2b21d | 79 | * @retval 0 if ok, an error code otherwise. |
nikapov | 0:cad5dab2b21d | 80 | */ |
nikapov | 0:cad5dab2b21d | 81 | uint8_t IO_Read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead) |
nikapov | 0:cad5dab2b21d | 82 | { |
nikapov | 0:cad5dab2b21d | 83 | return (uint8_t) dev_i2c.i2c_read(pBuffer, address, RegisterAddr, NumByteToRead); |
nikapov | 0:cad5dab2b21d | 84 | } |
nikapov | 0:cad5dab2b21d | 85 | |
nikapov | 0:cad5dab2b21d | 86 | /** |
nikapov | 0:cad5dab2b21d | 87 | * @brief Utility function to write data. |
nikapov | 0:cad5dab2b21d | 88 | * @param pBuffer: pointer to data to be written. |
nikapov | 0:cad5dab2b21d | 89 | * @param RegisterAddr: specifies internal address register to be written. |
nikapov | 0:cad5dab2b21d | 90 | * @param NumByteToWrite: number of bytes to write. |
nikapov | 0:cad5dab2b21d | 91 | * @retval 0 if ok, an error code otherwise. |
nikapov | 0:cad5dab2b21d | 92 | */ |
nikapov | 0:cad5dab2b21d | 93 | uint8_t IO_Write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite) |
nikapov | 0:cad5dab2b21d | 94 | { |
nikapov | 0:cad5dab2b21d | 95 | return (uint8_t) dev_i2c.i2c_write(pBuffer, address, RegisterAddr, NumByteToWrite); |
nikapov | 0:cad5dab2b21d | 96 | } |
nikapov | 0:cad5dab2b21d | 97 | |
nikapov | 0:cad5dab2b21d | 98 | private: |
nikapov | 0:cad5dab2b21d | 99 | int Set_ODR_When_Enabled(float odr); |
nikapov | 0:cad5dab2b21d | 100 | int Set_ODR_When_Disabled(float odr); |
nikapov | 0:cad5dab2b21d | 101 | |
nikapov | 0:cad5dab2b21d | 102 | /* Helper classes. */ |
nikapov | 0:cad5dab2b21d | 103 | DevI2C &dev_i2c; |
nikapov | 0:cad5dab2b21d | 104 | |
nikapov | 0:cad5dab2b21d | 105 | /* Configuration */ |
nikapov | 0:cad5dab2b21d | 106 | uint8_t address; |
nikapov | 0:cad5dab2b21d | 107 | |
nikapov | 0:cad5dab2b21d | 108 | uint8_t isEnabled; |
nikapov | 0:cad5dab2b21d | 109 | float Last_ODR; |
nikapov | 0:cad5dab2b21d | 110 | }; |
nikapov | 0:cad5dab2b21d | 111 | |
nikapov | 0:cad5dab2b21d | 112 | #ifdef __cplusplus |
nikapov | 0:cad5dab2b21d | 113 | extern "C" { |
nikapov | 0:cad5dab2b21d | 114 | #endif |
nikapov | 0:cad5dab2b21d | 115 | uint8_t LPS22HB_IO_Write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); |
nikapov | 0:cad5dab2b21d | 116 | uint8_t LPS22HB_IO_Read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ); |
nikapov | 0:cad5dab2b21d | 117 | #ifdef __cplusplus |
nikapov | 0:cad5dab2b21d | 118 | } |
nikapov | 0:cad5dab2b21d | 119 | #endif |
nikapov | 0:cad5dab2b21d | 120 | |
nikapov | 0:cad5dab2b21d | 121 | #endif |