PowerManager Class Reference

Power manager class. More...

#include <PowerManager.h>

Inheritance diagram for PowerManager:
EventBroadcaster< PowerEventListener >

List of all members.

Public Member Functions

virtual ~PowerManager ()
 Class destructor.
void enableTransitions (bool flag)
 Enable power state switching.
bool setPowerMode (PowerState newState)
 Set device power mode.
bool kickIdle ()
 Deferring idle mode.
int getIdleDuration ()
 Get idle period duration.
void ledEnable (bool red, bool green)
 Enable LED outputs.
void keybSetBackLight (unsigned char level)
 Set keypad backlight brightness.
void keybFadeBackLight (unsigned char level)
 Fade keypad backlight brightness.
bool oledEnable (bool flag)
 Enable display.
bool oledSetBrightness (unsigned char level)
 Set display brightness.
bool oledFadeBrightness (unsigned char level)
 Fade display brightness.
bool oledFreeze (bool flag)
 Freeze display.
void oledSetMaxBrightness (int maxLevel)
 Set maximum display brightness.
void buzzerPlay (int freq, int duration)
 Sound buzzer.
bool gprsPowerOn ()
 Power on GPRS module.
bool gprsPowerOff ()
 Power off GPRS module.
void gprsReset ()
 Reset GPRS module.
bool gprsGetPower ()
 Get GPRS module state.
void gprsSetDTR (bool active)
 Set DTR line of GPRS module.
void mpciEnableRadio (bool enable)
 Enable radio interface of the communication module.
void mpciEnable3V3 (bool enable)
 Enable communication module 3.3V power supply.
bool scannerPowerUp ()
 Power up barcode scanner.
bool scannerPowerDown ()
 Power down barcode scanner.
bool scannerSetAim (bool flag)
 Set barcode scanner aiming.
bool rtcGetAlarmState ()
 Get RTC alarm status.
bool rtcSetAlarm (int delay)
 Set RTC alarm.
bool rtcEnableAlarm (bool flag)
 Enable RTC alarm.
bool rtcSetTime (time_t now)
 Set RTC time.
bool rtcGetTime (time_t *pNow)
 Get RTC time.
int getBatteryCapacity (int *pVoltage=NULL)
 Get battery capacity and voltage.
int getBatteryVoltage ()
 Get battery voltage.
int getTempReading ()
 Read temperature.
int getAmbientLight ()
 Get ambient light intensity.
PowerState getCurrentState ()
 Get current power state.
bool isUsbConnected ()
 Get USB VBus pin state.
void setPowerSaveSleep (int sec)
 Set power saving sleep duration.

Static Public Member Functions

static bool initPowerManager ()
 Initialize power manager.
static bool deinitPowerManager ()
 Release power manager.
static PowerManagergetPowerManager ()
 Retrieve power manager.
static int kickIdleProc ()
 Deferring idle mode.

Protected Member Functions

 PowerManager ()
 Class constructor.
bool initialize ()
 Initialization routine The actual routine to perform power manager initialization:

  • Tries to open power management driver
  • Finds speaker device
  • Opens RTC device
  • Sets power mode to FULLY_OPERATIONAL.

bool deinitialize ()
 Uninitialization routine The actual routine to perform device uninitialization. Closes speaker device, power driver and RTC driver handles.

Detailed Description

Power manager class.

Power manager implements a singleton class that takes care of basic power management functions of the mobile terminal. Power manager must be initialized at the beginning of the application life and uninitialized at the end. Power manager does not maintain any worker threads by itself. Instead, an external supervisor or monitor should initiate power state transitions.


Constructor & Destructor Documentation

PowerManager::~PowerManager (  )  [virtual]

Class destructor.

Destroys the power manager object.

PowerManager::PowerManager (  )  [protected]

Class constructor.

Presets power manager attributes. Maximum screen brightness is initially set to 255.


Member Function Documentation

void PowerManager::buzzerPlay ( int  freq,
int  duration 
)

Sound buzzer.

Generates a buzzer tone.

Parameters:
freq Specifies buzzer tone frequency, in Hertz.
duration Specifies tone duration, in milliseconds.
bool PowerManager::deinitialize (  )  [protected]

Uninitialization routine The actual routine to perform device uninitialization. Closes speaker device, power driver and RTC driver handles.

Returns:
Returns true if the uninitialization was performed successfully, false otherwise
bool PowerManager::deinitPowerManager (  )  [static]

Release power manager.

Uninitializes the power manager singleton object and deletes it. Must be called at the end of the application life.

Returns:
Returns true if the power manager was released successfully.
void PowerManager::enableTransitions ( bool  flag  ) 

Enable power state switching.

Enables or disables power manager state switching.

Parameters:
flag When set to false, setPowerState() method will not have any effect. When set to true, setPowerState() operates normally.
int PowerManager::getAmbientLight (  ) 

Get ambient light intensity.

Reads integrated ambient light sensor data, combining both IR and visible light spectra.

Returns:
Returns ambient light sensor intensity.
int PowerManager::getBatteryCapacity ( int *  pVoltage = NULL  ) 

