Revision 14
Added by Mark Anderson about 8 years ago
PSoC/BLE916/Labs/Completed Labs/BLE Lab 2/BLE Lab 2.cywrk | ||
---|---|---|
<?xml version="1.0" encoding="utf-8"?>
|
||
<CyXmlSerializer>
|
||
<!--This file is machine generated and read. It is not intended to be edited by hand.-->
|
||
<!--Due to this, there is no schema for this file.-->
|
||
<CyGuid_2867d519-54d2-4c01-9830-c51cb08bc3dd type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtWrkspc" version="5" xml_contents_version="3" name="BLE Lab 2" persistent="" platform="NOT_USED">
|
||
<current_project name=".\BLE Lab 2.cydsn\BLE Lab 2.cyprj" />
|
||
<wrkspc_folders />
|
||
<files />
|
||
<projects>
|
||
<v>.\BLE Lab 2.cydsn\BLE Lab 2.cyprj</v>
|
||
</projects>
|
||
<workspace_id v="9b4472fb-3b57-47da-a447-676891fa8675" />
|
||
<WriteAppVersionLastSavedWith v="3.1.0.1722" />
|
||
<WriteAppMarketingVersionLastSavedWith v="3.1 SP1" />
|
||
<CyGuid_dcbd9771-0334-43dc-9cc3-fe99dc3c5316 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjDependencyList" version="4">
|
||
<wrkspc_dependencies />
|
||
</CyGuid_dcbd9771-0334-43dc-9cc3-fe99dc3c5316>
|
||
<CyGuid_63b68103-67f5-4406-8da6-5c8625765b82 type_name="CyDesigner.Common.ProjMgmt.Model.CyIgnoredSystemDepsList" version="1">
|
||
<wrkspc_dependencies />
|
||
</CyGuid_63b68103-67f5-4406-8da6-5c8625765b82>
|
||
</CyGuid_2867d519-54d2-4c01-9830-c51cb08bc3dd>
|
||
</CyXmlSerializer>
|
PSoC/BLE916/Labs/Completed Labs/BLE Lab 2_1/BLE Lab 2_1.cydsn/BleProcessing.c | ||
---|---|---|
/*****************************************************************************
|
||
* File Name: BleProcessing.c
|
||
*
|
||
* Version: 1.0
|
||
*
|
||
* Description:
|
||
* This file implements the BLE capability in the PSoC 4 BLE Lab 3.
|
||
*
|
||
* Hardware Dependency:
|
||
* CY8CKIT-042 BLE Pioneer Kit
|
||
*
|
||
******************************************************************************
|
||
* Copyright (2014), Cypress Semiconductor Corporation.
|
||
******************************************************************************
|
||
* This software is owned by Cypress Semiconductor Corporation (Cypress) and is
|
||
* protected by and subject to worldwide patent protection (United States and
|
||
* foreign), United States copyright laws and international treaty provisions.
|
||
* Cypress hereby grants to licensee a personal, non-exclusive, non-transferable
|
||
* license to copy, use, modify, create derivative works of, and compile the
|
||
* Cypress Source Code and derivative works for the sole purpose of creating
|
||
* custom software in support of licensee product to be used only in conjunction
|
||
* with a Cypress integrated circuit as specified in the applicable agreement.
|
||
* Any reproduction, modification, translation, compilation, or representation of
|
||
* this software except as specified above is prohibited without the express
|
||
* written permission of Cypress.
|
||
*
|
||
* Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH
|
||
* REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||
* Cypress reserves the right to make changes without further notice to the
|
||
* materials described herein. Cypress does not assume any liability arising out
|
||
* of the application or use of any product or circuit described herein. Cypress
|
||
* does not authorize its products for use as critical components in life-support
|
||
* systems where a malfunction or failure may reasonably be expected to result in
|
||
* significant injury to the user. The inclusion of Cypress' product in a life-
|
||
* support systems application implies that the manufacturer assumes all risk of
|
||
* such use and in doing so indemnifies Cypress against all charges. Use may be
|
||
* limited by and subject to the applicable Cypress software license agreement.
|
||
*****************************************************************************/
|
||
|
||
|
||
/*****************************************************************************
|
||
* Included headers
|
||
*****************************************************************************/
|
||
#include <project.h>
|
||
#include <stdbool.h>
|
||
#include "main.h"
|
||
#include "HeartRateProcessing.h"
|
||
#include "BleProcessing.h"
|
||
|
||
|
||
/*****************************************************************************
|
||
* Macros
|
||
*****************************************************************************/
|
||
#define HEART_RATE_DATA_LEN (2)
|
||
#define HRM_FLAG (0)
|
||
|
||
|
||
/*****************************************************************************
|
||
* Static variables
|
||
*****************************************************************************/
|
||
static uint8 deviceConnected = false;
|
||
static uint8 hrsNotification = false;
|
||
|
||
|
||
/*****************************************************************************
|
||
* Public variables
|
||
*****************************************************************************/
|
||
bool enterHibernateFlag = false;
|
||
#if CONNECTION_PARAM_UPDATE
|
||
uint32 timestampWhenConnected = 0;
|
||
CONN_PARAM_REQUEST_STATE connParamRequestState = CONN_PARAM_REQUEST_NOT_SENT;
|
||
#endif
|
||
|
||
/*****************************************************************************
|
||
* Public function definitions
|
||
*****************************************************************************/
|
||
|
||
/*****************************************************************************
|
||
* Function Name: SendHeartRateOverBLE
|
||
******************************************************************************
|
||
* Summary:
|
||
* Creates and sends the Heart Rate Measurement characteristic notification
|
||
* packet.
|
||
*
|
||
* Parameters:
|
||
* None
|
||
*
|
||
* Return:
|
||
* None
|
||
*
|
||
* Theory:
|
||
* The function caches the value of the Heart Rate Measurement characteristic
|
||
* and updates the heart rate value in it. It then calls the BLE HRS service
|
||
* API to send this data via notification.
|
||
*
|
||
* Side Effects:
|
||
* None
|
||
*
|
||
*****************************************************************************/
|
||
void SendHeartRateOverBLE(void)
|
||
{
|
||
/* Two byte packet for heart rate notification since the heart rate
|
||
* measurement value is 8-bit (this is sufficient since our heart rate
|
||
* does not cross 255) and we are not using the Energy Expended
|
||
* and RR-interval fields.
|
||
*/
|
||
uint8 heartRatePacket[2];
|
||
|
||
if(hrsNotification)
|
||
{
|
||
/* Read the existing characteristic value into a
|
||
* two-byte array, by using CyBle_HrssGetCharacteristicValue().
|
||
*/
|
||
CyBle_HrssGetCharacteristicValue(CYBLE_HRS_HRM, HEART_RATE_DATA_LEN, heartRatePacket);
|
||
|
||
|
||
/* Update the second byte with the actual heart rate value. */
|
||
heartRatePacket[1] = heartRate;
|
||
|
||
|
||
/* Call the BLE component API to send notification */
|
||
CyBle_HrssSendNotification(cyBle_connHandle, CYBLE_HRS_HRM, HEART_RATE_DATA_LEN, heartRatePacket);
|
||
}
|
||
}
|
||
|
||
|
||
/*****************************************************************************
|
||
* Function Name: HrsEventHandler
|
||
******************************************************************************
|
||
* Summary:
|
||
* Event handler for the Heart Rate Service specific events.
|
||
*
|
||
* Parameters:
|
||
* event: An enumerated value to be checked and accordingly some action to
|
||
* be taken. The list of events is defined in the CYBLE_EVT_T enum.
|
||
*
|
||
* eventParam: The parameter associated with the event. The type of parameter
|
||
* can vary depending on the event. For more details refer the
|
||
* BLE component datasheet.
|
||
*
|
||
* Return:
|
||
* None
|
||
*
|
||
* Theory:
|
||
* The function implements a switch statement to handle the notification
|
||
* enable and notification disable events for the Heart Rate Service.
|
||
*
|
||
* Side Effects:
|
||
* None
|
||
*
|
||
*****************************************************************************/
|
||
void HrsEventHandler(uint32 event, void *eventParam)
|
||
{
|
||
/* Event handler switch statement for the HRS service specific events. */
|
||
|
||
|
||
/* Set the hrsNotification variable on the notification
|
||
* enabled event, and clear it on the disabled event.
|
||
*/
|
||
switch(event)
|
||
{
|
||
case CYBLE_EVT_HRSS_NOTIFICATION_ENABLED:
|
||
hrsNotification = true;
|
||
break;
|
||
|
||
case CYBLE_EVT_HRSS_NOTIFICATION_DISABLED:
|
||
hrsNotification = false;
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
/*****************************************************************************
|
||
* Function Name: GeneralEventHandler
|
||
******************************************************************************
|
||
* Summary:
|
||
* Event handler for generic BLE events.
|
||
*
|
||
* Parameters:
|
||
* event: An enumerated value to be checked and accordingly some action to
|
||
* be taken. The list of events is defined in the CYBLE_EVENT_T enum.
|
||
*
|
||
* eventParam: The parameter associated with the event. The type of parameter
|
||
* can vary depending on the event. For more details refer the
|
||
* BLE component datasheet.
|
||
*
|
||
* Return:
|
||
* None
|
||
*
|
||
* Theory:
|
||
* The function implements a switch case to handle different events for BLE
|
||
* advertisement, connection and disconnection.
|
||
*
|
||
* Side Effects:
|
||
* None
|
||
*
|
||
*****************************************************************************/
|
||
void GeneralEventHandler(uint32 event, void *eventParam)
|
||
{
|
||
/* Handle various events for a general BLE connection */
|
||
switch(event)
|
||
{
|
||
case CYBLE_EVT_STACK_ON:
|
||
/* Start the fast advertisement upon BLE initialization. */
|
||
CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);
|
||
|
||
#if (RGB_LED_IN_PROJECT)
|
||
/* Turn ON Green LED to indicate advertisement state */
|
||
Led_Advertising_Green_Write(0);
|
||
#endif /* #if (RGB_LED_IN_PROJECT) */
|
||
break;
|
||
|
||
case CYBLE_EVT_GAPP_ADVERTISEMENT_START_STOP:
|
||
/* If advertisement finished, then enter Hibernate mode. */
|
||
if(CYBLE_STATE_DISCONNECTED == CyBle_GetState())
|
||
{
|
||
enterHibernateFlag = true;
|
||
}
|
||
break;
|
||
|
||
case CYBLE_EVT_GAP_DEVICE_DISCONNECTED:
|
||
/* Enter hibernate mode upon disconnect */
|
||
enterHibernateFlag = true;
|
||
break;
|
||
|
||
case CYBLE_EVT_GATT_CONNECT_IND:
|
||
deviceConnected = true;
|
||
|
||
#if (RGB_LED_IN_PROJECT)
|
||
/* Turn OFF Green LED; Turn ON Blue LED to indicate Connection */
|
||
Led_Advertising_Green_Write(1);
|
||
Led_Connected_Blue_Write(0);
|
||
#endif /* #if (RGB_LED_IN_PROJECT) */
|
||
break;
|
||
|
||
case CYBLE_EVT_GATT_DISCONNECT_IND:
|
||
/* Clear the HRS notification flag and the device connected flag */
|
||
hrsNotification = false;
|
||
deviceConnected = false;
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/* [] END OF FILE */
|
PSoC/BLE916/Labs/Completed Labs/BLE Lab 2/BLE Lab 2.cydsn/BleProcessing.c | ||
---|---|---|
/*****************************************************************************
|
||
* File Name: BleProcessing.c
|
||
*
|
||
* Version: 1.0
|
||
*
|
||
* Description:
|
||
* This file implements the BLE capability in the PSoC 4 BLE Lab 3.
|
||
*
|
||
* Hardware Dependency:
|
||
* CY8CKIT-042 BLE Pioneer Kit
|
||
*
|
||
******************************************************************************
|
||
* Copyright (2014), Cypress Semiconductor Corporation.
|
||
******************************************************************************
|
||
* This software is owned by Cypress Semiconductor Corporation (Cypress) and is
|
||
* protected by and subject to worldwide patent protection (United States and
|
||
* foreign), United States copyright laws and international treaty provisions.
|
||
* Cypress hereby grants to licensee a personal, non-exclusive, non-transferable
|
||
* license to copy, use, modify, create derivative works of, and compile the
|
||
* Cypress Source Code and derivative works for the sole purpose of creating
|
||
* custom software in support of licensee product to be used only in conjunction
|
||
* with a Cypress integrated circuit as specified in the applicable agreement.
|
||
* Any reproduction, modification, translation, compilation, or representation of
|
||
* this software except as specified above is prohibited without the express
|
||
* written permission of Cypress.
|
||
*
|
||
* Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH
|
||
* REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||
* Cypress reserves the right to make changes without further notice to the
|
||
* materials described herein. Cypress does not assume any liability arising out
|
||
* of the application or use of any product or circuit described herein. Cypress
|
||
* does not authorize its products for use as critical components in life-support
|
||
* systems where a malfunction or failure may reasonably be expected to result in
|
||
* significant injury to the user. The inclusion of Cypress' product in a life-
|
||
* support systems application implies that the manufacturer assumes all risk of
|
||
* such use and in doing so indemnifies Cypress against all charges. Use may be
|
||
* limited by and subject to the applicable Cypress software license agreement.
|
||
*****************************************************************************/
|
||
|
||
|
||
/*****************************************************************************
|
||
* Included headers
|
||
*****************************************************************************/
|
||
#include <project.h>
|
||
#include <stdbool.h>
|
||
#include "main.h"
|
||
#include "HeartRateProcessing.h"
|
||
#include "BleProcessing.h"
|
||
|
||
|
||
/*****************************************************************************
|
||
* Macros
|
||
*****************************************************************************/
|
||
#define HEART_RATE_DATA_LEN (2)
|
||
#define HRM_FLAG (0)
|
||
|
||
|
||
/*****************************************************************************
|
||
* Static variables
|
||
*****************************************************************************/
|
||
static uint8 deviceConnected = false;
|
||
static uint8 hrsNotification = false;
|
||
|
||
|
||
/*****************************************************************************
|
||
* Public variables
|
||
*****************************************************************************/
|
||
bool enterHibernateFlag = false;
|
||
#if CONNECTION_PARAM_UPDATE
|
||
uint32 timestampWhenConnected = 0;
|
||
CONN_PARAM_REQUEST_STATE connParamRequestState = CONN_PARAM_REQUEST_NOT_SENT;
|
||
#endif
|
||
|
||
/*****************************************************************************
|
||
* Public function definitions
|
||
*****************************************************************************/
|
||
|
||
/*****************************************************************************
|
||
* Function Name: SendHeartRateOverBLE
|
||
******************************************************************************
|
||
* Summary:
|
||
* Creates and sends the Heart Rate Measurement characteristic notification
|
||
* packet.
|
||
*
|
||
* Parameters:
|
||
* None
|
||
*
|
||
* Return:
|
||
* None
|
||
*
|
||
* Theory:
|
||
* The function caches the value of the Heart Rate Measurement characteristic
|
||
* and updates the heart rate value in it. It then calls the BLE HRS service
|
||
* API to send this data via notification.
|
||
*
|
||
* Side Effects:
|
||
* None
|
||
*
|
||
*****************************************************************************/
|
||
void SendHeartRateOverBLE(void)
|
||
{
|
||
/* Two byte packet for heart rate notification since the heart rate
|
||
* measurement value is 8-bit (this is sufficient since our heart rate
|
||
* does not cross 255) and we are not using the Energy Expended
|
||
* and RR-interval fields.
|
||
*/
|
||
uint8 heartRatePacket[2];
|
||
|
||
if(hrsNotification)
|
||
{
|
||
/* Read the existing characteristic value into a
|
||
* two-byte array, by using CyBle_HrssGetCharacteristicValue().
|
||
*/
|
||
CyBle_HrssGetCharacteristicValue(CYBLE_HRS_HRM, HEART_RATE_DATA_LEN, heartRatePacket);
|
||
|
||
|
||
/* Update the second byte with the actual heart rate value. */
|
||
heartRatePacket[1] = heartRate;
|
||
|
||
|
||
/* Call the BLE component API to send notification */
|
||
CyBle_HrssSendNotification(cyBle_connHandle, CYBLE_HRS_HRM, HEART_RATE_DATA_LEN, heartRatePacket);
|
||
}
|
||
}
|
||
|
||
|
||
/*****************************************************************************
|
||
* Function Name: HrsEventHandler
|
||
******************************************************************************
|
||
* Summary:
|
||
* Event handler for the Heart Rate Service specific events.
|
||
*
|
||
* Parameters:
|
||
* event: An enumerated value to be checked and accordingly some action to
|
||
* be taken. The list of events is defined in the CYBLE_EVT_T enum.
|
||
*
|
||
* eventParam: The parameter associated with the event. The type of parameter
|
||
* can vary depending on the event. For more details refer the
|
||
* BLE component datasheet.
|
||
*
|
||
* Return:
|
||
* None
|
||
*
|
||
* Theory:
|
||
* The function implements a switch statement to handle the notification
|
||
* enable and notification disable events for the Heart Rate Service.
|
||
*
|
||
* Side Effects:
|
||
* None
|
||
*
|
||
*****************************************************************************/
|
||
void HrsEventHandler(uint32 event, void *eventParam)
|
||
{
|
||
/* Event handler switch statement for the HRS service specific events. */
|
||
|
||
|
||
/* Set the hrsNotification variable on the notification
|
||
* enabled event, and clear it on the disabled event.
|
||
*/
|
||
switch(event)
|
||
{
|
||
case CYBLE_EVT_HRSS_NOTIFICATION_ENABLED:
|
||
hrsNotification = true;
|
||
break;
|
||
|
||
case CYBLE_EVT_HRSS_NOTIFICATION_DISABLED:
|
||
hrsNotification = false;
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
/*****************************************************************************
|
||
* Function Name: GeneralEventHandler
|
||
******************************************************************************
|
||
* Summary:
|
||
* Event handler for generic BLE events.
|
||
*
|
||
* Parameters:
|
||
* event: An enumerated value to be checked and accordingly some action to
|
||
* be taken. The list of events is defined in the CYBLE_EVENT_T enum.
|
||
*
|
||
* eventParam: The parameter associated with the event. The type of parameter
|
||
* can vary depending on the event. For more details refer the
|
||
* BLE component datasheet.
|
||
*
|
||
* Return:
|
||
* None
|
||
*
|
||
* Theory:
|
||
* The function implements a switch case to handle different events for BLE
|
||
* advertisement, connection and disconnection.
|
||
*
|
||
* Side Effects:
|
||
* None
|
||
*
|
||
*****************************************************************************/
|
||
void GeneralEventHandler(uint32 event, void *eventParam)
|
||
{
|
||
/* Handle various events for a general BLE connection */
|
||
switch(event)
|
||
{
|
||
case CYBLE_EVT_STACK_ON:
|
||
/* Start the fast advertisement upon BLE initialization. */
|
||
CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);
|
||
|
||
#if (RGB_LED_IN_PROJECT)
|
||
/* Turn ON Green LED to indicate advertisement state */
|
||
Led_Advertising_Green_Write(0);
|
||
#endif /* #if (RGB_LED_IN_PROJECT) */
|
||
break;
|
||
|
||
case CYBLE_EVT_GAPP_ADVERTISEMENT_START_STOP:
|
||
/* If advertisement finished, then enter Hibernate mode. */
|
||
if(CYBLE_STATE_DISCONNECTED == CyBle_GetState())
|
||
{
|
||
enterHibernateFlag = true;
|
||
}
|
||
break;
|
||
|
||
case CYBLE_EVT_GAP_DEVICE_DISCONNECTED:
|
||
/* Enter hibernate mode upon disconnect */
|
||
enterHibernateFlag = true;
|
||
break;
|
||
|
||
case CYBLE_EVT_GATT_CONNECT_IND:
|
||
deviceConnected = true;
|
||
|
||
#if (RGB_LED_IN_PROJECT)
|
||
/* Turn OFF Green LED; Turn ON Blue LED to indicate Connection */
|
||
Led_Advertising_Green_Write(1);
|
||
Led_Connected_Blue_Write(0);
|
||
#endif /* #if (RGB_LED_IN_PROJECT) */
|
||
break;
|
||
|
||
case CYBLE_EVT_GATT_DISCONNECT_IND:
|
||
/* Clear the HRS notification flag and the device connected flag */
|
||
hrsNotification = false;
|
||
deviceConnected = false;
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/* [] END OF FILE */
|
PSoC/BLE916/Labs/Completed Labs/BLE Lab 2/BLE Lab 2.cydsn/HeartRateProcessing.c | ||
---|---|---|
/*****************************************************************************
|
||
* File Name: HeartRateProcessing.c
|
||
*
|
||
* Version: 1.0
|
||
*
|
||
* Description:
|
||
* This file implements the heart rate measurement capability in the the PSoC 4
|
||
* BLE Lab 3.
|
||
*
|
||
* Hardware Dependency:
|
||
* CY8CKIT-042 BLE Pioneer Kit
|
||
*
|
||
******************************************************************************
|
||
* Copyright (2014), Cypress Semiconductor Corporation.
|
||
******************************************************************************
|
||
* This software is owned by Cypress Semiconductor Corporation (Cypress) and is
|
||
* protected by and subject to worldwide patent protection (United States and
|
||
* foreign), United States copyright laws and international treaty provisions.
|
||
* Cypress hereby grants to licensee a personal, non-exclusive, non-transferable
|
||
* license to copy, use, modify, create derivative works of, and compile the
|
||
* Cypress Source Code and derivative works for the sole purpose of creating
|
||
* custom software in support of licensee product to be used only in conjunction
|
||
* with a Cypress integrated circuit as specified in the applicable agreement.
|
||
* Any reproduction, modification, translation, compilation, or representation of
|
||
* this software except as specified above is prohibited without the express
|
||
* written permission of Cypress.
|
||
*
|
||
* Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH
|
||
* REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||
* Cypress reserves the right to make changes without further notice to the
|
||
* materials described herein. Cypress does not assume any liability arising out
|
||
* of the application or use of any product or circuit described herein. Cypress
|
||
* does not authorize its products for use as critical components in life-support
|
||
* systems where a malfunction or failure may reasonably be expected to result in
|
||
* significant injury to the user. The inclusion of Cypress' product in a life-
|
||
* support systems application implies that the manufacturer assumes all risk of
|
||
* such use and in doing so indemnifies Cypress against all charges. Use may be
|
||
* limited by and subject to the applicable Cypress software license agreement.
|
||
*****************************************************************************/
|
||
|
||
|
||
/*****************************************************************************
|
||
* Included headers
|
||
*****************************************************************************/
|
||
#include <project.h>
|
||
#include <stdbool.h>
|
||
#include "WatchdogTimer.h"
|
||
|
||
|
||
/*****************************************************************************
|
||
* Macros
|
||
*****************************************************************************/
|
||
#define HEART_RATE_CHANNEL (0)
|
||
#define ADC_THRESHOLD (0x06A0)
|
||
#define SEC_IN_MIN (60)
|
||
#define MS_TO_SECOND (1000)
|
||
|
||
|
||
/*****************************************************************************
|
||
* Public variables
|
||
*****************************************************************************/
|
||
uint8 heartRate = 0;
|
||
|
||
|
||
/*****************************************************************************
|
||
* Public function definitions
|
||
*****************************************************************************/
|
||
|
||
/*****************************************************************************
|
||
* Function Name: ProcessHeartRateSignal
|
||
******************************************************************************
|
||
* Summary:
|
||
* Measures the heart rate of the user.
|
||
*
|
||
* Parameters:
|
||
* None
|
||
*
|
||
* Return:
|
||
* None
|
||
*
|
||
* Theory:
|
||
* This function acts as a simple model for heart rate measurement.
|
||
* The function takes the ADC sampled output and compares it to a threshold.
|
||
* If the ADC output is more than the threshold then it is considered as a
|
||
* valid beat (R peak). The rising edge of this R peak is identified and the
|
||
* corresponding system timestamp is noted. The RR-interval between two
|
||
* peaks is then calculated and converted to a heart rate value in beats per
|
||
* minute. The RR-interval period is calculated over a rolling window.
|
||
*
|
||
* Side Effects:
|
||
* None
|
||
*
|
||
*****************************************************************************/
|
||
void ProcessHeartRateSignal(void)
|
||
{
|
||
static bool newBeat = true;
|
||
static bool firstTime = true;
|
||
static uint32 previousBeatTime = 0;
|
||
static uint32 newBeatTime = 0;
|
||
int16 adcOut;
|
||
uint32 twoSampleTime = 0;
|
||
|
||
/* Get the ADC output */
|
||
ADC_StartConvert();
|
||
ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);
|
||
adcOut = ADC_GetResult16(HEART_RATE_CHANNEL);
|
||
|
||
/* If the ADC output is more than a fixed threshold, consider that a
|
||
* valid R peak */
|
||
if (adcOut > ADC_THRESHOLD)
|
||
{
|
||
/* Check if the R peak just started - i.e. identify the rising
|
||
* edge of the R peak */
|
||
if(newBeat)
|
||
{
|
||
/* Check if this is the first R-peak seen by the device yet.
|
||
* If that is the case, we cannot calculate a heart rate value
|
||
* yet since a minimum of two peak time interval is required.
|
||
* Just note the timestamp of this peak.
|
||
*/
|
||
if(firstTime == true)
|
||
{
|
||
firstTime = false;
|
||
previousBeatTime = WatchdogTimer_GetTimestamp();
|
||
}
|
||
else
|
||
{
|
||
/* Rolling window of two samples. Note the timestamp of
|
||
* the new peak and subtract the timestamp of the previous
|
||
* to obtain the RR-interval. Extrapolate it to get a heart
|
||
* beat value in beats per minute.
|
||
*/
|
||
newBeatTime = WatchdogTimer_GetTimestamp();
|
||
twoSampleTime = newBeatTime - previousBeatTime;
|
||
|
||
if(twoSampleTime != 0)
|
||
{
|
||
heartRate = (uint32)SEC_IN_MIN * MS_TO_SECOND / twoSampleTime;
|
||
}
|
||
|
||
previousBeatTime = newBeatTime;
|
||
}
|
||
}
|
||
|
||
/* Clear the flag to indicate next time that this R peak has already
|
||
* been accounted for and we need to wait for the next peak.
|
||
*/
|
||
newBeat = false;
|
||
}
|
||
else
|
||
{
|
||
/* Set the flag to indicate that there is no R-peak going on right now.
|
||
* So it is expected that the next time the ADC output is more than
|
||
* the threshold, it will be a new peak.
|
||
*/
|
||
newBeat = true;
|
||
}
|
||
}
|
||
|
||
|
||
/* [] END OF FILE */
|
PSoC/BLE916/Labs/Completed Labs/BLE Lab 2_1/BLE Lab 2_1.cydsn/HeartRateProcessing.h | ||
---|---|---|
/*****************************************************************************
|
||
* File Name: HeartRateProcessing.h
|
||
*
|
||
* Version: 1.0
|
||
*
|
||
* Description:
|
||
* This file declares the variables and functions for heart rate measurement
|
||
* implemented as part of the PSoC 4 BLE Lab 3.
|
||
*
|
||
* Hardware Dependency:
|
||
* CY8CKIT-042 BLE Pioneer Kit
|
||
*
|
||
******************************************************************************
|
||
* Copyright (2014), Cypress Semiconductor Corporation.
|
||
******************************************************************************
|
||
* This software is owned by Cypress Semiconductor Corporation (Cypress) and is
|
||
* protected by and subject to worldwide patent protection (United States and
|
||
* foreign), United States copyright laws and international treaty provisions.
|
||
* Cypress hereby grants to licensee a personal, non-exclusive, non-transferable
|
||
* license to copy, use, modify, create derivative works of, and compile the
|
||
* Cypress Source Code and derivative works for the sole purpose of creating
|
||
* custom software in support of licensee product to be used only in conjunction
|
||
* with a Cypress integrated circuit as specified in the applicable agreement.
|
||
* Any reproduction, modification, translation, compilation, or representation of
|
||
* this software except as specified above is prohibited without the express
|
||
* written permission of Cypress.
|
||
*
|
||
* Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH
|
||
* REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||
* Cypress reserves the right to make changes without further notice to the
|
||
* materials described herein. Cypress does not assume any liability arising out
|
||
* of the application or use of any product or circuit described herein. Cypress
|
||
* does not authorize its products for use as critical components in life-support
|
||
* systems where a malfunction or failure may reasonably be expected to result in
|
||
* significant injury to the user. The inclusion of Cypress' product in a life-
|
||
* support systems application implies that the manufacturer assumes all risk of
|
||
* such use and in doing so indemnifies Cypress against all charges. Use may be
|
||
* limited by and subject to the applicable Cypress software license agreement.
|
||
*****************************************************************************/
|
||
#if !defined(_HEARTRATE_PROCESSING_H)
|
||
#define _HEARTRATE_PROCESSING_H
|
||
|
||
|
||
/*****************************************************************************
|
||
* Included headers
|
||
*****************************************************************************/
|
||
#include <project.h>
|
||
|
||
|
||
/*****************************************************************************
|
||
* Public variables
|
||
*****************************************************************************/
|
||
extern uint8 heartRate;
|
||
|
||
|
||
/*****************************************************************************
|
||
* Public functions
|
||
*****************************************************************************/
|
||
extern void ProcessHeartRateSignal(void);
|
||
|
||
|
||
#endif
|
||
|
||
/* [] END OF FILE */
|
PSoC/BLE916/Labs/Completed Labs/BLE Lab 2_1/BLE Lab 2_1.cydsn/main.c | ||
---|---|---|
/*****************************************************************************
|
||
* File Name: main.c
|
||
*
|
||
* Version: 1.0
|
||
*
|
||
* Description:
|
||
* This is the top level file for the PSoC 4 BLE Lab 3.
|
||
*
|
||
* Hardware Dependency:
|
||
* CY8CKIT-042 BLE Pioneer Kit
|
||
*
|
||
******************************************************************************
|
||
* Copyright (2014), Cypress Semiconductor Corporation.
|
||
******************************************************************************
|
||
* This software is owned by Cypress Semiconductor Corporation (Cypress) and is
|
||
* protected by and subject to worldwide patent protection (United States and
|
||
* foreign), United States copyright laws and international treaty provisions.
|
||
* Cypress hereby grants to licensee a personal, non-exclusive, non-transferable
|
||
* license to copy, use, modify, create derivative works of, and compile the
|
||
* Cypress Source Code and derivative works for the sole purpose of creating
|
||
* custom software in support of licensee product to be used only in conjunction
|
||
* with a Cypress integrated circuit as specified in the applicable agreement.
|
||
* Any reproduction, modification, translation, compilation, or representation of
|
||
* this software except as specified above is prohibited without the express
|
||
* written permission of Cypress.
|
||
*
|
||
* Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH
|
||
* REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||
* Cypress reserves the right to make changes without further notice to the
|
||
* materials described herein. Cypress does not assume any liability arising out
|
||
* of the application or use of any product or circuit described herein. Cypress
|
||
* does not authorize its products for use as critical components in life-support
|
||
* systems where a malfunction or failure may reasonably be expected to result in
|
||
* significant injury to the user. The inclusion of Cypress' product in a life-
|
||
* support systems application implies that the manufacturer assumes all risk of
|
||
* such use and in doing so indemnifies Cypress against all charges. Use may be
|
||
* limited by and subject to the applicable Cypress software license agreement.
|
||
*****************************************************************************/
|
||
|
||
|
||
/*****************************************************************************
|
||
* Included headers
|
||
*****************************************************************************/
|
||
#include <project.h>
|
||
#include <stdbool.h>
|
||
#include "main.h"
|
||
#include "HeartRateProcessing.h"
|
||
#include "BleProcessing.h"
|
||
#include "WatchdogTimer.h"
|
||
|
||
|
||
/*****************************************************************************
|
||
* Macros
|
||
*****************************************************************************/
|
||
#if CONNECTION_PARAM_UPDATE
|
||
#define TIME_SINCE_CONNECTED_MS (5000)
|
||
#endif
|
||
|
||
/*****************************************************************************
|
||
* Global variables
|
||
*****************************************************************************/
|
||
#if CONNECTION_PARAM_UPDATE
|
||
static CYBLE_GAP_CONN_UPDATE_PARAM_T hrmConnectionParam =
|
||
{
|
||
16, /* Minimum connection interval of 20 ms */
|
||
16, /* Maximum connection interval of 20 ms */
|
||
49, /* Slave latency of 49 */
|
||
500 /* Supervision timeout of 5 seconds */
|
||
};
|
||
#endif
|
||
|
||
#if SENSOR_LOCATION
|
||
BODY_SENSOR_LOCATION hrmSensorLocation = EAR_LOBE;
|
||
#endif
|
||
|
||
/*****************************************************************************
|
||
* Static function definitions
|
||
*****************************************************************************/
|
||
|
||
/*****************************************************************************
|
||
* Function Name: InitializeSystem
|
||
******************************************************************************
|
||
* Summary:
|
||
* Initializes all the blocks of the system.
|
||
*
|
||
* Parameters:
|
||
* None
|
||
*
|
||
* Return:
|
||
* None
|
||
*
|
||
* Theory:
|
||
* The function enables the Opamp and ADC for the heart rate measurement, and
|
||
* setups the BLE component. It also starts the watchdog timer and ensures that
|
||
* all the status LEDs are off at system startup.
|
||
*
|
||
* Side Effects:
|
||
* None
|
||
*
|
||
*****************************************************************************/
|
||
static void InitializeSystem(void)
|
||
{
|
||
#if (RGB_LED_IN_PROJECT)
|
||
/* Turn off all LEDs */
|
||
Led_Advertising_Green_Write(1);
|
||
Led_Connected_Blue_Write(1);
|
||
#endif /* #if (RGB_LED_IN_PROJECT) */
|
||
|
||
/* Enabling Global interrupts */
|
||
CyGlobalIntEnable;
|
||
|
||
/* Start Opamp and ADC components */
|
||
Opamp_Start();
|
||
ADC_Start();
|
||
|
||
/* Start BLE component */
|
||
CyBle_Start(GeneralEventHandler);
|
||
|
||
|
||
/* Register the Heart Rate Service event handler callback. The function
|
||
* to be registered is HrsEventHandler().
|
||
*/
|
||
CyBle_HrsRegisterAttrCallback(HrsEventHandler);
|
||
|
||
#if SENSOR_LOCATION
|
||
/* Update Body Sensor Location Characteristic with new sensor location */
|
||
CyBle_HrssSetCharacteristicValue(CYBLE_HRS_BSL, sizeof(hrmSensorLocation), (uint8*)(&hrmSensorLocation));
|
||
#endif
|
||
|
||
/* Start the Watchdog Timer */
|
||
WatchdogTimer_Start();
|
||
}
|
||
|
||
|
||
/*****************************************************************************
|
||
* Public function definitions
|
||
*****************************************************************************/
|
||
|
||
/*****************************************************************************
|
||
* Function Name: main
|
||
******************************************************************************
|
||
* Summary:
|
||
* The main function for the project.
|
||
*
|
||
* Parameters:
|
||
* None
|
||
*
|
||
* Return:
|
||
* None
|
||
*
|
||
* Theory:
|
||
* The main function first calls the initialization function to start the
|
||
* system, and then enters a loop to run forever. In the main loop, it scans
|
||
* the heart rate first, then sends a notification packet every second to a
|
||
* BLE connected device. It then enters low power (deep sleep) state, waiting
|
||
* for the periodic wakeup interrupt from watchdog timer.
|
||
* When the device is disconnected or when advertisement timeout happens,
|
||
* the device enters Hibernate mode, waiting for the SW2 switch press to wakeup.
|
||
*
|
||
* Side Effects:
|
||
* None
|
||
*
|
||
*****************************************************************************/
|
||
int main()
|
||
{
|
||
static uint32 previousTimestamp = 0;
|
||
static uint32 currentTimestamp = 0;
|
||
CYBLE_LP_MODE_T bleMode;
|
||
uint8 interruptStatus;
|
||
|
||
/* Initialize all blocks of the system */
|
||
InitializeSystem();
|
||
|
||
/* Run forever */
|
||
for(;;)
|
||
{
|
||
/* Wake up Opamp from low power mode */
|
||
/* This API has not effect when Opamp is operating in deep sleep mode */
|
||
Opamp_Wakeup();
|
||
|
||
/* Wake up ADC from low power mode */
|
||
ADC_Wakeup();
|
||
|
||
/* Analog Front End.
|
||
* Detects the input signal and measures Heart Rate
|
||
*/
|
||
ProcessHeartRateSignal();
|
||
|
||
/* Put ADC in low power mode */
|
||
ADC_Sleep();
|
||
|
||
/* Put Opamp in low power mode */
|
||
/* This API has not effect when Opamp is operating in deep sleep mode */
|
||
Opamp_Sleep();
|
||
|
||
/* Measure the current system timestamp from watchdog timer */
|
||
currentTimestamp = WatchdogTimer_GetTimestamp();
|
||
|
||
#if CONNECTION_PARAM_UPDATE
|
||
/* Update BLE connection parameters a few seconds after connection */
|
||
if((CyBle_GetState() == CYBLE_STATE_CONNECTED) &&
|
||
(connParamRequestState == CONN_PARAM_REQUEST_NOT_SENT))
|
||
{
|
||
if((currentTimestamp - timestampWhenConnected) > TIME_SINCE_CONNECTED_MS)
|
||
{
|
||
CyBle_L2capLeConnectionParamUpdateRequest(cyBle_connHandle.bdHandle, &hrmConnectionParam);
|
||
connParamRequestState = CONN_PARAM_REQUEST_SENT;
|
||
}
|
||
}
|
||
#endif
|
||
|
||
/* Send Heart Rate notification over BLE every second.
|
||
* Check if the current timestamp minus previous exceeds 1000 ms.
|
||
*/
|
||
if((currentTimestamp - previousTimestamp) >= 1000)
|
||
{
|
||
/* Call API defined in BleProcessing.c to send
|
||
* notification over BLE.
|
||
*/
|
||
SendHeartRateOverBLE();
|
||
|
||
/* Update the previous timestamp with the current timestamp. */
|
||
previousTimestamp = currentTimestamp;
|
||
}
|
||
|
||
/* Try to stay in low power mode until the next watchdog interrupt */
|
||
while(WatchdogTimer_GetTimestamp() == currentTimestamp)
|
||
{
|
||
/* Process any pending BLE events */
|
||
CyBle_ProcessEvents();
|
||
|
||
/* The idea of low power operation is to first request the BLE
|
||
* block go to Deep Sleep, and then check whether it actually
|
||
* entered Deep Sleep. This is important because the BLE block
|
||
* runs asynchronous to the rest of the application and thus
|
||
* could be busy/idle independent of the application state.
|
||
*
|
||
* Once the BLE block is in Deep Sleep, only then the system
|
||
* can enter Deep Sleep. This is important to maintain the BLE
|
||
* connection alive while being in Deep Sleep.
|
||
*/
|
||
|
||
|
||
/* Request the BLE block to enter Deep Sleep */
|
||
bleMode = CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP);
|
||
|
||
|
||
/* Check if the BLE block entered Deep Sleep and if so, then the
|
||
* system can enter Deep Sleep. This is done inside a Critical
|
||
* Section (where global interrupts are disabled) to avoid a
|
||
* race condition between application main (that wants to go to
|
||
* Deep Sleep) and other interrupts (which keep the device from
|
||
* going to Deep Sleep).
|
||
*/
|
||
interruptStatus = CyEnterCriticalSection();
|
||
|
||
/* Check if the BLE block entered Deep Sleep */
|
||
if(CYBLE_BLESS_DEEPSLEEP == bleMode)
|
||
{
|
||
/* Check the current state of BLE - System can enter Deep Sleep
|
||
* only when the BLE block is starting the ECO (during
|
||
* pre-processing for a new connection event) or when it is
|
||
* idle.
|
||
*/
|
||
if((CyBle_GetBleSsState() == CYBLE_BLESS_STATE_ECO_ON) ||
|
||
(CyBle_GetBleSsState() == CYBLE_BLESS_STATE_DEEPSLEEP))
|
||
{
|
||
CySysPmDeepSleep();
|
||
}
|
||
}
|
||
/* The else condition signifies that the BLE block cannot enter
|
||
* Deep Sleep and is in Active mode.
|
||
*/
|
||
else
|
||
{
|
||
/* At this point, the CPU can enter Sleep, but Deep Sleep is not
|
||
* allowed.
|
||
* There is one exception - at a connection event, when the BLE
|
||
* Rx/Tx has just finished, and the post processing for the
|
||
* connection event is ongoing, the CPU cannot go to sleep.
|
||
* The CPU should wait in Active mode until the post processing
|
||
* is complete while continuously polling the BLE low power
|
||
* entry. As soon as post processing is complete, the BLE block
|
||
* would enter Deep Sleep (because of the polling) and the
|
||
* system Deep Sleep would then be entered. Deep Sleep is the
|
||
* preferred low power mode since it takes much lesser current.
|
||
*/
|
||
if(CyBle_GetBleSsState() != CYBLE_BLESS_STATE_EVENT_CLOSE)
|
||
{
|
||
CySysPmSleep();
|
||
}
|
||
}
|
||
|
||
/* Exit Critical section - Global interrupts are enabled again */
|
||
CyExitCriticalSection(interruptStatus);
|
||
}
|
||
|
||
/* Hibernate entry point - Hibernate is entered upon a BLE disconnect
|
||
* event or advertisement timeout. Wakeup happens via SW2 switch press,
|
||
* upon which the execution starts from the first line of code.
|
||
* The I/O state, RAM and UDBs are retained during Hibernate.
|
||
*/
|
||
if(enterHibernateFlag)
|
||
{
|
||
/* Stop the BLE component */
|
||
CyBle_Stop();
|
||
|
||
/* Enable the Hibernate wakeup functionality */
|
||
SW2_Switch_ClearInterrupt();
|
||
Wakeup_ISR_Start();
|
||
|
||
#if (RGB_LED_IN_PROJECT)
|
||
/* Turn off Green and Blue LEDs to indicate Hibernate */
|
||
Led_Advertising_Green_Write(1);
|
||
Led_Connected_Blue_Write(1);
|
||
|
||
/* Change the GPIO state to High-Z */
|
||
Led_Advertising_Green_SetDriveMode(Led_Advertising_Green_DM_ALG_HIZ);
|
||
Led_Connected_Blue_SetDriveMode(Led_Connected_Blue_DM_ALG_HIZ);
|
||
#endif /* #if (RGB_LED_IN_PROJECT) */
|
||
|
||
/* Enter hibernate mode */
|
||
CySysPmHibernate();
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/* [] END OF FILE */
|
PSoC/BLE916/Labs/Completed Labs/BLE Lab 2_1/BLE Lab 2_1.cydsn/main.h | ||
---|---|---|
/*****************************************************************************
|
||
* File Name: main.h
|
||
*
|
||
* Version: 1.0
|
||
*
|
||
* Description:
|
||
* This file defines the compile-time options required for the PSoC 4 BLE Lab 3.
|
||
*
|
||
* Hardware Dependency:
|
||
* CY8CKIT-042 BLE Pioneer Kit
|
||
*
|
||
******************************************************************************
|
||
* Copyright (2014), Cypress Semiconductor Corporation.
|
||
******************************************************************************
|
||
* This software is owned by Cypress Semiconductor Corporation (Cypress) and is
|
||
* protected by and subject to worldwide patent protection (United States and
|
||
* foreign), United States copyright laws and international treaty provisions.
|
||
* Cypress hereby grants to licensee a personal, non-exclusive, non-transferable
|
||
* license to copy, use, modify, create derivative works of, and compile the
|
||
* Cypress Source Code and derivative works for the sole purpose of creating
|
||
* custom software in support of licensee product to be used only in conjunction
|
||
* with a Cypress integrated circuit as specified in the applicable agreement.
|
||
* Any reproduction, modification, translation, compilation, or representation of
|
||
* this software except as specified above is prohibited without the express
|
||
* written permission of Cypress.
|
||
*
|
||
* Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH
|
||
* REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||
* Cypress reserves the right to make changes without further notice to the
|
||
* materials described herein. Cypress does not assume any liability arising out
|
||
* of the application or use of any product or circuit described herein. Cypress
|
||
* does not authorize its products for use as critical components in life-support
|
||
* systems where a malfunction or failure may reasonably be expected to result in
|
||
* significant injury to the user. The inclusion of Cypress' product in a life-
|
||
* support systems application implies that the manufacturer assumes all risk of
|
||
* such use and in doing so indemnifies Cypress against all charges. Use may be
|
||
* limited by and subject to the applicable Cypress software license agreement.
|
||
*****************************************************************************/
|
||
#if !defined (_MAIN_H)
|
||
#define _MAIN_H
|
||
|
||
|
||
/*****************************************************************************
|
||
* Compile Time Options
|
||
*****************************************************************************/
|
||
#define RGB_LED_IN_PROJECT (1)
|
||
#define CONNECTION_PARAM_UPDATE (0)
|
||
#define SENSOR_LOCATION (0)
|
||
|
||
#endif /* #ifndef (_MAIN_H) */
|
||
|
||
|
||
/* [] END OF FILE */
|
PSoC/BLE916/Labs/Completed Labs/BLE Lab 2_2/BLE Lab 2_2.cydsn/BleProcessing.c | ||
---|---|---|
/*****************************************************************************
|
||
* File Name: BleProcessing.c
|
||
*
|
||
* Version: 1.0
|
||
*
|
||
* Description:
|
||
* This file implements the BLE capability in the PSoC 4 BLE Lab 3.
|
||
*
|
||
* Hardware Dependency:
|
||
* CY8CKIT-042 BLE Pioneer Kit
|
||
*
|
||
******************************************************************************
|
||
* Copyright (2014), Cypress Semiconductor Corporation.
|
||
******************************************************************************
|
||
* This software is owned by Cypress Semiconductor Corporation (Cypress) and is
|
||
* protected by and subject to worldwide patent protection (United States and
|
||
* foreign), United States copyright laws and international treaty provisions.
|
||
* Cypress hereby grants to licensee a personal, non-exclusive, non-transferable
|
||
* license to copy, use, modify, create derivative works of, and compile the
|
||
* Cypress Source Code and derivative works for the sole purpose of creating
|
||
* custom software in support of licensee product to be used only in conjunction
|
||
* with a Cypress integrated circuit as specified in the applicable agreement.
|
||
* Any reproduction, modification, translation, compilation, or representation of
|
||
* this software except as specified above is prohibited without the express
|
||
* written permission of Cypress.
|
||
*
|
||
* Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH
|
||
* REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||
* Cypress reserves the right to make changes without further notice to the
|
||
* materials described herein. Cypress does not assume any liability arising out
|
||
* of the application or use of any product or circuit described herein. Cypress
|
||
* does not authorize its products for use as critical components in life-support
|
||
* systems where a malfunction or failure may reasonably be expected to result in
|
||
* significant injury to the user. The inclusion of Cypress' product in a life-
|
||
* support systems application implies that the manufacturer assumes all risk of
|
||
* such use and in doing so indemnifies Cypress against all charges. Use may be
|
||
* limited by and subject to the applicable Cypress software license agreement.
|
||
*****************************************************************************/
|
||
|
||
|
||
/*****************************************************************************
|
||
* Included headers
|
||
*****************************************************************************/
|
||
#include <project.h>
|
||
#include <stdbool.h>
|
||
#include "main.h"
|
||
#include "HeartRateProcessing.h"
|
||
#include "BleProcessing.h"
|
||
|
||
|
||
/*****************************************************************************
|
||
* Macros
|
||
*****************************************************************************/
|
||
#define HEART_RATE_DATA_LEN (2)
|
||
#define HRM_FLAG (0)
|
||
|
||
|
||
/*****************************************************************************
|
||
* Static variables
|
||
*****************************************************************************/
|
||
static uint8 deviceConnected = false;
|
||
static uint8 hrsNotification = false;
|
||
|
||
|
||
/*****************************************************************************
|
||
* Public variables
|
||
*****************************************************************************/
|
||
bool enterHibernateFlag = false;
|
||
#if CONNECTION_PARAM_UPDATE
|
||
uint32 timestampWhenConnected = 0;
|
||
CONN_PARAM_REQUEST_STATE connParamRequestState = CONN_PARAM_REQUEST_NOT_SENT;
|
||
#endif
|
||
|
||
/*****************************************************************************
|
||
* Public function definitions
|
||
*****************************************************************************/
|
||
|
||
/*****************************************************************************
|
||
* Function Name: SendHeartRateOverBLE
|
||
******************************************************************************
|
||
* Summary:
|
||
* Creates and sends the Heart Rate Measurement characteristic notification
|
||
* packet.
|
||
*
|
||
* Parameters:
|
||
* None
|
||
*
|
||
* Return:
|
||
* None
|
||
*
|
||
* Theory:
|
||
* The function caches the value of the Heart Rate Measurement characteristic
|
||
* and updates the heart rate value in it. It then calls the BLE HRS service
|
||
* API to send this data via notification.
|
||
*
|
||
* Side Effects:
|
||
* None
|
||
*
|
||
*****************************************************************************/
|
||
void SendHeartRateOverBLE(void)
|
||
{
|
||
/* Two byte packet for heart rate notification since the heart rate
|
||
* measurement value is 8-bit (this is sufficient since our heart rate
|
||
* does not cross 255) and we are not using the Energy Expended
|
||
* and RR-interval fields.
|
||
*/
|
||
uint8 heartRatePacket[2];
|
||
|
||
if(hrsNotification)
|
||
{
|
||
/* Read the existing characteristic value into a
|
||
* two-byte array, by using CyBle_HrssGetCharacteristicValue().
|
||
*/
|
||
CyBle_HrssGetCharacteristicValue(CYBLE_HRS_HRM, HEART_RATE_DATA_LEN, heartRatePacket);
|
||
|
||
|
||
/* Update the second byte with the actual heart rate value. */
|
||
heartRatePacket[1] = heartRate;
|
||
|
||
|
||
/* Call the BLE component API to send notification */
|
||
CyBle_HrssSendNotification(cyBle_connHandle, CYBLE_HRS_HRM, HEART_RATE_DATA_LEN, heartRatePacket);
|
||
}
|
||
}
|
||
|
||
|
||
/*****************************************************************************
|
||
* Function Name: HrsEventHandler
|
||
******************************************************************************
|
||
* Summary:
|
||
* Event handler for the Heart Rate Service specific events.
|
||
*
|
||
* Parameters:
|
||
* event: An enumerated value to be checked and accordingly some action to
|
||
* be taken. The list of events is defined in the CYBLE_EVT_T enum.
|
||
*
|
||
* eventParam: The parameter associated with the event. The type of parameter
|
||
* can vary depending on the event. For more details refer the
|
||
* BLE component datasheet.
|
||
*
|
||
* Return:
|
||
* None
|
||
*
|
||
* Theory:
|
||
* The function implements a switch statement to handle the notification
|
||
* enable and notification disable events for the Heart Rate Service.
|
||
*
|
||
* Side Effects:
|
||
* None
|
||
*
|
||
*****************************************************************************/
|
||
void HrsEventHandler(uint32 event, void *eventParam)
|
||
{
|
||
/* Event handler switch statement for the HRS service specific events. */
|
||
|
||
|
||
/* Set the hrsNotification variable on the notification
|
||
* enabled event, and clear it on the disabled event.
|
||
*/
|
||
switch(event)
|
||
{
|
||
case CYBLE_EVT_HRSS_NOTIFICATION_ENABLED:
|
||
hrsNotification = true;
|
||
break;
|
||
|
||
case CYBLE_EVT_HRSS_NOTIFICATION_DISABLED:
|
||
hrsNotification = false;
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
/*****************************************************************************
|
||
* Function Name: GeneralEventHandler
|
||
******************************************************************************
|
||
* Summary:
|
||
* Event handler for generic BLE events.
|
||
*
|
||
* Parameters:
|
||
* event: An enumerated value to be checked and accordingly some action to
|
||
* be taken. The list of events is defined in the CYBLE_EVENT_T enum.
|
||
*
|
||
* eventParam: The parameter associated with the event. The type of parameter
|
||
* can vary depending on the event. For more details refer the
|
||
* BLE component datasheet.
|
||
*
|
||
* Return:
|
||
* None
|
||
*
|
||
* Theory:
|
||
* The function implements a switch case to handle different events for BLE
|
||
* advertisement, connection and disconnection.
|
||
*
|
||
* Side Effects:
|
||
* None
|
||
*
|
||
*****************************************************************************/
|
||
void GeneralEventHandler(uint32 event, void *eventParam)
|
||
{
|
||
/* Handle various events for a general BLE connection */
|
||
switch(event)
|
||
{
|
||
case CYBLE_EVT_STACK_ON:
|
||
/* Start the fast advertisement upon BLE initialization. */
|
||
CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);
|
||
|
||
#if (RGB_LED_IN_PROJECT)
|
||
/* Turn ON Green LED to indicate advertisement state */
|
||
Led_Advertising_Green_Write(0);
|
||
#endif /* #if (RGB_LED_IN_PROJECT) */
|
||
break;
|
||
|
||
case CYBLE_EVT_GAPP_ADVERTISEMENT_START_STOP:
|
||
/* If advertisement finished, then enter Hibernate mode. */
|
||
if(CYBLE_STATE_DISCONNECTED == CyBle_GetState())
|
||
{
|
||
enterHibernateFlag = true;
|
||
}
|
||
break;
|
||
|
||
case CYBLE_EVT_GAP_DEVICE_DISCONNECTED:
|
||
/* Enter hibernate mode upon disconnect */
|
||
enterHibernateFlag = true;
|
||
break;
|
||
|
||
case CYBLE_EVT_GATT_CONNECT_IND:
|
||
deviceConnected = true;
|
||
|
||
#if (RGB_LED_IN_PROJECT)
|
||
/* Turn OFF Green LED; Turn ON Blue LED to indicate Connection */
|
||
Led_Advertising_Green_Write(1);
|
||
Led_Connected_Blue_Write(0);
|
||
#endif /* #if (RGB_LED_IN_PROJECT) */
|
||
break;
|
||
|
||
case CYBLE_EVT_GATT_DISCONNECT_IND:
|
||
/* Clear the HRS notification flag and the device connected flag */
|
||
hrsNotification = false;
|
||
deviceConnected = false;
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/* [] END OF FILE */
|
PSoC/BLE916/Labs/Completed Labs/BLE Lab 2_2/BLE Lab 2_2.cydsn/BLE Lab 2_2.cyprj | ||
---|---|---|
<?xml version="1.0" encoding="utf-8"?>
|
||
<CyXmlSerializer>
|
||
<!--This file is machine generated and read. It is not intended to be edited by hand.-->
|
||
<!--Due to this, there is no schema for this file.-->
|
||
<CyGuid_fec8f9e8-2365-4bdb-96d3-a4380222e01b type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtProjectPSoCExe" version="4">
|
||
<CyGuid_60697ce6-dce2-4816-8680-4de0635742eb type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtProjectExe" version="3">
|
||
<CyGuid_49cfd574-032a-4a64-b7be-d4eeeaf25e43 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtProject" version="7" xml_contents_version="1">
|
||
<CyGuid_2f73275c-45bf-46ba-b3b1-00a2fe0c8dd8 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtBaseContainer" version="1">
|
||
<CyGuid_31768f72-0253-412b-af77-e7dba74d1330 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItem" version="2" name="BLE Lab 2_2" persistent="">
|
||
<Hidden v="False" />
|
||
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
|
||
<CyGuid_0820c2e7-528d-4137-9a08-97257b946089 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItemList" version="2">
|
||
<dependencies>
|
||
<CyGuid_ebc4f06d-207f-49c2-a540-72acf4adabc0 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFolder" version="2">
|
||
<CyGuid_2f73275c-45bf-46ba-b3b1-00a2fe0c8dd8 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtBaseContainer" version="1">
|
||
<CyGuid_31768f72-0253-412b-af77-e7dba74d1330 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItem" version="2" name="Source Files" persistent="">
|
||
<Hidden v="False" />
|
||
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
|
||
<CyGuid_0820c2e7-528d-4137-9a08-97257b946089 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItemList" version="2">
|
||
<dependencies>
|
||
<CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFile" version="3" xml_contents_version="1">
|
||
<CyGuid_31768f72-0253-412b-af77-e7dba74d1330 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItem" version="2" name="main.c" persistent=".\main.c">
|
||
<Hidden v="False" />
|
||
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
|
||
<build_action v="C_FILE" />
|
||
<PropertyDeltas />
|
||
</CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b>
|
||
<CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFile" version="3" xml_contents_version="1">
|
||
<CyGuid_31768f72-0253-412b-af77-e7dba74d1330 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItem" version="2" name="HeartRateProcessing.c" persistent=".\HeartRateProcessing.c">
|
||
<Hidden v="False" />
|
||
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
|
||
<build_action v="C_FILE" />
|
||
<PropertyDeltas />
|
||
</CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b>
|
||
<CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFile" version="3" xml_contents_version="1">
|
||
<CyGuid_31768f72-0253-412b-af77-e7dba74d1330 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItem" version="2" name="BleProcessing.c" persistent=".\BleProcessing.c">
|
||
<Hidden v="False" />
|
||
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
|
||
<build_action v="C_FILE" />
|
||
<PropertyDeltas />
|
||
</CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b>
|
Also available in: Unified diff
adding the workshop labs