1#ifndef SENSESP_SENSORS_DIGITAL_INPUT_H_
2#define SENSESP_SENSORS_DIGITAL_INPUT_H_
4#include <elapsedMillis.h>
24 pinMode(
pin_, pin_mode);
54 String config_path =
"")
57 read_delay_{read_delay},
61 repeat_event_ =
event_loop()->onRepeat(read_delay_,
62 [
this]() { this->
emit(digitalRead(
pin_)); });
66 if (repeat_event_ !=
nullptr) {
74 reactesp::RepeatEvent* repeat_event_ =
nullptr;
75 virtual bool to_json(JsonObject& root)
override;
76 virtual bool from_json(
const JsonObject& config)
override;
104 unsigned int read_delay, String config_path =
"")
127 virtual bool to_json(JsonObject& root)
override;
128 virtual bool from_json(
const JsonObject& config)
override;
132 unsigned int read_delay, String config_path,
133 std::function<
void()> interrupt_handler)
137 interrupt_type_{interrupt_type},
138 interrupt_handler_{interrupt_handler} {
149 std::function<void()> interrupt_handler_;
180 unsigned int read_delay,
181 unsigned int ignore_interval_ms,
182 String config_path =
"")
184 config_path, [this]() { this->handleInterrupt(); }),
185 ignore_interval_ms_{ignore_interval_ms} {}
188 void handleInterrupt();
190 unsigned int ignore_interval_ms_;
191 elapsedMillis since_last_event_;
192 virtual bool to_json(JsonObject& root)
override;
193 virtual bool from_json(
const JsonObject& config)
override;
223 String config_path =
"")
225 Sensor<bool>(config_path),
226 interrupt_type_{interrupt_type},
232 isr_event_ =
event_loop()->onInterrupt(
pin_, interrupt_type_, [
this]() {
241 if (t && (val != last_output_)) {
253 if (tick_event_ !=
nullptr) {
256 if (isr_event_ !=
nullptr) {
265 reactesp::TickEvent* tick_event_ =
nullptr;
266 reactesp::ISREvent* isr_event_ =
nullptr;
267 virtual bool to_json(JsonObject& doc)
override {
return true; }
268 virtual bool from_json(
const JsonObject& config)
override {
return true; }
virtual bool load() override
Load and populate the object from a persistent storage.
Sensor(String config_path)
virtual const int & get() const
void emit(const bool &new_value)
const String ConfigSchema(const SmartSwitchController &obj)
std::shared_ptr< reactesp::EventLoop > event_loop()
bool ConfigRequiresRestart(const HTTPServer &obj)