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

Add raw rangefinder distance to OSD #6801

Merged
merged 3 commits into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/main/io/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ FILE_COMPILE_FOR_SPEED
#include "sensors/pitotmeter.h"
#include "sensors/temperature.h"
#include "sensors/esc_sensor.h"
#include "sensors/rangefinder.h"

#include "programming/logic_condition.h"
#include "programming/global_variables.h"
Expand Down Expand Up @@ -312,11 +313,11 @@ static void osdLeftAlignString(char *buff)
* prefixed by a a symbol to indicate the unit used.
* @param dist Distance in centimeters
*/
static void osdFormatDistanceSymbol(char *buff, int32_t dist)
static void osdFormatDistanceSymbol(char *buff, int32_t dist, uint8_t decimals)
{
switch ((osd_unit_e)osdConfig()->units) {
case OSD_UNIT_IMPERIAL:
if (osdFormatCentiNumber(buff, CENTIMETERS_TO_CENTIFEET(dist), FEET_PER_MILE, 0, 3, 3)) {
if (osdFormatCentiNumber(buff, CENTIMETERS_TO_CENTIFEET(dist), FEET_PER_MILE, decimals, 3, 3)) {
buff[3] = SYM_DIST_MI;
} else {
buff[3] = SYM_DIST_FT;
Expand All @@ -326,7 +327,7 @@ static void osdFormatDistanceSymbol(char *buff, int32_t dist)
case OSD_UNIT_UK:
FALLTHROUGH;
case OSD_UNIT_METRIC:
if (osdFormatCentiNumber(buff, dist, METERS_PER_KILOMETER, 0, 3, 3)) {
if (osdFormatCentiNumber(buff, dist, METERS_PER_KILOMETER, decimals, 3, 3)) {
buff[3] = SYM_DIST_KM;
} else {
buff[3] = SYM_DIST_M;
Expand Down Expand Up @@ -1458,7 +1459,7 @@ static bool osdDrawSingleElement(uint8_t item)
case OSD_HOME_DIST:
{
buff[0] = SYM_HOME;
osdFormatDistanceSymbol(&buff[1], GPS_distanceToHome * 100);
osdFormatDistanceSymbol(&buff[1], GPS_distanceToHome * 100, 0);
uint16_t dist_alarm = osdConfig()->dist_alarm;
if (dist_alarm > 0 && GPS_distanceToHome > dist_alarm) {
TEXT_ATTRIBUTES_ADD_BLINK(elemAttr);
Expand All @@ -1468,7 +1469,7 @@ static bool osdDrawSingleElement(uint8_t item)

case OSD_TRIP_DIST:
buff[0] = SYM_TOTAL;
osdFormatDistanceSymbol(buff + 1, getTotalTravelDistance());
osdFormatDistanceSymbol(buff + 1, getTotalTravelDistance(), 0);
break;

case OSD_HEADING:
Expand Down Expand Up @@ -1586,6 +1587,19 @@ static bool osdDrawSingleElement(uint8_t item)
break;
}

#ifdef USE_RANGEFINDER
case OSD_RANGEFINDER:
{
int32_t range = rangefinderGetLatestRawAltitude();
if (range < 0) {
buff[0] = '-';
} else {
osdFormatDistanceSymbol(buff, range, 1);
}
}
break;
#endif

case OSD_ONTIME:
{
osdFormatOnTime(buff);
Expand Down Expand Up @@ -1657,7 +1671,7 @@ static bool osdDrawSingleElement(uint8_t item)
buff[5] = '\0';
TEXT_ATTRIBUTES_ADD_BLINK(elemAttr);
} else {
osdFormatDistanceSymbol(buff + 1, distanceMeters * 100);
osdFormatDistanceSymbol(buff + 1, distanceMeters * 100, 0);
if (distanceMeters == 0)
TEXT_ATTRIBUTES_ADD_BLINK(elemAttr);
}
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 @@ -220,6 +220,7 @@ typedef enum {
OSD_TPA,
OSD_NAV_FW_CONTROL_SMOOTHNESS,
OSD_VERSION,
OSD_RANGEFINDER,
OSD_ITEM_COUNT // MUST BE LAST
} osd_items_e;

Expand Down