Skip to content

Commit

Permalink
Merge pull request #9334 from iNavFlight/MrD_Enhance-mAh-remaining-OS…
Browse files Browse the repository at this point in the history
…D-Element

Enhance mAh remaining OSD element
  • Loading branch information
DzikuVx authored Oct 26, 2023
2 parents eb79057 + 6129f04 commit 692c61c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 22 deletions.
4 changes: 2 additions & 2 deletions docs/Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -4472,9 +4472,9 @@ LQ % indicator blinks below this value. For Crossfire use 70%, for Tracer use 50

---

### osd_mah_used_precision
### osd_mah_precision

Number of digits used to display mAh used.
Number of digits used for mAh precision. Currently used by mAh Used and Battery Remaining Capacity

| Default | Min | Max |
| --- | --- | --- |
Expand Down
6 changes: 3 additions & 3 deletions src/main/fc/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3557,9 +3557,9 @@ groups:
max: 6
default_value: 3

- name: osd_mah_used_precision
description: Number of digits used to display mAh used.
field: mAh_used_precision
- name: osd_mah_precision
description: Number of digits used for mAh precision. Currently used by mAh Used and Battery Remaining Capacity
field: mAh_precision
min: 4
max: 6
default_value: 4
Expand Down
53 changes: 37 additions & 16 deletions src/main/io/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1718,21 +1718,17 @@ static bool osdDrawSingleElement(uint8_t item)
}

case OSD_MAH_DRAWN: {
uint8_t mah_digits = osdConfig()->mAh_used_precision; // Initialize to config value
bool bfcompat = false; // Assume BFCOMPAT is off
uint8_t mah_digits = osdConfig()->mAh_precision; // Initialize to config value

#ifndef DISABLE_MSP_BF_COMPAT // IF BFCOMPAT is not supported, there's no need to check for it
if (isBfCompatibleVideoSystem(osdConfig())) {
bfcompat = true;
}
#endif

if (bfcompat) {
//BFcompat is unable to work with scaled values and it only has mAh symbol to work with
tfp_sprintf(buff, "%5d", (int)getMAhDrawn()); // Use 5 digits to allow 10Ah+ packs
tfp_sprintf(buff, "%5d", (int)getMAhDrawn()); // Use 5 digits to allow packs below 100Ah
buff[5] = SYM_MAH;
buff[6] = '\0';
} else {
} else
#endif
{
if (osdFormatCentiNumber(buff, getMAhDrawn() * 100, 1000, 0, (mah_digits - 2), mah_digits, false)) {
// Shown in Ah
buff[mah_digits] = SYM_AH;
Expand All @@ -1755,25 +1751,50 @@ static bool osdDrawSingleElement(uint8_t item)
break;

case OSD_BATTERY_REMAINING_CAPACITY:
{
bool unitsDrawn = false;

if (currentBatteryProfile->capacity.value == 0)
tfp_sprintf(buff, " NA");
else if (!batteryWasFullWhenPluggedIn())
tfp_sprintf(buff, " NF");
else if (currentBatteryProfile->capacity.unit == BAT_CAPACITY_UNIT_MAH)
tfp_sprintf(buff, "%4lu", (unsigned long)getBatteryRemainingCapacity());
else // currentBatteryProfile->capacity.unit == BAT_CAPACITY_UNIT_MWH
else if (currentBatteryProfile->capacity.unit == BAT_CAPACITY_UNIT_MAH) {
uint8_t mah_digits = osdConfig()->mAh_precision; // Initialize to config value

#ifndef DISABLE_MSP_BF_COMPAT // IF BFCOMPAT is not supported, there's no need to check for it
if (isBfCompatibleVideoSystem(osdConfig())) {
//BFcompat is unable to work with scaled values and it only has mAh symbol to work with
tfp_sprintf(buff, "%5d", (int)getBatteryRemainingCapacity()); // Use 5 digits to allow packs below 100Ah
buff[5] = SYM_MAH;
buff[6] = '\0';
unitsDrawn = true;
} else
#endif
{
if (osdFormatCentiNumber(buff, getBatteryRemainingCapacity() * 100, 1000, 0, (mah_digits - 2), mah_digits, false)) {
// Shown in Ah
buff[mah_digits] = SYM_AH;
} else {
// Shown in mAh
buff[mah_digits] = SYM_MAH;
}
buff[mah_digits + 1] = '\0';
unitsDrawn = true;
}
} else // currentBatteryProfile->capacity.unit == BAT_CAPACITY_UNIT_MWH
osdFormatCentiNumber(buff + 1, getBatteryRemainingCapacity() / 10, 0, 2, 0, 3, false);

buff[4] = currentBatteryProfile->capacity.unit == BAT_CAPACITY_UNIT_MAH ? SYM_MAH : SYM_WH;
buff[5] = '\0';
if (!unitsDrawn) {
buff[4] = currentBatteryProfile->capacity.unit == BAT_CAPACITY_UNIT_MAH ? SYM_MAH : SYM_WH;
buff[5] = '\0';
}

if (batteryUsesCapacityThresholds()) {
osdUpdateBatteryCapacityOrVoltageTextAttributes(&elemAttr);
}

break;

}
case OSD_BATTERY_REMAINING_PERCENT:
osdFormatBatteryChargeSymbol(buff);
tfp_sprintf(buff + 1, "%3d%%", calculateBatteryPercentage());
Expand Down Expand Up @@ -3741,7 +3762,7 @@ PG_RESET_TEMPLATE(osdConfig_t, osdConfig,
.pan_servo_offcentre_warning = SETTING_OSD_PAN_SERVO_OFFCENTRE_WARNING_DEFAULT,
.pan_servo_indicator_show_degrees = SETTING_OSD_PAN_SERVO_INDICATOR_SHOW_DEGREES_DEFAULT,
.esc_rpm_precision = SETTING_OSD_ESC_RPM_PRECISION_DEFAULT,
.mAh_used_precision = SETTING_OSD_MAH_USED_PRECISION_DEFAULT,
.mAh_precision = SETTING_OSD_MAH_PRECISION_DEFAULT,
.osd_switch_indicator0_name = SETTING_OSD_SWITCH_INDICATOR_ZERO_NAME_DEFAULT,
.osd_switch_indicator0_channel = SETTING_OSD_SWITCH_INDICATOR_ZERO_CHANNEL_DEFAULT,
.osd_switch_indicator1_name = SETTING_OSD_SWITCH_INDICATOR_ONE_NAME_DEFAULT,
Expand Down
2 changes: 1 addition & 1 deletion src/main/io/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ typedef struct osdConfig_s {
uint8_t telemetry; // use telemetry on displayed pixel line 0
uint8_t esc_rpm_precision; // Number of characters used for the RPM numbers.
uint16_t system_msg_display_time; // system message display time for multiple messages (ms)
uint8_t mAh_used_precision; // Number of numbers used for mAh drawn. Plently of packs now are > 9999 mAh
uint8_t mAh_precision; // Number of numbers used for mAh drawn. Plently of packs now are > 9999 mAh
uint8_t ahi_pitch_interval; // redraws AHI at set pitch interval (Not pixel OSD)
char osd_switch_indicator0_name[OSD_SWITCH_INDICATOR_NAME_LENGTH + 1]; // Name to use for switch indicator 0.
uint8_t osd_switch_indicator0_channel; // RC Channel to use for switch indicator 0.
Expand Down

0 comments on commit 692c61c

Please sign in to comment.