altoslib: Add Ms5607 constructor that just takes config_data
authorKeith Packard <keithp@keithp.com>
Tue, 9 May 2017 07:16:36 +0000 (00:16 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 9 May 2017 07:16:36 +0000 (00:16 -0700)
Use for making Ms5607 from eeprom files.

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

index 14a026a9b5d83749a3547fa1f327cd75b1890beb..16019c8c280320c10cd86c84b7dada7fd71efa9a 100644 (file)
@@ -49,13 +49,11 @@ public class AltosEepromFireTwo extends AltosEeprom {
        private static final double r_below = 10000.0;
        private static final double v_adc = 3.3;
 
-       private static double
-       firetwo_adc(int raw) {
+       private static double firetwo_adc(int raw) {
                return raw / 4095.0;
        }
 
-       private static double
-       adc_to_pa(int adc) {
+       public static double adc_to_pa(int adc) {
 
                /* raw adc to processor voltage, then back through the
                 * voltage divider to the sensor voltage
@@ -71,6 +69,13 @@ public class AltosEepromFireTwo extends AltosEeprom {
                return AltosConvert.psi_to_pa(psi);
        }
 
+       public static double adc_to_n(int adc) {
+               double v = firetwo_adc(adc);
+
+               /* this is a total guess */
+               return AltosConvert.lb_to_n(v * 298 * 9.807);
+       }
+
        public void update_state(AltosState state) {
                super.update_state(state);
 
index 19d2dd6db0b94fc6b85a9e6e9c5c15d4dbeea602..c598d01e4a6021c5b8d15e8ddf3565c37fa3735f 100644 (file)
@@ -138,6 +138,17 @@ public class AltosMs5607 {
                }
        }
 
+       public boolean valid_config() {
+               return reserved != AltosLib.MISSING &&
+                       sens != AltosLib.MISSING &&
+                       off != AltosLib.MISSING &&
+                       tcs != AltosLib.MISSING &&
+                       tco != AltosLib.MISSING &&
+                       tref != AltosLib.MISSING &&
+                       tempsens != AltosLib.MISSING &&
+                       crc  != AltosLib.MISSING;
+       }
+
        public AltosMs5607() {
                raw_pres = AltosLib.MISSING;
                raw_temp = AltosLib.MISSING;
@@ -145,7 +156,7 @@ public class AltosMs5607 {
                cc = AltosLib.MISSING;
        }
 
-       public AltosMs5607 (AltosLink link, AltosConfigData config_data) throws InterruptedException, TimeoutException {
+       public AltosMs5607(AltosConfigData config_data) {
                this();
                reserved = config_data.ms5607_reserved;
                sens = config_data.ms5607_sens;
@@ -155,6 +166,10 @@ public class AltosMs5607 {
                tref = config_data.ms5607_tref;
                tempsens = config_data.ms5607_tempsens;
                crc = config_data.ms5607_crc;
+       }
+
+       public AltosMs5607 (AltosLink link, AltosConfigData config_data) throws InterruptedException, TimeoutException {
+               this(config_data);
                link.printf("B\n");
                for (;;) {
                        String line = link.get_reply_no_dialog(5000);