本篇博客介绍ember zigbee的custom event的用法,ember zigbee application framework提供事件机制,通过事件,你可以控制一个事件发生的具体时间。那么该如何使用事件?请看下面介绍:
一个custom event有两部分构成:
1、custom event执行函数(event function):当事件时间到了就会执行该函数,你可以在这个函数添加需要执行的代码;
2、custom event结构体(EmberEventControl struct):它用来管理事件的时间,它的定义如下:
typedef struct {
/** The event's status, either inactive or the units for timeToExecute. */
EmberEventUnits status;
/** The id of the task this event belongs to. */
EmberTaskId taskid;
/** How long before the event fires.
* Units are always in milliseconds
*/
int32u timeToExecute;
} EmberEventControl;
status用来记录事件的状态是非激活状态还是延时执行,taskid每个事件都有一个事件ID,timeToExecute下一次事件执行还需要等待的时间
要使用custom event首先要创建一个custom event,在app builder的include选项卡中添加自己的custom事件如下图: