From 3a1d0b1fd9d02bc74b8b99b4d1ff8cb044d61ae4 Mon Sep 17 00:00:00 2001 From: bsongis Date: Mon, 4 Feb 2013 07:12:21 +0000 Subject: [PATCH] [ARM] Negative current values with PREC2, above 200.00A --- src/frsky.cpp | 8 ++++---- src/frsky.h | 6 ++---- src/lcd.cpp | 8 ++++++-- src/lcd.h | 10 ++++++++-- src/open9x.cpp | 2 +- src/open9x.h | 2 +- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/frsky.cpp b/src/frsky.cpp index 9022a55b5..d356029fd 100644 --- a/src/frsky.cpp +++ b/src/frsky.cpp @@ -77,7 +77,7 @@ uint16_t getChannelRatio(uint8_t channel) return (uint16_t)g_model.frsky.channels[channel].ratio << g_model.frsky.channels[channel].multiplier; } -telvalue_t applyChannelRatio(uint8_t channel, telvalue_t val) +lcdint_t applyChannelRatio(uint8_t channel, lcdint_t val) { return ((int32_t)val+g_model.frsky.channels[channel].offset) * getChannelRatio(channel) * 2 / 51; } @@ -1045,7 +1045,7 @@ const pm_uint8_t bchunit_ar[] PROGMEM = { UNIT_METERS, // GPS Alt }; -void putsTelemetryChannel(xcoord_t x, uint8_t y, uint8_t channel, telvalue_t val, uint8_t att) +void putsTelemetryChannel(xcoord_t x, uint8_t y, uint8_t channel, lcdint_t val, uint8_t att) { switch (channel) { case TELEM_TM1-1: @@ -1061,12 +1061,12 @@ void putsTelemetryChannel(xcoord_t x, uint8_t y, uint8_t channel, telvalue_t val channel -= TELEM_A1-1; // A1 and A2 { - telvalue_t converted_value = applyChannelRatio(channel, val); + lcdint_t converted_value = applyChannelRatio(channel, val); if (g_model.frsky.channels[channel].type >= UNIT_RAW) { converted_value /= 10; } else { - if (converted_value < 1000) { + if (abs(converted_value) < 1000) { att |= PREC2; } else { diff --git a/src/frsky.h b/src/frsky.h index fee8467e1..75f5ef2b7 100644 --- a/src/frsky.h +++ b/src/frsky.h @@ -212,15 +212,13 @@ NOINLINE uint8_t getRssiAlarmValue(uint8_t alarm); extern const pm_uint8_t bchunit_ar[]; #if defined(CPUARM) -#define telvalue_t int32_t #define FRSKY_MULTIPLIER_MAX 5 #else -#define telvalue_t int16_t #define FRSKY_MULTIPLIER_MAX 3 #endif -telvalue_t applyChannelRatio(uint8_t channel, telvalue_t val); -void putsTelemetryChannel(xcoord_t x, uint8_t y, uint8_t channel, telvalue_t val, uint8_t att); +lcdint_t applyChannelRatio(uint8_t channel, lcdint_t val); +void putsTelemetryChannel(xcoord_t x, uint8_t y, uint8_t channel, lcdint_t val, uint8_t att); #define IS_BARS_SCREEN(screenIndex) (g_model.frsky.screensType & (1<<(screenIndex))) diff --git a/src/lcd.cpp b/src/lcd.cpp index dcf3b1b6c..ccf8d420c 100644 --- a/src/lcd.cpp +++ b/src/lcd.cpp @@ -348,12 +348,12 @@ void lcd_outdez8(xcoord_t x, uint8_t y, int8_t val) lcd_outdezAtt(x, y, val); } -void lcd_outdezAtt(xcoord_t x, uint8_t y, int16_t val, LcdFlags flags) +void lcd_outdezAtt(xcoord_t x, uint8_t y, lcdint_t val, LcdFlags flags) { lcd_outdezNAtt(x, y, val, flags); } -void lcd_outdezNAtt(xcoord_t x, uint8_t y, int16_t val, LcdFlags flags, uint8_t len) +void lcd_outdezNAtt(xcoord_t x, uint8_t y, lcdint_t val, LcdFlags flags, uint8_t len) { uint8_t fw = FWNUM; int8_t mode = MODE(flags); @@ -375,7 +375,11 @@ void lcd_outdezNAtt(xcoord_t x, uint8_t y, int16_t val, LcdFlags flags, uint8_t if (mode != MODE(LEADING0)) { len = 1; +#if defined(CPUARM) + uint32_t tmp = ((uint32_t)val) / 10; +#else uint16_t tmp = ((uint16_t)val) / 10; +#endif while (tmp) { len++; tmp /= 10; diff --git a/src/lcd.h b/src/lcd.h index e58920192..4866b9a7a 100644 --- a/src/lcd.h +++ b/src/lcd.h @@ -55,6 +55,12 @@ #define CENTER_OFS 0 #endif +#if defined(CPUARM) +#define lcdint_t int32_t +#else +#define lcdint_t int16_t +#endif + #if LCD_H > 64 #define LCD_LINES 9 #else @@ -159,8 +165,8 @@ extern void lcd_putsLeft(uint8_t y, const pm_char * s); #define lcd_putsCenter(y, s) lcd_puts((LCD_W-sizeof(TR_##s)*FW+FW-2)/2, y, STR_##s) extern void lcd_outhex4(xcoord_t x, uint8_t y, uint16_t val); -extern void lcd_outdezAtt(xcoord_t x, uint8_t y, int16_t val, LcdFlags mode=0); -extern void lcd_outdezNAtt(xcoord_t x, uint8_t y, int16_t val, LcdFlags mode=0, uint8_t len=0); +extern void lcd_outdezAtt(xcoord_t x, uint8_t y, lcdint_t val, LcdFlags mode=0); +extern void lcd_outdezNAtt(xcoord_t x, uint8_t y, lcdint_t val, LcdFlags mode=0, uint8_t len=0); extern void lcd_outdez8(xcoord_t x, uint8_t y, int8_t val); extern void putsStrIdx(xcoord_t x, uint8_t y, const pm_char *str, uint8_t idx, LcdFlags att=0); diff --git a/src/open9x.cpp b/src/open9x.cpp index a0757056d..0b44264b7 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -1140,7 +1140,7 @@ void setGVarValue(uint8_t idx, int8_t value, int8_t phase) #endif #if defined(FRSKY) || defined(CPUARM) -void putsTelemetryValue(xcoord_t x, uint8_t y, telvalue_t val, uint8_t unit, uint8_t att) +void putsTelemetryValue(xcoord_t x, uint8_t y, lcdint_t val, uint8_t unit, uint8_t att) { #ifdef IMPERIAL_UNITS if (unit == UNIT_DEGREES) { diff --git a/src/open9x.h b/src/open9x.h index f845e19c9..620e33502 100644 --- a/src/open9x.h +++ b/src/open9x.h @@ -1220,7 +1220,7 @@ extern union ReusableBuffer reusableBuffer; void checkFlashOnBeep(); #if defined(FRSKY) || defined(CPUARM) -void putsTelemetryValue(xcoord_t x, uint8_t y, telvalue_t val, uint8_t unit, uint8_t att); +void putsTelemetryValue(xcoord_t x, uint8_t y, lcdint_t val, uint8_t unit, uint8_t att); #endif #if defined(CPUARM)