1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-24 00:35:18 +03:00

Proper rounding for values that are scaled down. Displayed and spoken values affected.

Example: value 3.47V was spoken as 3.4V, new spoken value is 3.5V
This commit is contained in:
Damjan Adamic 2014-03-23 20:50:02 +01:00
parent 32090b8bbe
commit e5cbba4ee2
14 changed files with 44 additions and 18 deletions

View file

@ -1190,7 +1190,7 @@ void putsTelemetryChannel(xcoord_t x, uint8_t y, uint8_t channel, lcdint_t val,
{ {
lcdint_t converted_value = applyChannelRatio(channel, val); lcdint_t converted_value = applyChannelRatio(channel, val);
if (g_model.frsky.channels[channel].type >= UNIT_RAW) { if (g_model.frsky.channels[channel].type >= UNIT_RAW) {
converted_value /= 10; converted_value = div10_and_round(converted_value);
} }
else { else {
#if !defined(PCBTARANIS) #if !defined(PCBTARANIS)
@ -1198,7 +1198,7 @@ void putsTelemetryChannel(xcoord_t x, uint8_t y, uint8_t channel, lcdint_t val,
att |= PREC2; att |= PREC2;
} }
else { else {
converted_value /= 10; converted_value = div10_and_round(converted_value);
att |= PREC1; att |= PREC1;
} }
#else #else
@ -1255,7 +1255,7 @@ void putsTelemetryChannel(xcoord_t x, uint8_t y, uint8_t channel, lcdint_t val,
#if defined(FRSKY_SPORT) #if defined(FRSKY_SPORT)
case TELEM_ALT-1: case TELEM_ALT-1:
putsTelemetryValue(x, y, val/10, UNIT_DIST, att|PREC1); putsTelemetryValue(x, y, div10_and_round(val), UNIT_DIST, att|PREC1);
break; break;
#elif defined(WS_HOW_HIGH) #elif defined(WS_HOW_HIGH)
case TELEM_ALT-1: case TELEM_ALT-1:

View file

@ -36,6 +36,29 @@
#include "opentx.h" #include "opentx.h"
/*
Division by 10 and rounding or fixed point arithmetic values
Examples:
value -> result
105 -> 11
104 -> 10
-205 -> -21
-204 -> -20
*/
getvalue_t div10_and_round(getvalue_t value)
{
if (value >= 0 ) {
value += 5;
}
else {
value -= 5;
}
return value/10;
}
#if defined(FRSKY) #if defined(FRSKY)
uint16_t getChannelRatio(uint8_t channel) uint16_t getChannelRatio(uint8_t channel)
{ {

View file

@ -3253,7 +3253,7 @@ PLAY_FUNCTION(playValue, uint8_t idx)
{ {
if (TELEMETRY_STREAMING()) { if (TELEMETRY_STREAMING()) {
uint8_t att = 0; uint8_t att = 0;
int16_t converted_value = applyChannelRatio(idx, val) / 10; int16_t converted_value = div10_and_round(applyChannelRatio(idx, val));;
if (g_model.frsky.channels[idx].type < UNIT_RAW) { if (g_model.frsky.channels[idx].type < UNIT_RAW) {
att = PREC1; att = PREC1;
} }
@ -3264,7 +3264,7 @@ PLAY_FUNCTION(playValue, uint8_t idx)
case MIXSRC_FIRST_TELEM+TELEM_CELL-1: case MIXSRC_FIRST_TELEM+TELEM_CELL-1:
case MIXSRC_FIRST_TELEM+TELEM_MIN_CELL-1: case MIXSRC_FIRST_TELEM+TELEM_MIN_CELL-1:
PLAY_NUMBER(val/10, 1+UNIT_VOLTS, PREC1); PLAY_NUMBER(div10_and_round(val), 1+UNIT_VOLTS, PREC1);
break; break;
case MIXSRC_FIRST_TELEM+TELEM_VFAS-1: case MIXSRC_FIRST_TELEM+TELEM_VFAS-1:
@ -3282,12 +3282,12 @@ PLAY_FUNCTION(playValue, uint8_t idx)
case MIXSRC_FIRST_TELEM+TELEM_ACCx-1: case MIXSRC_FIRST_TELEM+TELEM_ACCx-1:
case MIXSRC_FIRST_TELEM+TELEM_ACCy-1: case MIXSRC_FIRST_TELEM+TELEM_ACCy-1:
case MIXSRC_FIRST_TELEM+TELEM_ACCz-1: case MIXSRC_FIRST_TELEM+TELEM_ACCz-1:
PLAY_NUMBER(val/10, 1+UNIT_G, PREC1); PLAY_NUMBER(div10_and_round(val), 1+UNIT_G, PREC1);
break; break;
case MIXSRC_FIRST_TELEM+TELEM_VSPD-1: case MIXSRC_FIRST_TELEM+TELEM_VSPD-1:
case MIXSRC_FIRST_TELEM+TELEM_ASPD-1: case MIXSRC_FIRST_TELEM+TELEM_ASPD-1:
PLAY_NUMBER(val/10, 1+UNIT_METERS_PER_SECOND, PREC1); PLAY_NUMBER(div10_and_round(val), 1+UNIT_METERS_PER_SECOND, PREC1);
break; break;
case MIXSRC_FIRST_TELEM+TELEM_CONSUMPTION-1: case MIXSRC_FIRST_TELEM+TELEM_CONSUMPTION-1:
@ -3300,7 +3300,7 @@ PLAY_FUNCTION(playValue, uint8_t idx)
case MIXSRC_FIRST_TELEM+TELEM_ALT-1: case MIXSRC_FIRST_TELEM+TELEM_ALT-1:
#if defined(PCBTARANIS) #if defined(PCBTARANIS)
PLAY_NUMBER(val/10, 1+UNIT_DIST, PREC1); PLAY_NUMBER(div10_and_round(val), 1+UNIT_DIST, PREC1);
break; break;
#endif #endif
case MIXSRC_FIRST_TELEM+TELEM_MIN_ALT-1: case MIXSRC_FIRST_TELEM+TELEM_MIN_ALT-1:

View file

@ -1514,6 +1514,9 @@ getvalue_t convertCswTelemValue(LogicalSwitchData * cs);
lcdint_t applyChannelRatio(uint8_t channel, lcdint_t val); lcdint_t applyChannelRatio(uint8_t channel, lcdint_t val);
#endif #endif
getvalue_t div10_and_round(getvalue_t value);
#if defined(FRSKY) #if defined(FRSKY)
NOINLINE uint8_t getRssiAlarmValue(uint8_t alarm); NOINLINE uint8_t getRssiAlarmValue(uint8_t alarm);

View file

@ -129,7 +129,7 @@ I18N_PLAY_FUNCTION(cz, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
} }
#if defined(CPUARM) #if defined(CPUARM)
if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) { if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) {
number /= 10; number = div10_and_round(number);
att -= PREC1; att -= PREC1;
} }
#endif #endif

View file

@ -119,7 +119,7 @@ I18N_PLAY_FUNCTION(de, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
} }
#if defined(CPUARM) #if defined(CPUARM)
if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) { if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) {
number /= 10; number = div10_and_round(number);
att -= PREC1; att -= PREC1;
} }
#endif #endif

View file

@ -106,7 +106,7 @@ I18N_PLAY_FUNCTION(en, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
} }
#if defined(CPUARM) #if defined(CPUARM)
if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) { if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) {
number /= 10; number = div10_and_round(number);
att -= PREC1; att -= PREC1;
} }
#endif #endif

View file

@ -143,7 +143,7 @@ I18N_PLAY_FUNCTION(es, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
} }
#if defined(CPUARM) #if defined(CPUARM)
if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) { if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) {
number /= 10; number = div10_and_round(number);
att -= PREC1; att -= PREC1;
} }
#endif #endif

