+ static double
+ thermometer_to_temperature(double thermo)
+ {
+ return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247;
+ }
+
+ static double mega_adc(int raw) {
+ return raw / 4095.0;
+ }
+
+ static public double mega_battery_voltage(int v_batt) {
+ if (v_batt != AltosLib.MISSING)
+ return 3.3 * mega_adc(v_batt) * (5.6 + 10.0) / 10.0;
+ return AltosLib.MISSING;
+ }
+
+ static double mega_pyro_voltage(int raw) {
+ if (raw != AltosLib.MISSING)
+ return 3.3 * mega_adc(raw) * (100.0 + 27.0) / 27.0;
+ return AltosLib.MISSING;
+ }
+
+ static double tele_mini_3_adc(int raw) {
+ return raw / 4095.0;
+ }
+
+ static public double tele_mini_3_battery_voltage(int v_batt) {
+ if (v_batt != AltosLib.MISSING)
+ return 3.3 * tele_mini_3_adc(v_batt) * (5.6 + 10.0) / 10.0;
+ return AltosLib.MISSING;
+ }
+
+ static double tele_mini_3_pyro_voltage(int raw) {
+ if (raw != AltosLib.MISSING)
+ return 3.3 * tele_mini_3_adc(raw) * (100.0 + 27.0) / 27.0;
+ return AltosLib.MISSING;
+ }
+
+ static double tele_mini_2_voltage(int sensor) {
+ double supply = 3.3;
+
+ return sensor / 32767.0 * supply * 127/27;
+ }
+
+ static double tele_gps_1_voltage(int sensor) {
+ double supply = 3.3;
+
+ return sensor / 32767.0 * supply * (5.6 + 10.0) / 10.0;
+ }
+
+ static double tele_gps_2_voltage(int sensor) {
+ double supply = 3.3;
+
+ return sensor / 4095.0 * supply * (5.6 + 10.0) / 10.0;
+ }
+
+ static double tele_bt_3_battery(int raw) {
+ if (raw == AltosLib.MISSING)
+ return AltosLib.MISSING;
+ return 3.3 * mega_adc(raw) * (5.1 + 10.0) / 10.0;
+ }
+
+ static double easy_timer_voltage(int sensor) {
+ return 3.3 * mega_adc(sensor) * (100.0 + 27.0) / 27.0;
+ }
+
+ static double easy_mini_2_adc(double raw) {
+ return raw / 4095.0;
+ }
+
+ static double easy_mini_1_adc(double raw) {
+ return raw / 32767.0;
+ }
+
+ static double easy_mini_1_voltage(int sensor, int serial) {
+ double supply = 3.3;
+ double diode_offset = 0.0;
+
+ /* early prototypes had a 3.0V regulator */
+ if (serial < 1000)
+ supply = 3.0;
+
+ /* Purple v1.0 boards had the sensor after the
+ * blocking diode, which drops about 150mV
+ */
+ if (serial < 1665)
+ diode_offset = 0.150;
+
+ return easy_mini_1_adc(sensor) * supply * 127/27 + diode_offset;
+ }
+
+ static double easy_mini_2_voltage(int sensor) {
+ double supply = 3.3;
+
+ return easy_mini_2_adc(sensor) * supply * 127/27;
+ }
+
+ static double motor_pressure(double voltage) {
+ double base = 0.5;
+ double max = 4.5;
+ double full_scale_pressure = psi_to_pa(1600);
+
+ if (voltage < base)
+ voltage = base;
+ if (voltage > max)
+ voltage = max;
+ return (voltage - base) / (max - base) * full_scale_pressure;
+ }
+
+ static double easy_motor_2_motor_pressure(int sensor, double ground_sensor) {
+ double supply = 3.3;
+ double ground_voltage = easy_mini_2_adc(ground_sensor) * supply * 15.6 / 10.0;
+ double voltage = easy_mini_2_adc(sensor) * supply * 15.6 / 10.0;
+
+ return motor_pressure(voltage) - motor_pressure(ground_voltage);
+ }
+