SensESP 2.7.2
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
change_filter.cpp
Go to the documentation of this file.
1#include "change_filter.h"
2
3namespace sensesp {
4
5static float absf(float val) {
6 if (val < 0) {
7 return -val;
8 } else {
9 return val;
10 }
11}
12
16 min_delta_{min_delta},
17 max_delta_{max_delta},
18 max_skips_{max_skips} {
20 skips_ = max_skips_ + 1;
21}
22
24 float delta = absf(new_value - output);
25 if ((delta >= min_delta_ && delta <= max_delta_) || skips_ > max_skips_) {
26 skips_ = 0;
27 this->emit(new_value);
28 } else {
29 skips_++;
30 }
31}
32
34 root["min_delta"] = min_delta_;
35 root["max_delta"] = max_delta_;
36 root["max_skips"] = max_skips_;
37}
38
39static const char SCHEMA[] PROGMEM = R"({
40 "type": "object",
41 "properties": {
42 "min_delta": { "title": "Minimum delta", "description": "Minimum difference in change of value before forwarding", "type": "number" },
43 "max_delta": { "title": "Maximum delta", "description": "Maximum difference in change of value to allow forwarding", "type": "number" },
44 "max_skips": { "title": "Max skip count", "description": "Maximum number of consecutive filtered values before one is allowed through", "type": "number" }
45 }
46 })";
47
49
51 String expected[] = {"min_delta", "max_delta", "max_skips"};
52 for (auto str : expected) {
53 if (!config.containsKey(str)) {
54 return false;
55 }
56 }
57 min_delta_ = config["min_delta"];
58 max_delta_ = config["max_delta"];
59 max_skips_ = config["max_skips"];
60 skips_ = max_skips_ + 1;
61 return true;
62}
63
64} // namespace sensesp
ChangeFilter(float min_delta=0.0, float max_delta=9999.0, int max_skips=99, String config_path="")
virtual void set_input(float new_value, uint8_t input_channel=0) override
virtual void get_configuration(JsonObject &doc) override
virtual String get_config_schema() override
virtual bool set_configuration(const JsonObject &config) override
virtual void load_configuration()
Construct a new transform based on a single function.
const uint8_t PAGE_css_bootstrap[] PROGMEM