Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New constructors for device. #200

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 50 additions & 5 deletions diozero-core/src/main/java/com/diozero/devices/PCA9685.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Organisation: diozero
* Project: diozero - Core
* Filename: PCA9685.java
*
*
* This file is part of the diozero project. More information about this project
* can be found at https://www.diozero.com/.
* %%
Expand All @@ -17,10 +17,10 @@
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -123,22 +123,67 @@ public class PCA9685 extends AbstractDeviceFactory
private double periodUs = 1_000_000.0 / DEFAULT_PWM_FREQUENCY;
private final BoardPinInfo boardPinInfo;

/**
* Default I2C bus, address, and PWM frequency.
*
* @throws RuntimeIOException on error
*/
public PCA9685() throws RuntimeIOException {
this(I2CConstants.CONTROLLER_1, DEFAULT_ADDRESS, DEFAULT_PWM_FREQUENCY);
}

/**
* Default I2C bus, address.
*
* @param pwmFrequency the board frequency in Hz
* @throws RuntimeIOException on error
*/
public PCA9685(int pwmFrequency) throws RuntimeIOException {
this(I2CConstants.CONTROLLER_1, DEFAULT_ADDRESS, pwmFrequency);
}

/**
* Default address.
*
* @param controller I2C bus/controller
* @param pwmFrequency the board frequency in Hz
* @throws RuntimeIOException
*/
public PCA9685(int controller, int pwmFrequency) throws RuntimeIOException {
this(controller, DEFAULT_ADDRESS, pwmFrequency);
}

/**
* @param controller I2C bus/controller
* @param address the device address
* @param pwmFrequency the board frequency in Hz
* @throws RuntimeIOException on error
*/
public PCA9685(int controller, int address, int pwmFrequency) throws RuntimeIOException {
super(DEVICE_NAME + "-" + controller + "-" + address);
this(I2CDevice.builder(address)
.setController(controller)
.setByteOrder(ByteOrder.BIG_ENDIAN)
.build(),
pwmFrequency);
}

device = I2CDevice.builder(address).setController(controller).setByteOrder(ByteOrder.BIG_ENDIAN).build();
/**
* Default PWM frequency.
*
* @param device I2C device to use
*/
public PCA9685(I2CDeviceInterface device) {
this(device, DEFAULT_PWM_FREQUENCY);
}

/**
* @param device I2C device to use
* @param pwmFrequency the board frequency in Hz
* @throws RuntimeIOException on error
*/
public PCA9685(I2CDeviceInterface device, int pwmFrequency) throws RuntimeIOException {
super(DEVICE_NAME + "-" + device.getController() + "-" + device.getAddress());
this.device = device;
boardPinInfo = new PCA9685BoardPinInfo();

reset();
Expand Down
Loading