Search in sources :

Example 1 with UserConfigurationType

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

the class EditLynxModuleActivity method editI2cBus.

/**
 * @see com.qualcomm.hardware.HardwareFactory#buildLynxI2cDevices
 */
private void editI2cBus(DisplayNameAndRequestCode key, int busZ) {
    EditParameters parameters = initParameters(0, LynxI2cDeviceConfiguration.class, lynxModuleConfiguration.getI2cDevices(busZ));
    // 
    List<ConfigurationType> list = new LinkedList<ConfigurationType>();
    list.add(BuiltInConfigurationType.I2C_DEVICE_SYNCH);
    list.add(BuiltInConfigurationType.IR_SEEKER_V3);
    list.add(BuiltInConfigurationType.ADAFRUIT_COLOR_SENSOR);
    list.add(BuiltInConfigurationType.LYNX_COLOR_SENSOR);
    list.add(BuiltInConfigurationType.COLOR_SENSOR);
    list.add(BuiltInConfigurationType.GYRO);
    list.add(BuiltInConfigurationType.NOTHING);
    // 
    UserConfigurationType embeddedIMUConfigurationType = UserI2cSensorType.getLynxEmbeddedIMUType();
    for (UserConfigurationType userConfigurationType : UserConfigurationTypeManager.getInstance().allUserTypes(UserConfigurationType.Flavor.I2C)) {
        // We don't allow the embedded IMU on anything but its correct bus
        if (busZ != LynxConstants.EMBEDDED_IMU_BUS) {
            if (userConfigurationType == embeddedIMUConfigurationType) {
                continue;
            }
        }
        list.add(userConfigurationType);
    }
    // 
    parameters.setConfigurationTypes(list.toArray(new ConfigurationType[list.size()]));
    // 
    parameters.setGrowable(true);
    handleLaunchEdit(key.requestCode, EditI2cDevicesActivityLynx.class, parameters);
}
Also used : ConfigurationType(com.qualcomm.robotcore.hardware.configuration.ConfigurationType) UserConfigurationType(com.qualcomm.robotcore.hardware.configuration.UserConfigurationType) BuiltInConfigurationType(com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType) UserConfigurationType(com.qualcomm.robotcore.hardware.configuration.UserConfigurationType) LinkedList(java.util.LinkedList)

Example 2 with UserConfigurationType

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

UserConfigurationType (com.qualcomm.robotcore.hardware.configuration.UserConfigurationType)2 NonNull (android.support.annotation.NonNull)1 BuiltInConfigurationType (com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType)1 ConfigurationType (com.qualcomm.robotcore.hardware.configuration.ConfigurationType)1 UserI2cSensorType (com.qualcomm.robotcore.hardware.configuration.UserI2cSensorType)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 LinkedList (java.util.LinkedList)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 StreamSource (javax.xml.transform.stream.StreamSource)1 Dom2XmlPullBuilder (org.firstinspires.ftc.robotcore.internal.system.Dom2XmlPullBuilder)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1