Skip to content

Commit 427f55e

Browse files
committed
Helper: Battery: Add NUM_CELLS_IN_SERIES support to bring down the voltage to a single cell version
Signed-off-by: Luis Garcia <git@luigi311.com>
1 parent 8104609 commit 427f55e

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/helpers/Battery.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ int batteryPercentFromMilliVolts(uint16_t batteryMilliVolts) {
1515
const uint8_t stepPct = 10; // distance between table entries (100 → 90 → ... → 0)
1616
const size_t n = kOcvTableSize; // should be 11
1717

18+
if (NUM_CELLS_IN_SERIES > 1) {
19+
// Adjust the input voltage to per-cell basis
20+
batteryMilliVolts /= NUM_CELLS_IN_SERIES;
21+
}
22+
1823
if (n != 11 || batteryMilliVolts <= 0) {
1924
// Error: invalid OCV_ARRAY table size or voltage
2025
return -1;

src/helpers/Battery.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
#endif
3232
#endif
3333

34+
/**
35+
* Number of cells in series (for multi-cell battery packs)
36+
* Default to 1 if not defined.
37+
*/
38+
#ifndef NUM_CELLS_IN_SERIES
39+
#define NUM_CELLS_IN_SERIES 1
40+
#endif
41+
3442

3543
/**
3644
* Convert a battery voltage (in millivolts) to approximate state-of-charge (%),

0 commit comments

Comments
 (0)