LIS2MDL magnetometer modified library
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Diff: LIS2MDLSensor.cpp
- Revision:
- 3:a16e6dd1ee7f
- Parent:
- 2:0d9d7f8f871b
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