LPS22HH pressure sensor library
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Revision 2:a8417bcdc2e8, committed 2019-09-17
- Comitter:
- martlefebvre94
- Date:
- Tue Sep 17 08:40:31 2019 +0000
- Parent:
- 1:978cae936ddb
- Commit message:
- Addition of functions for the configuration of the pressure sensor
Changed in this revision
LPS22HHSensor.cpp | Show annotated file Show diff for this revision Revisions of this file |
LPS22HHSensor.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 978cae936ddb -r a8417bcdc2e8 LPS22HHSensor.cpp --- a/LPS22HHSensor.cpp Wed Jul 24 14:19:09 2019 +0000 +++ b/LPS22HHSensor.cpp Tue Sep 17 08:40:31 2019 +0000 @@ -193,7 +193,7 @@ * @param odr the output data rate value * @retval 0 in case of success, an error code otherwise */ -int LPS22HHSensor::get_odr(float *odr) +int LPS22HHSensor::get_odr(float *odr, uint8_t *low_noise_en) { int ret = 0; lps22hh_odr_t odr_low_level; @@ -205,34 +205,67 @@ switch (odr_low_level) { case LPS22HH_POWER_DOWN: *odr = 0.0f; + *low_noise_en = 0; break; case LPS22HH_1_Hz: *odr = 1.0f; + *low_noise_en = 0; break; case LPS22HH_10_Hz: *odr = 10.0f; + *low_noise_en = 0; break; case LPS22HH_25_Hz: *odr = 25.0f; + *low_noise_en = 0; break; case LPS22HH_50_Hz: *odr = 50.0f; + *low_noise_en = 0; break; case LPS22HH_75_Hz: *odr = 75.0f; + *low_noise_en = 0; break; - + + case LPS22HH_1_Hz_LOW_NOISE: + *odr = 1.0f; + *low_noise_en = 1; + break; + + case LPS22HH_10_Hz_LOW_NOISE: + *odr = 10.0f; + *low_noise_en = 1; + break; + + case LPS22HH_25_Hz_LOW_NOISE: + *odr = 25.0f; + *low_noise_en = 1; + break; + + case LPS22HH_50_Hz_LOW_NOISE: + *odr = 50.0f; + *low_noise_en = 1; + break; + + case LPS22HH_75_Hz_LOW_NOISE: + *odr = 75.0f; + *low_noise_en = 1; + break; + case LPS22HH_100_Hz: *odr = 100.0f; + *low_noise_en = 0; break; case LPS22HH_200_Hz: *odr = 200.0f; + *low_noise_en = 0; break; default: @@ -248,33 +281,37 @@ * @param odr the output data rate value to be set * @retval 0 in case of success, an error code otherwise */ -int LPS22HHSensor::set_odr(float odr) +int LPS22HHSensor::set_odr(float odr, uint8_t low_noise_en) { /* Check if the component is _is_enabled */ if (_is_enabled == 1U) { - return set_odr_when_enabled(odr); + return set_odr_when_enabled(odr, low_noise_en); } else { - return set_odr_when_disabled(odr); + return set_odr_when_disabled(odr, low_noise_en); } } - /** * @brief Set output data rate * @param odr the output data rate value to be set * @retval 0 in case of success, an error code otherwise */ -int LPS22HHSensor::set_odr_when_enabled(float odr) +int LPS22HHSensor::set_odr_when_enabled(float odr, uint8_t low_noise_en) { lps22hh_odr_t new_odr; - new_odr = (odr <= 1.0f) ? LPS22HH_1_Hz - : (odr <= 10.0f) ? LPS22HH_10_Hz - : (odr <= 25.0f) ? LPS22HH_25_Hz - : (odr <= 50.0f) ? LPS22HH_50_Hz - : (odr <= 75.0f) ? LPS22HH_75_Hz - : (odr <= 100.0f) ? LPS22HH_100_Hz - : LPS22HH_200_Hz; + new_odr = ((odr <= 1.0f) && !low_noise_en) ? LPS22HH_1_Hz + : ((odr <= 1.0f) && low_noise_en) ? LPS22HH_1_Hz_LOW_NOISE + : ((odr <= 10.0f) && !low_noise_en) ? LPS22HH_10_Hz + : ((odr <= 10.0f) && low_noise_en) ? LPS22HH_10_Hz_LOW_NOISE + : ((odr <= 25.0f) && !low_noise_en) ? LPS22HH_25_Hz + : ((odr <= 25.0f) && low_noise_en) ? LPS22HH_25_Hz_LOW_NOISE + : ((odr <= 50.0f) && !low_noise_en) ? LPS22HH_50_Hz + : ((odr <= 50.0f) && low_noise_en) ? LPS22HH_50_Hz_LOW_NOISE + : ((odr <= 75.0f) && !low_noise_en) ? LPS22HH_75_Hz + : ((odr <= 75.0f) && low_noise_en) ? LPS22HH_75_Hz_LOW_NOISE + : (odr <= 100.0f) ? LPS22HH_100_Hz + : LPS22HH_200_Hz; if (lps22hh_data_rate_set(&_reg_ctx, new_odr) != 0) { return 1; @@ -292,15 +329,76 @@ * @param odr the output data rate value to be set * @retval 0 in case of success, an error code otherwise */ -int LPS22HHSensor::set_odr_when_disabled(float odr) +int LPS22HHSensor::set_odr_when_disabled(float odr, uint8_t low_noise_en) +{ + _last_odr = ((odr <= 1.0f) && !low_noise_en) ? LPS22HH_1_Hz + : ((odr <= 1.0f) && low_noise_en) ? LPS22HH_1_Hz_LOW_NOISE + : ((odr <= 10.0f) && !low_noise_en) ? LPS22HH_10_Hz + : ((odr <= 10.0f) && low_noise_en) ? LPS22HH_10_Hz_LOW_NOISE + : ((odr <= 25.0f) && !low_noise_en) ? LPS22HH_25_Hz + : ((odr <= 25.0f) && low_noise_en) ? LPS22HH_25_Hz_LOW_NOISE + : ((odr <= 50.0f) && !low_noise_en) ? LPS22HH_50_Hz + : ((odr <= 50.0f) && low_noise_en) ? LPS22HH_50_Hz_LOW_NOISE + : ((odr <= 75.0f) && !low_noise_en) ? LPS22HH_75_Hz + : ((odr <= 75.0f) && low_noise_en) ? LPS22HH_75_Hz_LOW_NOISE + : (odr <= 100.0f) ? LPS22HH_100_Hz + : LPS22HH_200_Hz; + + return 0; +} + + +/** + * @brief Get low-pass configuration + * @param lpfp_cfg the low-pass configuration value + * @retval 0 in case of success, an error code otherwise + */ +int LPS22HHSensor::get_lpfp_cfg(uint8_t *lpfp_cfg) { - _last_odr = (odr <= 1.0f) ? LPS22HH_1_Hz - : (odr <= 10.0f) ? LPS22HH_10_Hz - : (odr <= 25.0f) ? LPS22HH_25_Hz - : (odr <= 50.0f) ? LPS22HH_50_Hz - : (odr <= 75.0f) ? LPS22HH_75_Hz - : (odr <= 100.0f) ? LPS22HH_100_Hz - : LPS22HH_200_Hz; + int ret = 0; + lps22hh_lpfp_cfg_t lpfp_cfg_low_level; + + if (lps22hh_lp_bandwidth_get(&_reg_ctx, &lpfp_cfg_low_level) != 0) { + return 1; + } + + switch (lpfp_cfg_low_level) { + case LPS22HH_LPF_ODR_DIV_2: + *lpfp_cfg = 0; + break; + + case LPS22HH_LPF_ODR_DIV_9: + *lpfp_cfg = 2; + break; + + case LPS22HH_LPF_ODR_DIV_20: + *lpfp_cfg = 3; + break; + + default: + ret = 1; + break; + } + + return ret; +} + +/** + * @brief Set the LPS22HH pressure sensor low-pass configuration + * @param lpfp_cfg the low-pass configuration value to be set + * @retval 0 in case of success, an error code otherwise + */ +int LPS22HHSensor::set_lpfp_cfg(uint8_t lpfp_cfg) +{ + lps22hh_lpfp_cfg_t new_lpfp_cfg; + + new_lpfp_cfg = (lpfp_cfg == 2) ? LPS22HH_LPF_ODR_DIV_9 + : (lpfp_cfg == 3) ? LPS22HH_LPF_ODR_DIV_20 + : LPS22HH_LPF_ODR_DIV_2; + + if (lps22hh_lp_bandwidth_set(&_reg_ctx, new_lpfp_cfg) != 0) { + return 1; + } return 0; }
diff -r 978cae936ddb -r a8417bcdc2e8 LPS22HHSensor.h --- a/LPS22HHSensor.h Wed Jul 24 14:19:09 2019 +0000 +++ b/LPS22HHSensor.h Tue Sep 17 08:40:31 2019 +0000 @@ -68,8 +68,10 @@ virtual int get_temperature(float *value); int enable(void); int disable(void); - int get_odr(float *odr); - int set_odr(float odr); + int get_odr(float *odr, uint8_t *low_noise_en); + int set_odr(float odr, uint8_t low_noise_en); + int get_lpfp_cfg(uint8_t *lpfp_cfg); + int set_lpfp_cfg(uint8_t lpfp_cfg); int read_reg(uint8_t reg, uint8_t *data); int write_reg(uint8_t reg, uint8_t data); int get_press_drdy_status(uint8_t *status); @@ -176,8 +178,8 @@ } private: - int set_odr_when_enabled(float odr); - int set_odr_when_disabled(float odr); + int set_odr_when_enabled(float odr, uint8_t low_noise_en); + int set_odr_when_disabled(float odr, uint8_t low_noise_en); /* Helper classes. */ DevI2C *_dev_i2c;