FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
Loading...
Searching...
No Matches
events Namespace Reference

Defines all API to handle events within FastArduino programs. More...

Namespaces

namespace  Type
 Defines pre-defined types of events gegenarted by FastArduino API.
 

Classes

class  Dispatcher
 Utility to dispatch an event to a list of EventHandlers that are registered for its type. More...
 
class  Event
 A standard Event as managed by FastArduino event API. More...
 
class  EventHandler
 Abstract event handler, used by Dispatcher to get called back when an event of the expected type is dispatched. More...
 
class  Job
 Abstract class holding some action to be executed at given periods of time. More...
 
class  Scheduler
 Schedule jobs at predefined periods of time. More...
 

Detailed Description

Defines all API to handle events within FastArduino programs.

Some of FastArduino API use this API for event support.

In FastArduino, Events are handled mainly through an event queue, created by your program and passed to event API:

// Define the Event type we need (no additional value)
using namespace events;
using EVENT = Event<void>;
// Define the event queue we will use in the program
EVENT buffer[32];
containers::Queue<EVENT> event_queue{buffer};
int main()
{
... initialization code here ...
// Main event loop
while (true)
{
EVENT event = containers::pull(event_queue);
// Handle event here
}
}
Queue of type T_ items.
Definition: queue.h:59
A standard Event as managed by FastArduino event API.
Definition: events.h:144
T pull(Queue< T, TREF > &queue)
Pull an item from the beginning of queue.
Definition: queue.h:556
Defines all API to handle events within FastArduino programs.
Definition: events.h:82

Actually, the code above does not show FastArduino Event handling API but only the Event type.

Event support provides some API to more easily handle events once pulled from the event queue:

// Define an event handler
class MyHandler: public EventHandler<EVENT> {...};
int main()
{
// Instantiate event handlers (one per type of event)
MyHandler handler;
// Create Dispatcher and register each handler
Dispatcher<EVENT> dispatcher;
dispatcher.insert(handler);
// Main event loop
while (true)
{
EVENT event = containers::pull(event_queue);
dispatcher.dispatch(event);
}
}
void insert(T &item) INLINE
Insert item at the beginning of this list.
Definition: linked_list.h:103
Utility to dispatch an event to a list of EventHandlers that are registered for its type.
Definition: events.h:242
void dispatch(const EVENT &event)
Dispatch the given event to the right EventHandler, based on the event type.
Definition: events.h:258
Abstract event handler, used by Dispatcher to get called back when an event of the expected type is d...
Definition: events.h:288