ring.c

来自「蓝牙耳机软件源代码」· C语言 代码 · 共 75 行

C
75
字号
#include "demohs.h"
#include "hal.h"

#include <audio.h>

#ifdef DEV_BOARD_HS
#include <pio.h>
#endif


static const audio_note twilight[] =
{
    AUDIO_TEMPO(180), AUDIO_VOLUME(64), AUDIO_TIMBRE(sine),
    AUDIO_NOTE(E7, QUAVER),
    AUDIO_NOTE(F7, QUAVER),
    AUDIO_NOTE(E7, QUAVER),
    AUDIO_NOTE(C7, QUAVER),
    
    AUDIO_NOTE(E7, QUAVER),
    AUDIO_NOTE(F7, QUAVER),
    AUDIO_NOTE(E7, QUAVER),
    AUDIO_NOTE(C7, QUAVER),

    AUDIO_END
};

#ifdef DEV_BOARD_HS
static Delay delayRingPlay(TimerHandle h)
{
    /* keep the compiler happy */
    h=h;
    
    /* play the ring tone */
    hsState.AudioRingHandle = AudioPlay(twilight);

    return D_NEVER;
}
#endif


/*
    ringInd 
    
    Called by the headset framework to tell us that a RING command has 
    been received over RFCOMM (state =1) or that the ring duration has 
    expired (state = 0)
*/
void ringInd(const HS_RING_IND_T * ind)
{
#ifdef DEV_BOARD_HS
    if(ind->state)
    {
        /* enable the codec */
        PioSet(PIO_CODEC, CODEC_ON);

        /* small delay */        
        TimerAdd(D_mSEC(100), delayRingPlay);        
    }
    else
    {
        if (!hsState.scoConnected)
        {
            /* 
                disable the codec only if there is no sco up otherwise 
                we'll be in trouble 
            */
            PioSet(PIO_CODEC, CODEC_OFF);
        }
    }
#else
    if (ind->state)
        hsState.AudioRingHandle = AudioPlay(twilight);
#endif
}

⌨️ 快捷键说明

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