char str[9];
uint16 GasData;
uint16 adcReading;
char vol[6];
float vol_value;
osal_memset(vol, 0, 6);
adcReading = HalAdcRead(6,4); //选择通道6,以及12位分辨率
vol_value = (float)(adcReading/(float)4096)*3.3; //换算成电压值
vol_value = vol_value*2.172;//换算为压力值
format(vol_value, vol);
HalUARTWrite(0, (uint8 *)vol, 6);
HalUARTWrite(0, "\n", 1);
if ( AF_DataRequest( &SampleApp_P2P_DstAddr, &SampleApp_epDesc,
SAMPLEAPP_P2P_CLUSTERID,
6,
(uint8 *)vol,
&SampleApp_TransID,
AF_DISCV_ROUTE,
AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
{
//睡眠时间设定
halSleep(2000);
HalLedBlink( HAL_LED_2, 4, 50, 1000);
}
else
{
// Error occurred in request to send.
}
}
void format(float vol, char buf[6])
{
char ge = 0; //个位
char fen = 0; //分位
char shifen = 0; //十分位
char baifen = 0; //百分位
uint16 i = 0;
vol = vol*1000; //扩大1000倍
i = (uint16)vol; //转换为整形
ge = (i / 1000) + 0x30;//转成字符
fen = (i / 100 % 10) + 0x30;
shifen =(i % 100 / 10) + 0x30;
baifen = (i % 10) + 0x30;
buf[0] = ge;
buf[1] = '.';
buf[2] = fen;
buf[3] = shifen;
buf[4] = baifen;
buf[5] = 'v';
}
uint16 GasData;
uint16 adcReading;
char vol[6];
float vol_value;
osal_memset(vol, 0, 6);
adcReading = HalAdcRead(6,4); //选择通道6,以及12位分辨率
vol_value = (float)(adcReading/(float)4096)*3.3; //换算成电压值
vol_value = vol_value*2.172;//换算为压力值
format(vol_value, vol);
HalUARTWrite(0, (uint8 *)vol, 6);
HalUARTWrite(0, "\n", 1);
if ( AF_DataRequest( &SampleApp_P2P_DstAddr, &SampleApp_epDesc,
SAMPLEAPP_P2P_CLUSTERID,
6,
(uint8 *)vol,
&SampleApp_TransID,
AF_DISCV_ROUTE,
AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
{
//睡眠时间设定
halSleep(2000);
HalLedBlink( HAL_LED_2, 4, 50, 1000);
}
else
{
// Error occurred in request to send.
}
}
void format(float vol, char buf[6])
{
char ge = 0; //个位
char fen = 0; //分位
char shifen = 0; //十分位
char baifen = 0; //百分位
uint16 i = 0;
vol = vol*1000; //扩大1000倍
i = (uint16)vol; //转换为整形
ge = (i / 1000) + 0x30;//转成字符
fen = (i / 100 % 10) + 0x30;
shifen =(i % 100 / 10) + 0x30;
baifen = (i % 10) + 0x30;
buf[0] = ge;
buf[1] = '.';
buf[2] = fen;
buf[3] = shifen;
buf[4] = baifen;
buf[5] = 'v';
}