Merge pull request #4926 from DanNixon/osd_temperatures

Add temperature sensors to OSD
This commit is contained in:
Michael Keller 2018-01-16 01:03:19 +13:00 committed by GitHub
commit bf1d31083b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 94 additions and 2 deletions

View File

@ -767,6 +767,7 @@ const clivalue_t valueTable[] = {
{ "osd_esc_rpm_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_ESC_RPM]) },
{ "osd_rtc_date_time_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_RTC_DATETIME]) },
{ "osd_adjustment_range_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_ADJUSTMENT_RANGE]) },
{ "osd_core_temp_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_CORE_TEMPERATURE]) },
{ "osd_stat_max_spd", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_OSD_CONFIG, offsetof(osdConfig_t, enabled_stats[OSD_STAT_MAX_SPEED])},
{ "osd_stat_max_dist", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_OSD_CONFIG, offsetof(osdConfig_t, enabled_stats[OSD_STAT_MAX_DISTANCE])},

View File

@ -78,6 +78,7 @@
#include "rx/rx.h"
#include "sensors/adcinternal.h"
#include "sensors/barometer.h"
#include "sensors/battery.h"
#include "sensors/esc_sensor.h"
@ -206,6 +207,28 @@ static int32_t osdGetMetersToSelectedUnit(int32_t meters)
}
}
#if defined(USE_ADC_INTERNAL) || defined(USE_ESC_SENSOR)
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';
}
}
#endif
static void osdFormatAltitudeString(char * buff, int altitude, bool pad)
{
const int alt = osdGetMetersToSelectedUnit(altitude);
@ -739,7 +762,7 @@ static bool osdDrawSingleElement(uint8_t item)
#ifdef USE_ESC_SENSOR
case OSD_ESC_TMP:
tfp_sprintf(buff, "%3d%c", escData == NULL ? 0 : escData->temperature, SYM_TEMP_C);
tfp_sprintf(buff, "%3d%c", osdConvertTemperatureToSelectedUnit(escData->temperature * 10) / 10, osdGetTemperatureSymbolForSelectedUnit());
break;
case OSD_ESC_RPM:
@ -756,7 +779,12 @@ static bool osdDrawSingleElement(uint8_t item)
#ifdef USE_OSD_ADJUSTMENTS
case OSD_ADJUSTMENT_RANGE:
tfp_sprintf(buff, "%s: %3d", adjustmentRangeName, adjustmentRangeValue);
break;
#endif
#ifdef USE_ADC_INTERNAL
case OSD_CORE_TEMPERATURE:
tfp_sprintf(buff, "%3d%c", osdConvertTemperatureToSelectedUnit(getCoreTemperatureCelsius() * 10) / 10, osdGetTemperatureSymbolForSelectedUnit());
break;
#endif
@ -835,6 +863,10 @@ static void osdDrawElements(void)
#ifdef USE_OSD_ADJUSTMENTS
osdDrawSingleElement(OSD_ADJUSTMENT_RANGE);
#endif
#ifdef USE_ADC_INTERNAL
osdDrawSingleElement(OSD_CORE_TEMPERATURE);
#endif
}
void pgResetFn_osdConfig(osdConfig_t *osdConfig)

View File

@ -85,6 +85,7 @@ typedef enum {
OSD_REMAINING_TIME_ESTIMATE,
OSD_RTC_DATETIME,
OSD_ADJUSTMENT_RANGE,
OSD_CORE_TEMPERATURE,
OSD_ITEM_COUNT // MUST BE LAST
} osd_items_e;

View File

@ -160,7 +160,8 @@ osd_unittest_SRC := \
osd_unittest_DEFINES := \
USE_OSD \
USE_RTC_TIME
USE_RTC_TIME \
USE_ADC_INTERNAL
pg_unittest_SRC := \

View File

@ -52,6 +52,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);
uint16_t rssi;
attitudeEulerAngles_t attitude;
@ -77,6 +78,7 @@ extern "C" {
uint32_t simulationMahDrawn;
int32_t simulationAltitude;
int32_t simulationVerticalSpeed;
uint16_t simulationCoreTemperature;
}
/* #define DEBUG_OSD */
@ -96,6 +98,7 @@ void setDefualtSimulationState()
simulationMahDrawn = 0;
simulationAltitude = 0;
simulationVerticalSpeed = 0;
simulationCoreTemperature = 0;
}
/*
@ -743,6 +746,48 @@ TEST(OsdTest, TestElementAltitude)
displayPortTestBufferSubstring(23, 7, " -2.4%c", SYM_M);
}
/*
* Tests the core temperature OSD element.
*/
TEST(OsdTest, TestElementCoreTemperature)
{
// given
osdConfigMutable()->item_pos[OSD_CORE_TEMPERATURE] = OSD_POS(1, 8) | VISIBLE_FLAG;
// and
osdConfigMutable()->units = OSD_UNIT_METRIC;
// and
simulationCoreTemperature = 0;
// when
displayClearScreen(&testDisplayPort);
osdRefresh(simulationTime);
// then
displayPortTestBufferSubstring(1, 8, " 0C");
// given
simulationCoreTemperature = 33;
// when
displayClearScreen(&testDisplayPort);
osdRefresh(simulationTime);
// then
displayPortTestBufferSubstring(1, 8, " 33C");
// given
osdConfigMutable()->units = OSD_UNIT_IMPERIAL;
// when
displayClearScreen(&testDisplayPort);
osdRefresh(simulationTime);
// then
displayPortTestBufferSubstring(1, 8, " 91F");
}
/*
* Tests the battery notifications shown on the warnings OSD element.
*/
@ -874,6 +919,16 @@ TEST(OsdTest, TestFormatTimeString)
EXPECT_EQ(0, strcmp("01:59.00", buff));
}
TEST(OsdTest, TestConvertTemperatureUnits)
{
/* In Celsius */
osdConfigMutable()->units = OSD_UNIT_METRIC;
EXPECT_EQ(osdConvertTemperatureToSelectedUnit(330), 330);
/* In Fahrenheit */
osdConfigMutable()->units = OSD_UNIT_IMPERIAL;
EXPECT_EQ(osdConvertTemperatureToSelectedUnit(330), 914);
}
// STUBS
extern "C" {
@ -958,4 +1013,6 @@ extern "C" {
}
uint16_t getRssi(void) { return rssi; }
uint16_t getCoreTemperatureCelsius(void) { return simulationCoreTemperature; }
}