SensESP 3.0.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
throttle.h
Go to the documentation of this file.
1#ifndef SENSESP_SRC_SENSESP_TRANSFORMS_THROTTLE_H_
2#define SENSESP_SRC_SENSESP_TRANSFORMS_THROTTLE_H_
3
4#include <climits>
5#include <elapsedMillis.h>
6
7#include "transform.h"
8
9namespace sensesp {
10
28template <typename T>
29class Throttle : public SymmetricTransform<T> {
30 public:
31 Throttle(long min_interval)
32 : SymmetricTransform<T>(), min_interval_{min_interval} {}
33
34 void set(const T& input) override {
35 if (age_ < min_interval_) {
36 return;
37 }
38 age_ = 0;
39 this->emit(input);
40 }
41
42 protected:
44 elapsedMillis age_ = LONG_MAX;
45};
46
47} // namespace sensesp
48
49#endif // SENSESP_SRC_SENSESP_TRANSFORMS_THROTTLE_H_
A common type of transform that consumes, transforms, then outputs values of the same data type.
Definition transform.h:94
Throttle the input rate.
Definition throttle.h:29
Throttle(long min_interval)
Definition throttle.h:31
void set(const T &input) override
Definition throttle.h:34
elapsedMillis age_
Definition throttle.h:44
void emit(const T &new_value)