You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
microbit-dal/source/MicroBitEvent.cpp

47 lines
1.1 KiB

/**
* 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);
}