4#include <FunctionalInterrupt.h>
15uint64_t ICACHE_RAM_ATTR micros64() {
return esp_timer_get_time(); }
51 auto now = micros64();
69 if (stream.available()) {
77bool ISRReaction::isr_service_installed =
false;
89 attachInterrupt(digitalPinToInterrupt(pin_number),
callback, mode);
97 gpio_isr_handler_remove((gpio_num_t)pin_number);
99 detachInterrupt(digitalPinToInterrupt(this->pin_number));
114void ReactESP::tickTimed() {
115 uint64_t now = micros64();
120 if (timed_queue.empty()) {
123 top = timed_queue.top();
130 if (now >= trigger_t) {
139void ReactESP::tickUntimed() {
std::function< void()> react_callback
Reaction that is triggered after a certain time delay.
DelayReaction(const uint32_t delay, const react_callback callback)
Construct a new Delay Reaction object.
Reaction that is triggered on an input pin change.
Main class of a ReactESP program.
ISRReaction * onInterrupt(const uint8_t pin_number, int mode, const react_callback cb)
Create a new ISRReaction (interrupt reaction)
static ReactESP * app
Static singleton reference to the instantiated ReactESP object.
RepeatReaction * onRepeatMicros(const uint64_t t, const react_callback cb)
Create a new RepeatReaction.
friend class RepeatReaction
TickReaction * onTick(const react_callback cb)
Create a new TickReaction.
StreamReaction * onAvailable(Stream &stream, const react_callback cb)
Create a new StreamReaction.
DelayReaction * onDelay(const uint32_t t, const react_callback cb)
Create a new DelayReaction.
DelayReaction * onDelayMicros(const uint64_t t, const react_callback cb)
Create a new DelayReaction.
RepeatReaction * onRepeat(const uint32_t t, const react_callback cb)
Create a new RepeatReaction.
const react_callback callback
Reaction that is triggered repeatedly.
Reaction that is triggered when there is input available at the given Arduino Stream.
Reaction that is triggered unconditionally at each execution loop.
TimedReactions are called based on elapsing of time.
uint64_t last_trigger_time
bool operator<(const TimedReaction &other)
Return the current time since the device restart in microseconds.
uint64_t getTriggerTimeMicros()
Reactions that are triggered based on something else than time.
void ICACHE_RAM_ATTR isr()