📄 apus_sensor.c
字号:
|| (Apus_NwkState == DEV_NWK_REJOIN))
{
// find matched router node
ZDApp_AutoFindDestination( Apus_epDesc.endPoint );
}
break;
default:
break;
}
// Release the memory
osal_msg_deallocate( (uint8 *)MSGpkt );
// Next
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( Apus_TaskID );
}
// return unprocessed events
return (events ^ SYS_EVENT_MSG);
}
// Send a message out - This event is generated by a timer
// (setup in Apus_Init()).
if ( events & APUS_SEND_MSG_EVT )
{
DispTemperature();
// Send "the" message
Apus_SendTheMessage();
// Setup to send message again
osal_start_timer( APUS_SEND_MSG_EVT,
APUS_SEND_MSG_TIMEOUT );
// return unprocessed events
return (events ^ APUS_SEND_MSG_EVT);
}
// Discard unknown events
return 0;
}
/*********************************************************************
* Event Generation Functions
*/
/*********************************************************************
* @fn Apus_HandleKeys
*
* @brief Handles all key events for this device.
*
* @param shift - true if in shift/alt.
* @param keys - bit field for key events. Valid entries:
* HAL_KEY_SW_4
* HAL_KEY_SW_3
* HAL_KEY_SW_2
* HAL_KEY_SW_1
*
* @return none
*/
void Apus_HandleKeys( byte shift, byte keys )
{
// Shift is used to make each button/switch dual purpose.
if ( shift )
{
if ( keys & HAL_KEY_SW_1 )
{
}
if ( keys & HAL_KEY_SW_2 )
{
}
if ( keys & HAL_KEY_SW_3 )
{
}
if ( keys & HAL_KEY_SW_4 )
{
}
}
else
{
if ( keys & HAL_KEY_SW_1 )
{
osal_set_event(Apus_TaskID,APUS_DISP_VAL_EVT);
}
if ( keys & HAL_KEY_SW_2 )
{
// Initiate an End Device Bind Request for the mandatory endpoint
ZDApp_SendEndDeviceBindReq( Apus_epDesc.endPoint );
}
if ( keys & HAL_KEY_SW_3 )
{
}
if ( keys & HAL_KEY_SW_4 )
{
// Initiate a Match Description Request (Service Discovery)
// for the mandatory endpoint
ZDApp_AutoFindDestination( Apus_epDesc.endPoint );
}
}
}
/*********************************************************************
* LOCAL FUNCTIONS
*/
/*********************************************************************
* @fn Apus_MessageMSGCB
*
* @brief Data message processor callback. This function processes
* any incoming data - probably from other devices. So, based
* on cluster ID, perform the intended action.
*
* @param none
*
* @return none
*/
void Apus_MessageMSGCB( afIncomingMSGPacket_t *pkt )
{
char displayBuf[10];
uint16 shortAddr;
char ch;
char i;
displayBuf[0] = 'N';
displayBuf[1] = 'o';
displayBuf[2] = 'd';
displayBuf[3] = 'e';
displayBuf[4] = ':';
switch ( pkt->clusterId )
{
case APUS_CLUSTERID:
shortAddr = pkt->srcAddr.addr.shortAddr;
for (i=0; i<4; i++)
{
ch = (char ) (shortAddr >> (4* (3-i))) & 0x0f;
displayBuf[5+i] = ch + (( ch < 10 ) ? '0' : '7');
}
displayBuf [9] = '\0';
// "the" message
#if defined( LCD_SUPPORTED )
HalLcdWriteScreen(displayBuf, (char*)pkt->cmd.Data );
#elif defined( WIN32 )
WPRINTSTR( pkt->cmd.Data );
#endif
break;
}
}
/*********************************************************************
* @fn Apus_SendTheMessage
*
* @brief Send "the" message.
*
* @param none
*
* @return none
*/
void Apus_SendTheMessage( void )
{
uint8 buf[4];
buf[0]=HI_UINT16(temperature);
buf[1]=LO_UINT16(temperature);
buf[2]='\0';
if ( AF_DataRequest( &Apus_DstAddr, &Apus_epDesc,
APUS_CLUSTERID,
4, buf,
&Apus_TransID,
AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
{
// Successfully requested to be sent.
}
else
{
// Error occurred in request to send.
}
}
/******************************************************************************
*
* @fn GetTemperature
*
* @brief
* Return the temperature measured with the internal temperature sensor.
*
* Parameters:
*
* @param none
*
* @return temperature
*
******************************************************************************/
int16 GetTemperature(void)
{
uint16 value;
ADCIF = 0;
ADCCON3 = ( ADC_REF_1_25_V | ADC_14_BIT | ADC_TEMP_SENS );
while( !ADCIF );
value = ADCL;
value |= (uint16) (ADCH << 8);
return (int16) (ADC14_TO_CELSIUS(value));
}
/******************************************************************************
*
* @fn DispTemperature
*
* @brief
* Disp the temperature
*
* Parameters:
*
* @param void
*
* @return none
*
******************************************************************************/
void DispTemperature(void)
{
temperature = GetTemperature();
}
//buf[0]=temperature/100+'0';
//buf[1] = (temperature % 100)/10+'0';
// temperature %= 10;
// buf[2] = temperature +'0';
// buf[3]='\0';
/* if (temperature < 0)
{
buf[0] = '-';
temperature *= -1;
}
else
buf[0] = ' ';
buf[1] = temperature/100 + '0';
if(buf[1] == '0')
buf[1] = ' ';
buf[2] = (temperature % 100)/10 + '0';
buf[3] = '.';
temperature %= 10;
buf[4] = temperature + '0';
buf[5] = 'C';
buf[6] = '\0';
#if defined ( LCD_SUPPORTED )
//HalLcdWriteString( "The Present", HAL_LCD_LINE_1 );
HalLcdWriteString( (char*)buf, HAL_LCD_LINE_2 );
#endif*/
/*********************************************************************
*********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -