use of com.qualcomm.robotcore.hardware.I2cDeviceSynch in project robotcode by OutoftheBoxFTC.
the class AMSColorSensorImpl method internalInitialize.
// ----------------------------------------------------------------------------------------------
// Initialization
// ----------------------------------------------------------------------------------------------
@Override
protected synchronized boolean internalInitialize(@NonNull Parameters parameters) {
RobotLog.vv(TAG, "internalInitialize()...");
try {
if (this.parameters.deviceId != parameters.deviceId) {
throw new IllegalArgumentException(String.format("can't change device types (modify existing params instead): old=%d new=%d", this.parameters.deviceId, parameters.deviceId));
}
// Remember the parameters for future use
this.parameters = parameters.clone();
// Make sure we're talking to the correct I2c device
this.setI2cAddress(parameters.i2cAddr);
// Can't do anything if we're not really talking to the hardware
if (!this.deviceClient.isArmed()) {
return false;
}
// Verify that that's a color sensor!
byte id = this.getDeviceID();
if (id != parameters.deviceId) {
RobotLog.ee(TAG, "unexpected AMS color sensor chipid: found=%d expected=%d", id, parameters.deviceId);
return false;
}
// sanity check: before
dumpState();
// Turn off the integrator so that we can change parameters
disable();
// Set the gain and integration time. Note that we don't seem to be
// able to successfully set these values AFTER we enable, so we need to
// do so before.
setIntegrationTime(parameters.atime);
setGain(parameters.gain);
setPDrive(parameters.ledDrive);
if (is3782() && parameters.useProximityIfAvailable) {
setProximityPulseCount(parameters.proximityPulseCount);
}
// Enable the device
enable();
// sanity check: after
dumpState();
// Set up a read-ahead, if supported and requested
if (this.deviceClient instanceof I2cDeviceSynch && parameters.readWindow != null) {
I2cDeviceSynch synch = ((I2cDeviceSynch) this.deviceClient);
synch.setReadWindow(parameters.readWindow);
}
return true;
} finally {
RobotLog.vv(TAG, "...internalInitialize()");
}
}
use of com.qualcomm.robotcore.hardware.I2cDeviceSynch in project robotcode by OutoftheBoxFTC.
the class UserI2cSensorType method createInstance.
@NonNull
public HardwareDevice createInstance(I2cController controller, int port) throws InvocationTargetException {
try {
Constructor ctor;
ctor = findMatch(ctorI2cDeviceSynch);
if (null == ctor) {
ctor = findMatch(ctorI2cDeviceSynchSimple);
}
if (null != ctor) {
I2cDevice i2cDevice = new I2cDeviceImpl(controller, port);
I2cDeviceSynch i2cDeviceSynch = new I2cDeviceSynchImpl(i2cDevice, true);
return (HardwareDevice) ctor.newInstance(i2cDeviceSynch);
}
ctor = findMatch(ctorI2cDevice);
if (null != ctor) {
I2cDevice i2cDevice = new I2cDeviceImpl(controller, port);
return (HardwareDevice) ctor.newInstance(i2cDevice);
}
ctor = findMatch(ctorI2cControllerPort);
if (null != ctor) {
return (HardwareDevice) ctor.newInstance(controller, port);
}
} catch (IllegalAccessException | InstantiationException e) {
throw new RuntimeException("internal error: exception");
}
throw new RuntimeException("internal error: unable to locate constructor for user sensor type");
}
Aggregations