Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/pbio/sys/battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

// These values are for LEGO rechargeable battery packs
#define LIION_FULL_MV 8190 // 4.095V per cell
#define LIION_FULL_HYSTERESIS_MV 100 // 50mV per cell hysteresis on full level check
#define LIION_OK_MV 7200 // 3.6V per cell
#define LIION_LOW_MV 6800 // 3.4V per cell
#define LIION_CRITICAL_MV 6000 // 3.0V per cell
Expand Down Expand Up @@ -127,7 +128,16 @@ void pbsys_battery_poll(void) {
* This is only valid on hubs with a built-in battery charger.
*/
bool pbsys_battery_is_full(void) {
return pbio_battery_get_average_voltage() >= LIION_FULL_MV;
static bool was_full;
int32_t voltage = pbio_battery_get_average_voltage();

if (was_full) {
Comment thread
dlech marked this conversation as resolved.
was_full = voltage >= LIION_FULL_MV - LIION_FULL_HYSTERESIS_MV;
} else {
was_full = voltage >= LIION_FULL_MV;
}

return was_full;
}

#endif // PBSYS_CONFIG_BATTERY
Loading