Skip to content

Commit f6cc3c7

Browse files
authored
[Lookup table version] Improved battery percentage tracking based off actual energy remaining (#55)
* update lookup table and refactor code slightly for readability * Fix small bug in lookup table * Add small comment
1 parent 96dd6ab commit f6cc3c7

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

lib/bms/packet_parsers.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ inline int16_t int16FromNetworkOrder(const void* const p) {
1818
}
1919

2020
int openCircuitSocFromCellVoltage(int cellVoltageMillivolts) {
21-
static constexpr int LOOKUP_TABLE_RANGE_MIN_MV = 2762;
22-
static constexpr int LOOKUP_TABLE_RANGE_MAX_MV = 4140;
23-
static uint8_t LOOKUP_TABLE[11] = {0, 0, 0, 2, 4, 11, 26, 44, 61, 78, 100};
21+
static constexpr int LOOKUP_TABLE_RANGE_MIN_MV = 2700;
22+
static constexpr int LOOKUP_TABLE_RANGE_MAX_MV = 4200;
23+
static uint8_t LOOKUP_TABLE[31] = {0, 0, 0, 0, 1, 2, 3, 4, 5, 7, 8, 11, 14, 16, 18, 19, 25, 30, 33, 37, 43, 48, 53, 60, 67, 71, 76, 82, 92, 97, 100};
2424
static constexpr int LOOKUP_TABLE_SIZE = (sizeof(LOOKUP_TABLE)/sizeof(*LOOKUP_TABLE));
2525
static constexpr int RANGE = LOOKUP_TABLE_RANGE_MAX_MV - LOOKUP_TABLE_RANGE_MIN_MV;
2626
// (RANGE - 1) upper limit effectively clamps the leftIndex below to (LOOKUP_TABLE_SIZE - 2)

0 commit comments

Comments
 (0)