FastArduino  v1.7
C++ library to build fast but small Arduino/AVR projects
events Namespace Reference

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

Namespaces

 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
}
}

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);
}
}
containers::Queue< EVENT >
events::Event
A standard Event as managed by FastArduino event API.
Definition: events.h:144
events
Defines all API to handle events within FastArduino programs.
Definition: events.h:82
containers::pull
T pull(Queue< T, TREF > &queue)
Pull an item from the beginning of queue.
Definition: queue.h:556