Get battery capacity and voltage.

Reads current battery capacity in percent. Alternatively, reads approximate battery voltage for post-processing. Note that averaging is applied for successive reads, to reduce voltage jitter and drift.

Parameters:
pVoltage Pointer to integer that holds the approximated voltage level. If the parameter is not NULL, the voltage is stored in millivolts.
Returns:
Returns battery capacity in percent (0..100). In case of an error returns -1.
int PowerManager::getBatteryVoltage (  ) 

Get battery voltage.

Reads current battery raw voltage for post-processing.

Returns:
Returns battery voltage in millivolts. Returns -1 in case of an error.
PowerState PowerManager::getCurrentState (  ) 

Get current power state.

Returns:
Returns current power manager state.
int PowerManager::getIdleDuration (  ) 

Get idle period duration.

Calculates and returns the duration of idle state. The idle duration is calculated based on the last kickIdle() call instant.

Returns:
Returns idle period, in seconds.
PowerManager * PowerManager::getPowerManager (  )  [static]

Retrieve power manager.

Static function used to return a pointer to the one and the only power manager object.

Returns:
Returns a pointer to the power manager singleton object.
int PowerManager::getTempReading (  ) 

Read temperature.

Reads internal temperature sensor.

Returns:
Returns current temperature in degrees Centigrade multiplied by 10. In case of an error returns INT_MIN.
bool PowerManager::gprsGetPower (  ) 

Get GPRS module state.

Reads current power state of the GPRS module on GSM-enabled data terminals.

Returns:
Returns true if the GPRS module is powered up.
bool PowerManager::gprsPowerOff (  ) 

Power off GPRS module.

Powers down the GPRS module on GSM-enabled data terminals. The GPRS module resulting state is sensed and reported back. Depending on network state, the call may take variable amount of time. If the module does not report a valid shutdown in 10 seconds, the module power supply is disconnected.

Returns:
Returns true.
bool PowerManager::gprsPowerOn (  ) 

Power on GPRS module.

Powers up the GPRS module on GSM-enabled data terminals. The GPRS module resulting state is sensed and reported back.

Returns:
Returns true if the GPRS module has reported a successful start.
void PowerManager::gprsReset (  ) 

Reset GPRS module.

Generates a reset pulse to restart the GPRS module on GSM-enable data terminals.

void PowerManager::gprsSetDTR ( bool  active  ) 

Set DTR line of GPRS module.

Enables or disables DTR signal on the GPRS module serial port interface. DTR signal is used to control operation of the GPRS module, for example its power saving mode.

Parameters:
active Specifies the DTR line state.
bool PowerManager::initialize (  )  [protected]

Initialization routine The actual routine to perform power manager initialization:

  • Tries to open power management driver
  • Finds speaker device
  • Opens RTC device
  • Sets power mode to FULLY_OPERATIONAL.

Returns:
Returns true if initialization was performed successfully, false otherwise
bool PowerManager::initPowerManager (  )  [static]

Initialize power manager.

Creates the power manager singleton object and initializes it. Must be called before any other power manager function.

Note:
Device initialization is performed by calling the initialize() method
Returns:
Returns true if the power manager initialization was a success.
bool PowerManager::isUsbConnected (  ) 

Get USB VBus pin state.

Returns:
Returns true if USB VBus pin is powered.
void PowerManager::keybFadeBackLight ( unsigned char  level  ) 

Fade keypad backlight brightness.

Fades the keypad backlight brightness to the desired level fluently.

Parameters:
level Specifies the destination keypad backlight brightness (0..255).
void PowerManager::keybSetBackLight ( unsigned char  level  ) 

Set keypad backlight brightness.

Sets the keypad backlight brightness to absolute level instantly.

Parameters:
level Specifies the keypad backlight brightness (0..255).
bool PowerManager::kickIdle (  ) 

Deferring idle mode.

Instructs power manager that the device is not idle at the moment. Power manager saves current timestamp that is further used for calculation of the idle duration.

Returns:
Returns false if system was already idle, true otherwise
int PowerManager::kickIdleProc (  )  [static]

Deferring idle mode.

Instructs power manager that the device is not idle at the moment. Power manager saves current timestamp that is further used for calculation of the idle duration. Calls the kickIdle() method.

Returns:
Returns false if system was already idle, true otherwise
void PowerManager::ledEnable ( bool  red,
bool  green 
)

Enable LED outputs.

Enables or disables LED outputs of the data terminal. Note that the battery charger circuitry also drives LED outputs, which may interfere with software.

Parameters:
red Enables red LED.
green Enables green LED.
void PowerManager::mpciEnable3V3 ( bool  enable  ) 

Enable communication module 3.3V power supply.

Enables or disables the 3.3V power supply to the data terminal communication module. Currently implemented on WLAN-enabled devices.

Parameters:
enable Specifies if the power supply is to be enabled.
void PowerManager::mpciEnableRadio ( bool  enable  ) 

Enable radio interface of the communication module.

Enables or disables the radio interface of the data terminal communication module. Currently implemented on WLAN-enabled devices.

