1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-19 14:25:20 +03:00

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_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_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_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_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])}, { "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 "rx/rx.h"
#include "sensors/adcinternal.h"
#include "sensors/barometer.h" #include "sensors/barometer.h"
#include "sensors/battery.h" #include "sensors/battery.h"
#include "sensors/esc_sensor.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) static void osdFormatAltitudeString(char * buff, int altitude, bool pad)
{ {
const int alt = osdGetMetersToSelectedUnit(altitude); const int alt = osdGetMetersToSelectedUnit(altitude);
@ -739,7 +762,7 @@ static bool osdDrawSingleElement(uint8_t item)
#ifdef USE_ESC_SENSOR #ifdef USE_ESC_SENSOR
case OSD_ESC_TMP: 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; break;
case OSD_ESC_RPM: case OSD_ESC_RPM:
@ -756,7 +779,12 @@ static bool osdDrawSingleElement(uint8_t item)
#ifdef USE_OSD_ADJUSTMENTS #ifdef USE_OSD_ADJUSTMENTS
case OSD_ADJUSTMENT_RANGE: case OSD_ADJUSTMENT_RANGE:
tfp_sprintf(buff, "%s: %3d", adjustmentRangeName, adjustmentRangeValue); 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; break;
#endif #endif
@ -835,6 +863,10 @@ static void osdDrawElements(void)
#ifdef USE_OSD_ADJUSTMENTS #ifdef USE_OSD_ADJUSTMENTS
osdDrawSingleElement(OSD_ADJUSTMENT_RANGE); osdDrawSingleElement(OSD_ADJUSTMENT_RANGE);
#endif #endif
#ifdef USE_ADC_INTERNAL
osdDrawSingleElement(OSD_CORE_TEMPERATURE);
#endif
} }
void pgResetFn_osdConfig(osdConfig_t *osdConfig) void pgResetFn_osdConfig(osdConfig_t *osdConfig)

View file

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

View file

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

View file

@ -52,6 +52,7 @@ extern "C" {
void osdRefresh(timeUs_t currentTimeUs); void osdRefresh(timeUs_t currentTimeUs);
void osdFormatTime(char * buff, osd_timer_precision_e precision, timeUs_t time); void osdFormatTime(char * buff, osd_timer_precision_e precision, timeUs_t time);
void osdFormatTimer(char *buff, bool showSymbol, int timerIndex); void osdFormatTimer(char *buff, bool showSymbol, int timerIndex);
int osdConvertTemperatureToSelectedUnit(int tempInDeciDegrees);
uint16_t rssi; uint16_t rssi;
attitudeEulerAngles_t attitude; attitudeEulerAngles_t attitude;
@ -77,6 +78,7 @@ extern "C" {
uint32_t simulationMahDrawn; uint32_t simulationMahDrawn;
int32_t simulationAltitude; int32_t simulationAltitude;
int32_t simulationVerticalSpeed; int32_t simulationVerticalSpeed;
uint16_t simulationCoreTemperature;
} }
/* #define DEBUG_OSD */ /* #define DEBUG_OSD */
@ -96,6 +98,7 @@ void setDefualtSimulationState()
simulationMahDrawn = 0; simulationMahDrawn = 0;
simulationAltitude = 0; simulationAltitude = 0;
simulationVerticalSpeed = 0; simulationVerticalSpeed = 0;
simulationCoreTemperature = 0;
} }
/* /*
@ -743,6 +746,48 @@ TEST(OsdTest, TestElementAltitude)
displayPortTestBufferSubstring(23, 7, " -2.4%c", SYM_M); 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. * 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)); 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 // STUBS
extern "C" { extern "C" {
@ -958,4 +1013,6 @@ extern "C" {
} }
uint16_t getRssi(void) { return rssi; } uint16_t getRssi(void) { return rssi; }
uint16_t getCoreTemperatureCelsius(void) { return simulationCoreTemperature; }
} }