SensESP 2.7.2
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
smart_switch_controller.cpp
Go to the documentation of this file.
2
4
5namespace sensesp {
6
9 const char* sk_sync_paths[])
10 : BooleanTransform(config_path), auto_initialize_{auto_initialize} {
11 if (sk_sync_paths != NULL) {
12 sync_paths.clear();
13 int i = 0;
14 while (strlen(sk_sync_paths[i]) > 0) {
16 sync_paths.insert(path);
17 i++;
18 } // while
19 }
20
22}
23
25 if (auto_initialize_) {
26 this->emit(is_on);
27 }
28}
29
34
38 // Ignore button presses (we only want interpreted clicks)
39 return;
40 }
41
43 // Long clicks reboot the system...
44 ESP.restart();
45 return;
46 }
47
48 // All other click types toggle the current state...
49 is_on = !is_on;
50 this->emit(is_on);
51
52 if (new_value == ClickTypes::DoubleClick) {
53 // Sync any specified sync paths...
54 for (auto& path : sync_paths) {
55 debugD("Sync status to %s", path.sk_sync_path.c_str());
56 path.put_request->set_input(is_on);
57 }
58 }
59}
60
63 is_on = true;
65 is_on = false;
66 } else {
67 // All other values simply toggle...
68 is_on = !is_on;
69 }
70 this->emit(is_on);
71}
72
74 JsonArray jPaths = root.createNestedArray("sync_paths");
75 for (auto& path : sync_paths) {
76 jPaths.add(path.sk_sync_path);
77 }
78}
79
80static const char SCHEMA[] PROGMEM = R"({
81 "type": "object",
82 "properties": {
83 "sync_paths": { "title": "Sync on double click",
84 "type": "array",
85 "items": { "type": "string"}
86 }
87 }
88 })";
89
91
93 JsonArray arr = config["sync_paths"];
94 if (arr.size() > 0) {
95 sync_paths.clear();
96 for (String sk_path : arr) {
97 SyncPath path(sk_path);
98 sync_paths.insert(path);
99 }
100 }
101
102 return true;
103}
104
106
108 : sk_sync_path{sk_sync_path} {
109 debugD("DoubleClick will also sync %s", sk_sync_path.c_str());
110 this->put_request = new BoolSKPutRequest(sk_sync_path, "", false);
111}
112
113} // namespace sensesp
static bool is_click(ClickTypes value)
virtual void load_configuration()
Construct a new transform based on a single function.
void set_input(IN input, uint8_t input_channel=0) override
Used to store configuration internally.
void set_input(bool new_value, uint8_t input_channel=0) override
virtual void get_configuration(JsonObject &doc) override
SmartSwitchController(bool auto_initialize=true, String config_path="", const char *sk_sync_paths[]=NULL)
virtual bool set_configuration(const JsonObject &config) override
virtual String get_config_schema() override
A common type of transform that consumes, transforms, then outputs values of the same data type.
Definition transform.h:95
static bool is_valid_false(String value)
static bool is_valid_true(String value)
Definition truth_text.cpp:5
void emit(T new_value)
#define debugD(fmt,...)
Definition local_debug.h:47
SKPutRequest< bool > BoolSKPutRequest