1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-22 03:33:52 +01:00
This commit is contained in:
J. Nick Koston
2025-10-15 18:44:37 -10:00
parent 4ff39ee82c
commit a4b14902db

View File

@@ -53,11 +53,13 @@ optional<float> SlidingWindowFilter::new_value(float value) {
// Buffer not yet full - just append
this->window_.push_back(value);
this->window_count_++;
this->window_head_ = this->window_count_ % this->window_size_;
} else {
// Buffer full - overwrite oldest value (ring buffer)
this->window_[this->window_head_] = value;
this->window_head_ = (this->window_head_ + 1) % this->window_size_;
this->window_head_++;
if (this->window_head_ >= this->window_size_) {
this->window_head_ = 0;
}
}
// Check if we should send a result