SensESP 3.0.0-beta.3
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
34 // Primary purpose of this was to supply Signal K sources
35 // (now handled by SKEmitter::get_sources). Should
36 // this be deprecated?
37 static const std::set<TransformBase*>& get_transforms() {
38 return transforms_;
39 }
40
41 private:
42 static std::set<TransformBase*> transforms_;
43};
44
50template <typename C, typename P>
51class Transform : public TransformBase,
52 public ValueConsumer<C>,
53 public ValueProducer<P> {
54 public:
55 Transform(String config_path = "")
56 : TransformBase(config_path), ValueConsumer<C>(), ValueProducer<P>() {}
57
68 ValueProducer<P>* producer1 = NULL,
69 ValueProducer<P>* producer2 = NULL,
70 ValueProducer<P>* producer3 = NULL,
71 ValueProducer<P>* producer4 = NULL) {
72 this->ValueConsumer<C>::connect_from(producer0);
73 if (producer1 != NULL) {
74 this->ValueConsumer<C>::connect_from(producer1, 1);
75 }
76 if (producer2 != NULL) {
77 this->ValueConsumer<C>::connect_from(producer2, 2);
78 }
79 if (producer3 != NULL) {
80 this->ValueConsumer<C>::connect_from(producer3, 3);
81 }
82 if (producer4 != NULL) {
83 this->ValueConsumer<C>::connect_from(producer4, 4);
84 }
85 return this;
86 }
87};
88
93template <typename T>
94class SymmetricTransform : public Transform<T, T> {
95 public:
96 SymmetricTransform(String config_path = "") : Transform<T, T>(config_path) {}
97};
98
103
104} // namespace sensesp
105
106#endif
An object that is capable of having configuration data that can be set remotely using a RESTful API,...
A common type of transform that consumes, transforms, then outputs values of the same data type.
Definition transform.h:94
SymmetricTransform(String config_path="")
Definition transform.h:96
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:37
TransformBase(const String &config_path="")
Definition transform.cpp:15
The main Transform class. A transform is identified primarily by the type of value that is produces (...
Definition transform.h:53
Transform(String config_path="")
Definition transform.h:55
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:67
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:102
SymmetricTransform< bool > BooleanTransform
Definition transform.h:101
SymmetricTransform< int > IntegerTransform
Definition transform.h:100
SymmetricTransform< float > FloatTransform
Definition transform.h:99