Skip to content

Commit

Permalink
Allow higher-resolution SoC in live view header
Browse files Browse the repository at this point in the history
Commit accc70d added the battery SoC to
the live view header. But due to getSoC returning an int the precision
is currently limited.

This changes getSoC to return float so when a source with higher
precision is available the full precision is shown.
  • Loading branch information
ranma committed Aug 25, 2024
1 parent dcc8313 commit c658bce
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/BatteryStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class BatteryStats {
uint32_t getAgeSeconds() const { return (millis() - _lastUpdate) / 1000; }
bool updateAvailable(uint32_t since) const;

uint8_t getSoC() const { return _soc; }
float getSoC() const { return _soc; }
uint32_t getSoCAgeSeconds() const { return (millis() - _lastUpdateSoC) / 1000; }
uint8_t getSoCPrecision() const { return _socPrecision; }

Expand Down
2 changes: 1 addition & 1 deletion src/PowerLimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void PowerLimiterClass::loop()
_batteryDischargeEnabled = getBatteryPower();

if (_verboseLogging && !config.PowerLimiter.IsInverterSolarPowered) {
MessageOutput.printf("[DPL::loop] battery interface %s, SoC: %d %%, StartTH: %d %%, StopTH: %d %%, SoC age: %d s, ignore: %s\r\n",
MessageOutput.printf("[DPL::loop] battery interface %s, SoC: %f %%, StartTH: %d %%, StopTH: %d %%, SoC age: %d s, ignore: %s\r\n",
(config.Battery.Enabled?"enabled":"disabled"),
Battery.getStats()->getSoC(),
config.PowerLimiter.BatterySocStartThreshold,
Expand Down
2 changes: 1 addition & 1 deletion src/PylontechCanReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void PylontechCanReceiver::onMessage(twai_message_t rx_message)
_stats->_stateOfHealth = this->readUnsignedInt16(rx_message.data + 2);

if (_verboseLogging) {
MessageOutput.printf("[Pylontech] soc: %d soh: %d\r\n",
MessageOutput.printf("[Pylontech] soc: %f soh: %d\r\n",
_stats->getSoC(), _stats->_stateOfHealth);
}
break;
Expand Down
2 changes: 1 addition & 1 deletion src/PytesCanReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void PytesCanReceiver::onMessage(twai_message_t rx_message)
_stats->_stateOfHealth = this->readUnsignedInt16(rx_message.data + 2);

if (_verboseLogging) {
MessageOutput.printf("[Pytes] soc: %d soh: %d\r\n",
MessageOutput.printf("[Pytes] soc: %f soh: %d\r\n",
_stats->getSoC(), _stats->_stateOfHealth);
}
break;
Expand Down

0 comments on commit c658bce

Please sign in to comment.