See: Description
| Interface | Description |
|---|---|
| PowerManaged |
The
PowerManaged interface provides methods that a Peripheral class may implement to control how the
underlying peripheral hardware resource is managed by the power management facility of the device. |
| PowerManaged.Group |
The
Group interface provides methods for registering for power state changes of peripherals belonging
to the same power management group. |
| PowerSavingHandler |
The
PowerSavingHandler interface defines methods for getting notified of power state change requests on a
specific Peripheral instance. |
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.Copyright © 2012, 2013, Oracle and/or its affiliates. All rights reserved.
Legal Notices