See: Description
Interface | Description |
---|---|
GenerationListener |
The
GenerationListener interface defines methods for getting notified of pulse generation completion
conditions (i.e. |
GenerationRoundListener |
The
GenerationRoundListener interface defines methods for getting notified of the completion of the
generation of a sequence of pulses and that more pulses (the width thereof) to generate may be specified. |
PWMChannel |
The
PWMChannel interface provides methods for controlling a PWM (Pulse Width Modulation) signal generator
channel. |
Class | Description |
---|---|
GenerationEvent |
The
GenerationEvent class encapsulates pulse a generation completion condition (i.e. |
PWMChannelConfig |
The
PWMChannelConfig class encapsulates the hardware addressing information, and static and dynamic
configuration parameters of a PWM channel. |
PWMChannelConfig.Builder |
The
Builder class allows for creating and initializing PWMChannelConfig objects. |
PWMPermission |
The
PWMPermission class defines permissions for PWM channel access. |
Exception | Description |
---|---|
InvalidPulseRateException |
Thrown by an instance of
PWMChannel in case the requested pulse period results
in a pulse rate higher or lower
than the maximum, respectively minimum, rate/frequency the PWM device can support. |
In order to access and control a specific PWM channel, an application should first open and obtain an
PWMChannel
instance for the PWM generator's channel the application wants to
access and control, using its numeric ID, name, type (interface) and/or properties:
- Using its ID
PWMChannel channel = (PWMChannel) DeviceManager.open(8);- Using its name and interface
PWMChannel channel = DeviceManager.open("DIMMER", PWMChannel.class, null);
Once opened, an application can set the period of generated pulses using the
PWMChannel.setPulsePeriod(int)
method ; then generate pulses of a specified width or
duty cycle by calling one of the PWMChannel.generate(int, int)
or
PWMChannel.startGeneration(int)
.
channel.setPulsePeriod(1000000); // Pulse period = 1 second channel.generate(500000, 10); // Generate 10 pulses with a width of 0.5 second
When done, the application should call the PWMChannel.close
method to close PWM channel.
channel.close();
The following sample code gives an example of using the PWM channel API to progressively dim the light of a LED (for example) starting from its maximum intensity (100% duty cycle) in 10 successive steps of 10 seconds each:
class VaryingDimmer implements GenerationRoundListener { private PWMChannel channel = null; private int step = 10; public void pulseGenerationCompleted(GenerationEvent event) { if (step > 0) { try { channel.startGeneration((channel.getPulsePeriod() / 10) * --step, 10, this); } catch (IOException ex) { // Ignored } } } public void start(int channelID) throws IOException, NonAvailableDeviceException, DeviceNotFoundException { if (channel != null) { throw new IllegalStateException(); } channel = (PWMChannel) DeviceManager.open(channelID); channel.setPulsePeriod(1000000); // period = 1 second channel.startGeneration((channel.getPulsePeriod() / 10) * step, 10, this); } public void stop() throws IOException, NonAvailableDeviceException { if (channel != null) { channel.stopGeneration(); channel.close(); } } public void failed(Throwable exception, PWMChannel source) { // Ignored } }
Because of performance issue, procedures handling PWM events, and especially event listeners, should be implemented to be as fast as possible.
Unless otherwise noted, permission and security checks that may cause
a SecurityException
to be thrown must be performed
in priority to any other checks or operations once performed the checking of the input parameters
from which the permission target names and action lists are retrieved and assembled.
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.
This package requires the jdk.dio.gpio
package.
Copyright © 2012, 2015, Oracle and/or its affiliates. All rights reserved.
Legal Notices