From 24948ea1d41f2a7c96ac09e35d1250909e5726ae Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 9 Dec 2012 14:32:35 -0800 Subject: altos: Store altitude in 32-bits for MicroPeak Needs all 32 bits to store .1 meter resolution Signed-off-by: Keith Packard --- src/micropeak/ao_pins.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/micropeak/ao_pins.h b/src/micropeak/ao_pins.h index 257b8694..187b2544 100644 --- a/src/micropeak/ao_pins.h +++ b/src/micropeak/ao_pins.h @@ -57,6 +57,7 @@ #define I2C_PIN_SDA PINB0 #define AO_CONST_ATTRIB PROGMEM +typedef int32_t alt_t; #define FETCH_ALT(o) ((alt_t) pgm_read_dword(&altitude_table[o])) #define AO_ALT_VALUE(x) ((x) * 10) -- cgit v1.2.3 From defd5d0784a754be30e3295067fbc85a108ad172 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 9 Dec 2012 18:27:49 -0800 Subject: 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 --- src/core/ao_convert_pa.c | 8 ++++---- 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_ */ -- cgit v1.2.3 From c233ef67f42c14cb1d0e0542a9523b279f826af5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 9 Dec 2012 18:28:33 -0800 Subject: altos: Use alt_t value to hold displayed height in micropeak Heights are 32 bits (to get .1 meter resolution) in micropeak; make sure we have enough bits while blinking out the computed value. Signed-off-by: Keith Packard --- src/micropeak/ao_report_tiny.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/micropeak/ao_report_tiny.c b/src/micropeak/ao_report_tiny.c index 109af1ed..bdcc131e 100644 --- a/src/micropeak/ao_report_tiny.c +++ b/src/micropeak/ao_report_tiny.c @@ -38,8 +38,8 @@ ao_report_digit(uint8_t digit) __reentrant void ao_report_altitude(void) { - __pdata int16_t agl = ao_max_height; - __xdata uint8_t digits[10]; + __pdata alt_t agl = ao_max_height; + static __xdata uint8_t digits[11]; __pdata uint8_t ndigits, i; if (agl < 0) -- cgit v1.2.3