DAAPI B (b02)
- Java ME Embedded 3.3 Release

Package com.oracle.deviceaccess.power

Interfaces and classes for power management of peripheral devices.

See: Description

Package com.oracle.deviceaccess.power Description

Interfaces and classes for power management of peripheral devices.

A Peripheral implementing class may implement the PowerManaged interface if the underlying peripheral device supports some form of power management and saving states that can be mapped to the states defined by this API.

The following sample code gives an examples of using the power saving/management API:

 class SignalLevelMonitor implements MonitoringListener, PowerSavingHandler {
 
     private ADCChannel channel = null;
     private boolean inRange = false;
 
     public void start(int channelID, int low, int high) throws IOException, PeripheralNotAvailableException, PeripheralNotFoundException {
         channel = (ADCChannel) PeripheralManager.open(channelID);
         channel.setSamplingInterval(1000); // every 1 seconds
         channel.startMonitoring(low, high, this);
         if (channel instanceof PowerManaged) {
             ((PowerManaged) channel).enablePowerSaving(LOW_POWER, this); // Only enable LOW_POWER saving mode (POWER_ON is implicit)
         }
     }
 
     public void thresholdReached(MonitoringEvent event) {
         inRange = (event.getType() == MonitoringEvent.BACK_TO_RANGE);
     }
 
     public long handlePowerStateChangeRequest(Peripheral peripheral, int currentState, int requestedState, long duration) {
         if (requestedState == PowerManaged.LOW_POWER) {
              return inRange ? duration : 0; // Only accept to change to LOW_POWER if signal is back in range
         }
         return duration; // Accept returning to POWER_ON
     }
 
     public void stop() throws IOException, PeripheralNotAvailableException {
         if (channel != null) {
             channel.stopMonitoring();
             if (channel instanceof PowerManaged) {
                 ((PowerManaged) channel).disablePowerSaving();
             }
             channel.close();
         }
     }
 }
 

Security

As any other peripheral devices, peripheral devices that can be power-managed are opened by invoking one of the com.oracle.deviceaccess.PeripheralManager.open methods. The "com.oracle.deviceaccess.power" permission allows access to be granted to peripheral power management.
DAAPI B (b02)
5-February-2013 04:40

Copyright (c) 2012, Oracle and/or its affiliates. All Rights Reserved. Use of this specification is subject to license terms.