All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jdk.dio.pwm.package-info Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */
/**
 * Interfaces and classes for generating width-modulated pulses - Pulse Width Modulation (PWM) - on a digital output line.
 * 

* In order to access and control a specific PWM channel, an application should first open and obtain an * {@link jdk.dio.pwm.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 * {@link jdk.dio.pwm.PWMChannel#setPulsePeriod} method ; then generate pulses of a specified width or * duty cycle by calling one of the {@link jdk.dio.pwm.PWMChannel#generate} or * {@link jdk.dio.pwm.PWMChannel#startGeneration}.

*
*
 * 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 {@link jdk.dio.pwm.PWMChannel#close * 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 {@link java.lang.SecurityException 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 {@code null} argument to a constructor or method in any class * or interface in this package will cause a {@link java.lang.NullPointerException NullPointerException} to be thrown. *

* This package requires the {@link jdk.dio.gpio} package. *

* * @since 1.0 */ package jdk.dio.pwm;




© 2015 - 2025 Weber Informatics LLC | Privacy Policy