SensESP 3.0.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
hysteresis.h
Go to the documentation of this file.
1#ifndef SENSESP_TRANSFORMS_HYSTERESIS_H_
2#define SENSESP_TRANSFORMS_HYSTERESIS_H_
3
4#include "lambda_transform.h"
5
6namespace sensesp {
7
8// Web UI parameter name definition
10 {"lower_threshold", "Lower threshold"},
11 {"upper_threshold", "Upper threshold"},
12 {"low_output", "Low output"},
13 {"high_output", "High output"}};
14
31template <class IN, class OUT>
32// Hysteresis inherits from a specialized LambdaTransform type
33class Hysteresis : public LambdaTransform<IN, OUT, IN, IN, OUT, OUT> {
34 public:
35 Hysteresis(IN lower_threshold, IN upper_threshold, OUT low_output,
36 OUT high_output, String config_path = "")
37 : LambdaTransform<IN, OUT, IN, IN, OUT, OUT>(
38 // the lambda function needs to be defined in this awkward
39 // location because it needs to be able to capture `this`
40 [this](IN input, IN lower_threshold, IN upper_threshold,
41 OUT low_output, OUT high_output) {
42 if (input < lower_threshold) {
43 this->last_value_ = low_output;
44 } else if (upper_threshold <= input) {
45 this->last_value_ = high_output;
46 }
47 // If neither of the above conditions were met, input is between
48 // the lower and upper thresholds (in the hysteresis region)
49 return this->last_value_;
50 },
51 lower_threshold, upper_threshold, low_output, high_output,
52 hysteresis_param_info, config_path) {}
53
54 private:
55 OUT last_value_;
56};
57
58} // namespace sensesp
59#endif
Hysteresis function.
Definition hysteresis.h:33
Hysteresis(IN lower_threshold, IN upper_threshold, OUT low_output, OUT high_output, String config_path="")
Definition hysteresis.h:35
Construct a new transform based on a single function.
const ParamInfo hysteresis_param_info[4]
Definition hysteresis.h:9