diff --git a/include/PowerLimiter.h b/include/PowerLimiter.h index 27b8e15d..34e6920a 100644 --- a/include/PowerLimiter.h +++ b/include/PowerLimiter.h @@ -88,7 +88,7 @@ private: bool isStartThresholdReached(); bool isStopThresholdReached(); bool isBelowStopThreshold(); - bool useFullSolarPassthrough(std::shared_ptr inverter); + bool useFullSolarPassthrough(); }; extern PowerLimiterClass PowerLimiter; diff --git a/src/PowerLimiter.cpp b/src/PowerLimiter.cpp index f76729ef..3e031a98 100644 --- a/src/PowerLimiter.cpp +++ b/src/PowerLimiter.cpp @@ -462,7 +462,7 @@ int32_t PowerLimiterClass::calcPowerLimit(std::shared_ptr inve int32_t adjustedVictronChargePower = inverterPowerDcToAc(inverter, getSolarChargePower()); // Battery can be discharged and we should output max (Victron solar power || power meter value) - if(batteryDischargeEnabled && useFullSolarPassthrough(inverter)) { + if(batteryDischargeEnabled && useFullSolarPassthrough()) { // Case 5 newPowerLimit = newPowerLimit > adjustedVictronChargePower ? newPowerLimit : adjustedVictronChargePower; } else { @@ -689,7 +689,7 @@ void PowerLimiterClass::calcNextInverterRestart() MessageOutput.printf("[DPL::calcNextInverterRestart] _nextInverterRestart @ %d millis\r\n", _nextInverterRestart); } -bool PowerLimiterClass::useFullSolarPassthrough(std::shared_ptr inverter) +bool PowerLimiterClass::useFullSolarPassthrough() { CONFIG_T& config = Configuration.get(); @@ -698,35 +698,16 @@ bool PowerLimiterClass::useFullSolarPassthrough(std::shared_ptr 0.0 - && (millis() - Battery.stateOfChargeLastUpdate) < 60000) { - return Battery.stateOfCharge >= config.PowerLimiter_FullSolarPassThroughSoc; - } - - // Otherwise we use the voltage threshold - if (config.PowerLimiter_FullSolarPassThroughStartVoltage <= 0.0 || config.PowerLimiter_FullSolarPassThroughStopVoltage <= 0.0) { - return false; + if (testThreshold(config.PowerLimiter_FullSolarPassThroughSoc, + config.PowerLimiter_FullSolarPassThroughStartVoltage, + [](float a, float b) -> bool { return a >= b; })) { + _fullSolarPassThroughEnabled = true; } - float dcVoltage = inverter->Statistics()->getChannelFieldValue(TYPE_DC, (ChannelNum_t) config.PowerLimiter_InverterChannelId, FLD_UDC); - - if (_verboseLogging) { - MessageOutput.printf("[DPL::loop] useFullSolarPassthrough: FullSolarPT Start %.2f V, FullSolarPT Stop: %.2f V, dcVoltage: %.2f V\r\n", - config.PowerLimiter_FullSolarPassThroughStartVoltage, config.PowerLimiter_FullSolarPassThroughStopVoltage, dcVoltage); - } - - if (dcVoltage <= 0.0) { - return false; - } - - if (dcVoltage >= config.PowerLimiter_FullSolarPassThroughStartVoltage) { - _fullSolarPassThroughEnabled = true; - } - - if (dcVoltage <= config.PowerLimiter_FullSolarPassThroughStopVoltage) { - _fullSolarPassThroughEnabled = false; + if (testThreshold(config.PowerLimiter_FullSolarPassThroughSoc, + config.PowerLimiter_FullSolarPassThroughStopVoltage, + [](float a, float b) -> bool { return a < b; })) { + _fullSolarPassThroughEnabled = false; } return _fullSolarPassThroughEnabled;