LSM6DSO accelerometer and gyroscope sensor library

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   X_NUCLEO_IKS01A3

Revision:
4:bcf0cf6e43a7
Parent:
3:4274d9103f1d
Child:
5:213250c75a9e
--- a/LSM6DSOSensor.cpp	Wed Jul 24 14:19:35 2019 +0000
+++ b/LSM6DSOSensor.cpp	Tue Sep 17 08:40:49 2019 +0000
@@ -390,7 +390,6 @@
     return 0;
 }
 
-
 /**
  * @brief  Get the LSM6DSO accelerometer sensor full scale
  * @param  full_scale pointer where the full scale is written
@@ -455,6 +454,66 @@
 }
 
 /**
+ * @brief  Get the LSM6DSO accelerometer sensor power mode
+ * @param  xl_hm_mode the pointer where the high-performance mode is written, xl_ulp_en the pointer where the ultra-low-power enable is written
+ * @retval 0 in case of success, an error code otherwise
+ */
+int LSM6DSOSensor::get_x_power_mode(uint8_t *xl_hm_mode, uint8_t *xl_ulp_en)
+{
+    int ret = 0;
+    lsm6dso_xl_hm_mode_t power_mode_low_level;
+
+    /* Read actual power mode from sensor. */
+    if (lsm6dso_xl_power_mode_get(&_reg_ctx, &power_mode_low_level) != 0) {
+        return 1;
+    }
+
+    switch (power_mode_low_level) {
+        case LSM6DSO_HIGH_PERFORMANCE_MD:
+            *xl_hm_mode = 0;
+            *xl_ulp_en = 0;
+            break;
+
+        case LSM6DSO_LOW_NORMAL_POWER_MD:
+            *xl_hm_mode = 1;
+            *xl_ulp_en = 0;
+            break;
+
+        case LSM6DSO_ULTRA_LOW_POWER_MD:
+            *xl_hm_mode = 0;
+            *xl_ulp_en = 1;
+            break;
+
+        default:
+            ret = 1;
+            break;
+    }
+
+    return ret;
+}
+
+/**
+ * @brief  Set the LSM6DSO accelerometer sensor power mode
+ * @param  xl_hm_mode the high-performance mode to be set, xl_ulp_en the ultra-low-power enable to be set
+ * @retval 0 in case of success, an error code otherwise
+ */
+int LSM6DSOSensor::set_x_power_mode(uint8_t xl_hm_mode, uint8_t xl_ulp_en)
+{
+    uint8_t power_mode = xl_hm_mode + (xl_ulp_en << 1);
+    lsm6dso_xl_hm_mode_t new_power_mode;
+
+    new_power_mode = (power_mode == 0)  ? LSM6DSO_HIGH_PERFORMANCE_MD
+                    : (power_mode == 1) ? LSM6DSO_LOW_NORMAL_POWER_MD
+                    :                     LSM6DSO_ULTRA_LOW_POWER_MD;
+
+    if (lsm6dso_xl_power_mode_set(&_reg_ctx, new_power_mode) != 0) {
+        return 1;
+    }
+
+    return 0;
+}
+
+/**
  * @brief  Get the LSM6DSO accelerometer sensor raw axes
  * @param  value pointer where the raw values of the axes are written
  * @retval 0 in case of success, an error code otherwise