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

📄 headset_ledmanager.c

📁 bc5_stereo:bluetooth stereo Headset CODE 支持A2DP HSP 和 HSP 。可作为车载免提。BlueLab 2007环境下编译
💻 C
📖 第 1 页 / 共 2 页
字号:
    {
        LedManagerEnableLEDS ( pTask ) ;
    }
}


/*****************************************************************************/
void LedManagerResetLEDIndications ( LedTaskData * pTask )
{    
    LedsResetAllLeds ( pTask ) ;
    
    pTask->gCurrentlyIndicatingEvent = FALSE ;
    
    LEDManagerIndicateState (pTask , stateManagerGetHfpState() , stateManagerGetA2dpState () ) ;
}


/*****************************************************************************/
void LEDManagerResetStateIndNumRepeatsComplete  ( LedTaskData * pTask ) 
{
    /*get state*/
    uint16 led_state = stateManagerGetCombinedState();
    /*get pattern*/ 
    LEDPattern_t * lPattern = pTask->gStatePatterns[led_state] ;

    if (lPattern)
    {
        LEDActivity_t * lLED   = &pTask->gActiveLEDS[lPattern->LED_A] ;
        if (lLED)
        {
            /*reset num repeats complete to 0*/
            lLED->NumRepeatsComplete = 0 ;
        }    
    }
}


/*****************************************************************************/
void LMPrintPattern ( LEDPattern_t * pLED ) 
{
#ifdef DEBUG_LM
    const char * const lColStrings [ 5 ] =   {"LED_E ","LED_A","LED_B","ALT","Both"} ;

    LM_DEBUG(("[%d][%d] [%d][%d][%d] ", pLED->LED_A , pLED->LED_B, pLED->OnTime, pLED->OffTime, pLED->RepeatTime)) ;  
    LM_DEBUG(("[%d] [%d] [%s]\n",       pLED->NumFlashes, pLED->TimeOut, lColStrings[pLED->Colour])) ;    
    LM_DEBUG(("[%d]\n",       pLED->OverideDisable)) ;    
#endif

}


/****************************************************************************
NAME 
    LEDManagerInitActiveLEDS

DESCRIPTION
    Creates the active LED space for the number of leds the system supports.

*/
static void LEDManagerInitActiveLEDS ( LedTaskData * ptheLEDTask ) 
{
    uint16 lIndex = 0; 
 
    for ( lIndex= 0 ; lIndex < HEADSET_NUM_LEDS ; lIndex ++ )
    {
        LedsSetLedActivity ( &ptheLEDTask->gActiveLEDS [ lIndex ] , IT_Undefined , 0 , 0 ) ;    
    }
}


/****************************************************************************
NAME 
    LEDManagerInitStatePatterns

DESCRIPTION
    Creates the state patterns space for the system states.
    
*/
static void LEDManagerInitStatePatterns ( LedTaskData * ptheLEDTask ) 
{
    uint16 lIndex = 0; 
 
    for ( lIndex= 0 ; lIndex < (HEADSET_NUM_HFP_STATES * HEADSET_NUM_A2DP_STATES); lIndex ++ )
    {
        ptheLEDTask->gStatePatterns [ lIndex ] = NULL ;     
    }
}


/****************************************************************************
NAME 
    LEDManagerInitEventPatterns

DESCRIPTION
    Inits the Event pattern pointers.

*/
static void LEDManagerInitEventPatterns ( LedTaskData * ptheLEDTask )
{
    uint16 lIndex = 0; 
 
    for ( lIndex= 0 ; lIndex < EVENTS_MAX_EVENTS ; lIndex ++ )
    {
       ptheLEDTask->gEventPatterns [ lIndex ] = NULL ;     
    } 
}


/****************************************************************************
NAME 
    LEDManagerCreateFilterPatterns

DESCRIPTION
    Creates the Filter patterns space.
    
*/
static void LEDManagerCreateFilterPatterns ( LedTaskData * ptheLEDTask )
{
    uint16 lIndex = 0 ;
    /*create the space for the filter patterns*/
    
    ptheLEDTask->gEventFilters = (LEDFilter_t *) PanicUnlessMalloc ( sizeof (LEDFilter_t ) * LM_NUM_FILTER_EVENTS ) ;
    
    for (lIndex = 0 ; lIndex < LM_NUM_FILTER_EVENTS ; lIndex++ )
    {
        ptheLEDTask->gEventFilters [ lIndex ].Event             = 0 ;
        ptheLEDTask->gEventFilters [ lIndex ].IsFilterActive    = FALSE ;      
        ptheLEDTask->gEventFilters [ lIndex ].Speed             = 0 ;
        ptheLEDTask->gEventFilters [ lIndex ].SpeedAction       = SPEED_MULTIPLY ;
        ptheLEDTask->gEventFilters [ lIndex ].Colour            = LED_COL_EITHER ;  
        ptheLEDTask->gEventFilters [ lIndex ].OverideLED        = 0 ;  
        ptheLEDTask->gEventFilters [ lIndex ].FilterToCancel    = 0 ;
        ptheLEDTask->gEventFilters [ lIndex ].OverideLEDActive  = FALSE ;
        ptheLEDTask->gEventFilters [ lIndex ].FollowerLEDActive = FALSE ;
        ptheLEDTask->gEventFilters [ lIndex ].FollowerLEDDelay  = 0 ;
        ptheLEDTask->gEventFilters [ lIndex ].OverideDisable    = FALSE ;
    }
    
    ptheLEDTask->gLMNumFiltersUsed = 0 ;

    ptheLEDTask->gTheActiveFilters = 0x0000 ;
}


