Search in sources :

Example 1 with HardwareDevice

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");
}
Also used : I2cDeviceSynchSimple(com.qualcomm.robotcore.hardware.I2cDeviceSynchSimple) Constructor(java.lang.reflect.Constructor) I2cDeviceSynch(com.qualcomm.robotcore.hardware.I2cDeviceSynch) HardwareDevice(com.qualcomm.robotcore.hardware.HardwareDevice) NonNull(android.support.annotation.NonNull)

Example 2 with 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, 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));
            }
        }
    }
}
Also used : HardwareMap(com.qualcomm.robotcore.hardware.HardwareMap) HardwareDevice(com.qualcomm.robotcore.hardware.HardwareDevice) UserI2cSensorType(com.qualcomm.robotcore.hardware.configuration.UserI2cSensorType)

Example 3 with 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);
    }
}
Also used : HardwareDevice(com.qualcomm.robotcore.hardware.HardwareDevice) UserI2cSensorType(com.qualcomm.robotcore.hardware.configuration.UserI2cSensorType)

Example 4 with 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 "";
    }
}
Also used : RobotConfigNameable(com.qualcomm.robotcore.hardware.RobotConfigNameable) HardwareDevice(com.qualcomm.robotcore.hardware.HardwareDevice) NonNull(android.support.annotation.NonNull)

Example 5 with HardwareDevice

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");
}
Also used : I2cDeviceSynchImpl(com.qualcomm.robotcore.hardware.I2cDeviceSynchImpl) Constructor(java.lang.reflect.Constructor) I2cDevice(com.qualcomm.robotcore.hardware.I2cDevice) I2cDeviceSynch(com.qualcomm.robotcore.hardware.I2cDeviceSynch) HardwareDevice(com.qualcomm.robotcore.hardware.HardwareDevice) I2cDeviceImpl(com.qualcomm.robotcore.hardware.I2cDeviceImpl) NonNull(android.support.annotation.NonNull)

Aggregations

HardwareDevice (com.qualcomm.robotcore.hardware.HardwareDevice)5 NonNull (android.support.annotation.NonNull)3 I2cDeviceSynch (com.qualcomm.robotcore.hardware.I2cDeviceSynch)2 UserI2cSensorType (com.qualcomm.robotcore.hardware.configuration.UserI2cSensorType)2 Constructor (java.lang.reflect.Constructor)2 HardwareMap (com.qualcomm.robotcore.hardware.HardwareMap)1 I2cDevice (com.qualcomm.robotcore.hardware.I2cDevice)1 I2cDeviceImpl (com.qualcomm.robotcore.hardware.I2cDeviceImpl)1 I2cDeviceSynchImpl (com.qualcomm.robotcore.hardware.I2cDeviceSynchImpl)1 I2cDeviceSynchSimple (com.qualcomm.robotcore.hardware.I2cDeviceSynchSimple)1 RobotConfigNameable (com.qualcomm.robotcore.hardware.RobotConfigNameable)1