altoslib: Avoid sending negative accel cal values to flight computer
authorKeith Packard <keithp@keithp.com>
Thu, 29 Oct 2020 18:37:03 +0000 (11:37 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 18 Nov 2020 05:40:21 +0000 (21:40 -0800)
Pre-1.9.7 firmware does not handle negative values. Instead, send
large positive values which will wrap around to negative values inside
the flight computer.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosAccelCal.java
altoslib/AltosConfigData.java

index e8859b27aec7c7ddbff9b73a6d16be44f99d961d..8d0e992710f39cb265dfdbbb421b306f86e99e35 100644 (file)
@@ -182,6 +182,10 @@ public class AltosAccelCal implements Runnable {
                                if (config_data.pad_orientation != AltosLib.MISSING)
                                        link.printf("c o %d\n", config_data.pad_orientation);
                                if (plus != AltosLib.MISSING && minus != AltosLib.MISSING && plus != 0) {
+                                       if (plus < 0)
+                                               plus = 65536 + plus;
+                                       if (minus < 0)
+                                               minus = 65536 + minus;
                                        if (config_data.accel_zero_along != AltosLib.MISSING)
                                                link.printf("c a %d %d %d %d %d\n",
                                                            plus, minus,
index 5634ff410229f9fa77386c805e4f3b88c41446e2..c0855728541737b58aa8435b3ffcc663dde4f4d9 100644 (file)
@@ -839,6 +839,10 @@ public class AltosConfigData {
                int plus = accel_cal_plus(pad_orientation);
                int minus = accel_cal_minus(pad_orientation);
                if (plus != AltosLib.MISSING && minus != AltosLib.MISSING) {
+                       if (plus < 0)
+                               plus = 65536 + plus;
+                       if (minus < 0)
+                               minus = 65536 + minus;
                        if (accel_zero_along != AltosLib.MISSING &&
                            accel_zero_across != AltosLib.MISSING &&
                            accel_zero_through != AltosLib.MISSING)