1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-25 01:05:27 +03:00

Add temperature unit conversion

Selects unit based on OSD unit system setting: metric is degC and
imperial is degF.
This commit is contained in:
Dan Nixon 2018-01-13 13:00:01 +00:00
parent f8e4d02c99
commit 52d45ff72b
2 changed files with 45 additions and 1 deletions

View file

@ -207,6 +207,26 @@ static int32_t osdGetMetersToSelectedUnit(int32_t meters)
}
}
STATIC_UNIT_TESTED int osdConvertTemperatureToSelectedUnit(int tempInDeciDegrees)
{
switch (osdConfig()->units) {
case OSD_UNIT_IMPERIAL:
return ((tempInDeciDegrees * 9) / 5) + 320;
default:
return tempInDeciDegrees;
}
}
static char osdGetTemperatureSymbolForSelectedUnit(void)
{
switch (osdConfig()->units) {
case OSD_UNIT_IMPERIAL:
return 'F';
default:
return 'C';
}
}
static void osdFormatAltitudeString(char * buff, int altitude, bool pad)
{
const int alt = osdGetMetersToSelectedUnit(altitude);
@ -762,7 +782,7 @@ static bool osdDrawSingleElement(uint8_t item)
#ifdef USE_ADC_INTERNAL
case OSD_CORE_TEMPERATURE:
tfp_sprintf(buff, "%02dC", getCoreTemperatureCelsius());
tfp_sprintf(buff, "%02d%c", osdConvertTemperatureToSelectedUnit(getCoreTemperatureCelsius() * 10) / 10, osdGetTemperatureSymbolForSelectedUnit());
break;
#endif