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

📄 headset_configmanager.c

📁 bluelab的一个很好的例程
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004

FILE NAME
    headset_configmanager.c
    
DESCRIPTION
    Configuration manager for the headset - resoponsible for extracting user information out of the 
    PSKEYs and initialising the configurable nature of the headset components
    
*/

#include "headset_configmanager.h"
#include "headset_config.h"
#include "headset_buttonmanager.h"
#include "headset_LEDmanager.h"
#include "headset_soundmanager.h"
#include "headset_statemanager.h"
#include "headset_powermanager.h"
#include "headset_volume.h"

#include "headset_private.h"
#include "headset_events.h"

#include <csrtypes.h>
#include <ps.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>


#ifdef DEBUG_CONFIG
#define CONF_DEBUG(x) DEBUG(x)
#else
#define CONF_DEBUG(x) 
#endif

#define HCI_PAGESCAN_INTERVAL_DEFAULT  (0x800)
#define HCI_PAGESCAN_WINDOW_DEFAULT   (0x12)
#define HCI_INQUIRYSCAN_INTERVAL_DEFAULT  (0x800)
#define HCI_INQUIRYSCAN_WINDOW_DEFAULT   (0x12)


#define DEFAULT_VOLUME_MUTE_REMINDER_TIME_SEC 10


/****************************************************************************
LOCAL FUNCTIONS
*/
static void   	configManagerButtons(hsTaskData* theHeadset);
static void  	configManagerLEDS(hsTaskData* theHeadset);
static void  	configManagerButtonDurations(hsTaskData* theHeadset);
static void  	configManagerFeatureBlock(hsTaskData* theHeadset);
static void     configManagerPIOBlock(hsTaskData * theHeadset);
static void 	configManagerPower(hsTaskData* theHeadset);
static void  	configManagerRadio(hsTaskData* theHeadset);
static void     configManagerVolume(hsTaskData * theHeadset);
static void     configManagerEventTones(hsTaskData* theHeadset );
static void     configManagerTimeouts(hsTaskData* theHeadset);
static void     configManagerReadVolumeOrientation ( hsTaskData * theHeadset ) ;

static void configManagerButtonPatterns(hsTaskData * theHeadset)  ;

/****************************************************************************
NAME 
  	configManagerInit

DESCRIPTION
  	The Configuration Manager is responsible for reading the user configuration
  	from the persistent store are setting up the system.  Each system component
  	is initialised in order.  Where appropriate, each configuration parameter
  	is limit checked and a default assigned if found to be out of range.

RETURNS
  	void
    
*/
void configManagerInit(hsTaskData* theHeadset)  
{ 
  	/* Read and configure the button durations */
  	configManagerButtonDurations(theHeadset);
    
  	/* Read the system event configuration and configure the buttons */
    configManagerButtons(theHeadset);

        /*configures the pattern button events*/
    configManagerButtonPatterns(theHeadset) ;

    /*Read and configure the event tones*/
    configManagerEventTones( theHeadset ) ;

  	/* Read and configure the LEDs */
    configManagerLEDS(theHeadset);
 
  	/* Read and configure the voume settings */
  	configManagerVolume(theHeadset);
 
  	/* Read and configure the system features */
  	configManagerFeatureBlock(theHeadset);
    
    /* Read and configure the system PIOs*/    
    configManagerPIOBlock ( theHeadset ) ;

    /* Read and configure the automatic switch off time*/
    configManagerTimeouts(theHeadset);
 
  	/* Read and configure the power management system */
  	configManagerPower(theHeadset);
 
  	/* Read and configure the radio parameters */
  	configManagerRadio(theHeadset);
 
    /*Read and configure the HFP 1.5 supported features*/
    configManagerHFP_1_5_SupportedFeatures ( theHeadset) ;
    
    /*read and configurethe volume orientation*/
    configManagerReadVolumeOrientation ( theHeadset ) ;
 
}


/****************************************************************************
NAME 
  	configManagerButtons

DESCRIPTION
 	Read the system event configuration from persistent store and configure
  	the buttons by mapping the associated events to them
 
RETURNS
  	void
*/  

