SensESP 2.7.2
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
press_repeater.cpp
Go to the documentation of this file.
1#include "press_repeater.h"
2
3namespace sensesp {
4
8 integer_false_{integer_false},
9 repeat_start_interval_{repeat_start_interval},
10 repeat_interval_{repeat_interval},
11 pushed_{false},
12 repeating_{false} {
14}
15
17 ReactESP::app->onRepeat(10, [this]() {
18 if (pushed_) {
19 // A press is currently in progress
20 if (repeating_) {
21 if (last_value_sent_ > (unsigned long)repeat_interval_) {
22 debugD("Repeating press report");
24 this->emit(true);
25 }
26 } else if (last_value_sent_ > (unsigned long)repeat_start_interval_) {
27 debugD("Starting press report repeat");
28 repeating_ = true;
30 this->emit(true);
31 }
32 }
33 });
34}
35
39
41 if (new_value != pushed_) {
43
44 if (!pushed_) {
45 repeating_ = false;
46 }
47
49 this->emit(pushed_);
50 }
51}
52
54 root["repeat_start_interval"] = repeat_start_interval_;
55 root["repeat_interval"] = repeat_interval_;
56}
57
58static const char SCHEMA[] PROGMEM = R"###({
59 "type": "object",
60 "properties": {
61 "repeat_start_interval": { "title": "Start repeating after (ms)", "type": "integer" },
62 "repeat_interval": { "title": "Repeat report interval (ms)", "type": "integer" }
63 }
64})###";
65
67
69 String expected[] = {"repeat_start_interval", "repeat_interval"};
70 for (auto str : expected) {
71 if (!config.containsKey(str)) {
72 return false;
73 }
74 }
75 repeat_start_interval_ = config["repeat_start_interval"];
76 repeat_interval_ = config["repeat_interval"];
77 return true;
78}
79
80} // namespace sensesp
virtual void load_configuration()
Construct a new transform based on a single function.
virtual void get_configuration(JsonObject &doc) override
PressRepeater(String config_path="", int integer_false=0, int repeat_start_interval=1500, int repeat_interval=250)
elapsedMillis last_value_sent_
virtual bool set_configuration(const JsonObject &config) override
virtual String get_config_schema() override
virtual void set_input(bool new_value, uint8_t input_channel=0) override
virtual void start() override
A common type of transform that consumes, transforms, then outputs values of the same data type.
Definition transform.h:95
void emit(T new_value)
const uint8_t PAGE_css_bootstrap[] PROGMEM
#define debugD(fmt,...)
Definition local_debug.h:47