]> git.gag.com Git - fw/altos/commitdiff
ao-accel-cal: Validate ADXL375 sensitivity hack-adxl
authorKeith Packard <keithp@keithp.com>
Wed, 31 Jul 2024 20:12:04 +0000 (13:12 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 31 Jul 2024 20:13:23 +0000 (13:13 -0700)
If the accel device is an ADXL375, make sure the Z axis sensitivity is
within the data sheet range of 18.4 to 22.6 g. Allow for rounding as the
device only records the integer value (sigh).

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/ao-cal-accel/ao-cal-accel.c

index 671e4ba53925b9e6f05a9c398c45a22fe855da57..1272efecc37fea2a3528e7eb15d85cc4a24df1d1 100644 (file)
@@ -80,7 +80,7 @@ static struct flash *
 flash(struct cc_usb *usb)
 {
        struct flash    *head = NULL, **tail = &head;
-       cc_usb_printf(usb, "c s\nv\n");
+       cc_usb_printf(usb, "c s\nA\nv\n");
        for (;;) {
                char    line[512];
                struct flash    *b;
@@ -125,6 +125,7 @@ static int
 do_cal(struct cc_usb *usb) {
        struct flash    *b;
        char    **accel;
+       char    **sensor;
        char    line[1024];
        int     l = 0;
        int     running = 0;
@@ -172,6 +173,35 @@ do_cal(struct cc_usb *usb) {
        printf ("Accel cal +1g: %s -1g: %s\n",
                accel[3], accel[5]);
 
+       sensor = find_flash(b, "ADXL375");
+
+       if (sensor) {
+               char    *plus_end = NULL, *minus_end = NULL;
+               long    accel_plus = strtol(accel[3], &plus_end, 10);
+               long    accel_minus = strtol(accel[5], &minus_end, 10);
+               double  one_g;
+
+               if (plus_end == NULL || plus_end == accel[3]) {
+                       printf("can't extract plus value from %s\n", accel[3]);
+                       return 0;
+               }
+
+               if (minus_end == NULL || minus_end == accel[5]) {
+                       printf("can't extract minus value from %s\n", accel[5]);
+                       return 0;
+               }
+               one_g = (accel_minus - accel_plus) / 2.0;
+               if (one_g < 0)
+                       one_g = -one_g;
+
+               if (one_g < 18 || 23 < one_g) {
+                       printf("Device out of spec. LSB/g is %g. Should be >= 18.4 and <= 22.6\n", one_g);
+                       return 0;
+               }
+
+               printf("Device sensitivity: %g LSB/g\n", one_g);
+       }
+
        printf ("Saving..."); fflush(stdout);
        cc_usb_printf (usb, "c w\n");
        cc_usb_sync(usb);