SensESP 3.0.1
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 bool initialized_;
48};
49
50const String ConfigSchema(const MovingAverage& obj);
51
52inline bool ConfigRequiresRestart(const MovingAverage& obj) {
53 return true;
54}
55
56} // namespace sensesp
57#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
MovingAverage(int sample_size, float multiplier=1.0, const String &config_path="")
const String ConfigSchema(const SmartSwitchController &obj)
bool ConfigRequiresRestart(const HTTPServer &obj)