Merge pull request #6973 from etracer65/osd_temperature_cleanup
OSD temperature display and calculations cleanup
This commit is contained in:
commit
8ae0e929d1
|
@ -268,13 +268,13 @@ static int32_t osdGetMetersToSelectedUnit(int32_t meters)
|
|||
}
|
||||
|
||||
#if defined(USE_ADC_INTERNAL) || defined(USE_ESC_SENSOR)
|
||||
STATIC_UNIT_TESTED int osdConvertTemperatureToSelectedUnit(int tempInDeciDegrees)
|
||||
STATIC_UNIT_TESTED int osdConvertTemperatureToSelectedUnit(int tempInDegreesCelcius)
|
||||
{
|
||||
switch (osdConfig()->units) {
|
||||
case OSD_UNIT_IMPERIAL:
|
||||
return ((tempInDeciDegrees * 9) / 5) + 320;
|
||||
return lrintf(((tempInDegreesCelcius * 9.0f) / 5) + 32);
|
||||
default:
|
||||
return tempInDeciDegrees;
|
||||
return tempInDegreesCelcius;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -851,10 +851,10 @@ static bool osdDrawSingleElement(uint8_t item)
|
|||
}
|
||||
|
||||
#ifdef USE_ADC_INTERNAL
|
||||
uint8_t coreTemperature = getCoreTemperatureCelsius();
|
||||
const int16_t coreTemperature = getCoreTemperatureCelsius();
|
||||
if (osdWarnGetState(OSD_WARNING_CORE_TEMPERATURE) && coreTemperature >= osdConfig()->core_temp_alarm) {
|
||||
char coreTemperatureWarningMsg[OSD_FORMAT_MESSAGE_BUFFER_SIZE];
|
||||
tfp_sprintf(coreTemperatureWarningMsg, "CORE: %3d%c", osdConvertTemperatureToSelectedUnit(getCoreTemperatureCelsius() * 10) / 10, osdGetTemperatureSymbolForSelectedUnit());
|
||||
tfp_sprintf(coreTemperatureWarningMsg, "CORE: %3d%c", osdConvertTemperatureToSelectedUnit(coreTemperature), osdGetTemperatureSymbolForSelectedUnit());
|
||||
|
||||
osdFormatMessage(buff, OSD_FORMAT_MESSAGE_BUFFER_SIZE, coreTemperatureWarningMsg);
|
||||
|
||||
|
@ -1022,7 +1022,7 @@ static bool osdDrawSingleElement(uint8_t item)
|
|||
#ifdef USE_ESC_SENSOR
|
||||
case OSD_ESC_TMP:
|
||||
if (featureIsEnabled(FEATURE_ESC_SENSOR)) {
|
||||
tfp_sprintf(buff, "%3d%c", osdConvertTemperatureToSelectedUnit(escDataCombined->temperature * 10) / 10, osdGetTemperatureSymbolForSelectedUnit());
|
||||
tfp_sprintf(buff, "%3d%c", osdConvertTemperatureToSelectedUnit(escDataCombined->temperature), osdGetTemperatureSymbolForSelectedUnit());
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -1049,7 +1049,7 @@ static bool osdDrawSingleElement(uint8_t item)
|
|||
|
||||
#ifdef USE_ADC_INTERNAL
|
||||
case OSD_CORE_TEMPERATURE:
|
||||
tfp_sprintf(buff, "%3d%c", osdConvertTemperatureToSelectedUnit(getCoreTemperatureCelsius() * 10) / 10, osdGetTemperatureSymbolForSelectedUnit());
|
||||
tfp_sprintf(buff, "%3d%c", osdConvertTemperatureToSelectedUnit(getCoreTemperatureCelsius()), osdGetTemperatureSymbolForSelectedUnit());
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
@ -1393,7 +1393,7 @@ static void osdUpdateStats(void)
|
|||
#endif
|
||||
#ifdef USE_ESC_SENSOR
|
||||
if (featureIsEnabled(FEATURE_ESC_SENSOR)) {
|
||||
value = (escDataCombined->temperature * 10) / 10;
|
||||
value = escDataCombined->temperature;
|
||||
if (stats.max_esc_temp < value) {
|
||||
stats.max_esc_temp = value;
|
||||
}
|
||||
|
@ -1568,7 +1568,7 @@ static void osdShowStats(uint16_t endBatteryVoltage)
|
|||
|
||||
#ifdef USE_ESC_SENSOR
|
||||
if (osdStatGetState(OSD_STAT_MAX_ESC_TEMP)) {
|
||||
tfp_sprintf(buff, "%3d%c", osdConvertTemperatureToSelectedUnit(stats.max_esc_temp * 10) / 10, osdGetTemperatureSymbolForSelectedUnit());
|
||||
tfp_sprintf(buff, "%3d%c", osdConvertTemperatureToSelectedUnit(stats.max_esc_temp), osdGetTemperatureSymbolForSelectedUnit());
|
||||
osdDisplayStatisticLabel(top++, "MAX ESC TEMP", buff);
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ extern "C" {
|
|||
void osdRefresh(timeUs_t currentTimeUs);
|
||||
void osdFormatTime(char * buff, osd_timer_precision_e precision, timeUs_t time);
|
||||
void osdFormatTimer(char *buff, bool showSymbol, int timerIndex);
|
||||
int osdConvertTemperatureToSelectedUnit(int tempInDeciDegrees);
|
||||
int osdConvertTemperatureToSelectedUnit(int tempInDegreesCelcius);
|
||||
|
||||
uint16_t rssi;
|
||||
attitudeEulerAngles_t attitude;
|
||||
|
@ -941,11 +941,15 @@ TEST(OsdTest, TestConvertTemperatureUnits)
|
|||
{
|
||||
/* In Celsius */
|
||||
osdConfigMutable()->units = OSD_UNIT_METRIC;
|
||||
EXPECT_EQ(osdConvertTemperatureToSelectedUnit(330), 330);
|
||||
EXPECT_EQ(osdConvertTemperatureToSelectedUnit(40), 40);
|
||||
|
||||
/* In Fahrenheit */
|
||||
osdConfigMutable()->units = OSD_UNIT_IMPERIAL;
|
||||
EXPECT_EQ(osdConvertTemperatureToSelectedUnit(330), 914);
|
||||
EXPECT_EQ(osdConvertTemperatureToSelectedUnit(40), 104);
|
||||
|
||||
/* In Fahrenheit with rounding */
|
||||
osdConfigMutable()->units = OSD_UNIT_IMPERIAL;
|
||||
EXPECT_EQ(osdConvertTemperatureToSelectedUnit(41), 106);
|
||||
}
|
||||
|
||||
// STUBS
|
||||
|
|
Loading…
Reference in New Issue