Skip to content

Commit

Permalink
Added climb efficiency
Browse files Browse the repository at this point in the history
  • Loading branch information
MrD-RC authored and sensei-hacker committed Nov 7, 2022
1 parent 4b3206c commit 9341697
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/drivers/osd_symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@
#define SYM_GLIDE_DIST 0xD0 // 208 Glide Distance
#define SYM_GLIDE_MINS 0xD1 // 209 Glide Minutes

#define SYM_MAH_V_FT_0 0xD5 // 213 mAh/v-ft left
#define SYM_MAH_V_FT_1 0xD6 // 214 mAh/v-ft right
#define SYM_MAH_V_M_0 0xD7 // 215 mAh/v-m left
#define SYM_MAH_V_M_1 0xD8 // 216 mAh/v-m right


#define SYM_LOGO_START 0x101 // 257 to 280, INAV logo
#define SYM_LOGO_WIDTH 6
Expand Down
60 changes: 60 additions & 0 deletions src/main/io/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2301,6 +2301,66 @@ static bool osdDrawSingleElement(uint8_t item)
buff[4] = '\0';
break;
}
case OSD_CLIMB_EFFICIENCY:
{
// amperage is in centi amps, vertical speed is in cms/s. We want
// mah/dist only to show when vertical speed > 1m/s.
static pt1Filter_t eFilterState;
static timeUs_t efficiencyUpdated = 0;
int32_t value = 0;
bool moreThanAh = false;
timeUs_t currentTimeUs = micros();
timeDelta_t efficiencyTimeDelta = cmpTimeUs(currentTimeUs, efficiencyUpdated);
if (getEstimatedActualVelocity(Z) > 0) {
if (efficiencyTimeDelta >= EFFICIENCY_UPDATE_INTERVAL) {
value = pt1FilterApply4(&eFilterState, ((float)getAmperage() / getEstimatedActualVelocity(Z)) / 0.0036f, 1, US2S(efficiencyTimeDelta));

efficiencyUpdated = currentTimeUs;
} else {
value = eFilterState.state;
}
}
bool efficiencyValid = (value > 0) && (getEstimatedActualVelocity(Z) > 100);
switch (osdConfig()->units) {
case OSD_UNIT_UK:
FALLTHROUGH;
case OSD_UNIT_GA:
FALLTHROUGH;
case OSD_UNIT_IMPERIAL:
// mAh/foot
moreThanAh = osdFormatCentiNumber(buff, value * METERS_PER_FOOT / 10, 1, 0, 2, 3);
if (!moreThanAh) {
tfp_sprintf(buff, "%s%c%c", buff, SYM_MAH_V_FT_0, SYM_MAH_V_FT_1);
} else {
tfp_sprintf(buff, "%s%c", buff, SYM_AH_MI);
}
if (!efficiencyValid) {
buff[0] = buff[1] = buff[2] = '-';
buff[3] = SYM_MAH_MI_0;
buff[4] = SYM_MAH_MI_1;
buff[5] = '\0';
}
break;
case OSD_UNIT_METRIC_MPH:
FALLTHROUGH;
case OSD_UNIT_METRIC:
// mAh/metre
moreThanAh = osdFormatCentiNumber(buff, value * 100, 1, 0, 2, 3);
if (!moreThanAh) {
tfp_sprintf(buff, "%s%c%c", buff, SYM_MAH_V_M_0, SYM_MAH_V_M_1);
} else {
tfp_sprintf(buff, "%s%c", buff, SYM_AH_KM);
}
if (!efficiencyValid) {
buff[0] = buff[1] = buff[2] = '-';
buff[3] = SYM_MAH_KM_0;
buff[4] = SYM_MAH_KM_1;
buff[5] = '\0';
}
break;
}
break;
}
case OSD_GLIDE_TIME_REMAINING:
{
uint16_t glideSeconds = osdGetRemainingGlideTime();
Expand Down
1 change: 1 addition & 0 deletions src/main/io/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ typedef enum {
OSD_FW_LEVEL_TRIM,
OSD_GLIDE_TIME_REMAINING,
OSD_GLIDE_RANGE,
OSD_CLIMB_EFFICIENCY,
OSD_ITEM_COUNT // MUST BE LAST
} osd_items_e;

Expand Down

0 comments on commit 9341697

Please sign in to comment.