📄 headset_leds.c
字号:
}
else
{
LED_DEBUG(("LED: Fil !\n")) ;
}
}
LED_DEBUG(("LM : Filter Found[%d]A[%x] [%d]\n", lFilterIndex , pEvent , pLEDTask->gEventFilters[ lFilterIndex ].IsFilterActive )) ;
}
}
}
/*****************************************************************************/
void LedsSetLedActivity ( LEDActivity_t * pLed , IndicationType_t pType , uint16 pIndex , uint16 pDimTime)
{
pLed->NumFlashesComplete = 0 ;
pLed->Type = pType ;
pLed->Index = pIndex ;
pLed->FilterIndex = 0 ;
pLed->OnOrOff = FALSE ;
pLed->NumRepeatsComplete = 0 ;
pLed->DimState = 0 ;
pLed->DimDir = 0 ;
pLed->DimTime = pDimTime ;
LED_DEBUG(("LED[%d]\n" , pDimTime)) ;
}
/*****************************************************************************/
void LedsResetAllLeds ( LedTaskData * pLEDTask)
{
/*Cancel all event indications*/
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) ;
}
}
/*cancel all state indications*/
LedsIndicateNoState ( pLEDTask ) ;
}
/****************************************************************************
NAME
LEDManagerMessageHandler
DESCRIPTION
The main message handler for the LED task. Controls the PIO in question, then
queues a message back to itself for the next LED update.
*/
static void LedsMessageHandler( Task task, MessageId id, Message message )
{
LedTaskData * lLEDTask = (LedTaskData *) task ;
bool lOldState = LED_OFF ;
uint16 lTime = 0 ;
LEDColour_t lColour ;
LEDActivity_t * lLED = &lLEDTask->gActiveLEDS[id] ;
LEDPattern_t * lPattern = NULL ;
bool lPatternComplete = FALSE ;
if (id < DIM_MSG_BASE )
{
/*which pattern are we currently indicating for this LED pair*/
if ( lLED->Type == IT_StateIndication)
{
lPattern = lLEDTask->gStatePatterns[ lLED->Index] ;
}
else
{ /*is an event indication*/
lPattern = lLEDTask->gEventPatterns [ lLED->Index ] ;
}
/*get which of the LEDs we are interested in for the pattern we are dealing with*/
lColour = LedsGetPatternColour ( lLEDTask , lPattern ) ;
/*get the state of the LED we are dealing with*/
lOldState = lLEDTask->gActiveLEDS [ lPattern->LED_A ].OnOrOff ;
LED_DEBUG(("LM : LED[%d] [%d] f[%d]of[%d]\n", id ,lOldState , lLED->NumFlashesComplete , lPattern->NumFlashes )) ;
/*The actual LED handling*/
if (lOldState == LED_OFF)
{
lTime = lPattern->OnTime ;
/*Increment the number of flashes*/
lLED->NumFlashesComplete++ ;
LED_DEBUG(("LED: Pair On\n")) ;
LedsTurnOnLEDPair ( lLEDTask , lPattern , lLED ) ;
}
else
{ /*restart the pattern if we have palayed all of the required flashes*/
if ( lLED->NumFlashesComplete >= lPattern->NumFlashes )
{
lTime = lPattern->RepeatTime ;
lLED->NumFlashesComplete = 0 ;
/*inc the Num times the pattern has been played*/
lLED->NumRepeatsComplete ++ ;
LED_DEBUG(("LED: Pat Rpt [%d][%d]\n",lLED->NumRepeatsComplete , lPattern->TimeOut)) ;
/*if a single pattern has completed*/
if ( lPattern->RepeatTime == 0 )
{
LED_DEBUG(("LED: PC: Rpt\n")) ;
lPatternComplete = TRUE ;
}
/*a pattern timeout has occured*/
if ( ( lPattern->TimeOut !=0 ) && ( lLED->NumRepeatsComplete >= lPattern->TimeOut) )
{
lPatternComplete = TRUE ;
LED_DEBUG(("LED: PC: Rpt b\n")) ;
}
/*if we have reached the end of the pattern and are using a follower then revert to the orig pattern*/
if (lLEDTask->gFollowing)
{
lLEDTask->gFollowing = FALSE ;
lTime = LedsGetLedFollowerRepeatTimeLeft( lLEDTask , lPattern ) ;
}
else
{
/*do we have a led follower filter and are we indicating a state, if so use these parameters*/
if (lLED->Type == IT_StateIndication)
{
if( LedsCheckFiltersForLEDFollower( lLEDTask ) )
{
lTime = LedsGetLedFollowerStartDelay( lLEDTask ) ;
lLEDTask->gFollowing = TRUE ;
}
}
}
}
else /*otherwise set up for the next flash*/
{
lTime = lPattern->OffTime ;
}
/*turn off both LEDS*/
LED_DEBUG(("LED: Pair OFF\n")) ;
if ( (lTime == 0 ) && ( lPatternComplete == FALSE ) )
{
/*ie we are switching off for 0 time - do not use the overide led as this results in a tiny blip*/
LedsTurnOffLEDPair ( lLEDTask , lPattern , FALSE) ;
}
else
{
LedsTurnOffLEDPair ( lLEDTask , lPattern , TRUE) ;
}
}
/*handle the completion of the pattern or send the next update message*/
if (lPatternComplete)
{
LED_DEBUG(("LM : P C [%x][%x] [%x][%x]\n" , lLEDTask->gActiveLEDS[lPattern->LED_B].Index, lLED->Index , lLEDTask->gActiveLEDS[lPattern->LED_B].Type , lLED->Type )) ;
/*set the type of indication for both LEDs as undefined as we are now indicating nothing*/
if ( lLEDTask->gActiveLEDS[id].Type == IT_EventIndication )
{
/*signal the completion of an event*/
LedsSendEventComplete ( lLED->Index + EVENTS_EVENT_BASE , TRUE ) ;
/*now complete the event, and indicate a new state if required*/
LedsEventComplete ( lLEDTask, lLED , &lLEDTask->gActiveLEDS[lPattern->LED_B] ) ;
}
else if (lLEDTask->gActiveLEDS[id].Type == IT_StateIndication )
{
/*then we have completed a state indication and the led pattern is now off*/
/*Indicate that we are now with LEDS disabled*/
lLEDTask->gLEDSStateTimeout = TRUE ;
}
}
else
{ /*apply the filter in there is one and schedule the next message to handle for this led pair*/
lTime = LedsApplyFilterToTime ( lLEDTask , lTime ) ;
MessageSendLater (&lLEDTask->task , id , 0 , lTime ) ;
}
}
else
{
/*DIMMING LED Update message */
PioSetDimState ( lLEDTask , (id - DIM_MSG_BASE) );
}
}
/****************************************************************************
NAME
LMTurnOnLEDPair
DESCRIPTION
Fn to turn on the LED associated with the pattern / LEDs depending upon the
colour.
*/
static void LedsTurnOnLEDPair ( LedTaskData * pLEDTask , LEDPattern_t * pPattern , LEDActivity_t * pLED )
{
LEDColour_t lColour = LedsGetPatternColour ( pLEDTask , pPattern ) ;
if (pLEDTask->gFollowing )
{ /*turn of the pair of leds (and dont use an overide LED */
LedsTurnOffLEDPair ( pLEDTask , pPattern , FALSE) ;
PioSetLedPin ( pLEDTask , LedsGetFollowerPin(pLEDTask), LED_ON );
}
else
{/*we are not following*/
/*Turn on the LED enable pin*/
LedsSetEnablePin ( pLEDTask , LED_ON ) ;
switch (lColour )
{
case LED_COL_LED_A:
LED_DEBUG(("LED: A ON[%x][%x]\n", pPattern->LED_A , pPattern->LED_B)) ;
if (pPattern->LED_A != pPattern->LED_B)
{
PioSetLedPin ( pLEDTask , pPattern->LED_B , LED_OFF ) ;
}
PioSetLedPin ( pLEDTask, pPattern->LED_A , LED_ON ) ;
break;
case LED_COL_LED_B:
LED_DEBUG(("LED: B ON[%x][%x]\n", pPattern->LED_A , pPattern->LED_B)) ;
if (pPattern->LED_A != pPattern->LED_B)
{
PioSetLedPin ( pLEDTask , pPattern->LED_A , LED_OFF ) ;
}
PioSetLedPin ( pLEDTask , pPattern->LED_B , LED_ON ) ;
break;
case LED_COL_LED_ALT:
if (pLED->NumFlashesComplete % 2 )
{
LED_DEBUG(("LED: A ALT[%x][%x]\n", pPattern->LED_A , pPattern->LED_B)) ;
PioSetLedPin ( pLEDTask , pPattern->LED_A , LED_OFF ) ;
PioSetLedPin ( pLEDTask , pPattern->LED_B , LED_ON ) ;
}
else
{
LED_DEBUG(("LED: B ALT[%x][%x]\n", pPattern->LED_A , pPattern->LED_B)) ;
PioSetLedPin ( pLEDTask , pPattern->LED_B , LED_OFF ) ;
PioSetLedPin ( pLEDTask , pPattern->LED_A , LED_ON ) ;
}
break;
case LED_COL_LED_BOTH:
LED_DEBUG(("LED: AB Both[%x][%x]\n", pPattern->LED_A , pPattern->LED_B)) ;
PioSetLedPin ( pLEDTask , pPattern->LED_A , LED_ON ) ;
PioSetLedPin ( pLEDTask , pPattern->LED_B , LED_ON ) ;
break;
default:
LED_DEBUG(("LM : ?Col\n")) ;
break;
}
}
/*handle an overide LED if there is one will also dealit is different to one of the pattern LEDS)*/
LedsHandleOverideLED ( pLEDTask , LED_OFF ) ;
pLED->OnOrOff = TRUE ;
}
/****************************************************************************
NAME
LMTurnOffLEDPair
DESCRIPTION
Fn to turn OFF the LEDs associated with the pattern.
*/
static void LedsTurnOffLEDPair ( LedTaskData * pLEDTask , LEDPattern_t * pPattern , bool pUseOveride )
{
/*turn off both LEDS*/
PioSetLedPin ( pLEDTask , pPattern->LED_A , LED_OFF ) ;
PioSetLedPin ( pLEDTask , pPattern->LED_B , LED_OFF ) ;
/*handle an overide LED if we want to use one*/
if ( pUseOveride )
{
LedsHandleOverideLED ( pLEDTask , LED_ON ) ;
}
pLEDTask->gActiveLEDS [ pPattern->LED_A ].OnOrOff = FALSE ;
/*Turn off the LED enable pin*/
LedsSetEnablePin ( pLEDTask , LED_OFF ) ;
}
/****************************************************************************
NAME
LedsHandleOverideLED
DESCRIPTION
Enables / diables any overide LEDS if there are some.
*/
static void LedsHandleOverideLED ( LedTaskData * pLEDTask , bool pOnOrOff )
{
uint16 lFilterIndex = 0 ;
for (lFilterIndex = 0 ; lFilterIndex< LM_NUM_FILTER_EVENTS ; lFilterIndex++ )
{
if ( LedsIsFilterEnabled(pLEDTask , lFilterIndex) )
{
if ( pLEDTask->gEventFilters[lFilterIndex].OverideLEDActive )
{
if ( pLEDTask->gEventFilters[lFilterIndex].OverideLED )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -