4#include <FunctionalInterrupt.h>
18uint64_t ICACHE_RAM_ATTR micros64() {
return esp_timer_get_time(); }
56 auto now = micros64();
63 event_loop->timed_queue.push(
this);
76 if (0 != stream.available()) {
84bool ISREvent::isr_service_installed =
false;
86void ISREvent::isr(
void* this_ptr) {
87 auto* this_ =
static_cast<ISREvent*
>(this_ptr);
94 gpio_isr_handler_add((gpio_num_t)pin_number, ISREvent::isr, (
void*)
this);
96 attachInterrupt(digitalPinToInterrupt(pin_number),
callback, mode);
104 gpio_isr_handler_remove((gpio_num_t)pin_number);
105#elif defined(ESP8266)
106 detachInterrupt(digitalPinToInterrupt(this->pin_number));
111void EventLoop::tickTimed() {
112 const uint64_t now = micros64();
116 if (timed_queue.empty()) {
119 top = timed_queue.top();
126 if (now >= trigger_t) {
135void EventLoop::tickUntimed() {
180 auto* isrre =
new ISREvent(pin_number, mode, callback);
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
Main event loop of a EventLoop program.
friend class UntimedEvent
DelayEvent * onDelayMicros(uint64_t delay, react_callback callback)
Create a new DelayEvent.
StreamEvent * onAvailable(Stream &stream, react_callback callback)
Create a new StreamEvent.
TickEvent * onTick(react_callback callback)
Create a new TickEvent.
DelayEvent * onDelay(uint32_t delay, react_callback callback)
Create a new DelayEvent.
RepeatEvent * onRepeatMicros(uint64_t interval, react_callback callback)
Create a new RepeatEvent.
ISREvent * onInterrupt(uint8_t pin_number, int mode, react_callback callback)
Create a new ISREvent (interrupt event)
RepeatEvent * onRepeat(uint32_t interval, react_callback callback)
Create a new RepeatEvent.
void remove(Event *event)
Remove a event from the list of active events.
Event that is triggered on an input pin change.
void remove(EventLoop *event_loop) override
void add(EventLoop *event_loop) override
Event that is triggered repeatedly.
void tick(EventLoop *event_loop) override
Event that is triggered when there is input available at the given Arduino Stream.
void tick(EventLoop *event_loop) override
Event that is triggered unconditionally at each execution loop.
void tick(EventLoop *event_loop) override
TimedEvents are called based on elapsing of time.
uint64_t getTriggerTimeMicros() const
void add(EventLoop *event_loop) override
void remove(EventLoop *event_loop) override
bool operator<(const TimedEvent &other) const
Return the current time since the device restart in microseconds.
uint64_t last_trigger_time
void add(EventLoop *event_loop) override
void remove(EventLoop *event_loop) override
std::function< void()> react_callback
virtual void tick(EventLoop *event_loop)=0