SensESP 3.4.1-alpha
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
transform.h
Go to the documentation of this file.
1#ifndef SENSESP_TRANSFORMS_TRANSFORM_H_
2#define SENSESP_TRANSFORMS_TRANSFORM_H_
3
4#include "sensesp.h"
5
6#include <ArduinoJson.h>
7#include <set>
8
13
14namespace sensesp {
15
16// TODO(mairas): Split into multiple files
17
19// Transforms transform raw device readouts into useful sensor values.
20
31 public:
32 TransformBase(const String& config_path);
33
38 virtual ~TransformBase();
39
40 // The transform registry's original purpose (supplying Signal K sources) is
41 // now handled by SKEmitter::get_sources(); nothing in the framework consumes
42 // get_transforms() anymore. get_sources() is not a drop-in replacement -- it
43 // returns only the Signal K emitters, not the full transform set, for which
44 // there is no equivalent accessor.
45 [[deprecated("Deprecated and unused internally; no direct replacement")]]
46 static const std::set<TransformBase*>& get_transforms() {
47 return transforms_;
48 }
49
54 static void clear_registry();
55
56 private:
57 static std::set<TransformBase*> transforms_;
58};
59
65template <typename C, typename P>
66class Transform : public TransformBase,
67 public ValueConsumer<C>,
68 public ValueProducer<P> {
69 public:
70 Transform(String config_path = "")
71 : TransformBase(config_path), ValueConsumer<C>(), ValueProducer<P>() {}
72
83 ValueProducer<P>* producer1 = NULL,
84 ValueProducer<P>* producer2 = NULL,
85 ValueProducer<P>* producer3 = NULL,
86 ValueProducer<P>* producer4 = NULL) {
87 this->ValueConsumer<C>::connect_from(producer0);
88 if (producer1 != NULL) {
89 this->ValueConsumer<C>::connect_from(producer1, 1);
90 }
91 if (producer2 != NULL) {
92 this->ValueConsumer<C>::connect_from(producer2, 2);
93 }
94 if (producer3 != NULL) {
95 this->ValueConsumer<C>::connect_from(producer3, 3);
96 }
97 if (producer4 != NULL) {
98 this->ValueConsumer<C>::connect_from(producer4, 4);
99 }
100 return this;
101 }
102};
103
108template <typename T>
109class SymmetricTransform : public Transform<T, T> {
110 public:
111 SymmetricTransform(String config_path = "") : Transform<T, T>(config_path) {}
112};
113
118
119} // namespace sensesp
120
121#endif
A common type of transform that consumes, transforms, then outputs values of the same data type.
Definition transform.h:109
SymmetricTransform(String config_path="")
Definition transform.h:111
The base class for all transforms. A transforms takes a value in, transforms it in some way,...
Definition transform.h:30
static const std::set< TransformBase * > & get_transforms()
Definition transform.h:46
static void clear_registry()
Definition transform.cpp:22
The main Transform class. A transform is identified primarily by the type of value that is produces (...
Definition transform.h:68
Transform(String config_path="")
Definition transform.h:70
Transform< C, P > * connect_from(ValueProducer< P > *producer0, ValueProducer< P > *producer1=NULL, ValueProducer< P > *producer2=NULL, ValueProducer< P > *producer3=NULL, ValueProducer< P > *producer4=NULL)
Definition transform.h:82
A base class for piece of code (like a transform) that accepts data for input. ValueConsumers can acc...
void connect_from(ValueProducer< T > *producer)
A base class for any sensor or piece of code that outputs a value for consumption elsewhere.
SymmetricTransform< String > StringTransform
Definition transform.h:117
SymmetricTransform< bool > BooleanTransform
Definition transform.h:116
SymmetricTransform< int > IntegerTransform
Definition transform.h:115
SymmetricTransform< float > FloatTransform
Definition transform.h:114