Added power factor register

This commit is contained in:
Emanuele Trabattoni
2025-07-16 20:41:38 +02:00
parent 53b82c32c3
commit 3923aa3c05
2 changed files with 17 additions and 8 deletions

View File

@@ -18,6 +18,7 @@ namespace drivers
info.pAct = getPact();
info.pApp = getPapp();
info.pRea = getPrea();
info.pf = getPf();
info.f = getF();
info.whTot = getWhTot();
info.whPar = getWhPar();
@@ -44,6 +45,10 @@ namespace drivers
{
return readFloatReg(REG_Prea);
}
const float_t S50140::getPf()
{
return readFloatReg(REG_Pf);
}
const float_t S50140::getF()
{
return readFloatReg(REG_Freq);
@@ -61,8 +66,8 @@ namespace drivers
{
auto now = millis();
if ((now - m_lastRequest) < minDelay)
{ // minimum 500ms between requests
delay(now - m_lastRequest);
{ // minimum m_lastRequest between requests
vTaskDelay(pdMS_TO_TICKS(now - m_lastRequest));
}
m_lastRequest = now;
}
@@ -90,21 +95,22 @@ namespace drivers
void S50140::resetPartialCounters()
{
uint8_t retries(0);
const uint16_t resetAll = 0x0A03;
const uint16_t stopAll = 0x0A02;
const uint16_t startAll = 0x0A01;
constexpr uint16_t nullVal = 0x0000;
constexpr uint16_t resetAll = 0x0A03;
constexpr uint16_t stopAll = 0x0A02;
constexpr uint16_t startAll = 0x0A01;
while (retries++ < maxRetries)
{
bool ok(true);
delayRequest();
LOG_WARN("Powermeter Counter STOP");
ok &= m_bus.writeRegisters(m_address, REG_PartCount, {0x0000, stopAll});
ok &= m_bus.writeRegisters(m_address, REG_PartCount, {nullVal, stopAll});
delayRequest();
LOG_WARN("Powermeter Counter RESET");
ok &= m_bus.writeRegisters(m_address, REG_PartCount, {0x0000, resetAll});
ok &= m_bus.writeRegisters(m_address, REG_PartCount, {nullVal, resetAll});
delayRequest();
LOG_WARN("Powermeter Counter START");
ok &= m_bus.writeRegisters(m_address, REG_PartCount, {0x0000, startAll});
ok &= m_bus.writeRegisters(m_address, REG_PartCount, {nullVal, startAll});
if (ok)
return;
LOG_ERROR("Unable to Reset Powermeter Partial Counters, device", m_address);