From b00d3e00bc8e3b4a61b5a8f06710e5040eacef01 Mon Sep 17 00:00:00 2001 From: giacomo892 Date: Thu, 20 Aug 2020 07:24:42 +0200 Subject: [PATCH] AP_OSD: Add OLC (pluscode) element --- libraries/AP_OSD/AP_OSD.h | 3 +++ libraries/AP_OSD/AP_OSD_Screen.cpp | 32 +++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/libraries/AP_OSD/AP_OSD.h b/libraries/AP_OSD/AP_OSD.h index f9a000b2b2..bb5e81aa43 100644 --- a/libraries/AP_OSD/AP_OSD.h +++ b/libraries/AP_OSD/AP_OSD.h @@ -175,6 +175,7 @@ private: AP_OSD_Setting bat2_vlt{false, 0, 0}; AP_OSD_Setting bat2used{false, 0, 0}; AP_OSD_Setting clk{false, 0, 0}; + AP_OSD_Setting pluscode{false, 0, 0}; // MSP OSD only AP_OSD_Setting sidebars{false, 0, 0}; @@ -185,6 +186,7 @@ private: AP_OSD_Setting cell_volt{true, 1, 1}; AP_OSD_Setting batt_bar{true, 1, 1}; AP_OSD_Setting arming{true, 1, 1}; + void draw_altitude(uint8_t x, uint8_t y); void draw_bat_volt(uint8_t x, uint8_t y); @@ -206,6 +208,7 @@ private: void draw_aspd1(uint8_t x, uint8_t y); void draw_aspd2(uint8_t x, uint8_t y); void draw_vspeed(uint8_t x, uint8_t y); + void draw_pluscode(uint8_t x, uint8_t y); //helper functions void draw_speed_vector(uint8_t x, uint8_t y, Vector2f v, int32_t yaw); diff --git a/libraries/AP_OSD/AP_OSD_Screen.cpp b/libraries/AP_OSD/AP_OSD_Screen.cpp index 506b889628..48f524a9eb 100644 --- a/libraries/AP_OSD/AP_OSD_Screen.cpp +++ b/libraries/AP_OSD/AP_OSD_Screen.cpp @@ -35,7 +35,7 @@ #include #include #include - +#include #include #include @@ -706,6 +706,22 @@ const AP_Param::GroupInfo AP_OSD_Screen::var_info[] = { // @Range: 0 15 AP_SUBGROUPINFO(clk, "CLK", 43, AP_OSD_Screen, AP_OSD_Setting), + // @Param: PLUSCODE_EN + // @DisplayName: PLUSCODE_EN + // @Description: Displays total flight time + // @Values: 0:Disabled,1:Enabled + + // @Param: PLUSCODE_X + // @DisplayName: PLUSCODE_X + // @Description: Horizontal position on screen + // @Range: 0 29 + + // @Param: PLUSCODE_Y + // @DisplayName: PLUSCODE_Y + // @Description: Vertical position on screen + // @Range: 0 15 + AP_SUBGROUPINFO(pluscode, "PLUSCODE", 44, AP_OSD_Screen, AP_OSD_Setting), + #if HAL_MSP_ENABLED // @Param: SIDEBARS_EN // @DisplayName: SIDEBARS_EN @@ -1690,6 +1706,19 @@ void AP_OSD_Screen::draw_clk(uint8_t x, uint8_t y) } } +void AP_OSD_Screen::draw_pluscode(uint8_t x, uint8_t y) +{ + AP_GPS & gps = AP::gps(); + const Location &loc = gps.location(); + char buff[16]; + if (gps.status() == AP_GPS::NO_GPS || gps.status() == AP_GPS::NO_FIX){ + backend->write(x, y, false, "--------+--"); + } else { + AP_OLC::olc_encode(loc.lat, loc.lng, 10, buff, sizeof(buff)); + backend->write(x, y, false, buff); + } +} + #define DRAW_SETTING(n) if (n.enabled) draw_ ## n(n.xpos, n.ypos) #if HAL_WITH_OSD_BITMAP @@ -1742,6 +1771,7 @@ void AP_OSD_Screen::draw(void) DRAW_SETTING(gps_latitude); DRAW_SETTING(gps_longitude); + DRAW_SETTING(pluscode); DRAW_SETTING(dist); DRAW_SETTING(stat); DRAW_SETTING(climbeff);