Skip to content

Commit a0c5930

Browse files
committed
pbio/battery: Use initial battery value when available.
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.
1 parent 16846a9 commit a0c5930

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

lib/pbio/drv/battery/battery_adc.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,6 @@ pbio_error_t pbdrv_battery_get_current_now(uint16_t *value) {
9494

9595
pbio_error_t pbdrv_battery_get_voltage_now(uint16_t *value) {
9696

97-
if (pbdrv_clock_get_ms() - pbdrv_battery_start_time < 100) {
98-
// The battery voltage is not reliable when the hub is just powered on.
99-
// This suppresses immediate low-battery warnings when the hub is
100-
// powered on. REVISIT: This can be integrated in the ADC driver to
101-
// hold the pbdrv init busy flag after currently pending driver changes
102-
// are merged.
103-
*value = 7500;
104-
return PBIO_SUCCESS;
105-
}
106-
10797
uint16_t raw;
10898
pbio_error_t err;
10999

@@ -134,6 +124,15 @@ pbio_error_t pbdrv_battery_get_voltage_now(uint16_t *value) {
134124
PBDRV_CONFIG_BATTERY_ADC_VOLTAGE_RAW_MAX + current *
135125
PBDRV_CONFIG_BATTERY_ADC_CURRENT_CORRECTION / 16;
136126

127+
if (*value < 7000 && (pbdrv_clock_get_ms() - pbdrv_battery_start_time) < 1000) {
128+
// The battery voltage is not reliable when the hub is just powered on.
129+
// This suppresses immediate low-battery warnings when the hub is
130+
// powered on. REVISIT: This can be integrated in the ADC driver to
131+
// hold the pbdrv init busy flag after currently pending driver changes
132+
// are merged.
133+
*value = 7000;
134+
}
135+
137136
return PBIO_SUCCESS;
138137
}
139138

0 commit comments

Comments
 (0)