You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2019/06/19 09:25:42 UTC

[mynewt-core] 01/05: sensors/bmp280: Fix shell oversample command

This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 2c4cebe58b2fde9d9809d6bcda488268cc1880be
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Wed Jun 12 12:03:23 2019 +0200

    sensors/bmp280: Fix shell oversample command
    
    Due to various incorrect condition checking oversample
    command was broken.
    
    - checking argc > 3 made setting value impossible
      (now it checks against 4).
    - querying oversampling with 5 6 argument never read any values
      from device since driver expected bit mask instead of bit position.
    - now 'bmp280 oversample' will print both pressure and temperature
      settings.
---
 hw/drivers/sensors/bmp280/src/bmp280_shell.c | 40 +++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 7 deletions(-)

diff --git a/hw/drivers/sensors/bmp280/src/bmp280_shell.c b/hw/drivers/sensors/bmp280/src/bmp280_shell.c
index 26dbb9d..50634f2 100644
--- a/hw/drivers/sensors/bmp280/src/bmp280_shell.c
+++ b/hw/drivers/sensors/bmp280/src/bmp280_shell.c
@@ -160,17 +160,43 @@ bmp280_shell_cmd_oversample(int argc, char **argv)
     uint8_t oversample;
     uint32_t type;
 
-    if (argc > 3) {
+    if (argc > 4) {
         return bmp280_shell_err_too_many_args(argv[1]);
     }
 
-    /* Display the oversample */
-    if (argc == 3) {
-        val = parse_ll_bounds(argv[2], 4, 8, &rc);
+    /* Display the oversampling */
+    if (argc == 2) {
+        rc = bmp280_get_oversample(&g_sensor_itf,
+                                   SENSOR_TYPE_AMBIENT_TEMPERATURE, &oversample);
+        if (rc == 0) {
+            if (oversample == 0) {
+                console_printf("Temperature measurement disabled\n");
+            } else {
+                console_printf("Temperature oversampling %u (x%u)\n",
+                               oversample, 1U << (oversample - 1));
+            }
+        } else {
+            console_printf("Error reading temperature oversampling %d\n", rc);
+        }
+        rc = bmp280_get_oversample(&g_sensor_itf, SENSOR_TYPE_PRESSURE,
+                                   &oversample);
+        if (rc == 0) {
+            if (oversample == 0) {
+                console_printf("Pressure measurement disabled\n");
+            } else {
+                console_printf("Pressure oversampling %u (x%u)\n",
+                               oversample, 1U << (oversample - 1));
+            }
+        } else {
+            console_printf("Error reading pressure oversampling %d\n", rc);
+        }
+    } else if (argc == 3) {
+        /* Display the oversample */
+        val = (uint8_t)parse_ll_bounds(argv[2], 5, 6, &rc);
         if (rc) {
             return bmp280_shell_err_invalid_arg(argv[2]);
         }
-        rc = bmp280_get_oversample(&g_sensor_itf, val, &oversample);
+        rc = bmp280_get_oversample(&g_sensor_itf, 1U << val, &oversample);
         if (rc) {
             goto err;
         }
@@ -179,12 +205,12 @@ bmp280_shell_cmd_oversample(int argc, char **argv)
 
     /* Update the oversampling  */
     if (argc == 4) {
-        val = parse_ll_bounds(argv[2], 4, 8, &rc);
+        val = (uint8_t)parse_ll_bounds(argv[2], 5, 6, &rc);
         if (rc) {
             return bmp280_shell_err_invalid_arg(argv[2]);
         }
 
-        type = val;
+        type = 1U << val;
 
         val = parse_ll_bounds(argv[3], 0, 5, &rc);
         if (rc) {