diff --git a/src/thinkfan.cpp b/src/thinkfan.cpp index 3eb64df..8e73ac4 100644 --- a/src/thinkfan.cpp +++ b/src/thinkfan.cpp @@ -41,6 +41,7 @@ #include "config.h" #include "message.h" +const int NOISE_MEASUREMENT = 10; namespace thinkfan { @@ -281,6 +282,8 @@ TemperatureState::TemperatureState(unsigned int num_temps) temp_(temps_.begin()), bias_(biases_.begin()), biased_temp_(biased_temps_.begin()), + noise_counters(num_temps, 0), + noise_counter(noise_counters.begin()), tmax(biased_temps_.begin()) {} @@ -291,6 +294,7 @@ void TemperatureState::restart() bias_ = biases_.begin(); biased_temp_ = biased_temps_.begin(); tmax = biased_temps_.begin(); + noise_counter = noise_counters.begin(); } @@ -299,6 +303,20 @@ void TemperatureState::add_temp(int t) int diff = t - *temp_; *temp_ = t; + if (diff == 0) { + if (*noise_counter < NOISE_MEASUREMENT) { + (*noise_counter)++; + } + else { + //log it + log(TF_NFY) << "No change on sensor readings. Are you using correct sensor?" << flush; + } + } + else { + *noise_counter = 0; + } + ++noise_counter; + if (unlikely(diff > 2)) { // Apply bias_ if temperature changed quickly float tmp_bias = float(diff) * bias_level; diff --git a/src/thinkfan.h b/src/thinkfan.h index 5b02595..b209d0a 100644 --- a/src/thinkfan.h +++ b/src/thinkfan.h @@ -75,6 +75,8 @@ class TemperatureState { std::vector::iterator temp_; std::vector::iterator bias_; std::vector::iterator biased_temp_; + std::vector noise_counters; + std::vector::iterator noise_counter; public: std::vector::const_iterator tmax; };