Only average available temperature samples

This commit is contained in:
Rodrigo Arias Mallo 2025-10-15 21:27:18 +02:00
parent 7bd0b44871
commit 3538225a91

View File

@ -77,6 +77,7 @@ struct state {
unsigned long hot_t0;
int ntc_i; /* Next available place */
int ntc_n; /* Samples in array */
float ntc_R;
float ntc_last_T;
float ntc_array_T[MAX_SAMPLES];
@ -132,12 +133,14 @@ void proc_ntc(struct state *state, const struct input *input)
state->ntc_array_T[state->ntc_i++] = state->ntc_last_T;
if (state->ntc_i >= MAX_SAMPLES)
state->ntc_i = 0;
if (state->ntc_n < MAX_SAMPLES)
state->ntc_n++;
float avg = 0;
for (int i = 0; i < MAX_SAMPLES; i++)
for (int i = 0; i < state->ntc_n; i++)
avg += state->ntc_array_T[i];
state->ntc_T = avg / MAX_SAMPLES;
state->ntc_T = avg / state->ntc_n;
overheat_input(&state->overheat, millis(), state->ntc_T);
}