Skip to content

Commit

Permalink
Merge pull request #3978 from nmaggioni/osd_temperature
Browse files Browse the repository at this point in the history
Gyro temperature element in OSD
  • Loading branch information
digitalentity authored Nov 24, 2018
2 parents 872b2e3 + 96a8cd2 commit f3b121f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/cms/cms_menu_osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ static const OSD_Entry menuOsdElemsEntries[] =
OSD_ELEMENT_ENTRY("WIND HOR", OSD_WIND_SPEED_HORIZONTAL),
OSD_ELEMENT_ENTRY("WIND VERT", OSD_WIND_SPEED_VERTICAL),

OSD_ELEMENT_ENTRY("TEMPERATURE", OSD_TEMPERATURE),

OSD_BACK_ENTRY,
OSD_END_ENTRY,
};
Expand Down
33 changes: 33 additions & 0 deletions src/main/io/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
#include "sensors/diagnostics.h"
#include "sensors/sensors.h"
#include "sensors/pitotmeter.h"
#include "sensors/temperature.h"

#ifdef USE_HARDWARE_REVISION_DETECTION
#include "hardware_revision.h"
Expand Down Expand Up @@ -484,6 +485,30 @@ static uint16_t osdConvertRSSI(void)
return constrain(getRSSI() * 100 / RSSI_MAX_VALUE, 0, 99);
}

/**
* Converts temperature into a string based on the current unit system
* postfixed with a symbol to indicate the unit used.
* @param temperature Raw temperature (i.e. as taken from getCurrentTemperature() in degC)
*/
static void osdFormatTemperatureSymbol(char *buff, float temperature)
{
int units_symbol;
switch ((osd_unit_e)osdConfig()->units) {
case OSD_UNIT_IMPERIAL:
units_symbol = SYM_TEMP_F;
temperature = (temperature * (9.0f/5)) + 32;
break;
case OSD_UNIT_UK:
FALLTHROUGH;
case OSD_UNIT_METRIC:
units_symbol = SYM_TEMP_C;
break;
}
osdFormatCentiNumber(buff, (int32_t) (temperature * 100), 0, 0, 0, 3);
buff[3] = units_symbol;
buff[4] = '\0';
}

static void osdFormatCoordinate(char *buff, char sym, int32_t val)
{
// up to 4 for number + 1 for the symbol + null terminator + fill the rest with decimals
Expand Down Expand Up @@ -2236,6 +2261,13 @@ static bool osdDrawSingleElement(uint8_t item)
break;
}

case OSD_TEMPERATURE:
{
int16_t temperature = getCurrentTemperature();
osdFormatTemperatureSymbol(buff, temperature);
break;
}

case OSD_WIND_SPEED_HORIZONTAL:
#ifdef USE_WIND_ESTIMATOR
{
Expand Down Expand Up @@ -2452,6 +2484,7 @@ void pgResetFn_osdConfig(osdConfig_t *osdConfig)
osdConfig->item_pos[0][OSD_MC_POS_XYZ_P_OUTPUTS] = OSD_POS(2, 12);

osdConfig->item_pos[0][OSD_POWER] = OSD_POS(15, 1);
osdConfig->item_pos[0][OSD_TEMPERATURE] = OSD_POS(23, 2);

osdConfig->item_pos[0][OSD_AIR_SPEED] = OSD_POS(3, 5);
osdConfig->item_pos[0][OSD_WIND_SPEED_HORIZONTAL] = OSD_POS(3, 6);
Expand Down
1 change: 1 addition & 0 deletions src/main/io/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ typedef enum {
OSD_MC_VEL_Z_PID_OUTPUTS,
OSD_MC_POS_XYZ_P_OUTPUTS,
OSD_3D_SPEED,
OSD_TEMPERATURE,
OSD_ITEM_COUNT // MUST BE LAST
} osd_items_e;

Expand Down

0 comments on commit f3b121f

Please sign in to comment.