SensESP 2.7.2
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
valueproducer.h
Go to the documentation of this file.
1#ifndef _value_producer_H_
2#define _value_producer_H_
3
4#include <ArduinoJson.h>
5
6#include "observable.h"
7#include "valueconsumer.h"
8
9namespace sensesp {
10
11// The Transform class is defined in transforms/transform.h
12template <typename C, typename P>
13class Transform;
14
23template <typename T>
24class ValueProducer : virtual public Observable {
25 public:
27
31 virtual const T& get() const { return output; }
32
43 this->attach([this, consumer, input_channel]() {
45 });
46 }
47
58 template <typename CT>
60 this->attach([this, consumer, input_channel]() {
62 });
63 }
64
76 template <typename T2>
79 this->attach([this, consumer_producer, input_channel]() {
81 });
82 return consumer_producer;
83 }
84
97 template <typename TT, typename T2>
100 this->attach([this, consumer_producer, input_channel]() {
102 });
103 return consumer_producer;
104 }
105
106 /*
107 * Set a new output value and notify consumers about it
108 */
109 void emit(T new_value) {
110 this->output = new_value;
112 }
113
114 protected:
120};
121
126
127} // namespace sensesp
128
129#endif
Construct a new transform based on a single function.
void set_input(IN input, uint8_t input_channel=0) override
A base class which allow observers to attach callbacks to themselves. The callbacks will be called wh...
Definition observable.h:16
void attach(std::function< void()> observer)
A base class for any sensor or piece of code that outputs a value for consumption elsewhere.
void connect_to(ValueConsumer< T > *consumer, uint8_t input_channel=0)
virtual const T & get() const
Transform< T, T2 > * connect_to(Transform< T, T2 > *consumer_producer, uint8_t input_channel=0)
void connect_to(ValueConsumer< CT > *consumer, uint8_t input_channel=0)
Connect a producer to a consumer of a different type.
void emit(T new_value)
Transform< TT, T2 > * connect_to(Transform< TT, T2 > *consumer_producer, uint8_t input_channel=0)
Connect a producer to a transform with a different input type.
ValueProducer< bool > BoolProducer
ValueProducer< float > FloatProducer
ValueProducer< int > IntProducer
ValueProducer< String > StringProducer