From aa40ee46bd648f51f3f3b54f146e1df79f67bd03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Mat=C4=9Bjek?= Date: Thu, 31 Oct 2019 02:43:08 +0100 Subject: [PATCH 1/3] WIP: Warn about unusual sensor readings --- src/drivers.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/drivers.cpp b/src/drivers.cpp index fc2cf34..8f3f1e0 100644 --- a/src/drivers.cpp +++ b/src/drivers.cpp @@ -25,6 +25,7 @@ #include "config.h" #include +#include #include #include #include @@ -403,6 +404,13 @@ void TpSensorDriver::read_temps() const int tmp; while (!(f.eof() || f.fail())) { f >> tmp; + if (tmp < 0) { + std::stringstream ss; + ss << "Getting unusual values from thermal sensor ("; + ss << tmp; + ss << "). Are you using right thermal sensor?"; + log(TF_NFY) << ss.str() << flush; + } if (f.bad()) throw IOerror(MSG_T_GET(path_), errno); if (!f.fail() && in_use_[tidx]) From 7b41c07cdfcc0bf7beaa8dbe77153be8f90e374a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Mat=C4=9Bjek?= Date: Wed, 13 Nov 2019 00:02:57 +0100 Subject: [PATCH 2/3] fixup! WIP: Warn about unusual sensor readings --- src/drivers.cpp | 8 -------- src/thinkfan.cpp | 19 ++++++++++++++++++- src/thinkfan.h | 2 ++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/drivers.cpp b/src/drivers.cpp index 8f3f1e0..fc2cf34 100644 --- a/src/drivers.cpp +++ b/src/drivers.cpp @@ -25,7 +25,6 @@ #include "config.h" #include -#include #include #include #include @@ -404,13 +403,6 @@ void TpSensorDriver::read_temps() const int tmp; while (!(f.eof() || f.fail())) { f >> tmp; - if (tmp < 0) { - std::stringstream ss; - ss << "Getting unusual values from thermal sensor ("; - ss << tmp; - ss << "). Are you using right thermal sensor?"; - log(TF_NFY) << ss.str() << flush; - } if (f.bad()) throw IOerror(MSG_T_GET(path_), errno); if (!f.fail() && in_use_[tidx]) diff --git a/src/thinkfan.cpp b/src/thinkfan.cpp index 3eb64df..69b06b6 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,7 +282,9 @@ TemperatureState::TemperatureState(unsigned int num_temps) temp_(temps_.begin()), bias_(biases_.begin()), biased_temp_(biased_temps_.begin()), - tmax(biased_temps_.begin()) + tmax(biased_temps_.begin()), + noise_counters(num_temps, 0), + noise_counter(noise_counters.begin()) {} @@ -299,6 +302,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..8649dcd 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; }; From bdbc1289a040884cf151c52990c11b06eafa811b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Mat=C4=9Bjek?= Date: Fri, 29 Nov 2019 22:50:06 +0100 Subject: [PATCH 3/3] fixup! fixup! WIP: Warn about unusual sensor readings --- src/thinkfan.cpp | 5 +++-- src/thinkfan.h | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/thinkfan.cpp b/src/thinkfan.cpp index 69b06b6..8e73ac4 100644 --- a/src/thinkfan.cpp +++ b/src/thinkfan.cpp @@ -282,9 +282,9 @@ TemperatureState::TemperatureState(unsigned int num_temps) temp_(temps_.begin()), bias_(biases_.begin()), biased_temp_(biased_temps_.begin()), - tmax(biased_temps_.begin()), noise_counters(num_temps, 0), - noise_counter(noise_counters.begin()) + noise_counter(noise_counters.begin()), + tmax(biased_temps_.begin()) {} @@ -294,6 +294,7 @@ void TemperatureState::restart() bias_ = biases_.begin(); biased_temp_ = biased_temps_.begin(); tmax = biased_temps_.begin(); + noise_counter = noise_counters.begin(); } diff --git a/src/thinkfan.h b/src/thinkfan.h index 8649dcd..b209d0a 100644 --- a/src/thinkfan.h +++ b/src/thinkfan.h @@ -75,8 +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; + std::vector noise_counters; + std::vector::iterator noise_counter; public: std::vector::const_iterator tmax; };