LIS2MDL magnetometer modified library
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Revision 3:a16e6dd1ee7f, committed 2019-09-05
- Comitter:
- martlefebvre94
- Date:
- Thu Sep 05 15:41:07 2019 +0000
- Parent:
- 2:0d9d7f8f871b
- Commit message:
- Temperature compensation and offset cancellation added to the set/get methods
Changed in this revision
LIS2MDLSensor.cpp | Show annotated file Show diff for this revision Revisions of this file |
LIS2MDLSensor.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 0d9d7f8f871b -r a16e6dd1ee7f LIS2MDLSensor.cpp --- a/LIS2MDLSensor.cpp Thu Sep 05 13:42:18 2019 +0000 +++ b/LIS2MDLSensor.cpp Thu Sep 05 15:41:07 2019 +0000 @@ -333,7 +333,7 @@ int ret = 0; lis2mdl_lpf_t current_lpf; - /* Get current power mode. */ + /* Get current bandwidth. */ if (lis2mdl_low_pass_bandwidth_get(&_reg_ctx, ¤t_lpf) != 0) { return 1; } @@ -375,6 +375,88 @@ } /** + * @brief Get the LIS2MDL magnetometer sensor temperature compensation + * @param comp_temp_en pointer where the temperature compensation is written + * @retval 0 in case of success, an error code otherwise + */ +int LIS2MDLSensor::get_m_comp_temp_en(uint8_t *comp_temp_en) +{ + if (lis2mdl_offset_temp_comp_get(&_reg_ctx, comp_temp_en) != 0) { + return 1; + } + return 0; +} + +/** + * @brief Set the LIS2MDL magnetometer sensor temperature compensation + * @param comp_temp_en the temperature compensation value to be set + * @retval 0 in case of success, an error code otherwise + */ +int LIS2MDLSensor::set_m_comp_temp_en(uint8_t comp_temp_en) +{ + if (lis2mdl_offset_temp_comp_set(&_reg_ctx, comp_temp_en) != 0) { + return 1; + } + return 0; +} + +/** + * @brief Get the LIS2MDL magnetometer sensor offset cancellation + * @param off_canc pointer where the offset cancellation is written + * @retval 0 in case of success, an error code otherwise + */ +int LIS2MDLSensor::get_m_off_canc(uint8_t *off_canc) +{ + int ret = 0; + lis2mdl_set_rst_t current_off_canc; + + /* Get current offset cancellation. */ + if (lis2mdl_set_rst_mode_get(&_reg_ctx, ¤t_off_canc) != 0) { + return 1; + } + + switch (current_off_canc) { + case LIS2MDL_SET_SENS_ODR_DIV_63: + *off_canc = 0; + break; + + case LIS2MDL_SENS_OFF_CANC_EVERY_ODR: + *off_canc = 1; + break; + + case LIS2MDL_SET_SENS_ONLY_AT_POWER_ON: + *off_canc = 2; + break; + + default: + ret = 1; + break; + } + + return ret; +} + +/** + * @brief Set the LIS2MDL magnetometer sensor offset cancellation + * @param off_canc the offset cancellation value to be set + * @retval 0 in case of success, an error code otherwise + */ +int LIS2MDLSensor::set_m_off_canc(uint8_t off_canc) +{ + lis2mdl_set_rst_t new_off_canc; + + new_off_canc = (off_canc == 0) ? LIS2MDL_SET_SENS_ODR_DIV_63 + : (off_canc == 1) ? LIS2MDL_SENS_OFF_CANC_EVERY_ODR + : LIS2MDL_SET_SENS_ONLY_AT_POWER_ON; + + if (lis2mdl_set_rst_mode_set(&_reg_ctx, new_off_canc) != 0) { + return 1; + } + + return 0; +} + +/** * @brief Get the LIS2MDL magnetometer sensor axes * @param magnetic_field pointer where the values of the axes are written * @retval 0 in case of success, an error code otherwise
diff -r 0d9d7f8f871b -r a16e6dd1ee7f LIS2MDLSensor.h --- a/LIS2MDLSensor.h Thu Sep 05 13:42:18 2019 +0000 +++ b/LIS2MDLSensor.h Thu Sep 05 15:41:07 2019 +0000 @@ -95,6 +95,10 @@ int set_m_lp(uint8_t lp); int get_m_lpf(uint8_t *lpf); int set_m_lpf(uint8_t lpf); + int get_m_comp_temp_en(uint8_t *comp_temp_en); + int set_m_comp_temp_en(uint8_t comp_temp_en); + int get_m_off_canc(uint8_t *off_canc); + int set_m_off_canc(uint8_t off_canc); int read_reg(uint8_t reg, uint8_t *data); int write_reg(uint8_t reg, uint8_t data); int set_m_self_test(uint8_t status);