Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gyro temperature element in OSD #3978

Merged
merged 9 commits into from Nov 24, 2018
Merged
2 changes: 2 additions & 0 deletions src/main/cms/cms_menu_osd.c
Expand Up @@ -244,6 +244,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("GYRO TEMPERATURE", OSD_GYRO_TEMPERATURE),
nmaggioni marked this conversation as resolved.
Show resolved Hide resolved

OSD_BACK_ENTRY,
OSD_END_ENTRY,
};
Expand Down
31 changes: 31 additions & 0 deletions src/main/io/osd.c
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,28 @@ 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/5)) + 32;
nmaggioni marked this conversation as resolved.
Show resolved Hide resolved
break;
case OSD_UNIT_UK:
FALLTHROUGH;
case OSD_UNIT_METRIC:
units_symbol = SYM_TEMP_C;
break;
}
tfp_sprintf(buff, "%d%c", (int) temperature, units_symbol);
nmaggioni marked this conversation as resolved.
Show resolved Hide resolved
}

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 @@ -2223,6 +2246,13 @@ static bool osdDrawSingleElement(uint8_t item)
break;
}

case OSD_GYRO_TEMPERATURE:
nmaggioni marked this conversation as resolved.
Show resolved Hide resolved
{
int16_t temperature = getCurrentTemperature();
osdFormatTemperatureSymbol(buff, temperature);
break;
}

case OSD_WIND_SPEED_HORIZONTAL:
#ifdef USE_WIND_ESTIMATOR
{
Expand Down Expand Up @@ -2434,6 +2464,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_GYRO_TEMPERATURE] = OSD_POS(23, 2);
nmaggioni marked this conversation as resolved.
Show resolved Hide resolved

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
Expand Up @@ -121,6 +121,7 @@ typedef enum {
OSD_MC_VEL_Y_PID_OUTPUTS,
OSD_MC_VEL_Z_PID_OUTPUTS,
OSD_MC_POS_XYZ_P_OUTPUTS,
OSD_GYRO_TEMPERATURE,
nmaggioni marked this conversation as resolved.
Show resolved Hide resolved
OSD_ITEM_COUNT // MUST BE LAST
} osd_items_e;

Expand Down