From 68308908afbd1f04b17056d2be408c89b3578c86 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 12 Oct 2012 13:59:50 -0700 Subject: [PATCH] altos: Parameterize altitude table access and initialization This allows projects to store the altitude data in different representations or with different access modes. By default, altitude data is stored in meters, but the initializers include decimeter values so those can be used instead if desired. Signed-off-by: Keith Packard --- src/core/ao_convert_pa.c | 10 +++++++++- src/util/make-altitude-pa | 10 +++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/core/ao_convert_pa.c b/src/core/ao_convert_pa.c index 1413681d..2793b77c 100644 --- a/src/core/ao_convert_pa.c +++ b/src/core/ao_convert_pa.c @@ -19,10 +19,18 @@ #include "ao.h" #endif -static const int32_t altitude_table[] = { +#ifndef AO_CONST_ATTRIB +#define AO_CONST_ATTRIB +#endif + +static const alt_t altitude_table[] AO_CONST_ATTRIB = { #include "altitude-pa.h" }; +#ifndef FETCH_ALT +#define FETCH_ALT(o) altitude_table[o] +#endif + #define ALT_SCALE (1 << ALT_SHIFT) #define ALT_MASK (ALT_SCALE - 1) diff --git a/src/util/make-altitude-pa b/src/util/make-altitude-pa index eae5ebe9..22831d50 100644 --- a/src/util/make-altitude-pa +++ b/src/util/make-altitude-pa @@ -239,8 +239,8 @@ real sample_to_fit_altitude(int sample) { real i_v; r_v = sample * l.m + l.b; - i_v = (round(alt_part[sub]) * (seg_len - off) + round(alt_part[sub+1]) * off) / seg_len; - return i_v; + i_v = (round(alt_part[sub]*10) * (seg_len - off) + round(alt_part[sub+1]*10) * off) / seg_len; + return i_v/10; } real max_error = 0; @@ -279,11 +279,11 @@ printf ("/*max error %f at %7.3f kPa. Average error %f*/\n", printf ("#define NALT %d\n", dim(alt_part)); printf ("#define ALT_SHIFT %d\n", pa_part_shift + pa_sample_shift); -printf ("#ifndef SATURATE\n#define SATURATE(x) (x)\n#endif\n"); +printf ("#ifndef AO_ALT_VALUE\n#define AO_ALT_VALUE(x) (alt_t) (x)\n#endif\n"); for (int part = 0; part < dim(alt_part); part++) { real kPa = sample_to_Pa(part_to_sample(part)) / 1000; - printf ("SATURATE(%9d), /* %6.2f kPa error %6.2fm */\n", - round (alt_part[part]), kPa, + printf ("AO_ALT_VALUE(%10.1f), /* %6.2f kPa error %6.2fm */\n", + round (alt_part[part]*10) / 10, kPa, alt_error[part]); } -- 2.30.2