Skip to content

Commit

Permalink
Merge pull request #200 from EAGrahamJr/servo-controller
Browse files Browse the repository at this point in the history
New constructors for device.
  • Loading branch information
mattjlewis committed Apr 18, 2024
2 parents 27ee16b + 45d4c81 commit 26e0abd
Showing 1 changed file with 50 additions and 5 deletions.
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

0 comments on commit 26e0abd

Please sign in to comment.