use of com.qualcomm.robotcore.hardware.HardwareDevice in project robotcode by OutoftheBoxFTC.
the class UserI2cSensorType method createInstance.
// ----------------------------------------------------------------------------------------------
// Instance creation
// ----------------------------------------------------------------------------------------------
@NonNull
public HardwareDevice createInstance(RobotCoreLynxModule lynxModule, Func<I2cDeviceSynchSimple> simpleSynchFunc, Func<I2cDeviceSynch> synchFunc) throws InvocationTargetException {
try {
Constructor ctor;
ctor = findMatch(ctorI2cDeviceSynchSimple);
if (null != ctor) {
I2cDeviceSynchSimple i2cDeviceSynchSimple = simpleSynchFunc.value();
return (HardwareDevice) ctor.newInstance(i2cDeviceSynchSimple);
}
ctor = findMatch(ctorI2cDeviceSynch);
if (null != ctor) {
I2cDeviceSynch i2cDeviceSynch = synchFunc.value();
return (HardwareDevice) ctor.newInstance(i2cDeviceSynch);
}
} catch (IllegalAccessException | InstantiationException e) {
throw new RuntimeException("internal error: exception");
}
throw new RuntimeException("internal error: unable to locate constructor for user sensor type");
}
use of com.qualcomm.robotcore.hardware.HardwareDevice in project robotcode by OutoftheBoxFTC.
the class HardwareFactory method mapUserI2cDevice.
private void mapUserI2cDevice(HardwareMap map, DeviceManager deviceMgr, I2cController i2cController, DeviceConfiguration devConf) {
if (!devConf.isEnabled()) {
return;
}
UserI2cSensorType userType = (UserI2cSensorType) devConf.getConfigurationType();
HardwareDevice hardwareDevice = deviceMgr.createUserI2cDevice(i2cController, devConf.getI2cChannel(), userType, devConf.getName());
if (hardwareDevice != null) {
// Put the device in the overall map
map.put(devConf.getName(), hardwareDevice);
// which it belongs, but don't overwrite any user-named sensor that might be there.
for (HardwareMap.DeviceMapping mapping : map.allDeviceMappings) {
if (mapping.getDeviceTypeClass().isInstance(hardwareDevice)) {
maybeAddToMapping(mapping, devConf.getName(), mapping.cast(hardwareDevice));
}
}
}
}
use of com.qualcomm.robotcore.hardware.HardwareDevice in project robotcode by OutoftheBoxFTC.
the class HardwareFactory method mapUserI2cDevice.
private void mapUserI2cDevice(HardwareMap map, DeviceManager deviceMgr, LynxModule lynxModule, DeviceConfiguration devConf) {
if (!devConf.isEnabled()) {
return;
}
UserI2cSensorType userType = (UserI2cSensorType) devConf.getConfigurationType();
HardwareDevice hardwareDevice = deviceMgr.createUserI2cDevice(lynxModule, devConf.getI2cChannel(), userType, devConf.getName());
if (hardwareDevice != null) {
// User-defined types don't live in a type-specific mapping, only in the overall one
map.put(devConf.getName(), hardwareDevice);
}
}
use of com.qualcomm.robotcore.hardware.HardwareDevice in project robotcode by OutoftheBoxFTC.
the class LynxModule method getHealthStatusWarningMessage.
/**
* Returns a status warning message indicative of the health of the indicated device, or an
* empty string if no such message is currently applicable.
*/
@NonNull
public static String getHealthStatusWarningMessage(HardwareDeviceHealth hardwareDeviceHealth) {
switch(hardwareDeviceHealth.getHealthStatus()) {
case UNHEALTHY:
String name = null;
if (hardwareDeviceHealth instanceof RobotConfigNameable) {
name = ((RobotConfigNameable) hardwareDeviceHealth).getUserConfiguredName();
if (name != null) {
name = AppUtil.getDefContext().getString(R.string.quotes, name);
}
}
if (name == null && hardwareDeviceHealth instanceof HardwareDevice) {
HardwareDevice hardwareDevice = (HardwareDevice) hardwareDeviceHealth;
String typeDescription = hardwareDevice.getDeviceName();
String connectionInfo = hardwareDevice.getConnectionInfo();
name = AppUtil.getDefContext().getString(R.string.hwDeviceDescriptionAndConnection, typeDescription, connectionInfo);
}
if (name == null) {
name = AppUtil.getDefContext().getString(R.string.hwPoorlyNamedDevice);
}
return AppUtil.getDefContext().getString(R.string.unhealthyDevice, name);
default:
return "";
}
}
use of com.qualcomm.robotcore.hardware.HardwareDevice 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