2015-09-02 11:42:24 +00:00
|
|
|
#ifndef MICROBIT_EVENT_H
|
|
|
|
#define MICROBIT_EVENT_H
|
2015-08-12 10:53:41 +00:00
|
|
|
|
2015-09-11 15:39:38 +00:00
|
|
|
#include "mbed.h"
|
2015-08-12 10:53:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class definition for a MicrobitEvent
|
|
|
|
* It represents a common event that is generated by the various components on the MB.
|
|
|
|
*/
|
|
|
|
class MicroBitEvent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
//These are public at the moment for backwards compatability with old code
|
|
|
|
//will be refactored in the future!
|
|
|
|
|
|
|
|
uint16_t source; // ID of the MicroBit Component that generated the event e.g. MICROBIT_ID_BUTTON_A.
|
|
|
|
uint16_t value; // Component specific code indicating the cause of the event.
|
|
|
|
uint32_t timestamp; // Time at which the event was generated. ms since power on.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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(uint16_t source, uint16_t value, bool fire = true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default constructor - initialises all values, and sets timestamp to the current time.
|
|
|
|
*/
|
|
|
|
MicroBitEvent();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fires the represented event onto the message bus.
|
|
|
|
*/
|
|
|
|
void fire();
|
|
|
|
};
|
|
|
|
|
2015-09-11 15:39:38 +00:00
|
|
|
/**
|
|
|
|
* Enclosing class to hold a chain of events.
|
|
|
|
*/
|
|
|
|
struct MicroBitEventQueueItem
|
|
|
|
{
|
|
|
|
MicroBitEvent evt;
|
|
|
|
MicroBitEventQueueItem *next;
|
2015-08-12 10:53:41 +00:00
|
|
|
|
2015-09-11 15:39:38 +00:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
* Creates a new MicroBitEventQueueItem.
|
|
|
|
* @param evt The event that is to be queued.
|
|
|
|
*/
|
|
|
|
MicroBitEventQueueItem(MicroBitEvent evt);
|
|
|
|
};
|
2015-08-12 10:53:41 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|