Device Access API
Proposal for Java ME 8

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, UnavailablePeripheralException,
             PeripheralNotFoundException {
         channel = (ADCChannel) PeripheralManager.open(channelID);
         channel.setSamplingInterval(1000); // every 1 seconds
         channel.startMonitoring(low, high, this);
         if (channel instanceof PowerManaged) {
             ((PowerManaged) channel).enablePowerSaving(PowerManaged.LOW_POWER, this); // Only enable LOW_POWER saving mode (POWER_ON is implicit)
         }
     }

     @Override
     public void thresholdReached(MonitoringEvent event) {
         inRange = (event.getType() == MonitoringEvent.BACK_TO_RANGE);
     }

     @Override
     public <P extends Peripheral<? super P>> long handlePowerStateChangeRequest(P peripheral,
             PowerManaged.Group group, 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
     }

     @Override
     public <P extends Peripheral<? super P>> void handlePowerStateChange(P peripheral,
             PowerManaged.Group group, int currentState, int requestedState, long duration) {
         // Do nothing
     }

     public void stop() throws IOException {
         if (channel != null) {
             channel.stopMonitoring();
             if (channel instanceof PowerManaged) {
                 ((PowerManaged) channel).disablePowerSaving();
             }
             channel.close();
         }
     }
 }
 

Unless otherwise noted, passing a null argument to a constructor or method in any class or interface in this package will cause a NullPointerException to be thrown.

Device Access API
Proposal for Java ME 8