diff options
author | Keith Packard <keithp@keithp.com> | 2012-12-09 18:27:49 -0800 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2012-12-09 18:27:49 -0800 |
commit | defd5d0784a754be30e3295067fbc85a108ad172 (patch) | |
tree | 891a08c4ea8f0eaad39b46cae64fb2a0f212c14f /src | |
parent | 24948ea1d41f2a7c96ac09e35d1250909e5726ae (diff) |
altos: Make sure pa to altitude conversion is done with 32 bits
We need 32 bits to hold intermediate values, even if the final
altitude is reported in only 16 bits.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/ao_convert_pa.c | 8 | ||||
-rw-r--r-- | src/micropeak/ao_pins.h | 2 |
2 files changed, 5 insertions, 5 deletions
diff --git a/src/core/ao_convert_pa.c b/src/core/ao_convert_pa.c index 55fe6e7d..fe6e0ef6 100644 --- a/src/core/ao_convert_pa.c +++ b/src/core/ao_convert_pa.c @@ -43,13 +43,13 @@ ao_pa_to_altitude(int32_t pa) if (pa < 0) pa = 0; - if (pa > 120000) - pa = 120000; + if (pa > 120000L) + pa = 120000L; o = pa >> ALT_SHIFT; part = pa & ALT_MASK; - low = (alt_t) FETCH_ALT(o) * (ALT_SCALE - part); - high = (alt_t) FETCH_ALT(o+1) * part + (ALT_SCALE >> 1); + low = (int32_t) FETCH_ALT(o) * (ALT_SCALE - part); + high = (int32_t) FETCH_ALT(o+1) * part + (ALT_SCALE >> 1); return (low + high) >> ALT_SHIFT; } diff --git a/src/micropeak/ao_pins.h b/src/micropeak/ao_pins.h index 187b2544..63e9cb1b 100644 --- a/src/micropeak/ao_pins.h +++ b/src/micropeak/ao_pins.h @@ -60,6 +60,6 @@ typedef int32_t alt_t; #define FETCH_ALT(o) ((alt_t) pgm_read_dword(&altitude_table[o])) -#define AO_ALT_VALUE(x) ((x) * 10) +#define AO_ALT_VALUE(x) ((x) * (alt_t) 10) #endif /* _AO_PINS_H_ */ |