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

📄 headset_leds.c

📁 bc5_stereo:bluetooth stereo Headset CODE 支持A2DP HSP 和 HSP 。可作为车载免提。BlueLab 2007环境下编译
💻 C
📖 第 1 页 / 共 3 页
字号:
                    /*Overide the Off LED with the Overide LED*/
                    LED_DEBUG(("LM: LEDOveride [%d] [%d]\n" , pLEDTask->gEventFilters[lFilterIndex].OverideLED , pOnOrOff)) ;    
                    PioSetLedPin ( pLEDTask , pLEDTask->gEventFilters[lFilterIndex].OverideLED , pOnOrOff) ;   
                    
                        /*Toggle the LED enable pin*/
                    /*    LedsSetEnablePin ( pLedTask , pOnOrOff )  ;*/    
                }
            }    
        }
    }  
}


/****************************************************************************
NAME 
    LMGetPatternColour

DESCRIPTION
    Fn to determine the LEDColour_t of the LED pair we are currently playing
    takes into account whether or not a filter is currently active.
    
RETURNS
    LEDColour_t
*/
static LEDColour_t LedsGetPatternColour (LedTaskData * pLEDTask , const  LEDPattern_t * pPattern )
{
    uint16 lFilterIndex = 0 ;
        /*sort out the colour of the LED we are interested in*/
    LEDColour_t lColour = pPattern->Colour ;
   
    for (lFilterIndex = 0 ; lFilterIndex< LM_NUM_FILTER_EVENTS ; lFilterIndex++ )
    {
        if ( LedsIsFilterEnabled(pLEDTask , lFilterIndex) )
        {
            if ( pLEDTask->gEventFilters[lFilterIndex].Colour != LED_COL_EITHER )
            {
                    /*Overide the Off LED with the Overide LED*/
                lColour = pLEDTask->gEventFilters[lFilterIndex].Colour;   
            } 
        }
    }
    return lColour ;
}


/****************************************************************************
NAME 
    LMApplyFilterToTime

DESCRIPTION
    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< LM_NUM_FILTER_EVENTS ; 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 
    LEDManagerSendEventComplete

DESCRIPTION
    Sends a message to the main task thread to say that an event indication has been completed.
    
*/
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 ) ;
    }
}


/****************************************************************************
NAME 
    LedsEventComplete

DESCRIPTION
    Signal that a given event indicatio has completed.

*/
static 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 , stateManagerGetHfpState () , stateManagerGetA2dpState () ) ; 
    
}     


/****************************************************************************
NAME 
    LedsEnableFilter

DESCRIPTION
    Enable / disable a given filter ID

*/
static void LedsEnableFilter ( LedTaskData * pLEDTask ,  uint16 pFilter , bool pEnable)
{
    uint16 lOldMask = pLEDTask->gTheActiveFilters ;
    
    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))    ;
    }
    
    /* Check if we should indicate state */
    if ((pLEDTask->gEventFilters[pFilter].OverideDisable) && (lOldMask != pLEDTask->gTheActiveFilters))
        LEDManagerIndicateState ( pLEDTask , stateManagerGetHfpState () , stateManagerGetA2dpState () ) ;                          
}

/****************************************************************************
NAME 
    LedsIsFilterEnabled

DESCRIPTION
    Determine if a filter is enabled.
    
RETURNS
 	bool - enabled or not
*/
static bool LedsIsFilterEnabled ( LedTaskData * pLEDTask , uint16 pFilter )
{
    bool lResult = FALSE ;
    
    if ( pLEDTask->gTheActiveFilters & (0x1 << pFilter ) )
    {
        lResult = TRUE ;
    }
    
    return lResult ;
}





/****************************************************************************
NAME 
	LedsCheckFiltersForLEDFollower
DESCRIPTION
    Determine if a follower is currently active.
RETURNS
 	bool - active or not
*/
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 ;
}


/****************************************************************************
NAME 
	LedsGetLedFollowerRepeatTimeLeft
DESCRIPTION
    Calculate the new repeat time based upon the follower led delay and the normal repeat time.
RETURNS
 	uint16 - updated repeat time to use
*/
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 ;        
}


/****************************************************************************
NAME 
	LedsGetLedFollowerStartDelay
DESCRIPTION
    Get the delay associated with a follower led pin.
RETURNS
 	uint16 - delay to use for the follower
*/             
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 ;
}


/****************************************************************************
NAME 
	LedsGetFollowerPin
DESCRIPTION
    Determine which follower pin is set - 0 = none set.
RETURNS
 	uint16 - which pin to use as a follower
*/
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 
    LedsSetEnablePin

DESCRIPTION
    If configured sets a pio as a led enable pin.

*/
static void LedsSetEnablePin ( LedTaskData * pLEDTask , bool pOnOrOff ) 
{
    /*
    hsTaskData * lApp = (hsTaskData *) getAppTask() ;
    
    if ( lApp->PIO.LedEnablePIO < 0xF ) 
    {
        PioSetLedPin ( pLEDTask , lApp->PIO.LedEnablePIO , pOnOrOff ) ;
    }*/
}

⌨️ 快捷键说明

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