English
Language : 

AN91162 Datasheet, PDF (29/43 Pages) Ramtron International Corporation – Creating a BLE Custom Profile
Creating a BLE Custom Profile
/* Update the PrISM component density value to represent color */
UpdateRGBLED(RGBledData, sizeof(RGBledData));
/* Update the GATT DB for RGB LED read characteristics*/
UpdateRGBcharacteristic(RGBledData,
sizeof(RGBledData),
CYBLE_RGB_LED_RGB_LED_CONTROL_CHAR_HANDLE);
}
/* Send the response to the write request received. */
CyBle_GattsWriteRsp(cyBle_connHandle);
break;
The UpdateRGBLED function calculates the brightness of each of the RGB LEDs using the four-byte (red, green, blue,
intensity) values received. It then updates the density value of the PrISM Components to achieve the desired color. Place the
following function in the project (defined in the led.c file of the associated project):
void UpdateRGBLED(uint8* ledData, uint8 len)
{
/* Local variables to store calculated color components */
uint8 calc_red;
uint8 calc_green;
uint8 calc_blue;
/* Check if the array has length equal to expected length for
* RGB LED data */
if(len == RGB_CHAR_DATA_LEN)
{
/* True color to be displayed is calculated on basis of color
* and intensity value received */
calc_red = (uint8)
(((uint16)ledData[RED_INDEX]*ledData[INTENSITY_INDEX])/RGB_LED_MAX_VAL);
calc_green = (uint8)
(((uint16)ledData[GREEN_INDEX]*ledData[INTENSITY_INDEX])/RGB_LED_MAX_VAL);
calc_blue = (uint8)
(((uint16)ledData[BLUE_INDEX]*ledData[INTENSITY_INDEX])/RGB_LED_MAX_VAL);
/* Update the density value of the PrISM module */
PrISM_1_WritePulse0(RGB_LED_MAX_VAL - calc_red);
PrISM_1_WritePulse1(RGB_LED_MAX_VAL - calc_green);
PrISM_2_WritePulse0(RGB_LED_MAX_VAL - calc_blue);
}
}
Once the LED color is set, the GATT database has to be updated for the RGB LED characteristic so that the Client receives
the latest RGB color set when it sends a Read request. The UpdateRGBcharacteristic function updates the attribute
value for RGB LED color control. Add the following function in the project (defined in BLEProcess.c file of the associated
project).
www.cypress.com
Document No. 001-91162 Rev. *A
29