From 8c5957564622b5a0b7a0140d3f77f841432c3334 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 12 Nov 2020 18:49:08 +1100 Subject: [PATCH] AP_OSD: support callsign display on OSD use a file "callsign.txt" on the sdcard for callsign --- libraries/AP_OSD/AP_OSD.h | 7 +++++ libraries/AP_OSD/AP_OSD_Screen.cpp | 50 +++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/libraries/AP_OSD/AP_OSD.h b/libraries/AP_OSD/AP_OSD.h index 5bbde079e2..89526f70f9 100644 --- a/libraries/AP_OSD/AP_OSD.h +++ b/libraries/AP_OSD/AP_OSD.h @@ -190,6 +190,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}; + AP_OSD_Setting callsign{false, 0, 0}; void draw_altitude(uint8_t x, uint8_t y); void draw_bat_volt(uint8_t x, uint8_t y); @@ -243,6 +244,12 @@ private: void draw_bat2_vlt(uint8_t x, uint8_t y); void draw_bat2used(uint8_t x, uint8_t y); void draw_clk(uint8_t x, uint8_t y); + void draw_callsign(uint8_t x, uint8_t y); + + struct { + bool load_attempted; + const char *str; + } callsign_data; }; #endif // OSD_ENABLED diff --git a/libraries/AP_OSD/AP_OSD_Screen.cpp b/libraries/AP_OSD/AP_OSD_Screen.cpp index 68c89bd83e..c4e1c5d5b0 100644 --- a/libraries/AP_OSD/AP_OSD_Screen.cpp +++ b/libraries/AP_OSD/AP_OSD_Screen.cpp @@ -40,6 +40,7 @@ #if APM_BUILD_TYPE(APM_BUILD_Rover) #include #endif +#include #include #include @@ -858,6 +859,25 @@ const AP_Param::GroupInfo AP_OSD_Screen::var_info[] = { // @Range: 0 15 AP_SUBGROUPINFO(pluscode, "PLUSCODE", 52, AP_OSD_Screen, AP_OSD_Setting), #endif + +#if HAVE_FILESYSTEM_SUPPORT + // @Param: CALLSIGN_EN + // @DisplayName: CALLSIGN_EN + // @Description: Displays callsign from callsign.txt on microSD card + // @Values: 0:Disabled,1:Enabled + + // @Param: CALLSIGN_X + // @DisplayName: CALLSIGN_X + // @Description: Horizontal position on screen + // @Range: 0 29 + + // @Param: CALLSIGN_Y + // @DisplayName: CALLSIGN_Y + // @Description: Vertical position on screen + // @Range: 0 15 + AP_SUBGROUPINFO(callsign, "CALLSIGN", 53, AP_OSD_Screen, AP_OSD_Setting), +#endif + AP_GROUPEND }; @@ -1749,6 +1769,33 @@ void AP_OSD_Screen::draw_pluscode(uint8_t x, uint8_t y) } #endif +/* + support callsign display from a file called callsign.txt + */ +void AP_OSD_Screen::draw_callsign(uint8_t x, uint8_t y) +{ +#if HAVE_FILESYSTEM_SUPPORT + if (!callsign_data.load_attempted) { + callsign_data.load_attempted = true; + int fd = AP::FS().open("callsign.txt", O_RDONLY); + if (fd != -1) { + char s[20] {}; + int32_t len = AP::FS().read(fd, s, sizeof(s)-1); + // trim off whitespace + while (len > 0 && isspace(s[len-1])) { + s[len-1] = 0; + len--; + } + AP::FS().close(fd); + callsign_data.str = strdup(s); + } + } + if (callsign_data.str != nullptr) { + backend->write(x, y, false, callsign_data.str); + } +#endif +} + #define DRAW_SETTING(n) if (n.enabled) draw_ ## n(n.xpos, n.ypos) #if HAL_WITH_OSD_BITMAP @@ -1808,6 +1855,7 @@ void AP_OSD_Screen::draw(void) DRAW_SETTING(stat); DRAW_SETTING(climbeff); DRAW_SETTING(eff); + DRAW_SETTING(callsign); } #endif -#endif // OSD_ENABLED \ No newline at end of file +#endif // OSD_ENABLED