View file

@ -125,7 +125,7 @@ I18N_PLAY_FUNCTION(fr, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
} }
#if defined(CPUARM) #if defined(CPUARM)
if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) { if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) {
number /= 10; number = div10_and_round(number);
att -= PREC1; att -= PREC1;
} }
#endif #endif

View file

@ -115,7 +115,7 @@ I18N_PLAY_FUNCTION(it, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
} }
#if defined(CPUARM) #if defined(CPUARM)
if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) { if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) {
number /= 10; number = div10_and_round(number);
att -= PREC1; att -= PREC1;
} }
#endif #endif

View file

@ -138,7 +138,7 @@ I18N_PLAY_FUNCTION(pl, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
} }
#if defined(CPUARM) #if defined(CPUARM)
if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) { if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) {
number /= 10; number = div10_and_round(number);
att -= PREC1; att -= PREC1;
} }
#endif #endif

View file

@ -128,7 +128,7 @@ I18N_PLAY_FUNCTION(pt, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
} }
#if defined(CPUARM) #if defined(CPUARM)
if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) { if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) {
number /= 10; number = div10_and_round(number);
att -= PREC1; att -= PREC1;
} }
#endif #endif

View file

@ -93,7 +93,7 @@ I18N_PLAY_FUNCTION(se, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
} }
#if defined(CPUARM) #if defined(CPUARM)
if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) { if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) {
number /= 10; number = div10_and_round(number);
att -= PREC1; att -= PREC1;
} }
#endif #endif

View file

@ -144,7 +144,7 @@ I18N_PLAY_FUNCTION(sk, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
} }
#if defined(CPUARM) #if defined(CPUARM)
if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) { if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) {
number /= 10; number = div10_and_round(number);
att -= PREC1; att -= PREC1;
} }
#endif #endif