コード例 #1
0
ファイル: app_Ble.c プロジェクト: nlbutts/POVDisplay
/***************************************************************
 * Function to update the SW Version string
 **************************************************************/
void DisUpdateFirmWareRevision(void)
{
    CYBLE_STACK_LIB_VERSION_T stackVersion;
    uint8 fwRev[9u] = "0.0.0.000";

    if(CyBle_GetStackLibraryVersion(&stackVersion) == CYBLE_ERROR_OK)
    {
        /* Transform numbers to ASCII string */
        fwRev[0u] = stackVersion.majorVersion + '0';
        fwRev[2u] = stackVersion.minorVersion + '0';
        fwRev[4u] = stackVersion.patch + '0';
        fwRev[6u] = (stackVersion.buildNumber / 100u) + '0';
        stackVersion.buildNumber %= 100u;
        fwRev[7u] = (stackVersion.buildNumber / 10u) + '0';
        fwRev[8u] = (stackVersion.buildNumber % 10u) + '0';
    }

    CyBle_DissSetCharacteristicValue(CYBLE_DIS_FIRMWARE_REV, sizeof(fwRev), fwRev);
}
コード例 #2
0
ファイル: main.c プロジェクト: hakanjansson/psoc_nuggets
int main()
{
    hkj_timer t;
    const uint16 myCharHandle = 0x0E;
    uint8 writeData = 0;
    CYBLE_GATT_VALUE_T writeValue = \
        { &writeData, sizeof(writeData), sizeof(writeData) };
    CYBLE_GATTC_WRITE_REQ_T writeReqParam = \
        { .value = writeValue, .attrHandle = myCharHandle };

    CYBLE_STACK_LIB_VERSION_T stackVersion;

    CyGlobalIntEnable;
    UART_Start();
    hkj_debug_init();
    CyBle_GetStackLibraryVersion(&stackVersion);
    debug_print("Latency Central      Stack: %u.%u.%u.%u\r\n", \
        stackVersion.majorVersion, stackVersion.minorVersion, \
        stackVersion.patch, stackVersion.buildNumber);
    CyBle_Start(BleEventHandler);

    hkj_timer_ms_init(&t);
    while(1)
    {
        CyBle_ProcessEvents();
        if (connHandle.bdHandle != 0)
        {
            if (hkj_timer_ms_get_delta(&t) > 500)
            {
                WRITE_CMD_PIN_Write(1);
                CyBle_GattcWriteWithoutResponse(connHandle, &writeReqParam);
                hkj_timer_ms_reset_delta(&t);
                CyDelay(2); 
                WRITE_CMD_PIN_Write(0);
            }
        }
        hkj_ble_events_log_debug_print();
    }
}
コード例 #3
0
ファイル: main.c プロジェクト: zandervdl/PSoC-4-BLE
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();
    }
}
コード例 #4
0
ファイル: main.c プロジェクト: Ahamedjee/PSoC-4-BLE
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();
    }
}