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

📄 headset_ledmanager.c

📁 bluelab的一个很好的例程
💻 C
📖 第 1 页 / 共 2 页
字号:
        }
        /*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->NumFlashes   = pSourcePattern->NumFlashes ;
            pDestPattern->Dimming      = pSourcePattern->Dimming ;
            pDestPattern->TimeOut      = pSourcePattern->TimeOut ;
            pDestPattern->Colour       = pSourcePattern->Colour ;
        
           LMPrintPattern ( pDestPattern ) ;
        }
        else
        {
            LM_DEBUG(("LM: NoPat!\n")) ;
        }
    }
        /*pass the new pointer back to the caller as we may have modified it*/
    return pDestPattern ;
}


/****************************************************************************
NAME 
 LEDManagerAddLEDFilter

DESCRIPTION
 Adds an event LED mapping

RETURNS
 void
    
*/
void LEDManagerAddLEDFilter  (  LedTaskData * ptheLEDTask , LEDFilter_t* pLedFilter ) 
{
    if ( ptheLEDTask->gLMNumFiltersUsed < LM_NUM_FILTER_EVENTS )
    {
        /*then add the filter pattern*/
       ptheLEDTask->gEventFilters [ ptheLEDTask->gLMNumFiltersUsed ] = *pLedFilter ;
  
       LM_DEBUG(("LM :  AF[%x][%d][%d][%d][%d] [%d][%d] [%d][%d]\n", pLedFilter->Event ,pLedFilter->IsFilterActive , 
                                                   pLedFilter->Speed, pLedFilter->SpeedAction, pLedFilter->Colour ,
                                                   pLedFilter->OverideLEDActive , pLedFilter->OverideLED , 
                                                   pLedFilter->FollowerLEDActive , pLedFilter->FollowerLEDDelay
                                                   )) ;
     /*inc the filters*/
        ptheLEDTask->gLMNumFiltersUsed ++ ;
    }
}


/****************************************************************************
NAME 
 LMPrintPattern

DESCRIPTION
    debug fn to output a LED pattern
    
RETURNS
 void
*/

void LMPrintPattern ( LEDPattern_t * pLED ) 
{

#ifdef DEBUG_LM
#ifdef DEBUG_PRINT_ENABLED
    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] ",          pLED->NumFlashes, pLED->Dimming)) ; 
    LM_DEBUG(("[%d][%s]\n",         pLED->TimeOut, lColStrings[pLED->Colour])) ;    
    #endif
#endif
}



/****************************************************************************
NAME 
 LedManagerClean

DESCRIPTION
    Frees all memory malloced on initialisation of the LED manager - to be called for clean
    shutdown
    
RETURNS
 void
*/
void LEDManagerClean ( LedTaskData * ptheLEDTask ) 
{    
}


/****************************************************************************
NAME 
 LEDManagerSetPowerPin

DESCRIPTION
 Abstraction for the PIO set power pin

RETURNS
 void
    
*/
void LEDManagerSetPowerPin ( hsTaskData * pApp ,  PowerPin_t pEnable ) 
{
    LM_DEBUG(("LM : Power [%c]\n", (pEnable ? 'T':'F') )) ;
    PioSetPowerPin ( pApp , pEnable) ;
}
/****************************************************************************
NAME 
 LEDManagerSetMicBias

DESCRIPTION
 Sets the appropriate Mic Bias pin

RETURNS
 void
    
*/

void LEDManagerSetMicBias ( hsTaskData * pApp , bool pEnable  ) 
{
    uint16 lMicPio = configManagerGetMicBiasPio() ;
    
    if (pApp->features.MicBiasUsesLDO )
    {
        /*set or unset the  LDO*/
        PioSetInternalLDO ( pEnable ) ;
    }
    else
    {
        /*update the pin as requested*/
        PioSetPin(  lMicPio , pEnable) ;
    }
    
    LM_DEBUG(("LM: Mic[%x]e[%c]\n" , lMicPio , (pEnable ? 'T':'F' ))) ;
}
/****************************************************************************
NAME 
 LEDManagerIndicateEvent

DESCRIPTION
 displays event notification
    This function also enables / disables the event filter actions - if a normal event indication is not
    associated with the event, it checks to see if a filer is set up for the event 

RETURNS
 void
    
*/

