Skip to content

Commit

Permalink
pbio/battery: Use initial battery value when available.
Browse files Browse the repository at this point in the history
Ensures the workaround is only applied as needed, so we don't delay the battery-full indicator. Also stretch to nearly a full second as needed on Technic Hub.
  • Loading branch information
laurensvalk committed Feb 14, 2025
1 parent 16846a9 commit a0c5930
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions lib/pbio/drv/battery/battery_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,6 @@ pbio_error_t pbdrv_battery_get_current_now(uint16_t *value) {

pbio_error_t pbdrv_battery_get_voltage_now(uint16_t *value) {

if (pbdrv_clock_get_ms() - pbdrv_battery_start_time < 100) {
// The battery voltage is not reliable when the hub is just powered on.
// This suppresses immediate low-battery warnings when the hub is
// powered on. REVISIT: This can be integrated in the ADC driver to
// hold the pbdrv init busy flag after currently pending driver changes
// are merged.
*value = 7500;
return PBIO_SUCCESS;
}

uint16_t raw;
pbio_error_t err;

Expand Down Expand Up @@ -134,6 +124,15 @@ pbio_error_t pbdrv_battery_get_voltage_now(uint16_t *value) {
PBDRV_CONFIG_BATTERY_ADC_VOLTAGE_RAW_MAX + current *
PBDRV_CONFIG_BATTERY_ADC_CURRENT_CORRECTION / 16;

if (*value < 7000 && (pbdrv_clock_get_ms() - pbdrv_battery_start_time) < 1000) {
// The battery voltage is not reliable when the hub is just powered on.
// This suppresses immediate low-battery warnings when the hub is
// powered on. REVISIT: This can be integrated in the ADC driver to
// hold the pbdrv init busy flag after currently pending driver changes
// are merged.
*value = 7000;
}

return PBIO_SUCCESS;
}

Expand Down

0 comments on commit a0c5930

Please sign in to comment.