altos: Use alt_t for all Pascal-based altitude data
authorKeith Packard <keithp@keithp.com>
Fri, 12 Oct 2012 20:57:49 +0000 (13:57 -0700)
committerKeith Packard <keithp@keithp.com>
Fri, 12 Oct 2012 20:57:49 +0000 (13:57 -0700)
This allows alt_t to be overridden for systems using the MS5607/MS5611
sensors

Signed-off-by: Keith Packard <keithp@keithp.com>
src/core/ao.h
src/core/ao_convert_pa.c
src/core/ao_convert_pa_test.c
src/core/ao_data.h

index 200d4bc49797296810e9a66c67cc07e502f043ec..e559e876b0209c62eece17b66785ca6e153606de 100644 (file)
@@ -272,11 +272,13 @@ ao_temp_to_dC(int16_t temp) __reentrant;
  * Convert between pressure in Pa and altitude in meters
  */
 
-int32_t
+#include <ao_data.h>
+
+alt_t
 ao_pa_to_altitude(int32_t pa);
 
 int32_t
-ao_altitude_to_pa(int32_t alt);
+ao_altitude_to_pa(alt_t alt);
 
 #if HAS_DBG
 #include <ao_dbg.h>
index 0c93caea60550acd80dac0a879453774fd532050..1413681d9f9b7c591f6cc5069978bca4e033d1ed 100644 (file)
@@ -26,7 +26,7 @@ static const int32_t altitude_table[] = {
 #define ALT_SCALE      (1 << ALT_SHIFT)
 #define ALT_MASK       (ALT_SCALE - 1)
 
-int32_t
+alt_t
 ao_pa_to_altitude(int32_t pa)
 {
        int16_t o;
@@ -40,8 +40,8 @@ ao_pa_to_altitude(int32_t pa)
        o = pa >> ALT_SHIFT;
        part = pa & ALT_MASK;
 
-       low = (int32_t) altitude_table[o] * (ALT_SCALE - part);
-       high = (int32_t) altitude_table[o+1] * part + (ALT_SCALE >> 1);
+       low = (alt_t) FETCH_ALT(o) * (ALT_SCALE - part);
+       high = (alt_t) FETCH_ALT(o+1) * part + (ALT_SCALE >> 1);
        return (low + high) >> ALT_SHIFT;
 }
 
index 972a4d4c7cad50042c9b2a82835ea70d0e18c602..143ce95858daf9aff6739872bce9b3fd4938f669 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <stdint.h>
 #define AO_CONVERT_TEST
+typedef int32_t alt_t;
 #include "ao_host.h"
 #include "ao_convert_pa.c"
 
index 2b9ef5ace922e5f4e5c4809da63d5524a1cf7305..90182b1253bb53e6620b74b1a0d6b1cf30b18458 100644 (file)
@@ -110,7 +110,12 @@ extern volatile __data uint8_t             ao_data_count;
 #define HAS_BARO       1
 
 typedef int32_t        pres_t;
-typedef int32_t alt_t;
+
+#ifndef AO_ALT_TYPE
+#define AO_ALT_TYPE    int32_t
+#endif
+
+typedef AO_ALT_TYPE    alt_t;
 
 #define ao_data_pres_cook(packet)      ao_ms5607_convert(&packet->ms5607_raw, &packet->ms5607_cooked)
 
@@ -135,6 +140,10 @@ typedef int16_t alt_t;
 
 #endif
 
+#if !HAS_BARO
+typedef int16_t alt_t;
+#endif
+
 /*
  * Need a few macros to pull data from the sensors:
  *