fsdfds
Dependencies: BLE_API mbed-dev-bin nRF51822
Fork of microbit-dal by
MicroBitEvent.h
00001 /* 00002 The MIT License (MIT) 00003 00004 Copyright (c) 2016 British Broadcasting Corporation. 00005 This software is provided by Lancaster University by arrangement with the BBC. 00006 00007 Permission is hereby granted, free of charge, to any person obtaining a 00008 copy of this software and associated documentation files (the "Software"), 00009 to deal in the Software without restriction, including without limitation 00010 the rights to use, copy, modify, merge, publish, distribute, sublicense, 00011 and/or sell copies of the Software, and to permit persons to whom the 00012 Software is furnished to do so, subject to the following conditions: 00013 00014 The above copyright notice and this permission notice shall be included in 00015 all copies or substantial portions of the Software. 00016 00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00020 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00021 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00022 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00023 DEALINGS IN THE SOFTWARE. 00024 */ 00025 00026 #ifndef MICROBIT_EVENT_H 00027 #define MICROBIT_EVENT_H 00028 00029 #include "mbed.h" 00030 #include "MicroBitConfig.h" 00031 00032 // Wildcard event codes 00033 #define MICROBIT_ID_ANY 0 00034 #define MICROBIT_EVT_ANY 0 00035 00036 enum MicroBitEventLaunchMode 00037 { 00038 CREATE_ONLY, 00039 CREATE_AND_FIRE 00040 }; 00041 00042 #define MICROBIT_EVENT_DEFAULT_LAUNCH_MODE CREATE_AND_FIRE 00043 00044 /** 00045 * Class definition for a MicroBitEvent 00046 * 00047 * It represents a common event that is generated by the various components on the micro:bit. 00048 */ 00049 class MicroBitEvent 00050 { 00051 public: 00052 00053 uint16_t source; // ID of the MicroBit Component that generated the event e.g. MICROBIT_ID_BUTTON_A. 00054 uint16_t value; // Component specific code indicating the cause of the event. 00055 uint64_t timestamp; // Time at which the event was generated. us since power on. 00056 00057 /** 00058 * Constructor. 00059 * 00060 * @param src The id of the MicroBit Component that generated the event e.g. MICROBIT_ID_BUTTON_A. 00061 * 00062 * @param value A component specific code indicating the cause of the event. 00063 * 00064 * @param mode Optional definition of how the event should be processed after construction (if at all): 00065 * CREATE_ONLY: MicroBitEvent is initialised, and no further processing takes place. 00066 * CREATE_AND_FIRE: MicroBitEvent is initialised, and its event handlers are immediately fired (not suitable for use in interrupts!). 00067 * 00068 * @code 00069 * // Create and launch an event using the default configuration 00070 * MicrobitEvent evt(id,MICROBIT_BUTTON_EVT_CLICK); 00071 * 00072 * // Create an event only, do not fire onto an EventModel. 00073 * MicrobitEvent evt(id,MICROBIT_BUTTON_EVT_CLICK,CREATE_AND_FIRE); 00074 * @endcode 00075 */ 00076 MicroBitEvent(uint16_t source, uint16_t value, MicroBitEventLaunchMode mode = MICROBIT_EVENT_DEFAULT_LAUNCH_MODE); 00077 00078 /** 00079 * Default constructor - initialises all values, and sets timestamp to the current time. 00080 */ 00081 MicroBitEvent(); 00082 00083 /** 00084 * Fires this MicroBitEvent onto the Default EventModel, or a custom one! 00085 */ 00086 void fire(); 00087 }; 00088 00089 /** 00090 * Enclosing class to hold a chain of events. 00091 */ 00092 struct MicroBitEventQueueItem 00093 { 00094 MicroBitEvent evt; 00095 MicroBitEventQueueItem *next; 00096 00097 /** 00098 * Constructor. 00099 * Create a new MicroBitEventQueueItem. 00100 * 00101 * @param evt The event to be queued. 00102 */ 00103 MicroBitEventQueueItem(MicroBitEvent evt); 00104 }; 00105 00106 #endif
Generated on Wed Jul 13 2022 00:58:03 by 1.7.2