File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 44
55## [ Unreleased]
66
7+ ### Fixed
8+ - Fixed low-battery warning on boot ([ pybricks-micropython #292 ] ) when the
9+ voltage is not actually low.
10+
711## [ 3.6.0b3] - 2025-02-14
812
913### Added
Original file line number Diff line number Diff line change 4343
4444#include <pbdrv/adc.h>
4545#include <pbdrv/battery.h>
46+ #include <pbdrv/clock.h>
4647#include <pbdrv/gpio.h>
4748#include <pbio/error.h>
4849
5253static pbdrv_battery_type_t pbdrv_battery_type ;
5354#endif
5455
56+ static uint32_t pbdrv_battery_start_time ;
57+
5558void pbdrv_battery_init (void ) {
5659 #if PBDRV_CONFIG_BATTERY_ADC_TYPE == 3
5760 const pbdrv_battery_adc_platform_data_t * pdata = & pbdrv_battery_adc_platform_data ;
5861 pbdrv_gpio_set_pull (& pdata -> gpio , pdata -> pull );
5962 pbdrv_battery_type = pbdrv_gpio_input (& pdata -> gpio ) ?
6063 PBDRV_BATTERY_TYPE_ALKALINE : PBDRV_BATTERY_TYPE_LIION ;
6164 #endif
65+ pbdrv_battery_start_time = pbdrv_clock_get_ms ();
6266}
6367
6468pbio_error_t pbdrv_battery_get_current_now (uint16_t * value ) {
@@ -89,6 +93,17 @@ pbio_error_t pbdrv_battery_get_current_now(uint16_t *value) {
8993}
9094
9195pbio_error_t pbdrv_battery_get_voltage_now (uint16_t * value ) {
96+
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+
92107 uint16_t raw ;
93108 pbio_error_t err ;
94109
You can’t perform that action at this time.
0 commit comments