int main() { CYBLE_STACK_LIB_VERSION_T stackVersion; CyGlobalIntEnable; UART_DEB_Start(); /* Start communication component */ printf("BLE Heart Rate Sensor Example Project \r\n"); Disconnect_LED_Write(LED_OFF); Advertising_LED_Write(LED_OFF); /* Start CYBLE component and register generic event handler */ apiResult = CyBle_Start(AppCallBack); if(apiResult != CYBLE_ERROR_OK) { printf("CyBle_Start API Error: %x \r\n", apiResult); } apiResult = CyBle_GetStackLibraryVersion(&stackVersion); if(apiResult != CYBLE_ERROR_OK) { printf("CyBle_GetStackLibraryVersion API Error: 0x%x \r\n", apiResult); } else { printf("Stack Version: %d.%d.%d.%d \r\n", stackVersion.majorVersion, stackVersion.minorVersion, stackVersion.patch, stackVersion.buildNumber); } /* Services initialization */ HrsInit(); WDT_Start(); /*************************************************************************** * Main polling loop ***************************************************************************/ while(1) { /*********************************************************************** * Wait for connection established with Central device ***********************************************************************/ if(CyBle_GetState() == CYBLE_STATE_CONNECTED) { /******************************************************************* * Periodically simulate heart rate and measure a battery level * and send results to the Client *******************************************************************/ if(mainTimer != 0u) { mainTimer = 0u; if(heartRateSimulation == ENABLED) { SimulateHeartRate(); } } } /******************************************************************* * Process all pending BLE events in the stack *******************************************************************/ CyBle_ProcessEvents(); } }
int main() { CYBLE_LP_MODE_T lpMode; CYBLE_BLESS_STATE_T blessState; CYBLE_STACK_LIB_VERSION_T stackVersion; CyGlobalIntEnable; UART_DEB_Start(); /* Start communication component */ printf("BLE Heart Rate Collector Example Project \r\n"); Disconnect_LED_Write(LED_OFF); Scanning_LED_Write(LED_OFF); Notification_LED_Write(LED_OFF); apiResult = CyBle_Start(AppCallBack); if(apiResult != CYBLE_ERROR_OK) { printf("CyBle_Start API Error: 0x%x \r\n", apiResult); } apiResult = CyBle_GetStackLibraryVersion(&stackVersion); if(apiResult != CYBLE_ERROR_OK) { printf("CyBle_GetStackLibraryVersion API Error: 0x%x \r\n", apiResult); } else { printf("Stack Version: %d.%d.%d.%d \r\n", stackVersion.majorVersion, stackVersion.minorVersion, stackVersion.patch, stackVersion.buildNumber); } CyBle_BasRegisterAttrCallback(BasCallBack); HrsInit(); while(1) { if(CyBle_GetState() != CYBLE_STATE_INITIALIZING) { /* Enter DeepSleep mode between connection intervals */ lpMode = CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP); CyGlobalIntDisable; blessState = CyBle_GetBleSsState(); if(lpMode == CYBLE_BLESS_DEEPSLEEP) { if(blessState == CYBLE_BLESS_STATE_ECO_ON || blessState == CYBLE_BLESS_STATE_DEEPSLEEP) { /* Put the device into the DeepSleep mode only when all debug information has been sent */ if((UART_DEB_SpiUartGetTxBufferSize() + UART_DEB_GET_TX_FIFO_SR_VALID) == 0u) { CySysPmDeepSleep(); } else { CySysPmSleep(); } } } else { if(blessState != CYBLE_BLESS_STATE_EVENT_CLOSE) { CySysPmSleep(); } } CyGlobalIntEnable; /* Handle advertising led blinking */ HandleLeds(); } /* Store bonding data to flash only when all debug information has been sent */ if((cyBle_pendingFlashWrite != 0u) && ((UART_DEB_SpiUartGetTxBufferSize() + UART_DEB_GET_TX_FIFO_SR_VALID) == 0u)) { apiResult = CyBle_StoreBondingData(0u); printf("Store bonding data, status: %x \r\n", apiResult); } /******************************************************************* * Processes all pending BLE events in the stack *******************************************************************/ CyBle_ProcessEvents(); } }
int main() { CYBLE_LP_MODE_T lpMode; CYBLE_BLESS_STATE_T blessState; CyGlobalIntEnable; UART_DEB_Start(); /* Start communication component */ printf("BLE Secure Connection Example Project \r\n"); Disconnect_LED_Write(LED_OFF); Advertising_LED_Write(LED_OFF); /* Start CYBLE component and register generic event handler */ apiResult = CyBle_Start(AppCallBack); if(apiResult != CYBLE_ERROR_OK) { printf("CyBle_Start API Error: %x \r\n", apiResult); } /* Services initialization */ HrsInit(); /*************************************************************************** * Main polling loop ***************************************************************************/ while(1) { if(CyBle_GetState() != CYBLE_STATE_INITIALIZING) { /* Enter DeepSleep mode between connection intervals */ lpMode = CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP); CyGlobalIntDisable; blessState = CyBle_GetBleSsState(); if(lpMode == CYBLE_BLESS_DEEPSLEEP) { if(blessState == CYBLE_BLESS_STATE_ECO_ON || blessState == CYBLE_BLESS_STATE_DEEPSLEEP) { /* Put the device into the Deep Sleep mode only when all debug information has been sent */ if((UART_DEB_SpiUartGetTxBufferSize() + UART_DEB_GET_TX_FIFO_SR_VALID) == 0u) { CySysPmDeepSleep(); } else { CySysPmSleep(); } } } else { if(blessState != CYBLE_BLESS_STATE_EVENT_CLOSE) { CySysPmSleep(); } } CyGlobalIntEnable; } /*********************************************************************** * Wait for connection established with Central device ***********************************************************************/ if(CyBle_GetState() == CYBLE_STATE_CONNECTED) { /******************************************************************* * Periodically simulates heart beat and sends the results to the Client *******************************************************************/ mainTimer++; if(mainTimer == MAIN_LOOP_SIMULATION_THRESHOLD) { mainTimer = 0u; if(heartRateSimulation == ENABLED) { SimulateHeartRate(); CyBle_ProcessEvents(); } } else if((cyBle_pendingFlashWrite != 0u) && ((UART_DEB_SpiUartGetTxBufferSize() + UART_DEB_GET_TX_FIFO_SR_VALID) == 0u)) { apiResult = CyBle_StoreBondingData(0u); printf("Store bonding data, status: %x \r\n", apiResult); } else { /* nothing else */ } } /******************************************************************* * Process all pending BLE events in the stack *******************************************************************/ CyBle_ProcessEvents(); } }