ignore peaks

This commit is contained in:
Wolfgang Hottgenroth 2019-11-04 12:02:10 +01:00
parent 8f2768c25c
commit 73111ff35c
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F

View File

@ -19,6 +19,8 @@ const int SPI_SPEED = 1000000;
config_t cfg;
const char EPSILON_KEY = "epsilon";
const double DEFAULT_EPSILON = 0.01;
void isr() {
static uint32_t lastCounter = 0;
@ -59,6 +61,7 @@ void start() {
}
int main (void) {
readConfig();
init();
ledInit();
@ -66,12 +69,25 @@ int main (void) {
influxInit(&cfg);
start();
double epsilon;
if (! config_lookup_float(&cfg, EPSILON_KEY, &epsilon)) {
epsilon = DEFAULT_EPSILON;
}
double lastF = 0;
bool settled = false;
uint8_t ledTick = 0;
while (1) {
uint32_t diff = ringbufferGet();
double f = 1.0 / (((double) diff) / 1000000.0);
if (settled && (abs(f - lastF) > epsilon)) {
printf("Current f=%f, last f=%f, gradient too large, skipped\n", f, lastF);
f = lastF;
}
lastF = f;
// printf("%f\n", f);
influxAddFrequency(f);
@ -79,7 +95,9 @@ int main (void) {
if (ledTick == 50) {
ledTick = 0;
led(E_GREEN, false);
settled = true;
}
}
// will never be reached