SensESP 3.4.1-alpha
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
moving_average.h
Go to the documentation of this file.
1#ifndef SENSP_TRANSFORMS_MOVING_AVERAGE_H_
2#define SENSP_TRANSFORMS_MOVING_AVERAGE_H_
3
4#include <vector>
5
7#include "transform.h"
8
9namespace sensesp {
10
22// y = k * 1/n * \sum_k=1^n(x_k)
24 public:
36 MovingAverage(int sample_size, float multiplier = 1.0,
37 const String& config_path = "");
38 virtual void set(const float& input) override;
39 virtual bool to_json(JsonObject& root) override;
40 virtual bool from_json(const JsonObject& config) override;
41
42 private:
43 std::vector<float> buf_{};
44 int ptr_ = 0;
45 int sample_size_;
46 float multiplier_;
47 float sum_ = 0;
48 bool initialized_;
49};
50
51const String ConfigSchema(const MovingAverage& obj);
52
53inline bool ConfigRequiresRestart(const MovingAverage& obj) {
54 return true;
55}
56
57} // namespace sensesp
58#endif
Outputs the moving average of the last sample_size inputs.
virtual void set(const float &input) override
virtual bool to_json(JsonObject &root) override
virtual bool from_json(const JsonObject &config) override
const String ConfigSchema(const SmartSwitchController &obj)
bool ConfigRequiresRestart(const HTTPServer &obj)