From 869bc258b727d2046835ac52a361d2ef529895ee Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 8 Jun 2020 20:55:28 -0700 Subject: [PATCH] altoslib: Add EasyTimer idle monitor support Signed-off-by: Keith Packard --- altoslib/AltosIMU.java | 19 +++++-- altoslib/AltosIdleFetch.java | 39 +++++++++------ altoslib/AltosSensorEasyTimer1.java | 77 +++++++++++++++++++++++++++++ altoslib/Makefile.am | 1 + 4 files changed, 119 insertions(+), 17 deletions(-) create mode 100644 altoslib/AltosSensorEasyTimer1.java diff --git a/altoslib/AltosIMU.java b/altoslib/AltosIMU.java index 87b9f08b..7f8be403 100644 --- a/altoslib/AltosIMU.java +++ b/altoslib/AltosIMU.java @@ -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; diff --git a/altoslib/AltosIdleFetch.java b/altoslib/AltosIdleFetch.java index 2a36983f..ca3e33eb 100644 --- a/altoslib/AltosIdleFetch.java +++ b/altoslib/AltosIdleFetch.java @@ -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 index 00000000..6af0cc14 --- /dev/null +++ b/altoslib/AltosSensorEasyTimer1.java @@ -0,0 +1,77 @@ +/* + * Copyright © 2020 Keith Packard + * + * 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) { + } + } +} + diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am index b7d30051..0c9392d1 100644 --- a/altoslib/Makefile.am +++ b/altoslib/Makefile.am @@ -105,6 +105,7 @@ altoslib_JAVA = \ AltosUsbId.java \ AltosSensorMM.java \ AltosSensorEMini.java \ + AltosSensorEasyTimer1.java \ AltosSensorTM.java \ AltosSensorTMini2.java \ AltosSensorTMini3.java \ -- 2.30.2