Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Warn about unusual sensor readings #78

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/thinkfan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "config.h"
#include "message.h"

const int NOISE_MEASUREMENT = 10;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constexpr int NOISE_MEASURE_COUNT = 10;


namespace thinkfan {

Expand Down Expand Up @@ -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())
{}

Expand All @@ -291,6 +294,7 @@ void TemperatureState::restart()
bias_ = biases_.begin();
biased_temp_ = biased_temps_.begin();
tmax = biased_temps_.begin();
noise_counter = noise_counters.begin();
}


Expand All @@ -299,6 +303,20 @@ void TemperatureState::add_temp(int t)
int diff = t - *temp_;
*temp_ = t;

if (diff == 0) {
if (*noise_counter < NOISE_MEASUREMENT) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why do we need the whole vector noise_counters when we only use the first element?
If I understand your logic, then you just need to keep one static count, increase that count every time diff==0 and compare that count with a fix threshold. In this case, you don't even need noise_counter and noise_counters as member variables.

(*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;
Expand Down
2 changes: 2 additions & 0 deletions src/thinkfan.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class TemperatureState {
std::vector<int>::iterator temp_;
std::vector<float>::iterator bias_;
std::vector<int>::iterator biased_temp_;
std::vector<int> noise_counters;
std::vector<int>::iterator noise_counter;
public:
std::vector<int>::const_iterator tmax;
};
Expand Down