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);
}
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;
}
Aggregations