diff --git a/src/main/cms/cms_menu_osd.c b/src/main/cms/cms_menu_osd.c index a7bb7d2fd..04bece5fc 100644 --- a/src/main/cms/cms_menu_osd.c +++ b/src/main/cms/cms_menu_osd.c @@ -68,6 +68,7 @@ OSD_Entry menuOsdActiveElemsEntries[] = {"HORIZON SIDEBARS", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_HORIZON_SIDEBARS], 0}, {"TIMER 1", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_ITEM_TIMER_1], 0}, {"TIMER 2", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_ITEM_TIMER_2], 0}, + {"REMAINING TIME ESTIMATE", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_REMAINING_TIME_ESTIMATE], 0}, {"FLY MODE", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_FLYMODE], 0}, {"NAME", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_CRAFT_NAME], 0}, {"THROTTLE", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_THROTTLE_POS], 0}, diff --git a/src/main/fc/settings.c b/src/main/fc/settings.c index 6f23b7628..b94c99aa1 100644 --- a/src/main/fc/settings.c +++ b/src/main/fc/settings.c @@ -698,6 +698,7 @@ const clivalue_t valueTable[] = { { "osd_rssi_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_RSSI_VALUE]) }, { "osd_tim_1_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_ITEM_TIMER_1]) }, { "osd_tim_2_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_ITEM_TIMER_2]) }, + { "osd_remaining_time_estimate_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_REMAINING_TIME_ESTIMATE]) }, { "osd_flymode_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_FLYMODE]) }, { "osd_throttle_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_THROTTLE_POS]) }, { "osd_vtx_channel_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_VTX_CHANNEL]) }, diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 261560012..3b7a5eb14 100755 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -452,6 +452,21 @@ static void osdDrawSingleElement(uint8_t item) break; } + case OSD_REMAINING_TIME_ESTIMATE: + { + const int mAhDrawn = getMAhDrawn(); + int remaining_time = (int)((osdConfig()->cap_alarm - mAhDrawn) * ((float)flyTime) / mAhDrawn); + + if (mAhDrawn < 0.1 * osdConfig()->cap_alarm) { + tfp_sprintf(buff, "--:--"); + } else if (mAhDrawn > osdConfig()->cap_alarm) { + tfp_sprintf(buff, "00:00"); + } else { + osdFormatTime(buff, OSD_TIMER_PREC_SECOND, remaining_time); + } + break; + } + case OSD_FLYMODE: { char *p = "ACRO"; @@ -769,6 +784,7 @@ static void osdDrawElements(void) osdDrawSingleElement(OSD_CROSSHAIRS); osdDrawSingleElement(OSD_ITEM_TIMER_1); osdDrawSingleElement(OSD_ITEM_TIMER_2); + osdDrawSingleElement(OSD_REMAINING_TIME_ESTIMATE); osdDrawSingleElement(OSD_FLYMODE); osdDrawSingleElement(OSD_THROTTLE_POS); osdDrawSingleElement(OSD_VTX_CHANNEL); @@ -950,9 +966,11 @@ void osdUpdateAlarms(void) if (getMAhDrawn() >= osdConfig()->cap_alarm) { SET_BLINK(OSD_MAH_DRAWN); SET_BLINK(OSD_MAIN_BATT_USAGE); + SET_BLINK(OSD_REMAINING_TIME_ESTIMATE); } else { CLR_BLINK(OSD_MAH_DRAWN); CLR_BLINK(OSD_MAIN_BATT_USAGE); + CLR_BLINK(OSD_REMAINING_TIME_ESTIMATE); } if (alt >= osdConfig()->alt_alarm) @@ -973,6 +991,7 @@ void osdResetAlarms(void) CLR_BLINK(OSD_MAIN_BATT_USAGE); CLR_BLINK(OSD_ITEM_TIMER_1); CLR_BLINK(OSD_ITEM_TIMER_2); + CLR_BLINK(OSD_REMAINING_TIME_ESTIMATE); } static void osdResetStats(void) diff --git a/src/main/io/osd.h b/src/main/io/osd.h index e3f5aef68..c79ccc213 100755 --- a/src/main/io/osd.h +++ b/src/main/io/osd.h @@ -83,6 +83,7 @@ typedef enum { OSD_COMPASS_BAR, OSD_ESC_TMP, OSD_ESC_RPM, + OSD_REMAINING_TIME_ESTIMATE, OSD_RTC_DATETIME, OSD_ADJUSTMENT_RANGE, OSD_ITEM_COUNT // MUST BE LAST diff --git a/src/test/unit/osd_unittest.cc b/src/test/unit/osd_unittest.cc index b807fe5a8..ec19ad19d 100644 --- a/src/test/unit/osd_unittest.cc +++ b/src/test/unit/osd_unittest.cc @@ -418,11 +418,12 @@ TEST(OsdTest, TestAlarms) // and // the following OSD elements are visible - osdConfigMutable()->item_pos[OSD_RSSI_VALUE] = OSD_POS(8, 1) | VISIBLE_FLAG; - osdConfigMutable()->item_pos[OSD_MAIN_BATT_VOLTAGE] = OSD_POS(12, 1) | VISIBLE_FLAG; - osdConfigMutable()->item_pos[OSD_ITEM_TIMER_1] = OSD_POS(20, 1) | VISIBLE_FLAG; - osdConfigMutable()->item_pos[OSD_ITEM_TIMER_2] = OSD_POS(1, 1) | VISIBLE_FLAG; - osdConfigMutable()->item_pos[OSD_ALTITUDE] = OSD_POS(23, 7) | VISIBLE_FLAG; + osdConfigMutable()->item_pos[OSD_RSSI_VALUE] = OSD_POS(8, 1) | VISIBLE_FLAG; + osdConfigMutable()->item_pos[OSD_MAIN_BATT_VOLTAGE] = OSD_POS(12, 1) | VISIBLE_FLAG; + osdConfigMutable()->item_pos[OSD_ITEM_TIMER_1] = OSD_POS(20, 1) | VISIBLE_FLAG; + osdConfigMutable()->item_pos[OSD_ITEM_TIMER_2] = OSD_POS(1, 1) | VISIBLE_FLAG; + osdConfigMutable()->item_pos[OSD_REMAINING_TIME_ESTIMATE] = OSD_POS(1, 2) | VISIBLE_FLAG; + osdConfigMutable()->item_pos[OSD_ALTITUDE] = OSD_POS(23, 7) | VISIBLE_FLAG; // and // this set of alarm values @@ -477,6 +478,7 @@ TEST(OsdTest, TestAlarms) simulationAltitude = 12000; simulationTime += 60e6; osdRefresh(simulationTime); + simulationMahDrawn = 999999; // then // elements showing values in alarm range should flash