summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2012-10-12 13:57:49 -0700
committerKeith Packard <keithp@keithp.com>2012-10-12 13:57:49 -0700
commit175380a436efa35bbfae2ee5e29e12e9ef86fbde (patch)
tree79a0348efd9ce552c3959ca59ce19de6e976b82a
parentbe0a28ee7a6fbd98fc8113db8501bb791a112fa0 (diff)
altos: Use alt_t for all Pascal-based altitude data
This allows alt_t to be overridden for systems using the MS5607/MS5611 sensors Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--src/core/ao.h6
-rw-r--r--src/core/ao_convert_pa.c6
-rw-r--r--src/core/ao_convert_pa_test.c1
-rw-r--r--src/core/ao_data.h11
4 files changed, 18 insertions, 6 deletions
diff --git a/src/core/ao.h b/src/core/ao.h
index 200d4bc4..e559e876 100644
--- a/src/core/ao.h
+++ b/src/core/ao.h
@@ -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>
diff --git a/src/core/ao_convert_pa.c b/src/core/ao_convert_pa.c
index 0c93caea..1413681d 100644
--- a/src/core/ao_convert_pa.c
+++ b/src/core/ao_convert_pa.c
@@ -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;
}
diff --git a/src/core/ao_convert_pa_test.c b/src/core/ao_convert_pa_test.c
index 972a4d4c..143ce958 100644
--- a/src/core/ao_convert_pa_test.c
+++ b/src/core/ao_convert_pa_test.c
@@ -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"
diff --git a/src/core/ao_data.h b/src/core/ao_data.h
index 2b9ef5ac..90182b12 100644
--- a/src/core/ao_data.h
+++ b/src/core/ao_data.h
@@ -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:
*