SensESP 3.0.0-beta.3
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
enable.h
Go to the documentation of this file.
1#ifndef SENSESP_SRC_SENSESP_TRANSFORMS_ENABLE_H_
2#define SENSESP_SRC_SENSESP_TRANSFORMS_ENABLE_H_
3
5
6namespace sensesp {
7
8static const char ENABLE_TRANSFORM_SCHEMA[] PROGMEM = R"({
9 "type": "object",
10 "properties": {
11 "enabled": { "type": "boolean", "title": "Enable", "description": "Enable or disable the transform output" }
12 }
13 })";
14
24template <typename T>
25class Enable : public Transform<T, T> {
26 public:
27 Enable(bool enabled = true, String config_path = "")
28 : Transform<T, T>(config_path) {
29 this->enabled_ = enabled;
30 this->load_configuration();
31 }
32 virtual void set(const T& input) override {
33 if (enabled_) {
34 this->emit(input);
35 }
36 }
37 virtual void get_configuration(JsonObject& doc) override {
38 doc["enabled"] = enabled_;
39 }
40 virtual bool set_configuration(const JsonObject& config) override {
41 if (config["enabled"].is<bool>()) {
42 enabled_ = config["enabled"];
43 } else {
44 return false;
45 }
46 return true;
47 }
48 virtual String get_config_schema() override {
49 return FPSTR(ENABLE_TRANSFORM_SCHEMA);
50 };
51
52 private:
53 bool enabled_;
54};
55
56} // namespace sensesp
57
58#endif
virtual void load_configuration()
On/off switch for signals: input is emitted as-is if the enable flag is set in the web UI.
Definition enable.h:25
Enable(bool enabled=true, String config_path="")
Definition enable.h:27
virtual bool set_configuration(const JsonObject &config) override
Definition enable.h:40
virtual void get_configuration(JsonObject &doc) override
Definition enable.h:37
virtual void set(const T &input) override
Definition enable.h:32
virtual String get_config_schema() override
Definition enable.h:48
The main Transform class. A transform is identified primarily by the type of value that is produces (...
Definition transform.h:53
void emit(const T &new_value)
const uint8_t PAGE_css_bootstrap[] PROGMEM