Skip to content

Commit

Permalink
Merge pull request #10389 from iNavFlight/MrD-Switch-some-additional-…
Browse files Browse the repository at this point in the history
…settings-when-changing-battery-capacity-unit
  • Loading branch information
MrD-RC authored Sep 28, 2024
2 parents bc814f3 + 5b3b601 commit 678434f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/fc/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -3714,6 +3714,17 @@ static void cliSet(char *cmdline)
}

if (changeValue) {
// If changing the battery capacity unit, update the osd stats energy unit to match
if (strcmp(name, "battery_capacity_unit") == 0) {
if (batteryMetersConfig()->capacity_unit != (uint8_t)tmp.int_value) {
if (tmp.int_value == BAT_CAPACITY_UNIT_MAH) {
osdConfigMutable()->stats_energy_unit = OSD_STATS_ENERGY_UNIT_MAH;
} else {
osdConfigMutable()->stats_energy_unit = OSD_STATS_ENERGY_UNIT_WH;
}
}
}

cliSetIntFloatVar(val, tmp);

cliPrintf("%s set to ", name);
Expand Down
14 changes: 14 additions & 0 deletions src/main/fc/fc_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)
currentBatteryProfileMutable->capacity.value = sbufReadU32(src);
currentBatteryProfileMutable->capacity.warning = sbufReadU32(src);
currentBatteryProfileMutable->capacity.critical = sbufReadU32(src);
uint8_t currentCapacityUnit = batteryMetersConfigMutable()->capacity_unit;
batteryMetersConfigMutable()->capacity_unit = sbufReadU8(src);
if ((batteryMetersConfig()->voltageSource != BAT_VOLTAGE_RAW) && (batteryMetersConfig()->voltageSource != BAT_VOLTAGE_SAG_COMP)) {
batteryMetersConfigMutable()->voltageSource = BAT_VOLTAGE_RAW;
Expand All @@ -2090,6 +2091,12 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)
if ((batteryMetersConfig()->capacity_unit != BAT_CAPACITY_UNIT_MAH) && (batteryMetersConfig()->capacity_unit != BAT_CAPACITY_UNIT_MWH)) {
batteryMetersConfigMutable()->capacity_unit = BAT_CAPACITY_UNIT_MAH;
return MSP_RESULT_ERROR;
} else if (currentCapacityUnit != batteryMetersConfig()->capacity_unit) {
if (batteryMetersConfig()->capacity_unit == BAT_CAPACITY_UNIT_MAH) {
osdConfigMutable()->stats_energy_unit = OSD_STATS_ENERGY_UNIT_MAH;
} else {
osdConfigMutable()->stats_energy_unit = OSD_STATS_ENERGY_UNIT_WH;
}
}
} else
return MSP_RESULT_ERROR;
Expand Down Expand Up @@ -2121,6 +2128,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)
currentBatteryProfileMutable->capacity.value = sbufReadU32(src);
currentBatteryProfileMutable->capacity.warning = sbufReadU32(src);
currentBatteryProfileMutable->capacity.critical = sbufReadU32(src);
uint8_t currentCapacityUnit = batteryMetersConfigMutable()->capacity_unit;
batteryMetersConfigMutable()->capacity_unit = sbufReadU8(src);
if ((batteryMetersConfig()->voltageSource != BAT_VOLTAGE_RAW) && (batteryMetersConfig()->voltageSource != BAT_VOLTAGE_SAG_COMP)) {
batteryMetersConfigMutable()->voltageSource = BAT_VOLTAGE_RAW;
Expand All @@ -2129,6 +2137,12 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)
if ((batteryMetersConfig()->capacity_unit != BAT_CAPACITY_UNIT_MAH) && (batteryMetersConfig()->capacity_unit != BAT_CAPACITY_UNIT_MWH)) {
batteryMetersConfigMutable()->capacity_unit = BAT_CAPACITY_UNIT_MAH;
return MSP_RESULT_ERROR;
} else if (currentCapacityUnit != batteryMetersConfig()->capacity_unit) {
if (batteryMetersConfig()->capacity_unit == BAT_CAPACITY_UNIT_MAH) {
osdConfigMutable()->stats_energy_unit = OSD_STATS_ENERGY_UNIT_MAH;
} else {
osdConfigMutable()->stats_energy_unit = OSD_STATS_ENERGY_UNIT_WH;
}
}
} else
return MSP_RESULT_ERROR;
Expand Down

0 comments on commit 678434f

Please sign in to comment.