OSDN Git Service

GMIN-2832: Accomodate high noise level on BMC150 magnetometer
authorPatrick Porlan <patrick.porlan@intel.com>
Mon, 4 Aug 2014 09:07:38 +0000 (11:07 +0200)
committerAdriana Reus <adriana.reus@intel.com>
Mon, 4 Aug 2014 15:40:01 +0000 (18:40 +0300)
Adriana suggested that we use a quirk to allow for higher error
margins during BMC150 magnetometer calibration. This is supported
by a few code changes in the HAL. The associated "quirks = noisy"
property has to be set in suitable configuration files.

Issue: GMIN-2832

Change-Id: Id43145aeb916cec02e2fedfe32cb7b89a01c8bbb
Signed-off-by: Patrick Porlan <patrick.porlan@intel.com>
compass-calibration.c
control.c
description.c
description.h

index 104f5e5..d194cdf 100644 (file)
@@ -11,7 +11,7 @@
 #include <utils/Log.h>
 #include "calibration.h"
 #include "matrix-ops.h"
-
+#include "description.h"
 
 #ifdef DBG_RAW_DATA
 #define MAX_RAW_DATA_COUNT 2000
@@ -398,6 +398,17 @@ static void compass_compute_cal (struct sensors_event_t* event, struct sensor_in
     event->magnetic.z = event->data[2] = result[2][0];
 }
 
+static inline float get_error_threshold (struct sensor_info_t* info)
+{
+    if (info->calibrated)
+            return MAX_SQR_ERR;
+
+    if (info->quirks & QUIRK_NOISY)
+            return FIRST_MAX_SQR_ERR * 2;
+
+    return FIRST_MAX_SQR_ERR;
+}
+
 static int compass_ready (struct sensor_info_t* info)
 {
     mat_input_t mat;
@@ -409,7 +420,7 @@ static int compass_ready (struct sensor_info_t* info)
     if (cal_data->sample_count < DS_SIZE)
         return info->calibrated;
 
-    max_sqr_err = info->calibrated ? MAX_SQR_ERR : FIRST_MAX_SQR_ERR;
+    max_sqr_err = get_error_threshold(info);
 
     /* enough points have been collected, do the ellipsoid calibration */
     for (i = 0; i < DS_SIZE; i++) {
index e7eaf83..19bb579 100644 (file)
--- a/control.c
+++ b/control.c
@@ -755,7 +755,7 @@ static void synthetize_duplicate_samples (void)
                        continue;
 
                /* If the sensor can generate duplicates, leave it alone */
-               if (!(sensor_info[s].quirks &  QUIRK_TERSE_DRIVER))
+               if (!(sensor_info[s].quirks & QUIRK_TERSE_DRIVER))
                        continue;
 
                /* If we haven't seen a sample, there's nothing to duplicate */
index 486ac31..ccc3870 100644 (file)
  * when the sensor reports a change. The HAL then periodically generates
  * duplicate events so the sensor behaves as a continously firing one.
  *
+ * The "noisy" quirk indicates that the underlying driver has a unusually high
+ * level of noise in its readings, and that the HAL has to accomodate it
+ * somehow, e.g. in the magnetometer calibration code path.
+ *
  * This one is used specifically to pass a calibration scale to ALS drivers:
  *
  * ro.iio.illuminance.name = CPLM3218x Ambient Light Sensor
@@ -220,7 +224,9 @@ uint32_t sensor_get_quirks (int s)
 
                if (strstr(quirks_buf, "terse"))
                        sensor_info[s].quirks |= QUIRK_TERSE_DRIVER;
-               ;
+
+               if (strstr(quirks_buf, "noisy"))
+                       sensor_info[s].quirks |= QUIRK_NOISY;
 
                sensor_info[s].quirks |= QUIRKS_ALREADY_DECODED;
        }
index 8856a74..f2ba07c 100644 (file)
@@ -7,9 +7,10 @@
 
 #include "common.h"
 
-#define QUIRKS_ALREADY_DECODED 0x1  /* Sensor quirks have been read */
-#define QUIRKS_INITIAL_RATE    0x2  /* Force initial sensor sampling rate */
-#define QUIRK_TERSE_DRIVER     0x8  /* Force duplicate events generation */
+#define QUIRKS_ALREADY_DECODED 0x01  /* Sensor quirks have been read       */
+#define QUIRKS_INITIAL_RATE    0x02  /* Force initial sensor sampling rate */
+#define QUIRK_TERSE_DRIVER     0x08  /* Force duplicate events generation  */
+#define QUIRK_NOISY            0x10  /* High noise level on readings       */
 
 char*  sensor_get_name         (int handle);
 char*  sensor_get_vendor       (int handle);