【Nucleo+BLUENRG心得】+BLUENRG 通过APP控制 RGB
APP:Multitool
硬件:
Nucleo+BLUENRG心
BLUENRG 服务定义:
通过其中一个服务了解它
//添加SERVICE 0XFFF0
ret = aci_gatt_add_serv(UUID_TYPE_16, service_uuid, PRIMARY_SERVICE, 7+10, &sampleServHandle); /* original is 9?? */
if (ret != BLE_STATUS_SUCCESS) goto fail;
//1添加一个 Characteristic 服务 0XFFF1
ret = aci_gatt_add_char(sampleServHandle, UUID_TYPE_16, charUuidTX, 1, CHAR_PROP_READ|CHAR_PROP_WRITE|CHAR_PROP_WRITE_WITHOUT_RESP, ATTR_PERMISSION_NONE, GATT_SERVER_ATTR_WRITE,
16, 1, &TXCharHandle);
if (ret != BLE_STATUS_SUCCESS) goto fail;
//1添加一个特征描述符来服务
//Add a characteristic descriptor to a service
ret = aci_gatt_add_char_desc(sampleServHandle,
TXCharHandle,
UUID_TYPE_16,
(tHalUint8 *)&charUuidRX4,
22,
4,
(char *)"Rad",
ATTR_PERMISSION_NONE,
ATTR_ACCESS_READ_ONLY,
0,
16,
1,
&descHandle[0]);
其他类推!
接收程序
void Attribute_Modified_CB(tHalUint16 handle, tHalUint8 data_length, tHalUint8 *att_data)
{
uint8 newVal;
uint8 rgbwVal[LIGHTSPROFILE_RGBW_LEN];
if (handle == TXCharHandle + 1) //11 UUID=0xFFB1 ATT_CHAR_USER_DESC_UUID=Red 接收状态下 //if(att_data[0] == 0x01) notification_enabled = TRUE;
{
receiveData(att_data, data_length);
lvalRed = att_data[0] << 4;
}
else if(handle == RXCharHandle + 1) //13 UUID=0xFFB2,ATT_CHAR_USER_DESC_UUID=Green
{
receiveData(att_data, data_length);
lvalGreen = att_data[0] << 4;
}
else if(handle == RXCharHandle1+1 ) //15 UUID=0xFFB3,ATT_CHAR_USER_DESC_UUID=Blue
{
receiveData(att_data, data_length);
lvalBlue = att_data[0] << 4;
}
else if(handle == RXCharHandle2+1) //17 UUID=0xFFB4,ATT_CHAR_USER_DESC_UUID=White
{
receiveData(att_data, data_length);
lvalWhite = att_data[0] << 4;
}
else if(handle == RXCharHandle3+1 ) //19 UUID=0xFFB5,ATT_CHAR_USER_DESC_UUID=RGBW 总开/关
{
receiveData(att_data, data_length);
//BSP_LED_Toggle(LED2);
lvalRed = att_data[0] << 4;
lvalGreen = att_data[1] << 4;
lvalBlue = att_data[2] << 4;
lvalWhite = att_data[3] << 4;
}
pwmFadeVals();
pwmUpdateVals();
/* if(HAL_UART_Transmit(&UartHandle, (uint8_t*)att_data, data_length, 5000)!= HAL_OK)
{
Error_Handler();
}*/
}