void LEDManagerIndicateEvent ( LedTaskData * pLEDTask , MessageId pEvent ) 
{
    uint16 lEventIndex = pEvent - EVENTS_EVENT_BASE ;

            /*only indicate if LEDs are enabled*/
    if ( pLEDTask->gLEDSEnabled == TRUE)
    {
    
        LM_DEBUG(("LM : IE[%x]\n",pEvent )) ;
            /*if there is an event configured*/
        if ( pLEDTask->gEventPatterns [lEventIndex] != NULL )
        {
                /*only update if wer are not currently indicating an event*/
            if ( ! pLEDTask->gCurrentlyIndicatingEvent )
            {
                LedsIndicateEvent ( pLEDTask , pEvent ) ;  
            }    
            else
            {
            
                hsTaskData * lApp = (hsTaskData *) getAppTask() ;

                if (lApp->features.QueueLEDEvents )
                {
             
                        /*try and add it to the queue*/
                    LM_DEBUG(("LM: Queue LED Event [%x]\n" , pEvent )) ;
                
                    if ( pLEDTask->Queue.Event1 == 0)
                    {
                        pLEDTask->Queue.Event1 = ( pEvent - EVENTS_EVENT_BASE) ;
                    }
                    else if ( pLEDTask->Queue.Event2 == 0)
                    {
                        pLEDTask->Queue.Event2 = ( pEvent - EVENTS_EVENT_BASE) ;
                    }
                    else if ( pLEDTask->Queue.Event3 == 0)
                    {
                        pLEDTask->Queue.Event3 = ( pEvent - EVENTS_EVENT_BASE) ;
                    }
                    else if ( pLEDTask->Queue.Event4 == 0)
                    {
                        pLEDTask->Queue.Event4 = ( pEvent - EVENTS_EVENT_BASE) ;
                    }    
                    else
                    {
                        LM_DEBUG(("LM: Err Queue Full!!\n")) ;
                    }
                }    
            }
        }
        else
        {
            LM_DEBUG(("LM: NoEvPatCfg\n")) ;
        }  
    
        /*indicate a filter if there is one present*/
       LedsCheckForFilter ( pLEDTask , pEvent ) ;
    }
    else
    {
        LM_DEBUG(("LM : No IE[%x] disabled\n",pEvent )) ;
    }

}

/****************************************************************************
NAME	
	LEDManagerIndicateState

DESCRIPTION
	displays state indication information

RETURNS
	void
    
*/
void LEDManagerIndicateState ( LedTaskData * pLEDTask , headsetState pState )  
{   
            /*only indicate if LEDs are enabled*/
    if ( pLEDTask->gLEDSEnabled == TRUE)
    {
            /*if there is no pattern associated with the sate then do nothing*/
        if ( pLEDTask->gStatePatterns[ pState ] == NULL )
        {
            LM_DEBUG(("LM: NoStCfg[%x]\n",pState)) ;
            LedsIndicateNoState ( pLEDTask ) ;
        }
        else
        {
            LM_DEBUG(("LM : IS[%x]\n", pState)) ;
            LedsIndicateState ( pLEDTask , pState );
        } 
    }
    else
    {
        LM_DEBUG(("LM : No IS[%x] Disabled\n", pState)) ;
    }
}


/****************************************************************************
NAME	
	LedManagerSetPIO

DESCRIPTION
	wrapper to set an individual PIO high or LOW
RETURNS
	void
    
*/
void LedManagerSetPIO ( uint16 pPIO , bool pOnOrOff  ) 
{
    PioSetPin ( pPIO , pOnOrOff  ) ; 
}


void LedManagerDisableLEDS ( LedTaskData * pTask )
{
    LM_DEBUG(("LM Disable LEDS\n")) ;

    /*turn off all current LED Indications*/
    LedsIndicateNoState ( pTask ) ;
    
    pTask->gLEDSEnabled = FALSE ;
}

void LedManagerEnableLEDS ( LedTaskData * pTask )
{
    LM_DEBUG(("LM Enable LEDS\n")) ;
    
    pTask->gLEDSEnabled = TRUE ;
         
    LEDManagerIndicateState ( pTask , stateManagerGetState () ) ;    
}


void LedManagerToggleLEDS ( LedTaskData * pTask ) 
{
    if ( pTask->gLEDSEnabled )
    {
        LedManagerDisableLEDS ( pTask ) ;        
    }
    else
    {
        LedManagerEnableLEDS ( pTask ) ;
    }
}

/****************************************************************************
NAME	
	LedManagerResetLEDIndications

DESCRIPTION
    Resets the LED Indications and reverts to state indications
	Sets the Flag to allow the Next Event to interrupt the current LED Indication
    Used if you have a permanent LED event indication that you now want to interrupt
RETURNS
	void
    
*/
void LedManagerResetLEDIndications ( LedTaskData * pTask )
{    
    LedsResetAllLeds ( pTask ) ;
    
    pTask->gCurrentlyIndicatingEvent = FALSE ;
    
    LEDManagerIndicateState (pTask , stateManagerGetState() ) ;
}

/****************************************************************************
NAME	
	LEDManagerResetStateIndNumRepeatsComplete

DESCRIPTION
    Resets the LED Number of Repeats complete for the current state indication
       This allows the time of the led indication to be reset every time an event 
       occurs.
RETURNS
	void
    
*/
void LEDManagerResetStateIndNumRepeatsComplete  ( LedTaskData * pTask ) 
{
    /*get state*/
    headsetState lState = stateManagerGetState() ;
    /*get pattern*/
    LEDPattern_t * lPattern = pTask->gStatePatterns[lState] ;

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


}


⌨️ 快捷键说明

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