microbit-dal/source/MicroBitEvent.cpp

59 lines
1.3 KiB
C++
Raw Normal View History

/**
* Class definition for a MicroBitEvent.
*
* The MicroBitEvent is the event object that represents an event that has occurred on the ubit.
*/
#include "MicroBit.h"
/**
* Constructor.
* @param src ID of the MicroBit Component that generated the event e.g. MICROBIT_ID_BUTTON_A.
* @param value Component specific code indicating the cause of the event.
* @param fire whether the event should be fire immediately upon construction
*
* Example:
* @code
* MicrobitEvent evt(id,MICROBIT_BUTTON_EVT_CLICK,true); // auto fire
* @endcode
*/
MicroBitEvent::MicroBitEvent(uint16_t source, uint16_t value, bool fire)
{
this->source = source;
this->value = value;
this->timestamp = ticks;
if(fire)
this->fire();
}
/**
* Default constructor - initialises all values, and sets timestamp to the current time.
*/
MicroBitEvent::MicroBitEvent()
{
this->source = 0;
this->value = 0;
this->timestamp = ticks;
}
/**
* Fires the represented event onto the message bus.
*/
void MicroBitEvent::fire()
{
uBit.MessageBus.send(*this);
}
microbit: Added configurable concurrency modes for MicroBitMessageBus handlers. MessageBus handlers can now have one of four concurrency modes for the eventuality of an event being raised whilst a previous event is still being processed. An additional (optional) parameter is provided to the listen() functions to allow this to be selected on a per event handler basis. The permissable options are: MESSAGE_BUS_LISTENER_REENTRANT: The event handler is fired with the new event, regardless of whether or not a previous event is still be processed by that handler. MESSAGE_BUS_LISTENER_QUEUE_IF_BUSY: The new event is queued until such a time as the previous event has completed execution. The new event is then processed. This option does not preclude the processing of the new event by other event handlers. MESSAGE_BUS_LISTENER_DROP_IF_BUSY: The new event is dropped, and will never be processed the the event handler. This option does not preclude the processing of the new event by other event handlers. MESSAGE_BUS_LISTENER_NONBLOCKING: The event handler is self-declaring that it never blocks. This flag is used purely for optimisation, as it permits direct execution of the event hadnelr without inducing any overhead from the scheduler. In addition, the following minor revisions were made in this release: * Cleanup of the #include dependencies contained in the microbit-dal .h files * Bugfix to the scheduler block on event matching code. * Introduced a MICROBIT_ID_ALERT MessageBus channel, for general purpose eventing using nonces.
2015-09-11 15:39:38 +00:00
/**
* Constructor.
* Create a new MicroBitEventQueueItem.
* @param evt The event to be queued.
*/
MicroBitEventQueueItem::MicroBitEventQueueItem(MicroBitEvent evt)
{
this->evt = evt;
this->next = NULL;
}