Skip to content

Commit

Permalink
Fix: Allow higher-resolution SoC in live view header (#1197)
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 was limited.

This changes getSoC() to return float so when a source with higher
precision is available, the respective precision is shown.
  • Loading branch information
ranma authored Sep 2, 2024
1 parent 5ad63e6 commit a87f9fa
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 a87f9fa

Please sign in to comment.