1#ifndef REACTESP_SRC_EVENTS_H_
2#define REACTESP_SRC_EVENTS_H_
21inline uint64_t ICACHE_RAM_ATTR
micros64() {
return esp_timer_get_time(); }
231 const uint8_t pin_number;
235 static bool isr_service_installed;
236 static void isr(
void* this_ptr);
251 gpio_int_type_t intr_type;
254 intr_type = GPIO_INTR_POSEDGE;
257 intr_type = GPIO_INTR_NEGEDGE;
260 intr_type = GPIO_INTR_ANYEDGE;
263 intr_type = GPIO_INTR_DISABLE;
267 gpio_set_intr_type((gpio_num_t)pin_number, intr_type);
269 if (!isr_service_installed) {
270 isr_service_installed =
true;
271 gpio_install_isr_service(ESP_INTR_FLAG_LOWMED);
Event that is triggered after a certain time delay.
DelayEvent(uint32_t delay, react_callback callback)
Construct a new Delay Event object.
void tick(EventLoop *event_loop) override
Events are code to be called when a given condition is fulfilled.
const react_callback callback
Event & operator=(Event &&)=delete
Event & operator=(const Event &)=delete
Event(react_callback callback)
Construct a new Event object.
Event(const Event &)=delete
Asynchronous event loop supporting timed (repeating and non-repeating), interrupt and stream events.
Event that is triggered on an input pin change.
void remove(EventLoop *event_loop) override
void tick(EventLoop *event_loop) override
ISREvent(uint8_t pin_number, int mode, react_callback callback)
Construct a new ISREvent object.
void add(EventLoop *event_loop) override
Event that is triggered repeatedly.
RepeatEvent(uint32_t interval, react_callback callback)
Construct a new Repeat Event object.
void tick(EventLoop *event_loop) override
RepeatEvent(uint64_t interval, react_callback callback)
Construct a new Repeat Event object.
Event that is triggered when there is input available at the given Arduino Stream.
StreamEvent(Stream &stream, react_callback callback)
Construct a new Stream Event object.
void tick(EventLoop *event_loop) override
Event that is triggered unconditionally at each execution loop.
TickEvent(react_callback callback)
Construct a new Tick Event object.
void tick(EventLoop *event_loop) override
TimedEvents are called based on elapsing of time.
uint64_t getTriggerTimeMicros() const
TimedEvent(uint64_t interval, react_callback callback)
Construct a new Timed Event object.
virtual void add(EventLoop *event_loop) override
virtual void remove(EventLoop *event_loop) override
bool operator<(const TimedEvent &other) const
uint64_t last_trigger_time
uint32_t getTriggerTime() const
TimedEvent(uint32_t interval, react_callback callback)
Construct a new Timed Event object.
Events that are triggered based on something else than time.
UntimedEvent(react_callback callback)
void add(EventLoop *event_loop) override
void remove(EventLoop *event_loop) override
std::function< void()> react_callback
uint64_t ICACHE_RAM_ATTR micros64()
Return the current time since the device restart in microseconds.
void(*)(void *) isr_react_callback
EventInterface defines the interface for all events.
virtual ~EventInterface()=default
Default virtual destructor.
virtual void add(EventLoop *event_loop)=0
virtual void remove(std::shared_ptr< EventLoop > event_loop)
virtual void tick(EventLoop *event_loop)=0
virtual void remove(EventLoop *event_loop)=0
virtual void tick(std::shared_ptr< EventLoop > event_loop)
virtual void add(std::shared_ptr< EventLoop > event_loop)
bool operator()(TimedEvent *a, TimedEvent *b)