Search in sources :

Example 1 with UserI2cSensorType

use of com.qualcomm.robotcore.hardware.configuration.UserI2cSensorType in project robotcode by OutoftheBoxFTC.

the class HardwareFactory method buildI2cDevices.

private void buildI2cDevices(List<DeviceConfiguration> list, HardwareMap map, DeviceManager deviceMgr, I2cController i2cController) {
    for (DeviceConfiguration deviceConfiguration : list) {
        ConfigurationType devType = deviceConfiguration.getConfigurationType();
        if (devType == BuiltInConfigurationType.I2C_DEVICE) {
            mapI2cDevice(map, deviceMgr, i2cController, deviceConfiguration);
            continue;
        }
        if (devType == BuiltInConfigurationType.I2C_DEVICE_SYNCH) {
            mapI2cDeviceSynch(map, deviceMgr, i2cController, deviceConfiguration);
            continue;
        }
        if (devType == BuiltInConfigurationType.IR_SEEKER_V3) {
            mapIrSeekerV3Device(map, deviceMgr, i2cController, deviceConfiguration);
            continue;
        }
        if (devType == BuiltInConfigurationType.ADAFRUIT_COLOR_SENSOR) {
            mapAdafruitColorSensor(map, deviceMgr, i2cController, deviceConfiguration);
            continue;
        }
        if (devType == BuiltInConfigurationType.COLOR_SENSOR) {
            mapModernRoboticsColorSensor(map, deviceMgr, i2cController, deviceConfiguration);
            continue;
        }
        if (devType == BuiltInConfigurationType.GYRO) {
            mapModernRoboticsGyro(map, deviceMgr, i2cController, deviceConfiguration);
            continue;
        }
        if (devType == BuiltInConfigurationType.NOTHING) {
            // nothing to do
            continue;
        }
        if (devType.isDeviceFlavor(UserConfigurationType.Flavor.I2C)) {
            if (devType instanceof UserI2cSensorType) {
                mapUserI2cDevice(map, deviceMgr, i2cController, deviceConfiguration);
                continue;
            }
        }
        RobotLog.w("Unexpected device type connected to I2c Controller while parsing XML: " + devType.toString());
    }
}
Also used : ConfigurationType(com.qualcomm.robotcore.hardware.configuration.ConfigurationType) BuiltInConfigurationType(com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType) UserConfigurationType(com.qualcomm.robotcore.hardware.configuration.UserConfigurationType) UserI2cSensorType(com.qualcomm.robotcore.hardware.configuration.UserI2cSensorType) LynxUsbDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxUsbDeviceConfiguration) LynxI2cDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxI2cDeviceConfiguration) DeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration)

Example 2 with UserI2cSensorType

use of com.qualcomm.robotcore.hardware.configuration.UserI2cSensorType 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 UserI2cSensorType

use of com.qualcomm.robotcore.hardware.configuration.UserI2cSensorType 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 UserI2cSensorType

use of com.qualcomm.robotcore.hardware.configuration.UserI2cSensorType in project robotcode by OutoftheBoxFTC.

the class RobotConfigFileManager method getRobotConfigDescriptionTransform.

/**
 * Returns a {@link Source} to the XSLT transformation that will transform robot config
 * templates/configurations into human-readable descriptions.
 */
@NonNull
protected Source getRobotConfigDescriptionTransform() throws XmlPullParserException, IOException, TransformerConfigurationException, TransformerException {
    // Load RobotConfigTaxonomy as a DOM
    Reader xmlConfigTaxonomyReader = new InputStreamReader(context.getAssets().open(ROBOT_CONFIG_TAXONOMY_XML));
    XmlPullParser xmlConfigTaxonomyParser = ReadXMLFileHandler.xmlPullParserFromReader(xmlConfigTaxonomyReader);
    Dom2XmlPullBuilder builder = new Dom2XmlPullBuilder();
    Element rootElement = builder.parseSubTree(xmlConfigTaxonomyParser);
    Document document = rootElement.getOwnerDocument();
    // Augment the DOM to add <Sensor>s corresponding to @I2cSensor elements that might be present
    for (UserConfigurationType userConfigurationType : UserConfigurationTypeManager.getInstance().allUserTypes(UserConfigurationType.Flavor.I2C)) {
        // 
        UserI2cSensorType userI2cSensorType = (UserI2cSensorType) userConfigurationType;
        Element sensor = document.createElement("Sensor");
        addChild(document, sensor, "XmlTag", userI2cSensorType.getXmlTag());
        addChild(document, sensor, "Description", userI2cSensorType.getDescription());
        addChild(document, sensor, "Bus", "i2cbus");
        addChild(document, sensor, "BusDefault", context.getString(R.string.userSensorTypeBusDefault));
        // 
        rootElement.appendChild(sensor);
    }
    // Turn that augmented taxonomy into a source
    Source sourceConfigTaxonomy = new DOMSource(rootElement);
    // Load the transform that will generate the transform we need
    Source xsltGenerate = new StreamSource(context.getAssets().open(ROBOT_CONFIG_DESCRIPTION_GENERATE_XSLT));
    // Transform the taxonomy to generate the description transformer
    StringWriter xsltDescriptionWriter = new StringWriter();
    Result transformerResult = new StreamResult(xsltDescriptionWriter);
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer(xsltGenerate);
    transformer.transform(sourceConfigTaxonomy, transformerResult);
    String xsltDescriptionTransform = xsltDescriptionWriter.toString().trim();
    // Return that as a Source
    StringReader xsltDescriptionTransformReader = new StringReader(xsltDescriptionTransform);
    Source result = new StreamSource(xsltDescriptionTransformReader);
    return result;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) InputStreamReader(java.io.InputStreamReader) StreamResult(javax.xml.transform.stream.StreamResult) Element(org.w3c.dom.Element) StreamSource(javax.xml.transform.stream.StreamSource) XmlPullParser(org.xmlpull.v1.XmlPullParser) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) Document(org.w3c.dom.Document) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) StringWriter(java.io.StringWriter) Dom2XmlPullBuilder(org.firstinspires.ftc.robotcore.internal.system.Dom2XmlPullBuilder) StringReader(java.io.StringReader) UserConfigurationType(com.qualcomm.robotcore.hardware.configuration.UserConfigurationType) UserI2cSensorType(com.qualcomm.robotcore.hardware.configuration.UserI2cSensorType) NonNull(android.support.annotation.NonNull)

Aggregations

UserI2cSensorType (com.qualcomm.robotcore.hardware.configuration.UserI2cSensorType)4 HardwareDevice (com.qualcomm.robotcore.hardware.HardwareDevice)2 UserConfigurationType (com.qualcomm.robotcore.hardware.configuration.UserConfigurationType)2 NonNull (android.support.annotation.NonNull)1 HardwareMap (com.qualcomm.robotcore.hardware.HardwareMap)1 BuiltInConfigurationType (com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType)1 ConfigurationType (com.qualcomm.robotcore.hardware.configuration.ConfigurationType)1 DeviceConfiguration (com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration)1 LynxI2cDeviceConfiguration (com.qualcomm.robotcore.hardware.configuration.LynxI2cDeviceConfiguration)1 LynxUsbDeviceConfiguration (com.qualcomm.robotcore.hardware.configuration.LynxUsbDeviceConfiguration)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Result (javax.xml.transform.Result)1 Source (javax.xml.transform.Source)1 Transformer (javax.xml.transform.Transformer)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1