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

📄 main.c

📁 蓝牙HANDFREE软件源代码
💻 C
字号:
/*
  Main.c - This file contains the main function, which kicks off the
  hands free application.
*/
#include "handsfree_private.h"
#include "handsfree.h"

#ifdef HS_HF_ENABLED
#include "piohshf.h"
#endif

#include <event.h>
#include <message.h>
#include <print.h>
#include <sched.h>
#include <stdlib.h>
#include <vm.h>






/*
    This is a global variable used to maintain the state of the hands
    free device itself.  The structure is defined in handsfree_private.h and
    includes information such as which state the device is in (idle,
    connecting, etc.), whether or not it is paired, ...
*/

HandsFreeState HFstate ;


int main(void)
{
    /*
        Initialize the timer subsystem.  Now we can use timers in the
        application.
    */
    TimerInit();

#ifdef HS_HF_ENABLED
    /* If running as a pio driven combined headset/hands_free app then start it */
    pioHsHfInit();
#endif



    /*
        Kick off the Virtual Machine scheduler.  This is what calls
        each of the tasks in the application.
    */
    Sched();
    
    return 0;
}


/*
    This function is used to put a message in the message queue to be
    delivered to another task.  In this case, the message is always
    delivered to task #1.  In the scope of the Headset demo, task #1
    is the Headset Framework Handler (hsf_handler.c).
*/

void putMsg(void *msg)
{
    MessagePut(HEADSET_FRAMEWORK_TASK, msg) ;
}


/*
    This is the declaration of the handsfree task.  This loop is
    called by the scheduler to process any incoming messages/events
    from external tasks.  Many of the events may be the result of an
    action started by this task.
*/

DECLARE_TASK(2)
{
    /* Need a void msg pointer for incoming messages. */
    void * msg ;  

    /*
        We need to know what type of message was sent. This type may
        be different for each implementation of applications, but the
        messages will not be very much different than those already
        defined by the Connection Manager.
    */
    MessageType type ;  

    /*
        Get the message, if any, from the queue so that we can process
        it.  Notice that only one message is processed at a time.
    */
    msg = MessageGet(HANDSFREE_TASK, &type) ;

    if (msg)
    {
        switch (type)
        {
            /*
              The actions taken by openReq(), which was called in main() 
              have finished.
            */
            case HS_OPEN_CFM:
                hfOpenCfm((HS_OPEN_CFM_T*) msg);
                break ;
 
            /* The pairing operation has completed. */
            case HS_PAIR_CFM:
                hfPairCfm((HS_PAIR_CFM_T*) msg);
                break ;
            
            case HS_RESET_CFM:
                hfResetCfm((HS_RESET_CFM_T*) msg);
                break;

                /* The connect operation has completed. */
            case HS_CONNECT_CFM:
                hfConnectCfm((HS_CONNECT_CFM_T *) msg);
                break ;
                
                /*
                    Indication that the RFCOMM connection has been diconnected
                    This can be due to a user action or to a failure resulting in
                    the disconnection.
                */
            case HS_CONNECT_STATUS_IND:
                hfConnectStatusInd((HS_CONNECT_STATUS_IND_T *) msg);
                break ;
                
                /* Data contained in msg could not be parsed by the AT parser */
            case HS_CMD_IND :
                hfCmdInd((HS_CMD_IND_T *) msg);
                break ;

            /*
                There is an incoming call.  This is the indication that should
                cause the device to "ring" or otherwise indicate to the user
                that there is an incoming call.
            */
            case HS_RING_IND :
                hfRingInd((HS_RING_IND_T *) msg);
                break ;            

            /*
                This event indicates that an error has occurred and gives an error
                code to indicate what went wrong
            */
            case HS_ERROR_IND:
                hfErrorInd((HS_ERROR_IND_T *) msg);
                break;

            /* This event relays information about volume gain adjustments. */
            case HS_VGS_IND :
                hfVolumeInd((HS_VGS_IND_T *) msg);
                break ;                       
                                        
            /*
                This event indicates news about the SCO connection.  Generally
                the news informs the application of a SCO disconnection.
            */
            case HS_SCO_STATUS_IND :
                hfScoStatusInd((HS_SCO_STATUS_IND_T *) msg) ;
                break ;

            /* Microphone gain change indication */
            case HS_MIC_IND:
                hfMicrophoneInd((HS_MIC_IND_T *)msg);
                break;
                
            /* Caller id indication */
            case HANDSFREE_CALLER_ID_IND:
                hfCallerIdInd((HANDSFREE_CALLER_ID_IND_T *) msg);
                break;
            
            /* Indicator status update */
            case HANDSFREE_INDICATOR_STATUS_IND:
                hfIndicatorStatusInd((HANDSFREE_INDICATOR_STATUS_IND_T *)msg);
                break;

            /* The in-band ring setting of the AG has changed */
            case HANDSFREE_IN_BAND_RING_IND:
                hfInBandRingEnable((HANDSFREE_IN_BAND_RING_IND_T *)msg);
                break;

            /* Voice dial status update */
            case HANDSFREE_VOICE_DIAL_ENABLE_IND:
                hfVoiceDialEnableInd((HANDSFREE_VOICE_DIAL_ENABLE_IND_T *)msg);
                break;

            default :
                PRINT(("hands-free device: Unrecognised msg type 0x%x\n",type));
                break ;
        }
        MessageDestroy(msg);  /* Done with the message.  Free the memory. */
    }
}

⌨️ 快捷键说明

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