static void configManagerButtons(hsTaskData* theHeadset)
{ 
  	uint16 no_events = 20;
 
	/* Allocate enough memory to hold event configuration */
    event_config_type* config = (event_config_type*) mallocPanic(no_events * sizeof(event_config_type));
   
    
    /* Now read in event configuration */
    if(config)
    {   
            /*read in the events for the first PSKEY*/                
        if(ConfigRetrieve(PSKEY_EVENTS_A, config, no_events * sizeof(event_config_type)))
      	{
            uint16 n;
     
        		/* Now we have the event configuration, map required events to system events */
            for(n = 0; n < no_events; n++)
            { 
                CONF_DEBUG(("Co : AddMap Ev[%x]\n", config[n].event )) ;
                        
                if ( config[n].pio_mask )
                {
                        /* Map PIO button event to system events in specified states */
                    buttonManagerAddMapping (config[n].pio_mask, 
                     						(config[n].event + EVENTS_EVENT_BASE) ,
                    						 config[n].state_mask, 
                    						(ButtonsTime_t)config[n].type); 
                }                                            
        	}
      	}
   		else
   		{
    	   CONF_DEBUG(("Co: !EvLen\n")) ;
        }
        
            /*now do the same for the second PSKEY*/
        if(ConfigRetrieve(PSKEY_EVENTS_B, config, no_events * sizeof(event_config_type)))
      	{
            uint16 n;
     
        		/* Now we have the event configuration, map required events to system events */
            for(n = 0; n < no_events; n++)
            { 
                CONF_DEBUG(("Co : AddMap Ev[%x]\n", config[n].event )) ;
                        
                if ( config[n].pio_mask )
                {
                        /* Map PIO button event to system events in specified states */
                    buttonManagerAddMapping (config[n].pio_mask, 
                     						(config[n].event + EVENTS_EVENT_BASE) ,
                    						 config[n].state_mask, 
                    						(ButtonsTime_t)config[n].type); 
                }          
        	}
      	}
   		else
   		{
    	   CONF_DEBUG(("Co: !EvLen2\n")) ;
        }        

        	/* Free up memory */
      	free(config);
    }
}
/****************************************************************************
NAME 
  	configManagerButtonPatterns

DESCRIPTION
  	Read and configure any buttonpattern matches that exist
 
RETURNS

*/
static void configManagerButtonPatterns(hsTaskData * theHeadset) 
{  
      		/* Allocate enough memory to hold event configuration */
    button_pattern_config_type* config = (button_pattern_config_type*) mallocPanic(BM_NUM_BUTTON_MATCH_PATTERNS * sizeof(button_pattern_config_type));
   
    CONF_DEBUG(("Co: No Button Patterns - %d\n", BM_NUM_BUTTON_MATCH_PATTERNS));
   
        /* Now read in event configuration */
    if(config)
    {
                
        if(ConfigRetrieve(PSKEY_BUTTON_PATTERN_CONFIG, config, BM_NUM_BUTTON_MATCH_PATTERNS * sizeof(button_pattern_config_type)))
        {
            uint16 n;
     
           /* Now we have the event configuration, map required events to system events */
            for(n = 0; n < BM_NUM_BUTTON_MATCH_PATTERNS ; n++)
            {	 
     	      CONF_DEBUG(("Co : AddPattern Ev[%x]\n", config[n].event )) ;
                        
          			   /* Map PIO button event to system events in specified states */
          	    BMAddPatternMapping (config[n].event , config[n].pattern ) ;
            }
        }
        else
 	    {
 	      CONF_DEBUG(("Co: !EvLen\n")) ;
        }
    }    
}


/****************************************************************************
NAME 
  	config

DESCRIPTION
  	Read the LED configuration from persistent store and configure the LEDS 
 
RETURNS
  	TRUE or FALSE
*/ 
static bool config(hsTaskData * theHeadset , configType type, uint16 pskey_no, uint16 pskey_config, uint16 max) 
{ 
  	bool success = FALSE;
  	uint16 no_events = 0;
 
  	/* First read the number of states/events configured */
  	if(ConfigRetrieve(pskey_no, &no_events, sizeof(uint16)))
  	{	  
    	/* Providing there are states to configure */
    	if((no_events > 0) && (no_events < max))
    	{
      		/* Allocate enough memory to hold state/event configuration */
      		led_config_type* config = (led_config_type*) mallocPanic(no_events * sizeof(led_config_type));
   
      		/* Now read in configuration */
      		if(config)
      		{  
       			if(ConfigRetrieve(pskey_config, config, no_events * sizeof(led_config_type)))
       			{
         			uint16    n;
         			LEDPattern_t  pattern;
    
         			/* Now we have the configuration, map to system states/events */
         			for(n = 0; n < no_events; n++)
         			{ 
           				pattern.LED_A       = config[n].led_a;
           				pattern.LED_B       = config[n].led_b;
             			pattern.OnTime      = config[n].on_time * 10;
           				pattern.OffTime     = config[n].off_time * 10;
           				pattern.RepeatTime  = config[n].repeat_time * 50;
           				pattern.NumFlashes  = config[n].number_flashes;
           				pattern.Dimming     = 0;
          				pattern.TimeOut     = config[n].timeout;
           				pattern.Colour      = config[n].colour;
      
           				switch(type)
           				{
             				case led_state_pattern:
              					LEDManagerAddLEDStatePattern(&theHeadset->theLEDTask , config[n].state, &pattern);
              					break;
             				case led_event_pattern:
              					LEDManagerAddLEDEventPattern(&theHeadset->theLEDTask , EVENTS_EVENT_BASE + config[n].state, &pattern);
              					break;
           				}       
         			}
         			success = TRUE;
       			}
                else
                {
                    CONF_DEBUG(("Co: !LedLen\n")) ;
                }
                /* Free up memory */
       			free(config);
      		}
  		}
  	}
  	return success;
}


