Merge pull request #848 from projectkk2glider/proper_rounding_of_spoken_values
Proper rounding of displayed and spoken values
This commit is contained in:
+3
-3
@@ -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);
|
||||
if (g_model.frsky.channels[channel].type >= UNIT_RAW) {
|
||||
converted_value /= 10;
|
||||
converted_value = div10_and_round(converted_value);
|
||||
}
|
||||
else {
|
||||
#if !defined(PCBTARANIS)
|
||||
@@ -1198,7 +1198,7 @@ void putsTelemetryChannel(xcoord_t x, uint8_t y, uint8_t channel, lcdint_t val,
|
||||
att |= PREC2;
|
||||
}
|
||||
else {
|
||||
converted_value /= 10;
|
||||
converted_value = div10_and_round(converted_value);
|
||||
att |= PREC1;
|
||||
}
|
||||
#else
|
||||
@@ -1255,7 +1255,7 @@ void putsTelemetryChannel(xcoord_t x, uint8_t y, uint8_t channel, lcdint_t val,
|
||||
|
||||
#if defined(FRSKY_SPORT)
|
||||
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;
|
||||
#elif defined(WS_HOW_HIGH)
|
||||
case TELEM_ALT-1:
|
||||
|
||||
@@ -36,6 +36,29 @@
|
||||
|
||||
#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)
|
||||
uint16_t getChannelRatio(uint8_t channel)
|
||||
{
|
||||
|
||||
@@ -3253,7 +3253,7 @@ PLAY_FUNCTION(playValue, uint8_t idx)
|
||||
{
|
||||
if (TELEMETRY_STREAMING()) {
|
||||
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) {
|
||||
att = PREC1;
|
||||
}
|
||||
@@ -3264,7 +3264,7 @@ PLAY_FUNCTION(playValue, uint8_t idx)
|
||||
|
||||
case MIXSRC_FIRST_TELEM+TELEM_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;
|
||||
|
||||
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_ACCy-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;
|
||||
|
||||
case MIXSRC_FIRST_TELEM+TELEM_VSPD-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;
|
||||
|
||||
case MIXSRC_FIRST_TELEM+TELEM_CONSUMPTION-1:
|
||||
@@ -3300,7 +3300,7 @@ PLAY_FUNCTION(playValue, uint8_t idx)
|
||||
|
||||
case MIXSRC_FIRST_TELEM+TELEM_ALT-1:
|
||||
#if defined(PCBTARANIS)
|
||||
PLAY_NUMBER(val/10, 1+UNIT_DIST, PREC1);
|
||||
PLAY_NUMBER(div10_and_round(val), 1+UNIT_DIST, PREC1);
|
||||
break;
|
||||
#endif
|
||||
case MIXSRC_FIRST_TELEM+TELEM_MIN_ALT-1:
|
||||
|
||||
@@ -1514,6 +1514,9 @@ getvalue_t convertCswTelemValue(LogicalSwitchData * cs);
|
||||
lcdint_t applyChannelRatio(uint8_t channel, lcdint_t val);
|
||||
#endif
|
||||
|
||||
getvalue_t div10_and_round(getvalue_t value);
|
||||
|
||||
|
||||
#if defined(FRSKY)
|
||||
NOINLINE uint8_t getRssiAlarmValue(uint8_t alarm);
|
||||
|
||||
|
||||
@@ -154,15 +154,17 @@
|
||||
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
|
||||
|
||||
/* __packed keyword used to decrease the data type alignment to 1-byte */
|
||||
#if defined (__CC_ARM) /* ARM Compiler */
|
||||
#define __packed __packed
|
||||
#elif defined (__ICCARM__) /* IAR Compiler */
|
||||
#define __packed __packed
|
||||
#elif defined ( __GNUC__ ) /* GNU Compiler */
|
||||
#define __packed __attribute__ ((__packed__))
|
||||
#elif defined (__TASKING__) /* TASKING Compiler */
|
||||
#define __packed __unaligned
|
||||
#endif /* __CC_ARM */
|
||||
#if !defined(__packed)
|
||||
#if defined (__CC_ARM) /* ARM Compiler */
|
||||
#define __packed __packed
|
||||
#elif defined (__ICCARM__) /* IAR Compiler */
|
||||
#define __packed __packed
|
||||
#elif defined ( __GNUC__ ) /* GNU Compiler */
|
||||
#define __packed __attribute__ ((__packed__))
|
||||
#elif defined (__TASKING__) /* TASKING Compiler */
|
||||
#define __packed __unaligned
|
||||
#endif /* __CC_ARM */
|
||||
#endif
|
||||
|
||||
#endif //__USB_CONF__H__
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ I18N_PLAY_FUNCTION(cz, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
|
||||
}
|
||||
#if defined(CPUARM)
|
||||
if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) {
|
||||
number /= 10;
|
||||
number = div10_and_round(number);
|
||||
att -= PREC1;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -119,7 +119,7 @@ I18N_PLAY_FUNCTION(de, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
|
||||
}
|
||||
#if defined(CPUARM)
|
||||
if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) {
|
||||
number /= 10;
|
||||
number = div10_and_round(number);
|
||||
att -= PREC1;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -105,8 +105,8 @@ I18N_PLAY_FUNCTION(en, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
|
||||
}
|
||||
}
|
||||
#if defined(CPUARM)
|
||||
if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_SPEED && number >= 100))) {
|
||||
number /= 10;
|
||||
if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) {
|
||||
number = div10_and_round(number);
|
||||
att -= PREC1;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -143,7 +143,7 @@ I18N_PLAY_FUNCTION(es, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
|
||||
}
|
||||
#if defined(CPUARM)
|
||||
if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) {
|
||||
number /= 10;
|
||||
number = div10_and_round(number);
|
||||
att -= PREC1;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -125,7 +125,7 @@ I18N_PLAY_FUNCTION(fr, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
|
||||
}
|
||||
#if defined(CPUARM)
|
||||
if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) {
|
||||
number /= 10;
|
||||
number = div10_and_round(number);
|
||||
att -= PREC1;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -115,7 +115,7 @@ I18N_PLAY_FUNCTION(it, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
|
||||
}
|
||||
#if defined(CPUARM)
|
||||
if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) {
|
||||
number /= 10;
|
||||
number = div10_and_round(number);
|
||||
att -= PREC1;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -138,7 +138,7 @@ I18N_PLAY_FUNCTION(pl, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
|
||||
}
|
||||
#if defined(CPUARM)
|
||||
if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) {
|
||||
number /= 10;
|
||||
number = div10_and_round(number);
|
||||
att -= PREC1;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -128,7 +128,7 @@ I18N_PLAY_FUNCTION(pt, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
|
||||
}
|
||||
#if defined(CPUARM)
|
||||
if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) {
|
||||
number /= 10;
|
||||
number = div10_and_round(number);
|
||||
att -= PREC1;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -93,7 +93,7 @@ I18N_PLAY_FUNCTION(se, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
|
||||
}
|
||||
#if defined(CPUARM)
|
||||
if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) {
|
||||
number /= 10;
|
||||
number = div10_and_round(number);
|
||||
att -= PREC1;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -144,7 +144,7 @@ I18N_PLAY_FUNCTION(sk, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
|
||||
}
|
||||
#if defined(CPUARM)
|
||||
if ((att & PREC1) && (unit == UNIT_FEET || (unit == UNIT_DIST && number >= 100))) {
|
||||
number /= 10;
|
||||
number = div10_and_round(number);
|
||||
att -= PREC1;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user