📄 headset_ledmanager.c
字号:
/****************************************************************************Copyright (C) Cambridge Silicon Radio Ltd. 2004-2006Part of BlueLab 3.6.2-releaseFILE NAME headset_LEDmanager.c DESCRIPTION Module responsible for managing the PIO outputs including LEDs *//****************************************************************************INCLUDES*/#include "headset_LEDmanager.h"#include "headset_private.h"#include "headset_configmanager.h"#include "headset_statemanager.h"#include "headset_leds.h"#include "headset_pio.h"#include <stddef.h>/****************************************************************************DEFINITIONS*/#ifdef DEBUG_LM#define LM_DEBUG(x) DEBUG(x)#else#define LM_DEBUG(x) #endif/****************************************************************************VARIABLES - TYPES and GLOBALS*//****************************************************************************LOCAL FUNCTION PROTOTYPES*/ /*internal method to provide a pointer to one of the malloced patterns*/static LEDPattern_t * LMGetPattern ( LedTaskData * ptheLEDTask ) ; /*method to release a pattern - actually clears data held in pattern so it can be used again*/static void LMResetPattern ( LEDPattern_t * pPattern ) ;static bool LMIsPatternEmpty (LEDPattern_t * pPattern ) ;static LEDPattern_t * LMAddPattern ( LedTaskData * ptheLEDTask , LEDPattern_t * pSourcePattern , LEDPattern_t * pDestPattern ) ; /*methods to allocate/ initialise the space for the patterns and mappings*/static void LEDManagerInitStatePatterns ( LedTaskData * ptheLEDTask ) ;static void LEDManagerInitEventPatterns ( LedTaskData * ptheLEDTask ) ;static void LEDManagerInitActiveLEDS ( LedTaskData * ptheLEDTask ) ;static void LEDManagerCreateFilterPatterns( LedTaskData * ptheLEDTask ) ;/****************************************************************************NAME PIOManagerInitDESCRIPTION Initialises LED managerRETURNS void */void LEDManagerInit ( LedTaskData * ptheLEDTask ) { uint16 lIndex = 0 ; uint16 lSize = 0; LM_DEBUG(("LM Init :\n")) ; /*allocate the space for all of the patterns*/ ptheLEDTask->gPatterns = mallocPanic ( sizeof (LEDPattern_t) * LM_MAX_NUM_PATTERNS ) ; for (lIndex = 0 ; lIndex < LM_MAX_NUM_PATTERNS ; lIndex ++ ) { /*make sure the pattern is released and ready for use*/ LMResetPattern ( &ptheLEDTask->gPatterns[lIndex] ) ; } /*malloc the space for all of the other data*/ lSize = ( (sizeof(LEDPattern_t *)) * HEADSET_NUM_STATES ) /*the state pattern pointers*/ + ( (sizeof(LEDPattern_t *)) * EVENTS_MAX_EVENTS ) ; /*the event pattern pointers*/ ptheLEDTask->gStatePatterns = (LEDPattern_t * * ) mallocPanic (lSize) ; /*the events are placed after the states*/ ptheLEDTask->gEventPatterns = (LEDPattern_t * *) (ptheLEDTask->gStatePatterns + HEADSET_NUM_STATES) ; /*malloc the LEDS seperately - for now*/ lSize = (sizeof (LEDActivity_t )) * HEADSET_NUM_LEDS; /*the active LEDS*/ ptheLEDTask->gActiveLEDS = (LEDActivity_t *) mallocPanic(lSize) ; LM_DEBUG(("LM : p[%x][%x][%x]\n" , (int)ptheLEDTask->gStatePatterns , (int)ptheLEDTask->gEventPatterns , (int)ptheLEDTask->gActiveLEDS )) ; /*create the patterns we want to use*/ LEDManagerInitStatePatterns ( ptheLEDTask) ; LEDManagerInitActiveLEDS( ptheLEDTask) ; LEDManagerInitEventPatterns( ptheLEDTask ) ; ptheLEDTask->Queue.Event1 = 0 ; ptheLEDTask->Queue.Event2 = 0 ; ptheLEDTask->Queue.Event3 = 0 ; ptheLEDTask->Queue.Event4 = 0 ; /*the filter information*/ LEDManagerCreateFilterPatterns( ptheLEDTask ) ; LedsInit ( ptheLEDTask ) ;}/****************************************************************************NAME LEDManagerInitActiveLEDSDESCRIPTION Creates the active LED space for the number of leds the system supportsRETURNS void */static void LEDManagerInitActiveLEDS ( LedTaskData * ptheLEDTask ) { uint16 lIndex = 0; for ( lIndex= 0 ; lIndex < HEADSET_NUM_LEDS ; lIndex ++ ) { LedsSetLedActivity ( &ptheLEDTask->gActiveLEDS [ lIndex ] , IT_Undefined , 0 ) ; }}/****************************************************************************NAME LEDManagerInitStatePatternsDESCRIPTION Creates the state patterns space for the system statesRETURNS void */static void LEDManagerInitStatePatterns ( LedTaskData * ptheLEDTask ) { uint16 lIndex = 0; for ( lIndex= 0 ; lIndex < HEADSET_NUM_STATES ; lIndex ++ ) { ptheLEDTask->gStatePatterns [ lIndex ] = NULL ; }}/****************************************************************************NAME LEDManagerInitEventPatternsDESCRIPTION inits the Event pattern pointersRETURNS void */static void LEDManagerInitEventPatterns ( LedTaskData * ptheLEDTask ){ uint16 lIndex = 0; for ( lIndex= 0 ; lIndex < EVENTS_MAX_EVENTS ; lIndex ++ ) { ptheLEDTask->gEventPatterns [ lIndex ] = NULL ; } }/****************************************************************************NAME LEDManagerCreateFilterPatternsDESCRIPTION Creates the Filter patterns space RETURNS void */static void LEDManagerCreateFilterPatterns ( LedTaskData * ptheLEDTask ){ uint16 lIndex = 0 ; /*create the space for the filter patterns*/ ptheLEDTask->gEventFilters = (LEDFilter_t *) mallocPanic ( 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->gLMNumFiltersUsed = 0 ; ptheLEDTask->gTheActiveFilters = 0x0000 ;}/****************************************************************************NAME LMGetPatternDESCRIPTION method to get a pointer to one of the pre allocated patterns - if there are no patterns left, returns NULLRETURNS 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 LMIsPatternUsedDESCRIPTION helper method to determine if a pattern has been used or not - checks whether the pattern contains valid dataRETURNS bool IsUsed */static bool LMIsPatternEmpty (LEDPattern_t * pPattern ){ bool lIsUsed = FALSE ; if ( pPattern->OnTime == 0 ) { if ( pPattern->OffTime == 0 ) { lIsUsed = TRUE ; } } return lIsUsed ; } /****************************************************************************NAME LMReleasePatternDESCRIPTION method to set apattern to a known state so that it can be used by GetPatternRETURNS */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->Dimming = FALSE ; pPattern->TimeOut = 0 ; pPattern->Colour = LED_COL_LED_A ; }/****************************************************************************NAME LEDManagerAddLEDStatePatternDESCRIPTION Adds a state LED mappingRETURNS void */void LEDManagerAddLEDStatePattern ( LedTaskData * ptheLEDTask , headsetState pState , LEDPattern_t* pPattern ){ ptheLEDTask->gStatePatterns [ pState ] = LMAddPattern ( ptheLEDTask , pPattern , ptheLEDTask->gStatePatterns [ pState ] ) ; LM_DEBUG(("LM: AddState[%x][%x]\n" , pState ,(int) ptheLEDTask->gStatePatterns [ pState ] )) ;}/****************************************************************************NAME LEDManagerAddLEDEventPatternDESCRIPTION Adds an event LED mappingRETURNS void */void LEDManagerAddLEDEventPattern ( LedTaskData * ptheLEDTask , headsetEvents_t pEvent , LEDPattern_t* pPattern ){ uint16 lIndex = pEvent - EVENTS_EVENT_BASE ; ptheLEDTask->gEventPatterns [ lIndex ] = LMAddPattern ( ptheLEDTask , pPattern , ptheLEDTask->gEventPatterns [ lIndex ] ) ; LM_DEBUG(("LM: AddEvent[%x] [%x]\n" , pEvent ,(int)ptheLEDTask->gEventPatterns [ lIndex ])) ; }/****************************************************************************NAME LMAddPatternDESCRIPTION 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 ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -