Skip to content

Commit

Permalink
use soc and current precision in live view
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasBoehm committed Jul 25, 2024
1 parent 91176eb commit a6a261d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/BatteryStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ class BatteryStats {

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

float getVoltage() const { return _voltage; }
uint32_t getVoltageAgeSeconds() const { return (millis() - _lastUpdateVoltage) / 1000; }

float getChargeCurrent() const { return _current; };
uint8_t getChargeCurrentPrecision() const { return _currentPrecision; }

// convert stats to JSON for web application live view
virtual void getLiveViewData(JsonVariant& root) const;
Expand Down
4 changes: 2 additions & 2 deletions src/WebApi_ws_live.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ void WebApiWsLiveClass::generateOnBatteryJsonResponse(JsonVariant& root, bool al

if (config.Battery.Enabled) {
if (spStats->isSoCValid()) {
addTotalField(batteryObj, "soc", spStats->getSoC(), "%", 0);
addTotalField(batteryObj, "soc", spStats->getSoC(), "%", spStats->getSoCPrecision());
}

if (spStats->isVoltageValid()) {
addTotalField(batteryObj, "voltage", spStats->getVoltage(), "V", 2);
}

if (spStats->isCurrentValid()) {
addTotalField(batteryObj, "current", spStats->getChargeCurrent(), "A", 1);
addTotalField(batteryObj, "current", spStats->getChargeCurrent(), "A", spStats->getChargeCurrentPrecision());
}

if (spStats->isVoltageValid() && spStats->isCurrentValid()) {
Expand Down

0 comments on commit a6a261d

Please sign in to comment.