|
@ -833,6 +833,11 @@ void sensorLoop() { |
|
|
// Pre-read hook
|
|
|
// Pre-read hook
|
|
|
_sensorPre(); |
|
|
_sensorPre(); |
|
|
|
|
|
|
|
|
|
|
|
// Get the first relay state
|
|
|
|
|
|
#if SENSOR_POWER_CHECK_STATUS
|
|
|
|
|
|
bool relay_off = (relayCount() > 0) && (relayStatus(0) == 0); |
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
// Get readings
|
|
|
// Get readings
|
|
|
for (unsigned char i=0; i<_magnitudes.size(); i++) { |
|
|
for (unsigned char i=0; i<_magnitudes.size(); i++) { |
|
|
|
|
|
|
|
@ -840,17 +845,34 @@ void sensorLoop() { |
|
|
|
|
|
|
|
|
if (magnitude.sensor->status()) { |
|
|
if (magnitude.sensor->status()) { |
|
|
|
|
|
|
|
|
unsigned char decimals = _magnitudeDecimals(magnitude.type); |
|
|
|
|
|
|
|
|
|
|
|
current = magnitude.sensor->value(magnitude.local); |
|
|
current = magnitude.sensor->value(magnitude.local); |
|
|
|
|
|
|
|
|
|
|
|
// Completely remove spurious values if relay is OFF
|
|
|
|
|
|
#if SENSOR_POWER_CHECK_STATUS
|
|
|
|
|
|
if (relay_off) { |
|
|
|
|
|
if (magnitude.type == MAGNITUDE_POWER_ACTIVE || |
|
|
|
|
|
magnitude.type == MAGNITUDE_POWER_REACTIVE || |
|
|
|
|
|
magnitude.type == MAGNITUDE_POWER_APPARENT || |
|
|
|
|
|
magnitude.type == MAGNITUDE_CURRENT || |
|
|
|
|
|
magnitude.type == MAGNITUDE_ENERGY_DELTA |
|
|
|
|
|
) { |
|
|
|
|
|
current = 0; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
magnitude.filter->add(current); |
|
|
magnitude.filter->add(current); |
|
|
|
|
|
|
|
|
// Special case
|
|
|
// Special case
|
|
|
if (magnitude.type == MAGNITUDE_EVENTS) current = magnitude.filter->result(); |
|
|
|
|
|
|
|
|
if (magnitude.type == MAGNITUDE_EVENTS) { |
|
|
|
|
|
current = magnitude.filter->result(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
current = _magnitudeProcess(magnitude.type, current); |
|
|
current = _magnitudeProcess(magnitude.type, current); |
|
|
_magnitudes[i].current = current; |
|
|
_magnitudes[i].current = current; |
|
|
|
|
|
|
|
|
|
|
|
unsigned char decimals = _magnitudeDecimals(magnitude.type); |
|
|
|
|
|
|
|
|
// Debug
|
|
|
// Debug
|
|
|
#if SENSOR_DEBUG
|
|
|
#if SENSOR_DEBUG
|
|
|
{ |
|
|
{ |
|
|