use of com.robo4j.units.rpi.I2CEndPoint in project robo4j by Robo4J.
the class PCA9685ServoUnit method onInitialization.
/**
*
* @param configuration
* - unit configuration
* @throws ConfigurationException
*/
@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
super.onInitialization(configuration);
Object pwmDevice = I2CRegistry.getI2CDeviceByEndPoint(new I2CEndPoint(getBus(), getAddress()));
PWMPCA9685Device pcaDevice = null;
try {
if (pwmDevice == null) {
pcaDevice = new PWMPCA9685Device(getBus(), getAddress());
I2CRegistry.registerI2CDevice(pcaDevice, new I2CEndPoint(getBus(), getAddress()));
pcaDevice.setPWMFrequency(50);
} else {
pcaDevice = (PWMPCA9685Device) pwmDevice;
}
} catch (IOException e) {
throw new ConfigurationException("Could not initialize hardware", e);
}
channel = configuration.getInteger(CONFIGURATION_KEY_CHANNEL, -1);
if (channel == -1) {
throw ConfigurationException.createMissingConfigNameException(CONFIGURATION_KEY_CHANNEL);
}
servo = new Servo(pcaDevice.getChannel(channel));
servo.setTrim(configuration.getFloat(CONFIGURATION_KEY_TRIM, 0f));
servo.setInverted(configuration.getBoolean(CONFIGURATION_KEY_INVERTED, false));
servo.setDualRate(configuration.getFloat(CONFIGURATION_KEY_DUAL_RATE, 1.0f));
servo.setExpo(configuration.getFloat(CONFIGURATION_KEY_EXPO, 0.0f));
}
Aggregations