• Select a language



Using Power and Display Context in the Intel
® 
Mobile Platform Software Development Kit (SDK) 1.1
Page & Feed Options
Print this
Bookmark This
Digg this | Add to your del.icio.us account
Table of Contents

Implementation
The Intel Mobile Platform SDK provides several APIs and properties to retrieve information from contexts such as Power and Display. Below is an overview of those used in the sample application.

Initialization

Power and Display context are initialized as shown below. Refer to the code in “BasicPhysics.CPP” to get details on variable definitions.

Once the objects are initialized, the properties of each of these can be retrieved as shown below.

‘Power/Display’ Properties and APIs

The Intel Mobile Platform SDK provides access to multiple APIs and properties. To see complete list, refer to the “Programmer's Guide” provided with the Intel Mobile Platform SDK.

One of the important properties provided by Power context is that it will retrieve information about the system power source, whether it is internal or external. The sample application uses this property to change application behavior based on the current power source.

if (!powerInstance->Source.IsNull())	
{
if (powerInstance->Source.GetValue() == SourceEnum::Internal)
	{
		// Running on Battery
	}
	else
	{
		// Running on AC
	}
}

Similarly, the Display context provides properties to retrieve the resolution of the current display. In this application, the Display resolution is changed based on if the system is running on external vs. internal power.

//Get current Horizontal and Vertical resolution values
//and store in OrigHorizRes and OrigVerRes from
//pMyDisplayAdapterInstance
OrigHorizRes = pMyDisplayAdapterInstance->HorizontalResolution.GetValue();
OrigVerRes = pMyDisplayAdapterInstance->VerticalResolution.GetValue();

In the sample application, the original display resolution is retrieved during application initialization so when the application exits, the resolution can be restored to the original values.

Event Notification

Event notification is the mechanism by which changes occurring in the system are tracked and the appropriate action is taken at runtime as they occur. If the power source is changed during an application run, the application should be able to see these changes without polling and take action appropriately. An application must register all relevant events for the item for which notification is to be received.

To receive notification of a change in power source, this application registers for both 'InternallyPowered' and 'ExternallyPowered'.

//Add Observers to appropriate properties to track changes from
//AC/Battery power source	
powerInstance->InternallyPowered.AddObserver(source);
powerInstance->ExternallyPowered.AddObserver(source);

Where “source” is an object of an “Observer” class.

An Observer class is an abstract base class provided by the Intel Mobile Platform SDK. Developers can derive and implement their own observer class by providing implementation for the “Notify()” method as shown below.

In this application, the Notify() method changes the Display resolution whenever the power source is changed. For example, when the power source is changed to “Internal,” the screen resolution is set to 800x600.

class PowerSource : public Observer
{
public:
	void Notify(const Event& e)
	{
		try
		{
			switch (e.GetType())
			{
			case Event::eInternallyPowered:

//Change display mode to lower resolution 
//800x600 using SetDisplayMode

			DisplayMode NewDispMode;
			NewDispMode.HorizontalResolution = 800;
			NewDispMode.VerticalResolution = 600;
NewDispMode.ColorDepth=     pMyDisplayAdapterInstance->ColorDepth.GetValue();
NewDispMode.RefreshRate=    pMyDisplayAdapterInstance->RefreshRate.GetValue();
pMyDisplayAdapterInstance->SetDisplayMode(NewDispMode);

			break;

			case Event::eExternallyPowered:
		
			// Re-set the display mode to original resolution
			DisplayMode dispMode;
			dispMode.HorizontalResolution = OrigHorizRes;
			dispMode.VerticalResolution = OrigVerRes;
dispMode.ColorDepth=        pMyDisplayAdapterInstance->ColorDepth.GetValue();
dispMode.RefreshRate=       pMyDisplayAdapterInstance->RefreshRate.GetValue();
			pMyDisplayAdapterInstance->SetDisplayMode(dispMode);	

			break;
			}
		}
		catch (IntelMobileException& ex)
		{
		}
	}
};

Thresholds

Another way to track changes to system context is by using “Thresholds.” Thresholds create events when specified conditions are met. To be notified of a threshold, an object of Threshold type needs to be created as shown below.

UIntGaugeThreshold LowThreshold;

//Set Property for observation
LowThreshold.SetObservedProperty(powerInstance->PercentRemaining);
//Set Low, High Threshold values and granularity period
LowThreshold.SetLowThreshold(power_level);
LowThreshold.SetHighThreshold(power_level+5);
LowThreshold.SetGranularityPeriod(5000);
//Add observer to gauge object
LowThreshold.AddObserver(powerStat);
//Start executing gauge object
LowThreshold.Start();

powerStat is an object of the “PowerStatus” observer class and it is defined as shown below. When the specified low battery life is reached, this class will set display screen state to “Blanked.”

class PowerStatus : public Observer
{
public:
	void Notify(const Event& e)
	{
		
		try
		{
			if (e.GetType() == Event::eThresholdLow)
			{
				
//Set ScreenState to Blanked when low power is //reached
pMyDisplayAdapterInstance->ScreenState.SetValue(ScreenStateEnum::Blanked);

			LowThreshold.Stop();
			}
		}
		catch (IntelMobileException& ex)
		{
		}
	}
};

It is also important to remove the observer to make sure that no hanging references remain when the application exits.

   powerInstance->InternallyPowered.RemoveObserver(source);
   powerInstance->ExternallyPowered.RemoveObserver(source);
   LowThreshold.RemoveObserver(powerStat);

Prev1  2  3  4  5  Next

Page 5 of 6