From d3d4dff9ba46453a52ebbf7f3f0250199f4d2d45 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 17 Nov 2019 11:36:07 +1100 Subject: [PATCH] AP_OSD: add clock panel --- libraries/AP_OSD/AP_OSD.h | 2 ++ libraries/AP_OSD/AP_OSD_Screen.cpp | 33 +++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/libraries/AP_OSD/AP_OSD.h b/libraries/AP_OSD/AP_OSD.h index 33730fa6f5..daf27f44bb 100644 --- a/libraries/AP_OSD/AP_OSD.h +++ b/libraries/AP_OSD/AP_OSD.h @@ -115,6 +115,7 @@ private: AP_OSD_Setting atemp{false, 0, 0}; AP_OSD_Setting bat2_vlt{false, 0, 0}; AP_OSD_Setting bat2used{false, 0, 0}; + AP_OSD_Setting clk{false, 0, 0}; bool check_option(uint32_t option); @@ -179,6 +180,7 @@ private: void draw_atemp(uint8_t x, uint8_t y); 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); }; class AP_OSD { diff --git a/libraries/AP_OSD/AP_OSD_Screen.cpp b/libraries/AP_OSD/AP_OSD_Screen.cpp index c24469487d..02374b361b 100644 --- a/libraries/AP_OSD/AP_OSD_Screen.cpp +++ b/libraries/AP_OSD/AP_OSD_Screen.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -687,7 +688,23 @@ const AP_Param::GroupInfo AP_OSD_Screen::var_info[] = { // @Description: Vertical position on screen // @Range: 0 15 AP_SUBGROUPINFO(aspd1, "ASPD1", 42, AP_OSD_Screen, AP_OSD_Setting), - + + // @Param: CLK_EN + // @DisplayName: CLK_EN + // @Description: Displays a clock panel based on AP_RTC local time + // @Values: 0:Disabled,1:Enabled + + // @Param: CLK_X + // @DisplayName: CLK_X + // @Description: Horizontal position on screen + // @Range: 0 29 + + // @Param: CLK_Y + // @DisplayName: CLK_Y + // @Description: Vertical position on screen + // @Range: 0 15 + AP_SUBGROUPINFO(clk, "CLK", 43, AP_OSD_Screen, AP_OSD_Setting), + AP_GROUPEND }; @@ -782,6 +799,7 @@ AP_OSD_Screen::AP_OSD_Screen() #define SYM_FLY 0x9C #define SYM_EFF 0xF2 #define SYM_AH 0xF3 +#define SYM_CLK 0xBC void AP_OSD_Screen::set_backend(AP_OSD_Backend *_backend) { @@ -1516,6 +1534,18 @@ void AP_OSD_Screen::draw_aspd2(uint8_t x, uint8_t y) } } +void AP_OSD_Screen::draw_clk(uint8_t x, uint8_t y) +{ + AP_RTC &rtc = AP::rtc(); + uint8_t hour, min, sec; + uint16_t ms; + if (!rtc.get_local_time(hour, min, sec, ms)) { + backend->write(x, y, false, "%c--:--%", SYM_CLK); + } else { + backend->write(x, y, false, "%c%02u:%02u", SYM_CLK, hour, min); + } +} + #define DRAW_SETTING(n) if (n.enabled) draw_ ## n(n.xpos, n.ypos) void AP_OSD_Screen::draw(void) @@ -1557,6 +1587,7 @@ void AP_OSD_Screen::draw(void) DRAW_SETTING(atemp); DRAW_SETTING(hdop); DRAW_SETTING(flightime); + DRAW_SETTING(clk); #ifdef HAVE_AP_BLHELI_SUPPORT DRAW_SETTING(blh_temp);