altos/adxl375: Clean up initialization, shortening self test period
authorKeith Packard <keithp@keithp.com>
Sat, 20 Oct 2018 14:34:57 +0000 (07:34 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 20 Oct 2018 14:42:28 +0000 (07:42 -0700)
Set the self test period to that suggested in the documentation.
Eliminate some debug variables.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/drivers/ao_adxl375.c

index e0d094f214b3a42a8f48a9f5cced8f0685f5debb..778c214b6e49b637a0ebd0be74b65c5de1120b68 100644 (file)
@@ -98,8 +98,8 @@ struct ao_adxl375_total {
        int32_t z;
 };
 
-#define AO_ADXL375_SELF_TEST_SAMPLES   16
-#define AO_ADXL375_SELF_TEST_SETTLE    6
+#define AO_ADXL375_SELF_TEST_SAMPLES   10
+#define AO_ADXL375_SELF_TEST_SETTLE    4
 
 #define MIN_LSB_G      18.4
 #define MAX_LSB_G      22.6
@@ -109,9 +109,6 @@ struct ao_adxl375_total {
 #define MIN_SELF_TEST  ((int32_t) (MIN_LSB_G * SELF_TEST_MIN_G * AO_ADXL375_SELF_TEST_SAMPLES + 0.5))
 #define MAX_SELF_TEST  ((int32_t) (MAX_LSB_G * SELF_TEST_MAX_G * AO_ADXL375_SELF_TEST_SAMPLES + 0.5))
 
-static const int32_t   min_self_test = MIN_SELF_TEST;
-static const int32_t   max_self_test = MAX_SELF_TEST;
-
 static void
 ao_adxl375_total_value(struct ao_adxl375_total *total, int samples)
 {
@@ -178,9 +175,6 @@ ao_adxl375_setup(void)
        (void) ao_adxl375_total_value;
        /* Perform self-test */
 
-#define AO_ADXL375_SELF_TEST_SAMPLES   16
-#define AO_ADXL375_SELF_TEST_SETTLE    6
-
        struct ao_adxl375_total self_test_off, self_test_on;
 
        /* Discard some samples to let it settle down */
@@ -210,22 +204,19 @@ ao_adxl375_setup(void)
 
        self_test_value = z_change;
 
-       if (z_change < min_self_test || max_self_test < z_change)
+       if (z_change < MIN_SELF_TEST || MAX_SELF_TEST < z_change)
                ao_sensor_errors = 1;
 
        /* Discard some samples to let it settle down */
        ao_adxl375_total_value(&self_test_off, AO_ADXL375_SELF_TEST_SETTLE);
 }
 
-static int     adxl375_count;
-
 static void
 ao_adxl375(void)
 {
        ao_adxl375_setup();
        for (;;) {
                ao_adxl375_value(&ao_adxl375_current);
-               ++adxl375_count;
                ao_arch_critical(
                        AO_DATA_PRESENT(AO_DATA_ADXL375);
                        AO_DATA_WAIT();
@@ -238,11 +229,10 @@ static struct ao_task ao_adxl375_task;
 static void
 ao_adxl375_dump(void)
 {
-       printf ("ADXL375 value %d %d %d count %d self test %d min %d max %d\n",
+       printf ("ADXL375 value %d %d %d self test %d min %d max %d\n",
                ao_adxl375_current.x,
                ao_adxl375_current.y,
                ao_adxl375_current.z,
-               adxl375_count,
                self_test_value,
                MIN_SELF_TEST,
                MAX_SELF_TEST);