天天看点

BLE实例-传感器采集

1.SimpleBLEPeripheral_ProcessEvent 中

if ( events & SBP_DHT11_READ_HUMITURE_EVT )
{
	//关总中断
	EA = 0;
	//采集 DHT11 温湿度
	DHT11_Read_Humiture(sbDHT11_data);
	//开总中断
	EA = 1;
	//启动定时器执行串口打印 DHT11 温湿度事件
	osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_DHT11_USART_EVT,
	SBP_DHT11_USART_EVT_PERIOD );
	//启动定时器执行周期采集 DHT11 温湿度事件
	osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_DHT11_READ_HUMITURE_EVT,
	SBP_DHT11_READ_HUMITURE_EVT_PERIOD );
	return (events ^ SBP_DHT11_READ_HUMITURE_EVT);
}

//串口打印 DHT11 温湿度事件
if ( events & SBP_DHT11_USART_EVT )
{
	uint8 nString[15] = {0};
	//温度
	sprintf((char *)nString, "DHT11 temp: %d.%d", sbDHT11_data[2], sbDHT11_data[3]);
	NPI_PrintString(nString);
	NPI_PrintString("\r\n");
	//湿度
	sprintf((char *)nString, "DHT11 humi: %d.%d", sbDHT11_data[0], sbDHT11_data[1]);
	NPI_PrintString(nString);
	NPI_PrintString("\r\n");
}
return (events ^ SBP_DHT11_USART_EVT);
           

2.添加调用 DHT11 采集事件

串口发送事件的宏

#define SBP_DHT11_READ_HUMITURE_EVT 0x0004			 //周期采集 DHT11 温湿度事件
#define SBP_DHT11_USART_EVT			0x0008 			//串口打印 DHT11 温湿度事件
           

事件用到的定时时间宏

#define SBP_DHT11_USART_EVT_PERIOD 			10
#define SBP_DHT11_READ_HUMITURE_EVT_PERIOD 	1000
           

在SimpleBLEPeripheral_ProcessEvent 中的 SBP_START_DEVICE_EVT 事件

if ( events & SBP_START_DEVICE_EVT )
{
	// Start the Device
	VOID GAPRole_StartDevice( &simpleBLEPeripheral_PeripheralCBs );
	// Start Bond Manager
	VOID GAPBondMgr_Register( &simpleBLEPeripheral_BondMgrCBs );
	// Set timer for first periodic event
	osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT,
	SBP_PERIODIC_EVT_PERIOD );
	//香瓜
	//启动定时器执行周期采集 DHT11 温湿度事件
	osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_DHT11_READ_HUMITURE_EVT,
	SBP_DHT11_READ_HUMITURE_EVT_PERIOD );
	//香瓜
	return ( events ^ SBP_START_DEVICE_EVT );
}
           

基于香瓜综合项目总结。

继续阅读