English
Language : 

AN91162 Datasheet, PDF (30/43 Pages) Ramtron International Corporation – Creating a BLE Custom Profile
Creating a BLE Custom Profile
void UpdateRGBcharacteristic(uint8* ledData, uint8 len, uint16 attrHandle)
{
/* 'rgbHandle' stores RGB control data parameters */
CYBLE_GATT_HANDLE_VALUE_PAIR_T
rgbHandle;
/* Update RGB control handle with new values */
rgbHandle.attrHandle = attrHandle;
rgbHandle.value.val = ledData;
rgbHandle.value.len = len;
/* Update the RGB LED attribute value. This will allow
* Client device to read the existing color values over
* RGB LED characteristic */
CyBle_GattsWriteAttributeValue(&rgbHandle,
FALSE,
&cyBle_connHandle,
CYBLE_GATT_DB_LOCALLY_INITIATED);
}
Handle BLE Disconnection
When the device is disconnected from the GATT client, the RGB LED and GATT database should be reset before next
connection. Place the following code snippet under the CYBLE_EVT_GATT_DISCONNECT_IND event in the general event
callback function:
case CYBLE_EVT_GATT_DISCONNECT_IND:
/* This event is generated at GATT disconnection */
/* Reset the color values*/
RGBledData[RED_INDEX] = FALSE;
RGBledData[GREEN_INDEX] = FALSE;
RGBledData[BLUE_INDEX] = FALSE;
RGBledData[INTENSITY_INDEX] = FALSE;
/* Switch off LEDs */
UpdateRGBLED(RGBledData, sizeof(RGBledData));
/* Register the new color in GATT DB*/
UpdateRGBcharacteristic(RGBledData,
sizeof(RGBledData),
CYBLE_RGB_LED_RGB_LED_CONTROL_CHAR_HANDLE);
break;
Main Function
With the general event callback function complete, we now modify the main function to initialize the Components in the project
and process the BLE events. Modify the main function already provided in main.c as shown here:
int main()
{
/* Start the components */
InitializeSystem();
www.cypress.com
Document No. 001-91162 Rev. *A
30