SensESP 2.7.2
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
integrator.h
Go to the documentation of this file.
1#ifndef _integrator_H_
2#define _integrator_H_
3
4#include "transform.h"
5
6namespace sensesp {
7
8static const char INTEGRATOR_SCHEMA[] PROGMEM = R"({
9 "type": "object",
10 "properties": {
11 "k": { "title": "Multiplier", "type": "number" }
12 }
13 })";
14
24template <class C, class P>
25class IntegratorT : public Transform<C, P> {
26 public:
34 IntegratorT(P k = 1, P value = 0, String config_path = "")
35 : Transform<C, P>(config_path), k{k}, value{value} {
36 this->load_configuration();
37 }
38
39 virtual void start() override final {
40 // save the integrator value every 10 s
41 // NOTE: Disabled for now because interrupts start throwing
42 // exceptions.
43 // ReactESP::app->onRepeat(10000, [this](){ this->save_configuration(); });
44 }
45
46 virtual void set_input(C input, uint8_t inputChannel = 0) override final {
47 value += input * k;
48 this->emit(value);
49 }
50
51 void reset() { value = 0; }
52
53 virtual void get_configuration(JsonObject& doc) override final {
54 doc["k"] = k;
55 }
56 virtual bool set_configuration(const JsonObject& config) override final {
57 String expected[] = {"k"};
58 for (auto str : expected) {
59 if (!config.containsKey(str)) {
60 return false;
61 }
62 }
63 k = config["k"];
64 return true;
65 }
66 virtual String get_config_schema() override {
68 }
69
70 private:
71 P k;
72 P value = 0;
73};
74
77
78} // namespace sensesp
79#endif
virtual void load_configuration()
Integrator integrates (accumulates) the incoming values.
Definition integrator.h:25
virtual void get_configuration(JsonObject &doc) override final
Definition integrator.h:53
IntegratorT(P k=1, P value=0, String config_path="")
Construct a new Integrator T object.
Definition integrator.h:34
virtual void start() override final
Definition integrator.h:39
virtual bool set_configuration(const JsonObject &config) override final
Definition integrator.h:56
virtual void set_input(C input, uint8_t inputChannel=0) override final
Definition integrator.h:46
virtual String get_config_schema() override
Definition integrator.h:66
Construct a new transform based on a single function.
The main Transform class. A transform is identified primarily by the type of value that is produces (...
Definition transform.h:54
const uint8_t PAGE_css_bootstrap[] PROGMEM
IntegratorT< int, int > Accumulator
Definition integrator.h:76
IntegratorT< float, float > Integrator
Definition integrator.h:75