Skip to content

Commit 073b54a

Browse files
committed
Reduce needless calculations
The factor multiplication can be done once instead of for each sample.
1 parent e83e36f commit 073b54a

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

arduino/node_relaywbutton.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,11 @@ void NodeRelayWithButton::check_current(unsigned long now)
121121
m_trace.sample(now, rval);
122122
#endif
123123
float val = m_adc.sample_to_float(rval);
124-
val *= 5; // calculated factor from coil and resistor
125124
m_current_sum += val*val;
126125
m_current_samples++;
127126

128127
if (m_current_samples == 1000) { // Approx. 1 second
129-
m_current = m_current_sum / m_current_samples;
130-
m_current = sqrt(m_current);
128+
m_current = 5.0*sqrt(m_current_sum / m_current_samples);
131129
m_current_sum = 0;
132130
m_current_samples = 0;
133131
}

0 commit comments

Comments
 (0)