The SmartSyncEvent
library provides a convenient way to manage timed events in Arduino and ESP32 projects, enabling you to check whether a certain amount of time has passed since the last event trigger.
- Automatic Instance Management: Manages unique event instances based on the file and line of invocation.
- Thread Safety: Provides thread-safe handling for ESP32 projects.
- Convenience: Utilize through a simple macro for triggering events.
PlatformIO offers a streamlined way to manage your project dependencies.
- Open your platformio.ini file in the root of your project.
- Add the following line under your environment's lib_deps:
lib_deps =
https://github.com/SlimeCodex/SmartSyncEvent@^1.0.0
- Save the platformio.ini file.
- Build your project. PlatformIO will automatically fetch and install the SmartSyncEvent library.
#include "SmartSyncEvent.h"
Utilize the SYNC_EVENT(ms)
macro. This returns a Result struct, which can be implicitly cast to bool to verify if the event was triggered. Moreover, the event's unique ID can be accessed with the .event_id member.
if (SYNC_EVENT(500)) {
// This block will execute every 500ms.
}
Directly obtain a unique ID for an event:
auto result = SYNC_EVENT(1000);
unsigned int event_id = result.event_id;
For manual timer resets of any sync event:
SmartSyncEvent::reset(event_id);
To enable a previously disabled event:
SmartSyncEvent::enable(event_id);
To disable a previously enabled event:
SmartSyncEvent::disable(event_id);
The force method provides a way to manually enforce an event to trigger the next time it's checked, regardless of the time interval set during its creation.
SmartSyncEvent::force(event_id);
Distributed under the GPL-3.0 License. See the LICENSE file for more information.