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

📄 pioag_buttons.c

📁 bluetooth audio gateway
💻 C
字号:
#include "pioag_private.h"
#include "ag.h"

#include <button.h>
#include <pio.h>
#include <ps.h>
#include <sched.h>
#include <stdlib.h>



/* 
    handleButtonChange
 
    This function is a call back from the button library, it is called
    every time the button states have changed. The PIO lines that are currently
    pressed come as a bit field in the first parameter. The changed parameter
    indicates the bit field of buttons that have changed since the last time
    this function was called. The function returns a parameter that indicates
    if the buttons should continue to be checked or not.
*/
ButtonChangeResult handleButtonChange(uint16 pressed, uint16 changed)
{
    uint16 new_set = pressed & changed;
    
    /* Check for chords first */
    if ((pressed & RESET_CONDITION) == RESET_CONDITION
        && (changed & RESET_CONDITION) != 0)
    {             
        if (agScoConnectedQuery())
        {
            /* Disconnect the SCO conection */
            agScoDisconnectReqAction(PioAgState.handle);
        }        
        else if (agRfcommConnectedQuery())
        {
            /* Disconnect the RFCOMM connection */
            agRfcommDisconnectReqAction(PioAgState.handle);
        }
        else  
        {
            /* Blow away pairing information */
            if (pioAgResetReq())                
                pioAgGetPinCode();            
        }

        return ButtonChangeContinue;
    }
    else if (new_set & PIO_ENTER1)
    {
        if (!PioAgState.pinEntered)
        {                        
            /* PIN digit selected */
            /* Clear LEDs */
            PioSet((LED1 | LED2), 0);
            
            /* 
                Convert input to ASCII, the count is actually 1 bigger than 
                intended due to the zero count at the beggining
            */
            if (PioAgState.pinCode[PioAgState.pinLengthBytes] != 0)
                PioAgState.pinCode[PioAgState.pinLengthBytes]--;
            
            PioAgState.pinCode[PioAgState.pinLengthBytes] += '0';                        
            
            /* Cancel Timer, adds delay between the enter and next pin number*/
            TimerCancel(PioAgState.timerHandle);
            PioAgState.timerHandle = NULL_TIMER;            

            /* Increase Pin Length we've just got one more digit */
            PioAgState.pinLengthBytes++;

            /* Check if we've reached the max allowed number of digits*/
            if (PioAgState.pinLengthBytes == MAX_PIN_LENGTH)
            {                             
                /* Stop getting more pin digits */
                pioAgPinEntryComplete();
            }
            else
            {
                /* Restart the timer and get the next pin digit */                
                pioAgGetPinCode();
            }
        }
        else if (agScoConnectedQuery())
        {
            /* Treat the buttons as volume controls if SCO up  - this is vol down */            
            pioAgVolumeReq(-1);            
        }
        else if (agRfcommConnectedQuery())
        {
            /* send a ring command to the headset */
            pioAgRingReq();
        }
        else
        {
            /* If connecting as slave flip to connect as master */
            pioAgCancelReq();
        }
        return ButtonChangeContinue;
    }
    else if(new_set & PIO_ENTER2)
    {
        if (!PioAgState.pinEntered)
        {
            /* Pin entry stage has completed, the user has said so */
            pioAgPinEntryComplete();
        }
        else if (agIdleQuery())
        {
            uint16 pin_length = 0;
            
            if(PsRetrieve(PIO_AG_PS_PIN_LENGTH, &pin_length, 1) && pin_length)
            {
                /* If we're idle go into pairing mode if we have a PIN code */
                pioAgInquiryReq();
            }
            else
            {
                /* First get a PIN code */
                if (pioAgResetReq())
                {
                    pioAgGetPinCode();
                }                
            }
        }
        else if (agScoConnectedQuery())
        {
            /* Treat the buttons as volume controls if SCO up - this is vol up */
            pioAgVolumeReq(1);
        }        
        return ButtonChangeContinue;
    }

    return ButtonChangeContinue;
}

⌨️ 快捷键说明

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