From 3bd525b0ae08890dc95b77d4aae1179cc93c94c4 Mon Sep 17 00:00:00 2001 From: Florian Ragwitz Date: Sat, 18 Mar 2017 11:40:38 -0700 Subject: [PATCH] Add average cell voltage to OSD This can make it a little easier for some pilots to see where their battery is at, especially if they move forth and back between different cell counts a lot. --- src/main/cms/cms_menu_osd.c | 1 + src/main/fc/cli.c | 1 + src/main/io/osd.c | 15 ++++++++++++++- src/main/io/osd.h | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/cms/cms_menu_osd.c b/src/main/cms/cms_menu_osd.c index dc56cb785..2de93f9b5 100644 --- a/src/main/cms/cms_menu_osd.c +++ b/src/main/cms/cms_menu_osd.c @@ -105,6 +105,7 @@ OSD_Entry menuOsdActiveElemsEntries[] = {"--- ACTIV ELEM ---", OME_Label, NULL, NULL, 0}, {"RSSI", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_RSSI_VALUE], 0}, {"MAIN BATTERY", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_MAIN_BATT_VOLTAGE], 0}, + {"AVG CELL VOLTAGE", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_AVG_CELL_VOLTAGE], 0}, {"HORIZON", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_ARTIFICIAL_HORIZON], 0}, {"HORIZON SIDEBARS", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_HORIZON_SIDEBARS], 0}, {"UPTIME", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_ONTIME], 0}, diff --git a/src/main/fc/cli.c b/src/main/fc/cli.c index ae60949a3..a35c6c2a1 100755 --- a/src/main/fc/cli.c +++ b/src/main/fc/cli.c @@ -835,6 +835,7 @@ static const clivalue_t valueTable[] = { { "osd_power_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_POWER]) }, { "osd_pidrate_profile_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_PIDRATE_PROFILE]) }, { "osd_battery_warning_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_MAIN_BATT_WARNING]) }, + { "osd_avg_cell_voltage_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_AVG_CELL_VOLTAGE]) }, #endif // PG_SYSTEM_CONFIG diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 542e11dde..633bf3d01 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -422,6 +422,14 @@ static void osdDrawSingleElement(uint8_t item) break; } + case OSD_AVG_CELL_VOLTAGE: + { + uint16_t cellV = getVbat() * 10 / batteryCellCount; + buff[0] = SYM_BATT_5; + sprintf(buff + 1, "%d.%dV", cellV / 100, cellV % 100); + break; + } + default: return; } @@ -471,6 +479,7 @@ void osdDrawElements(void) osdDrawSingleElement(OSD_POWER); osdDrawSingleElement(OSD_PIDRATE_PROFILE); osdDrawSingleElement(OSD_MAIN_BATT_WARNING); + osdDrawSingleElement(OSD_AVG_CELL_VOLTAGE); #ifdef GPS #ifdef CMS @@ -488,7 +497,6 @@ void osdDrawElements(void) void pgResetFn_osdConfig(osdConfig_t *osdProfile) { osdProfile->item_pos[OSD_RSSI_VALUE] = OSD_POS(8, 1) | VISIBLE_FLAG; - osdProfile->item_pos[OSD_MAIN_BATT_VOLTAGE] = OSD_POS(12, 1) | VISIBLE_FLAG; osdProfile->item_pos[OSD_ARTIFICIAL_HORIZON] = OSD_POS(8, 6) | VISIBLE_FLAG; osdProfile->item_pos[OSD_HORIZON_SIDEBARS] = OSD_POS(8, 6) | VISIBLE_FLAG; osdProfile->item_pos[OSD_ONTIME] = OSD_POS(22, 1) | VISIBLE_FLAG; @@ -508,6 +516,8 @@ void pgResetFn_osdConfig(osdConfig_t *osdProfile) osdProfile->item_pos[OSD_POWER] = OSD_POS(1, 10) | VISIBLE_FLAG; osdProfile->item_pos[OSD_PIDRATE_PROFILE] = OSD_POS(25, 10) | VISIBLE_FLAG; osdProfile->item_pos[OSD_MAIN_BATT_WARNING] = OSD_POS(9, 10) | VISIBLE_FLAG; + osdProfile->item_pos[OSD_MAIN_BATT_VOLTAGE] = OSD_POS(12, 1) | VISIBLE_FLAG; + osdProfile->item_pos[OSD_AVG_CELL_VOLTAGE] = OSD_POS(12, 2) | VISIBLE_FLAG; osdProfile->units = OSD_UNIT_METRIC; osdProfile->rssi_alarm = 20; @@ -575,9 +585,11 @@ void osdUpdateAlarms(void) if (getVbat() <= (batteryWarningVoltage - 1)) { SET_BLINK(OSD_MAIN_BATT_VOLTAGE); SET_BLINK(OSD_MAIN_BATT_WARNING); + SET_BLINK(OSD_AVG_CELL_VOLTAGE); } else { CLR_BLINK(OSD_MAIN_BATT_VOLTAGE); CLR_BLINK(OSD_MAIN_BATT_WARNING); + CLR_BLINK(OSD_AVG_CELL_VOLTAGE); } if (STATE(GPS_FIX) == 0) @@ -610,6 +622,7 @@ void osdResetAlarms(void) CLR_BLINK(OSD_FLYTIME); CLR_BLINK(OSD_MAH_DRAWN); CLR_BLINK(OSD_ALTITUDE); + CLR_BLINK(OSD_AVG_CELL_VOLTAGE); } static void osdResetStats(void) diff --git a/src/main/io/osd.h b/src/main/io/osd.h index 7381a97f3..60fd65963 100755 --- a/src/main/io/osd.h +++ b/src/main/io/osd.h @@ -48,6 +48,7 @@ typedef enum { OSD_POWER, OSD_PIDRATE_PROFILE, OSD_MAIN_BATT_WARNING, + OSD_AVG_CELL_VOLTAGE, OSD_ITEM_COUNT // MUST BE LAST } osd_items_e; -- 2.11.4.GIT