/****************************************************************************
NAME 
 	config_led_filter

DESCRIPTION
 	Read the LED filter configuration from persistent store and configure the
 	LED filters
 
RETURNS
 	TRUE or FALSE
*/ 
static bool config_filter( hsTaskData * theHeadset , uint16 pskey_no, uint16 pskey_filter, uint16 max)
{
 	bool success = FALSE;
 	uint16 no_filters = 0;
 
  	/* First read the number of filters configured */
  	if(ConfigRetrieve(pskey_no, &no_filters, sizeof(uint16)))
  	{  
    	/* Providing there are states to configure */
    	if((no_filters > 0) && (no_filters < max))
    	{
      		/* Allocate enough memory to hold filter configuration */
      		led_filter_config_type* config = (led_filter_config_type*) mallocPanic(no_filters * sizeof(led_filter_config_type));
   
      		/* Now read in configuration */
      		if(config)
      		{  
       			if(ConfigRetrieve(pskey_filter, config, no_filters * sizeof(led_filter_config_type)))
       			{
         			uint16    n;
         			LEDFilter_t  filter;
   
         			/* Now we have the configuration, map to system states/events */
         			for(n = 0; n < no_filters; n++)
         			{ 
           				filter.Event                = EVENTS_EVENT_BASE + config[n].event;
           				filter.Speed                = config[n].speed;
           				filter.IsFilterActive       = config[n].active;
           				filter.SpeedAction          = config[n].speed_action;
           				filter.Colour               = config[n].colour;
                        filter.FilterToCancel       = config[n].filter_to_cancel ;
                        filter.OverideLED           = config[n].overide_led ;

                        filter.OverideLEDActive     = config[n].overide_led_active ;
                        filter.FollowerLEDActive    = config[n].follower_led_active ;
    
                        filter.FollowerLEDDelay     = config[n].follower_led_delay_50ms ;
  
                            /*add the filter*/
          				LEDManagerAddLEDFilter(&theHeadset->theLEDTask , &filter);
                                    			} 
       			}
                else
                {
                    CONF_DEBUG(("Co :!FilLen\n")) ;
                }
        		/* Free up memory */
       			free(config);
      		}
      		success = TRUE;
    	}
  	} 
  	return success;
}


/****************************************************************************
NAME 
  	configManagerLEDS

DESCRIPTION
  	Read the system LED configuration from persistent store and configure
  	the LEDS 
 
RETURNS
  	void
*/ 
static void configManagerLEDS(hsTaskData* theHeadset)
{ 
  	/* 1. LED state configuration */
  	config(theHeadset , led_state_pattern, PSKEY_NO_LED_STATES, PSKEY_LED_STATES, MAX_LED_STATES);
 
  	/* 2. LED event configuration */
  	config(theHeadset , led_event_pattern, PSKEY_NO_LED_EVENTS, PSKEY_LED_EVENTS, MAX_LED_EVENTS);
 
  	/* 3. LED event filter configuration */
  	config_filter(theHeadset , PSKEY_NO_LED_FILTERS, PSKEY_LED_FILTERS, MAX_LED_FILTERS);         
}


/****************************************************************************
NAME 
  	configManagerFeatureBlock

DESCRIPTION
  	Read the system feature block and configure system accordingly
 
RETURNS
  	void
*/
static void configManagerFeatureBlock(hsTaskData* theHeadset) 
{
  	/* Get pairing timeout */
  	uint16 timeout; 
	if(!ConfigRetrieve(PSKEY_PAIRING_TIMEOUT, &timeout, sizeof(uint16)))
		timeout = 0;
 
    /* Read the feature block from persistent store */
  	if(ConfigRetrieve(PSKEY_FEATURE_BLOCK, &theHeadset->features, sizeof(feature_config_type)))
  	{
    	/* D0 - Pairing mode enable */
    	if(theHeadset->features.pair_mode_en)
      		stateManagerConfigureConnDiscoState(0, TRUE);
    	else
      		stateManagerConfigureConnDiscoState(timeout, FALSE);
    } 
 

⌨️ 快捷键说明

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