Parameters:
enable Specifies if the radio interface is to be enabled.
bool PowerManager::oledEnable ( bool  flag  ) 

Enable display.

Enables or disables the display of the data terminal. When the display is disabled, it is placed to a low-power mode.

Parameters:
flag Specifies if the display should be enabled.
Returns:
Returns true if operation was successful.
bool PowerManager::oledFadeBrightness ( unsigned char  level  ) 

Fade display brightness.

Fades the display brightness to the specified level fluently.

Parameters:
level Specifies the destination display brightness (0..255).
Returns:
Returns true if the call was successful.
bool PowerManager::oledFreeze ( bool  flag  ) 

Freeze display.

Freezes the content of the display. May be used to avoid flickering, for example.

Parameters:
flag Set to true to freeze the display. Set to false to unfreeze afterwards.
Returns:
Returns true if operation was successful.
bool PowerManager::oledSetBrightness ( unsigned char  level  ) 

Set display brightness.

Sets the display brightness to the absolute level instantly.

Parameters:
level Specifies the display brightness (0..255).
Returns:
Returns true if the call was successful.
void PowerManager::oledSetMaxBrightness ( int  maxLevel  ) 

Set maximum display brightness.

Sets maximum display brightness. Does not have any effect immediately, as the value is used for calculation of display brightnesses for FULLY_OPERATIONAL and DISPLAY_DIMMED power modes.

Parameters:
maxLevel Specifies maximum display brightness (0..255).
bool PowerManager::rtcEnableAlarm ( bool  flag  ) 

Enable RTC alarm.

Enables or disables RTC alarm.

Parameters:
flag Specifies if the RTC alarm is to be enabled.
Returns:
Returns true if operation was a success.
bool PowerManager::rtcGetAlarmState (  ) 

Get RTC alarm status.

Returns current RTC alarm status, as reported by kernel.

Returns:
Returns true if the RTC alarm has been triggered.
bool PowerManager::rtcGetTime ( time_t *  pNow  ) 

Get RTC time.

Reads current RTC time. The RTC must be running in order this call to succeed.

Parameters:
pNow Points to the destination timestamp returned in Unix format.
Returns:
Returns true if the RTC was read successfully.
bool PowerManager::rtcSetAlarm ( int  delay  ) 

Set RTC alarm.

Initializes RTC alarm to trigger in a specified time interval. The alarm may be used to bring the device out of a power saving mode.

Parameters:
delay Specifies the time interval after which the alarm is triggered, in seconds.
Returns:
Retruns true if operation was a success.
bool PowerManager::rtcSetTime ( time_t  now  ) 

Set RTC time.

Initializes the integrated RTC implemented by means of the CPU Real-Time Timer. The RTC must be re-initialized every time the data terminal device loses power supply for a long period.

Parameters:
now Contains the current timestamp in Unix format.
Returns:
Returns true if the RTC was set successfully
bool PowerManager::scannerPowerDown (  ) 

Power down barcode scanner.

Powers down a barcode scanner device on data terminals that have 1D or 2D barcode scanner integrated into the sensor module.

Returns:
Returns true if the scanner was powered down successfully.
bool PowerManager::scannerPowerUp (  ) 

Power up barcode scanner.

Powers up a barcode scanner device on data terminals that have 1D or 2D barcode scanner integrated into the sensor module.

Returns:
Returns true if the scanner was powered up successfully.
bool PowerManager::scannerSetAim ( bool  flag  ) 

Set barcode scanner aiming.

Enables or disables aiming of a barcode scanner device on data terminals that have 1D or 2D barcode scanner integrated into the sensor module.

Parameters:
flag Specifies if barcode scanner aiming is to be enabled.
Returns:
Returns true if operation was a success.
bool PowerManager::setPowerMode ( PowerState  newState  ) 

Set device power mode.

Sets current power state of the data terminal. Executes all operations required to enter the specified power state. All registered event listeners are called and queried for their readiness to proceed to the new power state.

The following states are supported: FULLY_OPERATIONAL, DISPLAY_DIMMED, DISPLAY_MINIMAL, DISPLAY_DISABLED, LOW_POWER_SLEEP, POWER_DOWN.

When LOW_POWER_SLEEP mode is specified, the system proceeds to a power saving mode where it runs on a slow clock and awaits for a GPIO or RTC alarm interrupt. In case of a GPIO interrupt (button press), the system proceeds to FULLY_OPERATIONAL state. In case of an RTC alarm interrupt, the system proceeds to a limited LOW_POWER_AWAKE state where it awaits further action.

Parameters:
newState Specifies the new power state.
Returns:
Returns true if the power mode was entered successfully.
void PowerManager::setPowerSaveSleep ( int  sec  ) 

Set power saving sleep duration.

Sets the time period that the data terminal spends in power saving mode, when entered. After the given period is elapsed, the device proceeds to a limited LOW_POWER_AWAKE state and awaits further action.

Parameters:
sec Specifies the power saving sleep duration, in seconds.

The documentation for this class was generated from the following files:
Generated on Wed Oct 20 11:13:44 2010 for libspatha by  doxygen 1.6.3