📄 ledoncoord.c
字号:
#include "LedOnCoord.h"
#include "zAPS.h"
#include "Console.h"
#include "show.h"
static ROM char * const ReceiveMsg = "Receive Data.\r\n";
static ROM char * const SendMsg = "Send Data.\r\n";
static EP_HANDLE hLED_D;
static EP_HANDLE hLED_S;
//static BYTE dataMSG;
static BYTE sendMSG;
static BYTE receiveBuf[20];
//static BYTE receiveCount;
typedef enum _LED_STATE
{
LED_IDLE = 0,
LED_SEND,
LED_WAIT
} LED_STATE;
static LED_STATE ledState;
void LEDInit(void)
{
hLED_D = APSOpenEP(EP_LED_D,
PICDEMZ_LED_CLUSTER_ID,
0,
FALSE);
hLED_S = APSOpenEP(EP_LED_S,
PICDEMZ_LED_CLUSTER_ID,
0,
FALSE);
sendMSG = FALSE;
ledState = LED_IDLE;
}
BOOL LEDTask(void)
{
BYTE dataLen;
BYTE transID;
/*if(getCmd)
{
getCmd = 0;
putValueToConsole(sendCount);
ConsolePutString(sendBuf);
sendCount = 0;
//sendMSG = TRUE;
//ledState = LED_SEND;
}*/
switch(ledState)
{
case LED_IDLE:
APSSetEP(hLED_S);
if ( APSIsGetReady() )
{
//ConsolePutROMString(ReceiveMsg);
// In MSG service, first two bytes are the transid, and length of payload to follow.
transID = APSGet();
dataLen = APSGet();
//dataMSG = APSGet();
if(dataLen > 19)
dataLen = 19;
APSGetArray(receiveBuf, dataLen);
ConsolePutString(receiveBuf);
//ConsolePut(dataMSG);
// After processing, you must discard current data packet.
APSDiscardRx();
return TRUE;
}
ledState = LED_SEND;
break;
case LED_SEND:
APSSetEP(hLED_D);
if ( APSIsPutReady() && sendMSG )
{
sendMSG = FALSE;
//APSSetClusterID(PICDEMZ_LED_CLUSTER_ID);
// As part of MSG APIs, you must declare total length of payload
// that you intend to transmit.
//size = sizeof(dataMSG);
//putValueToConsole(size);
if(sendCount <= 0)
return TRUE;
APSBeginMSG(sendCount);
//APSBeginMSG(1);
// Now load the entire command structure
//APSPutArray((BYTE*)&dataMSG, sizeof(dataMSG));
APSPutArray(sendBuf, sendCount);
// Send it.
APSSend();
//ConsolePutROMString(SendMsg);
//ledState = LED_WAIT;
//return TRUE;
}
ledState = LED_IDLE;
break;
}
// Task is complete.
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -