LIS2MDL magnetometer modified library

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Revision:
2:0d9d7f8f871b
Parent:
1:8562ae1a0534
Child:
3:a16e6dd1ee7f
--- a/LIS2MDLSensor.cpp	Wed Jul 24 14:18:39 2019 +0000
+++ b/LIS2MDLSensor.cpp	Thu Sep 05 13:42:18 2019 +0000
@@ -273,6 +273,108 @@
 }
 
 /**
+ * @brief  Get the LIS2MDL magnetometer sensor power mode
+ * @param  lp pointer where the power mode is written
+ * @retval 0 in case of success, an error code otherwise
+ */
+int LIS2MDLSensor::get_m_lp(uint8_t *lp)
+{
+    int ret = 0;
+    lis2mdl_lp_t current_lp;
+    
+    /* Get current power mode. */
+    if (lis2mdl_power_mode_get(&_reg_ctx, &current_lp) != 0) {
+        return 1;
+    }
+    
+    switch (current_lp) {
+        case LIS2MDL_HIGH_RESOLUTION:
+            *lp = 0;
+            break;
+
+        case LIS2MDL_LOW_POWER:
+            *lp = 1;
+            break;
+
+        default:
+            ret = 1;
+            break;
+    }
+
+    return ret;
+}
+
+/**
+ * @brief  Set the LIS2MDL magnetometer sensor power mode
+ * @param  lp the power mode value to be set
+ * @retval 0 in case of success, an error code otherwise
+ */
+int LIS2MDLSensor::set_m_lp(uint8_t lp)
+{
+    lis2mdl_lp_t new_lp;
+
+    new_lp = (lp == 0) ? LIS2MDL_HIGH_RESOLUTION
+              : LIS2MDL_LOW_POWER;
+
+    if (lis2mdl_power_mode_set(&_reg_ctx, new_lp) != 0) {
+        return 1;
+    }
+
+    return 0;
+}
+
+/**
+ * @brief  Get the LIS2MDL magnetometer sensor bandwidth
+ * @param  lpf pointer where the bandwidth is written
+ * @retval 0 in case of success, an error code otherwise
+ */
+int LIS2MDLSensor::get_m_lpf(uint8_t *lpf)
+{
+    int ret = 0;
+    lis2mdl_lpf_t current_lpf;
+    
+    /* Get current power mode. */
+    if (lis2mdl_low_pass_bandwidth_get(&_reg_ctx, &current_lpf) != 0) {
+        return 1;
+    }
+    
+    switch (current_lpf) {
+        case LIS2MDL_ODR_DIV_2:
+            *lpf = 0;
+            break;
+
+        case LIS2MDL_ODR_DIV_4:
+            *lpf = 1;
+            break;
+
+        default:
+            ret = 1;
+            break;
+    }
+
+    return ret;
+}
+
+/**
+ * @brief  Set the LIS2MDL magnetometer sensor bandwidth
+ * @param  lpf the bandwidth value to be set
+ * @retval 0 in case of success, an error code otherwise
+ */
+int LIS2MDLSensor::set_m_lpf(uint8_t lpf)
+{
+    lis2mdl_lpf_t new_lpf;
+
+    new_lpf = (lpf == 0) ? LIS2MDL_ODR_DIV_2
+              : LIS2MDL_ODR_DIV_4;
+
+    if (lis2mdl_low_pass_bandwidth_set(&_reg_ctx, new_lpf) != 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