From cf54d94f08443997dee467bfcc618e484cca1de1 Mon Sep 17 00:00:00 2001 From: bsongis Date: Sun, 3 Feb 2013 21:31:17 +0000 Subject: [PATCH] Issue 189 done (will be there only on ARM as we need 32bits calculations almost everywhere) --- src/frsky.cpp | 6 +++--- src/frsky.h | 13 +++++++++++-- src/model_menus.cpp | 2 +- src/myeeprom.h | 16 ++++++++++++++-- src/open9x.cpp | 2 +- src/open9x.h | 2 +- 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/frsky.cpp b/src/frsky.cpp index e67b5628b..9022a55b5 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; } -int16_t applyChannelRatio(uint8_t channel, int16_t val) +telvalue_t applyChannelRatio(uint8_t channel, telvalue_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(uint8_t x, uint8_t y, uint8_t channel, int16_t val, uint8_t att) +void putsTelemetryChannel(xcoord_t x, uint8_t y, uint8_t channel, telvalue_t val, uint8_t att) { switch (channel) { case TELEM_TM1-1: @@ -1061,7 +1061,7 @@ void putsTelemetryChannel(uint8_t x, uint8_t y, uint8_t channel, int16_t val, ui channel -= TELEM_A1-1; // A1 and A2 { - int16_t converted_value = applyChannelRatio(channel, val); + telvalue_t converted_value = applyChannelRatio(channel, val); if (g_model.frsky.channels[channel].type >= UNIT_RAW) { converted_value /= 10; } diff --git a/src/frsky.h b/src/frsky.h index 5cabdab79..fae5fbf70 100644 --- a/src/frsky.h +++ b/src/frsky.h @@ -210,8 +210,17 @@ int16_t convertCswTelemValue(CustomSwData * cs); NOINLINE uint8_t getRssiAlarmValue(uint8_t alarm); extern const pm_uint8_t bchunit_ar[]; -int16_t applyChannelRatio(uint8_t channel, int16_t val); -void putsTelemetryChannel(uint8_t x, uint8_t y, uint8_t channel, int16_t val, uint8_t att); + +#if defined(CPUARM) +#define telvalue_t int32_t +#define FRSKY_MULTIPLIER_MAX 5 +#else +#define telvalue_t int16_t +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); #define IS_BARS_SCREEN(screenIndex) (g_model.frsky.screensType & (1<<(screenIndex))) diff --git a/src/model_menus.cpp b/src/model_menus.cpp index 9a7626c38..c1b068f18 100644 --- a/src/model_menus.cpp +++ b/src/model_menus.cpp @@ -3301,7 +3301,7 @@ void menuModelTelemetry(uint8_t event) channel.multiplier--; channel.ratio = 255; } else if (ratio == 256) { - if (channel.multiplier < 3) { channel.multiplier++; channel.ratio = 128; } + if (channel.multiplier < FRSKY_MULTIPLIER_MAX) { channel.multiplier++; channel.ratio = 128; } } else { channel.ratio = ratio; diff --git a/src/myeeprom.h b/src/myeeprom.h index a963d0c84..941365faf 100644 --- a/src/myeeprom.h +++ b/src/myeeprom.h @@ -404,6 +404,18 @@ enum TelemetryUnit { UNIT_G, }; +#if defined(CPUARM) +PACK(typedef struct t_FrSkyChannelData { + uint8_t ratio; // 0.0 means not used, 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. + int16_t offset:12; + uint16_t type:4; // channel unit (0=volts, ...) + uint8_t alarms_value[2]; // 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. + uint8_t alarms_level:4; + uint8_t alarms_greater:2; // 0=LT(<), 1=GT(>) + uint8_t spare:2; + uint8_t multiplier; // 0=no multiplier, 1=*2 multiplier +}) FrSkyChannelData; +#else PACK(typedef struct t_FrSkyChannelData { uint8_t ratio; // 0.0 means not used, 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. int16_t offset:12; @@ -413,6 +425,7 @@ PACK(typedef struct t_FrSkyChannelData { uint8_t alarms_greater:2; // 0=LT(<), 1=GT(>) uint8_t multiplier:2; // 0=no multiplier, 1=*2 multiplier }) FrSkyChannelData; +#endif enum TelemetrySource { TELEM_NONE, @@ -503,7 +516,6 @@ enum FrskySource { #define MAX_FRSKY_SCREENS 3 PACK(typedef struct t_FrSkyData { FrSkyChannelData channels[2]; - FrSkyRSSIAlarm rssiAlarms[2]; uint8_t usrProto; // Protocol in FrSky user data, 0=None, 1=FrSky hub, 2=WS HowHigh, 3=Halcyon uint8_t voltsSource; uint8_t blades; // How many blades for RPMs, 0=2 blades, 1=3 blades @@ -515,7 +527,7 @@ PACK(typedef struct t_FrSkyData { int8_t varioCenterMin; int8_t varioMin; int8_t varioMax; - uint8_t spare[2]; + FrSkyRSSIAlarm rssiAlarms[2]; }) FrSkyData; #else #define MAX_FRSKY_SCREENS 2 diff --git a/src/open9x.cpp b/src/open9x.cpp index 67a97cdd0..a0757056d 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(uint8_t x, uint8_t y, int16_t val, uint8_t unit, uint8_t att) +void putsTelemetryValue(xcoord_t x, uint8_t y, telvalue_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 d96766d72..f845e19c9 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(uint8_t x, uint8_t y, int16_t val, uint8_t unit, uint8_t att); +void putsTelemetryValue(xcoord_t x, uint8_t y, telvalue_t val, uint8_t unit, uint8_t att); #endif #if defined(CPUARM)