⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pair.c

📁 蓝牙耳机软件源代码
💻 C
字号:
#include "demohs.h"
#include "hal.h"

#include <framework.h>
#include <message.h>
#include <print.h>


static void sendCallReject(void)
{
    MAKE_MSG(HS_REJECT_CALL_REQ);
    putMsg(msg);
}


/*
    pair

    Called when the user presses the 'pair' button.
*/
void pairButton(void)
{
    /* Take pairing action based on the current state of the headset. */
    switch (hsState.connectState)
    {
        /* If the headset is idle, initiate pairing */
        case idle :
        {
            /* Send a pair request */
            MAKE_MSG(HS_PAIR_REQ);
            msg->timeout = PAIRING_TIMEOUT;
            putMsg(msg);

            /* set the headset state */
            updateHsConnectState(pairing);
            hsState.pairingPending = 0;
        }
        break ;
                
        /*
            No longer have idle mode so we have to cancel the current 
            connect mode in order to go into pairing mode
        */
        case connectingAsSlave:
        case connectingAsMaster:
            cancelOperation();
            hsState.pairingPending = 1;
            break;
        
        /* 
            Reject call - since the pair button cannot be used when there 
            is an existing RFCOMM connection, use it to reject an incoming 
            call.
        */
        case connected:
            /* 
                TODO this code is unreachable since we removed the pair button 
                but keep it in for now as we can have an extra button on bc2 
                which can be used to reject a call 
            */
            sendCallReject();
            break;

        /* Remove the ability to cancel pairing */
        case pairing:
        /* For all other states, pairing is not possible */
        default:
            PRINT(("pair.c - pairButton() - can't pair in this state 0x%2x\n",hsState.connectState));
            break;
    }
}


/*
    pairCfm

    Called by the headset framework to indicate a change of pair
    status.  This can be one of a number of things: timout, acl
    connection, or link_key notification depending upon whether the
    Audio Gateway is using authentication.
*/
void pairCfm(const HS_PAIR_CFM_T * cfm)
{
    /* No matter the outcome of the pairing procedure, go to idle state */
    updateHsConnectState(idle);
    
    /*
        Take action based on the pairing status.  Currently, this
        function is not doing much of anything.  Consider this to be a
        framework for your own application.
    */
    switch (cfm->status)
    {
        case CmPairingComplete:
            talkButton();
            break;
        
        /* if pairing fails for any reason then go into pairing mode again */
        case CmPairingTimeout:
        case CmPairingCancelled:
        case CmPairingFail:
        case CmPairingNotFinished:
#ifdef DEV_BOARD_HS
            /* if we're trying to deep sleep don't re-enter pairing mode */
            if (hsState.turnOffHs)
            {
                updateHsConnectState(idle);
                return;
            }
#endif
            pairButton();
            break ;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -