Skip to content

Commit

Permalink
Merge pull request #32 from mairas/revert_micros64
Browse files Browse the repository at this point in the history
Revert micros64
  • Loading branch information
mairas authored Sep 26, 2024
2 parents ba2eedd + 78da58b commit a552d9e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 3.0.0
current_version = 3.0.1-alpha
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+))?
Expand Down
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = ReactESP
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 3.0.0
PROJECT_NUMBER = 3.0.1-alpha

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0
3.0.1-alpha
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}
],
"dependencies": [],
"version": "3.0.0",
"version": "3.0.1-alpha",
"frameworks": "arduino",
"platforms": "*"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ReactESP
version=3.0.0
version=3.0.1-alpha
author=Matti Airas <[email protected]>, Andrew Carter <[email protected]>
maintainer=Matti Airas <[email protected]>
sentence=Asynchronous programming library for the ESP32 and other microcontrollers compatible with the Arduino framework.
Expand Down
22 changes: 16 additions & 6 deletions src/ReactESP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@

namespace reactesp {

/**
* @brief Return the current time since the device restart in microseconds
*
* Returns the time since the device restart. Even though the time
* is in microseconds, a 64-bit integer is all but guaranteed not to
* rewrap, ever.
*/
#ifdef ESP32
uint64_t ICACHE_RAM_ATTR micros64() { return esp_timer_get_time(); }
#endif

// Event classes define the behaviour of each particular
// Event

Expand All @@ -27,22 +38,22 @@ void TimedEvent::remove(EventLoop* event_loop) {

DelayEvent::DelayEvent(uint32_t delay, react_callback callback)
: TimedEvent(delay, callback) {
this->last_trigger_time = micros();
this->last_trigger_time = micros64();
}

DelayEvent::DelayEvent(uint64_t delay, react_callback callback)
: TimedEvent(delay, callback) {
this->last_trigger_time = micros();
this->last_trigger_time = micros64();
}

void DelayEvent::tick(EventLoop* event_loop) {
this->last_trigger_time = micros();
this->last_trigger_time = micros64();
this->callback();
delete this;
}

void RepeatEvent::tick(EventLoop* event_loop) {
auto now = micros();
auto now = micros64();
this->last_trigger_time = this->last_trigger_time + this->interval;
if (this->last_trigger_time + this->interval < now) {
// we're lagging more than one full interval; reset the time
Expand Down Expand Up @@ -98,14 +109,13 @@ void ISREvent::remove(EventLoop* event_loop) {
}

void EventLoop::tickTimed() {
const uint64_t now = micros();
const uint64_t now = micros64();
TimedEvent* top = nullptr;

while (true) {
if (timed_queue.empty()) {
break;
}

top = timed_queue.top();
if (!top->isEnabled()) {
timed_queue.pop();
Expand Down
9 changes: 7 additions & 2 deletions src/ReactESP.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ using isr_react_callback = void (*)(void*);

class EventLoop;

// ESP32 doesn't have the micros64 function defined
#ifdef ESP32
uint64_t ICACHE_RAM_ATTR micros64();
#endif

/**
* @brief EventInterface defines the interface for all events
*/
Expand Down Expand Up @@ -71,7 +76,7 @@ class TimedEvent : public Event {
TimedEvent(uint32_t interval, react_callback callback)
: Event(callback),
interval((uint64_t)1000 * (uint64_t)interval),
last_trigger_time(micros()),
last_trigger_time(micros64()),
enabled(true) {}
/**
* @brief Construct a new Timed Event object
Expand All @@ -82,7 +87,7 @@ class TimedEvent : public Event {
TimedEvent(uint64_t interval, react_callback callback)
: Event(callback),
interval(interval),
last_trigger_time(micros()),
last_trigger_time(micros64()),
enabled(true) {}

bool operator<(const TimedEvent& other) const;
Expand Down

0 comments on commit a552d9e

Please sign in to comment.