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

📄 headset_leds.c

📁 蓝牙耳机的源代码,结合csr的开发套件使用
💻 C
📖 第 1 页 / 共 3 页
字号:
        }    }    return lColour ;}/****************************************************************************NAME  LMGetLEDStateFromPatternDESCRIPTION    Fn to determine the state of the active LED given appatern that is     currently being played    RETURNS bool - state of the last used LED*/static bool LedsGetLEDStateFromPattern ( LedTaskData * pLEDTask , const LEDPattern_t * pPattern , const LEDActivity_t * pLED  ) {        bool lState = LED_OFF ;        /*Q - Is it not just off then on depending on the odd / even?    if (pLEDTask->gActiveLEDS [ pPattern->LED_A ].NumFlashesComplete % 2 )    {        lState = LED_ON ;    }    */    lState = pLEDTask->gActiveLEDS [ pPattern->LED_A ].OnOrOff ;    return lState ;}/****************************************************************************NAME  LMApplyFilterToTimeDESCRIPTION    Fn to change the callback time if a filter has been applied - if no filter is applied    just returns the original time    RETURNS uint16 the callback time*/static uint16 LedsApplyFilterToTime ( LedTaskData * pLEDTask ,uint16 pTime ) {    uint16 lFilterIndex = 0 ;    uint16 lTime = pTime ;         for (lFilterIndex = 0 ; lFilterIndex< 10 ; lFilterIndex++ )    {        if ( LedsIsFilterEnabled(pLEDTask , lFilterIndex) )        {            if ( pLEDTask->gEventFilters[lFilterIndex].Speed )            {                if (pLEDTask->gEventFilters[lFilterIndex].SpeedAction == SPEED_MULTIPLY)                {                    LED_DEBUG(("LED: FIL_MULT[%d]\n" , pLEDTask->gEventFilters[lFilterIndex].Speed )) ;                    lTime *= pLEDTask->gEventFilters[lFilterIndex].Speed ;                }                else /*we want to divide*/                {                    if (lTime)                    {                       LED_DEBUG(("LED: FIL_DIV[%d]\n" , pLEDTask->gEventFilters[lFilterIndex].Speed )) ;                      lTime /= pLEDTask->gEventFilters[lFilterIndex].Speed ;                    }                }            }        }    }    return lTime ;}/****************************************************************************NAME  LEDManagerSendEventCompleteDESCRIPTION    Sends a message to the main task thread to say that an event indication has been completed        RETURNS void*/void LedsSendEventComplete ( headsetEvents_t pEvent , bool pPatternCompleted ){    LMEndMessage_t * lEventMessage = PanicUnlessNew ( LMEndMessage_t ) ;            /*check that the event is in the expected range*/    if ( (pEvent > EVENTS_EVENT_BASE) && (pEvent < EVENTS_LAST_EVENT ) )    {               /*need to add the message containing the EventType here*/        lEventMessage->Event = pEvent  ;        lEventMessage->PatternCompleted =  pPatternCompleted ;                                LED_DEBUG(("LM : lEvCmp[%x] [%x]\n",lEventMessage->Event , lEventMessage->PatternCompleted )) ;                    MessageSend ( getAppTask() , EventLEDEventComplete , lEventMessage ) ;    }    else    {     /*   LED_DEBUG(("LM : Comp[%x] ?\n",pEvent)) ;*/    }}static void LedsCancelStateIndications ( LedTaskData * pLEDTask ) {      uint16 lLoop = 0;        for ( lLoop = 0 ; lLoop < HEADSET_NUM_LEDS ; lLoop ++ )    {        if (pLEDTask->gActiveLEDS[lLoop].Type == IT_StateIndication)        {            MessageCancelAll ( &pLEDTask->task, lLoop ) ;             pLEDTask->gActiveLEDS[lLoop].Type =  IT_Undefined ;                        LED_DEBUG(("LED: CancelStateInd[%x]\n" , lLoop)) ;            LedsTurnOffLEDPair ( pLEDTask , pLEDTask->gStatePatterns[pLEDTask->gActiveLEDS[lLoop].Index] ,TRUE) ;        }    }}    static void LedsCancelEventIndications ( LedTaskData * pLEDTask ) {        uint16 lLoop = 0;        for ( lLoop = 0 ; lLoop < HEADSET_NUM_LEDS ; lLoop ++ )    {        if (pLEDTask->gActiveLEDS[lLoop].Type == IT_EventIndication)        {            MessageCancelAll ( &pLEDTask->task, lLoop ) ;             pLEDTask->gActiveLEDS[lLoop].Type =  IT_Undefined ;                        LED_DEBUG(("LED: CancelEventInd[%x]\n" , lLoop)) ;            LedsTurnOffLEDPair ( pLEDTask , pLEDTask->gEventPatterns[pLEDTask->gActiveLEDS[lLoop].Index] ,TRUE) ;        }    }}    void LedsEventComplete ( LedTaskData * pLEDTask, LEDActivity_t * pPrimaryLed , LEDActivity_t * pSecondaryLed ) {           pPrimaryLed->Type = IT_Undefined ;        pSecondaryLed->Type = IT_Undefined ;        pLEDTask->gCurrentlyIndicatingEvent = FALSE ;    /* restart state indication */    LEDManagerIndicateState ( pLEDTask , stateManagerGetState () ) ;     }        static void LedsEnableFilter ( LedTaskData * pLEDTask ,  uint16 pFilter , bool pEnable){    #ifdef DEBUG_LEDS    #ifdef DEBUG_PRINT_ENABLED        uint16 lOldMask = pLEDTask->gTheActiveFilters ;    #endif    #endif    if (pEnable)    {            /*to set*/        pLEDTask->gTheActiveFilters |= (  0x1 << pFilter ) ;        LED_DEBUG(("LED: EnF [%x] [%x] [%x]\n", lOldMask , pLEDTask->gTheActiveFilters , pFilter))    ;    }    else    {        /*to unset*/        pLEDTask->gTheActiveFilters &= (0xFFFF - (  0x1 << pFilter ) ) ;        LED_DEBUG(("LED: DisF [%x] [%x] [%x]\n", lOldMask , pLEDTask->gTheActiveFilters , pFilter))    ;    }}static bool LedsIsFilterEnabled ( LedTaskData * pLEDTask , uint16 pFilter ){    bool lResult = FALSE ;        if ( pLEDTask->gTheActiveFilters & (0x1 << pFilter ) )    {        lResult = TRUE ;    }        return lResult ;}/****************************************************************************NAME  LedsSetLedActivityDESCRIPTION    Sets a Led Activity to a known stateRETURNS void*/void LedsSetLedActivity ( LEDActivity_t * pLed , IndicationType_t pType , uint16 pIndex ){    pLed->NumFlashesComplete = 0 ;    pLed->Type               = pType ;    pLed->Index              = pIndex ;    pLed->FilterIndex        = 0 ;    pLed->OnOrOff            = FALSE ;    pLed->NumRepeatsComplete = 0 ;}static bool LedsCheckFiltersForLEDFollower( LedTaskData * pLEDTask ){    uint16 lResult = FALSE ;        uint16 lFilterIndex = 0 ;        for (lFilterIndex = 0 ; lFilterIndex< LM_NUM_FILTER_EVENTS ; lFilterIndex++ )    {        if ( LedsIsFilterEnabled(pLEDTask , lFilterIndex) )        {                /*if this filter defines a lefd follower*/            if ( pLEDTask->gEventFilters[lFilterIndex].FollowerLEDActive)            {                lResult = TRUE ;            }            }    }    return lResult ;}static uint16 LedsGetLedFollowerRepeatTimeLeft( LedTaskData * pLEDTask , LEDPattern_t * pPattern) {    uint16 lTime = pPattern->RepeatTime ;    uint16 lPatternTime = ( ( pPattern->OnTime  *  pPattern->NumFlashes) +                             ( pPattern->OffTime * (pPattern->NumFlashes - 1 ) )   +                            ( LedsGetLedFollowerStartDelay(pLEDTask) ) ) ;                                if(lPatternTime < pPattern->RepeatTime )    {        lTime = pPattern->RepeatTime - lPatternTime ;        LED_DEBUG(("LED: FOllower Rpt [%d] = [%d] - [%d]\n " , lTime , pPattern->RepeatTime , lPatternTime)) ;    }        return lTime ;        }             static uint16 LedsGetLedFollowerStartDelay( LedTaskData * pLEDTask ){    uint16 lDelay = 0 ;     uint16 lFilterIndex =0 ;            for (lFilterIndex = 0 ; lFilterIndex< LM_NUM_FILTER_EVENTS ; lFilterIndex++ )    {        if ( LedsIsFilterEnabled(pLEDTask , lFilterIndex) )        {                /*if this filter defines a lefd follower*/            if ( pLEDTask->gEventFilters[lFilterIndex].FollowerLEDActive)            {                    /*the led to use to follow with*/                LED_DEBUG(("LM: LEDFollower Led[%d] Delay[%d]\n" , pLEDTask->gEventFilters[lFilterIndex].OverideLED ,                                                                   pLEDTask->gEventFilters[lFilterIndex].FollowerLEDDelay)) ;                    lDelay = pLEDTask->gEventFilters[lFilterIndex].FollowerLEDDelay * 50 ;            }            }    }    return lDelay ;}static uint16 LedsGetFollowerPin( LedTaskData * pLEDTask ){    uint16 lLED = 0 ;    uint16 lFilterIndex =0 ;            for (lFilterIndex = 0 ; lFilterIndex< LM_NUM_FILTER_EVENTS ; lFilterIndex++ )    {        if ( LedsIsFilterEnabled(pLEDTask , lFilterIndex) )        {                /*if this filter defines a lefd follower*/            if ( pLEDTask->gEventFilters[lFilterIndex].FollowerLEDActive)            {                    /*the led to use to follow with*/                 lLED = pLEDTask->gEventFilters[lFilterIndex].OverideLED ;                            }            }    }           return lLED ;}/****************************************************************************NAME  LedsResetAllLedsDESCRIPTION    resets all led pins to off and cancels all led and state indicationsRETURNS void*/void LedsResetAllLeds ( LedTaskData * pLEDTask) {        LedsCancelEventIndications ( pLEDTask )  ;        LedsCancelStateIndications ( pLEDTask )  ;   }

⌨️ 快捷键说明

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