1#ifndef REACTESP_SRC_EVENTS_H_
2#define REACTESP_SRC_EVENTS_H_
22inline uint64_t ICACHE_RAM_ATTR
micros64() {
return esp_timer_get_time(); }
41 virtual void add(std::shared_ptr<EventLoop> event_loop) {
42 add(event_loop.get());
44 virtual void remove(std::shared_ptr<EventLoop> event_loop) {
47 virtual void tick(std::shared_ptr<EventLoop> event_loop) {
48 tick(event_loop.get());
147 if (ta != tb)
return ta < tb;
148 return std::less<const TimedEvent*>{}(a, b);
256 const uint8_t pin_number;
260 static bool isr_service_installed;
261 static void isr(
void* this_ptr);
276 gpio_int_type_t intr_type;
279 intr_type = GPIO_INTR_POSEDGE;
282 intr_type = GPIO_INTR_NEGEDGE;
285 intr_type = GPIO_INTR_ANYEDGE;
288 intr_type = GPIO_INTR_DISABLE;
292 gpio_set_intr_type((gpio_num_t)pin_number, intr_type);
294 if (!isr_service_installed) {
295 isr_service_installed =
true;
296 gpio_install_isr_service(ESP_INTR_FLAG_LOWMED);
DelayEvent(uint32_t delay, react_callback callback)
Construct a new Delay Event object.
void tick(EventLoop *event_loop) override
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.
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
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.
StreamEvent(Stream &stream, react_callback callback)
Construct a new Stream Event object.
void tick(EventLoop *event_loop) override
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.
bool isEnabled() const
Check if the event is still active.
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.
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)
Strict total ordering for TimedEvent pointers.
bool operator()(const TimedEvent *a, const TimedEvent *b) const