Events are widley used in skyward-boardcore as a form of communication among software components.
The src/shared/events/Event.h
file defines the Event struct which only contains the event ID as a member:
struct Event
{
uint8_t sig;
}
Some basic event IDs are also defined in the EventSignal enumeration:
enum EventSignal : uint8_t
{
EV_ENTRY = 0,
EV_EXIT = 1,
EV_EMPTY = 2,
EV_INIT = 3,
EV_FIRST_SIGNAL = 4
};
The last one in particular, EV_FIRST_SIGNAL
is needed when defining new custom events.
In fact you can defined a new enumeration that extends EventFirstSignal, in order to expand the list of event IDs. The only thing you have to keep in mind is that the first event of your new enumeration has to be set equal to EV_FIRST_SIGNAL
. The following events in the enumeration can be manually specified or assigned automatically.
Moreover your enumeration should be of type uint8_t
in order to maintain the same type of the basic event IDs.
Example
This example shows a custom enumeration of events:
enum ExampleEvents : uint8_t
{
EV_1 = EV_FIRST_SIGNAL, // first event
EV_2,
EV_3
};