altoslib: Add EasyTimer idle monitor support
authorKeith Packard <keithp@keithp.com>
Tue, 9 Jun 2020 03:55:28 +0000 (20:55 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 9 Jun 2020 04:29:08 +0000 (21:29 -0700)
Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosIMU.java
altoslib/AltosIdleFetch.java
altoslib/AltosSensorEasyTimer1.java [new file with mode: 0644]
altoslib/Makefile.am

index 87b9f08bedb58360decd8fa2c44ea14ca85da5be..7f8be40328faa7d848965d233727a08c90dcc05b 100644 (file)
@@ -45,6 +45,7 @@ public class AltosIMU implements Cloneable {
                case imu_type_easymega_v2:
                        return counts_per_g_mpu;
                case  imu_type_telemega_v4:
+               case imu_type_easytimer_v1:
                        return counts_per_g_bmx;
                default:
                        return AltosLib.MISSING;
@@ -69,7 +70,8 @@ public class AltosIMU implements Cloneable {
                case imu_type_easymega_v1:
                case imu_type_easymega_v2:
                        return counts_per_degree_mpu;
-               case  imu_type_telemega_v4:
+               case imu_type_telemega_v4:
+               case imu_type_easytimer_v1:
                        return counts_per_degree_bmx;
                default:
                        return AltosLib.MISSING;
@@ -99,6 +101,7 @@ public class AltosIMU implements Cloneable {
                case imu_type_easymega_v2:
                        return counts_per_gauss_mpu;
                case imu_type_telemega_v4:
+               case imu_type_easytimer_v1:
                        return 100.0;
                default:
                        return AltosLib.MISSING;
@@ -156,6 +159,8 @@ public class AltosIMU implements Cloneable {
        public static final int imu_type_easymega_v1 = 3;       /* MPU6000 */
        public static final int imu_type_easymega_v2 = 4;       /* MPU9250 */
 
+       public static final int imu_type_easytimer_v1 = 5;      /* BMX160 */
+
        private int accel_across(int imu_type) {
                switch (imu_type) {
                case imu_type_telemega_v1_v2:
@@ -164,7 +169,8 @@ public class AltosIMU implements Cloneable {
                        return accel_x;
                case imu_type_easymega_v2:
                        return -accel_y;
-               case  imu_type_telemega_v4:
+               case imu_type_telemega_v4:
+               case imu_type_easytimer_v1:
                        return -accel_y;
                default:
                        return AltosLib.MISSING;
@@ -179,6 +185,7 @@ public class AltosIMU implements Cloneable {
                        return accel_y;
                case imu_type_easymega_v2:
                case imu_type_telemega_v4:
+               case imu_type_easytimer_v1:
                        return accel_x;
                default:
                        return AltosLib.MISSING;
@@ -197,6 +204,7 @@ public class AltosIMU implements Cloneable {
                        return gyro_y;
                case imu_type_easymega_v2:
                case imu_type_telemega_v4:
+               case imu_type_easytimer_v1:
                        return gyro_x;
                default:
                        return AltosLib.MISSING;
@@ -212,6 +220,7 @@ public class AltosIMU implements Cloneable {
                case imu_type_easymega_v2:
                        return -gyro_y;
                case imu_type_telemega_v4:
+               case imu_type_easytimer_v1:
                        return -gyro_y;
                default:
                        return AltosLib.MISSING;
@@ -228,8 +237,9 @@ public class AltosIMU implements Cloneable {
                case imu_type_telemega_v3:
                case imu_type_easymega_v1:
                        return imu_axis_x;
-               case imu_type_telemega_v4:
                case imu_type_easymega_v2:
+               case imu_type_telemega_v4:
+               case imu_type_easytimer_v1:
                        return imu_axis_y;
                default:
                        return AltosLib.MISSING;
@@ -245,6 +255,7 @@ public class AltosIMU implements Cloneable {
                case imu_type_easymega_v2:
                        return -mag_y;
                case imu_type_telemega_v4:
+               case imu_type_easytimer_v1:
                        return mag_y;
                default:
                        return AltosLib.MISSING;
@@ -259,6 +270,7 @@ public class AltosIMU implements Cloneable {
                        return imu_axis_y;
                case imu_type_easymega_v2:
                case imu_type_telemega_v4:
+               case imu_type_easytimer_v1:
                        return imu_axis_x;
                default:
                        return AltosLib.MISSING;
@@ -273,6 +285,7 @@ public class AltosIMU implements Cloneable {
                        return mag_y;
                case imu_type_easymega_v2:
                case imu_type_telemega_v4:
+               case imu_type_easytimer_v1:
                        return mag_x;
                default:
                        return AltosLib.MISSING;
index 2a36983f93b4cec07c3783f49cc34182da6b653e..ca3e33eb244ffc91d47a4a035a8ffad5a9e5e668 100644 (file)
@@ -33,20 +33,22 @@ class AltosIdler {
        static final int        idle_imu_tm_v4 = 3;
        static final int        idle_imu_em_v1 = 4;
        static final int        idle_imu_em_v2 = 5;
-       static final int        idle_mag = 6;
-       static final int        idle_mma655x = 7;
-       static final int        idle_ms5607 = 8;
-       static final int        idle_adxl375 = 9;
-
-       static final int        idle_sensor_tm = 10;
-       static final int        idle_sensor_metrum = 11;
-       static final int        idle_sensor_mega = 12;
-       static final int        idle_sensor_emini1 = 13;
-       static final int        idle_sensor_emini2 = 14;
-       static final int        idle_sensor_tmini2 = 15;
-       static final int        idle_sensor_tgps1 = 16;
-       static final int        idle_sensor_tgps2 = 17;
-       static final int        idle_sensor_tmini3 = 18;
+       static final int        idle_imu_et_v1 = 6;
+       static final int        idle_mag = 7;
+       static final int        idle_mma655x = 8;
+       static final int        idle_ms5607 = 9;
+       static final int        idle_adxl375 = 10;
+
+       static final int        idle_sensor_tm = 100;
+       static final int        idle_sensor_metrum = 101;
+       static final int        idle_sensor_mega = 102;
+       static final int        idle_sensor_emini1 = 103;
+       static final int        idle_sensor_emini2 = 104;
+       static final int        idle_sensor_tmini2 = 105;
+       static final int        idle_sensor_tgps1 = 106;
+       static final int        idle_sensor_tgps2 = 107;
+       static final int        idle_sensor_tmini3 = 108;
+       static final int        idle_sensor_easytimer1 = 109;
 
        public void provide_data(AltosDataListener listener, AltosLink link) throws InterruptedException, TimeoutException, AltosUnknownProduct {
                for (int idler : idlers) {
@@ -69,6 +71,9 @@ class AltosIdler {
                        case idle_imu_em_v2:
                                AltosIMU.provide_data(listener, link, AltosIMU.imu_type_easymega_v2);
                                break;
+                       case idle_imu_et_v1:
+                               AltosIMU.provide_data(listener, link, AltosIMU.imu_type_easytimer_v1);
+                               break;
                        case idle_mag:
                                AltosMag.provide_data(listener, link);
                                break;
@@ -108,6 +113,9 @@ class AltosIdler {
                        case idle_sensor_tmini3:
                                AltosSensorTMini3.provide_data(listener, link);
                                break;
+                       case idle_sensor_easytimer1:
+                               AltosSensorEasyTimer1.provide_data(listener, link);
+                               break;
                        }
                }
        }
@@ -208,6 +216,9 @@ public class AltosIdleFetch implements AltosDataProvider {
                new AltosIdler("TeleGPS-v2",
                               AltosIdler.idle_gps,
                               AltosIdler.idle_sensor_tgps2),
+               new AltosIdler("EasyTimer-v1",
+                              AltosIdler.idle_imu_et_v1,
+                              AltosIdler.idle_sensor_easytimer1),
        };
 
        AltosLink               link;
diff --git a/altoslib/AltosSensorEasyTimer1.java b/altoslib/AltosSensorEasyTimer1.java
new file mode 100644 (file)
index 0000000..6af0cc1
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright © 2020 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package org.altusmetrum.altoslib_14;
+
+import java.util.concurrent.TimeoutException;
+
+class AltosSensorEasyTimer1 {
+       int             tick;
+       int[]           sense;
+       int             v_batt;
+       int             v_pbatt;
+       int             temp;
+
+       public AltosSensorEasyTimer1() {
+               sense = new int[2];
+       }
+
+       public AltosSensorEasyTimer1(AltosLink link) throws InterruptedException, TimeoutException {
+               this();
+               String[] items = link.adc();
+               for (int i = 0; i < items.length;) {
+                       if (items[i].equals("tick:")) {
+                               tick = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("A:")) {
+                               sense[0] = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("B:")) {
+                               sense[1] = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("batt:")) {
+                               v_batt = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       i++;
+               }
+       }
+
+       static public void provide_data(AltosDataListener listener, AltosLink link) throws InterruptedException {
+               try {
+                       AltosSensorEasyTimer1   sensor_easytimer1 = new AltosSensorEasyTimer1(link);
+
+                       listener.set_battery_voltage(AltosConvert.mega_battery_voltage(sensor_easytimer1.v_batt));
+
+                       double[]        igniter_voltage = new double[2];
+                       for (int i = 0; i < 2; i++)
+                               igniter_voltage[i] = AltosConvert.mega_pyro_voltage(sensor_easytimer1.sense[i]);
+                       listener.set_igniter_voltage(igniter_voltage);
+
+               } catch (TimeoutException te) {
+               }
+       }
+}
+
index b7d30051f87d351da8c061e129a6b6a9a9e4e2d4..0c9392d18a667110fc50b33aee01adfa6907816a 100644 (file)
@@ -105,6 +105,7 @@ altoslib_JAVA = \
        AltosUsbId.java \
        AltosSensorMM.java \
        AltosSensorEMini.java \
+       AltosSensorEasyTimer1.java \
        AltosSensorTM.java \
        AltosSensorTMini2.java \
        AltosSensorTMini3.java \