/****************************************************************************
NAME 
    LMGetPattern

DESCRIPTION
    Method to get a pointer to one of the pre allocated patterns - if there are no patterns left,
    returns NULL.

RETURNS
    LedPattern_t *
    
*/
static LEDPattern_t * LMGetPattern ( LedTaskData * ptheLEDTask ) 
{
    LEDPattern_t * lPattern = NULL ;
    
    uint16 lIndex = 0 ;
    
        /*iterate through the patterns looking for one that is unused*/
    for (lIndex = 0 ; lIndex < LM_MAX_NUM_PATTERNS ; lIndex ++ )
    {
        if ( LMIsPatternEmpty ( &ptheLEDTask->gPatterns [ lIndex ] ) )
        {
            /*then this pattern is not used and we can use it*/
            lPattern = &ptheLEDTask->gPatterns [ lIndex ] ;
            LM_DEBUG(("LM : PatFound[%d]\n", lIndex  )) ;
                /*if we have found a free pattern then there is no need to continue looking*/
            return lPattern ;
            
        }        
    }
        /*if we could not find a pattern*/
    if (lPattern == NULL)
    {
        LM_DEBUG(("LM : Pat !\n")) ;
    }
    
    return ( lPattern ) ;
}


/****************************************************************************
NAME 
    LMIsPatternUsed

DESCRIPTION
    Helper method to determine if a pattern has been used or not - checks
    whether the pattern contains valid data.

RETURNS
    bool IsUsed
    
*/
static bool LMIsPatternEmpty (LEDPattern_t * pPattern )
{
    bool lIsUsed = FALSE ;
    
     if ( pPattern->OnTime == 0 )
     {
        if ( pPattern->OffTime == 0 )
        {
            lIsUsed = TRUE ;
        }
     }
    return lIsUsed ; 
}
 

/****************************************************************************
NAME 
    LMReleasePattern

DESCRIPTION
    Method to set apattern to a known state so that it can be used by GetPattern.

*/
static void LMResetPattern ( LEDPattern_t * pPattern )
{
    pPattern->LED_A      = 0 ;
    pPattern->LED_B      = 0 ;
    pPattern->OnTime     = 0 ;
    pPattern->OffTime    = 0 ;
    pPattern->RepeatTime = 0 ;
    pPattern->NumFlashes = 0 ;
    pPattern->DimTime    = 0;
    pPattern->TimeOut    = 0 ;
    pPattern->Colour     = LED_COL_LED_A ;  
    pPattern->OverideDisable = FALSE;
}


/****************************************************************************
NAME 
    LMAddPattern

DESCRIPTION
    Adds an LED Mapping (Event / State). 

RETURNS
    The new destination ptr if there was one allocated.
    
*/
static LEDPattern_t * LMAddPattern ( LedTaskData * ptheLEDTask , LEDPattern_t * pSourcePattern , LEDPattern_t * pDestPattern ) 
{
        /*if the pattern we have been passed is empty then we want to make sure there is no pattern present*/
    if ( LMIsPatternEmpty ( pSourcePattern )  )
    {
            /*if a pattern is already defined for this Location*/
        if ( pDestPattern ) 
        {
                /*then delete the pattern*/
            LMResetPattern (  pDestPattern ) ;            
            pDestPattern = NULL ;
        }
        /*otherwise there was no pattern defined anyway*/
    }
    else
    {
           /*if a pattern is not already defined for this state*/
        if ( ! pDestPattern ) 
        {
                /*get a pattern pointer from our block*/  
            pDestPattern = LMGetPattern ( ptheLEDTask ) ;
        }
        
        /*if we have a pattern (wither from before or just given)*/
        if (pDestPattern)
        {
               /*populate the pattern*/ 
            pDestPattern->LED_A          = pSourcePattern->LED_A ;
            pDestPattern->LED_B          = pSourcePattern->LED_B ;
            pDestPattern->OnTime         = pSourcePattern->OnTime ;
            pDestPattern->OffTime        = pSourcePattern->OffTime ;
            pDestPattern->RepeatTime     = pSourcePattern->RepeatTime ;
            pDestPattern->DimTime        = pSourcePattern->DimTime ;
            pDestPattern->NumFlashes     = pSourcePattern->NumFlashes ;
            pDestPattern->TimeOut        = pSourcePattern->TimeOut ;
            pDestPattern->Colour         = pSourcePattern->Colour ;
            pDestPattern->OverideDisable = pSourcePattern->OverideDisable;
        
           #ifdef DEBUG_LM
           		LMPrintPattern ( pDestPattern ) ;
           #endif		
        }
        else
        {
            LM_DEBUG(("LM: NoPat!\n")) ;
        }
    }
        /*pass the new pointer back to the caller as we may have modified it*/
    return pDestPattern ;
}


































⌨️ 快捷键说明

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