use of com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration in project robotcode by OutoftheBoxFTC.
the class FtcConfigurationActivity method buildRobotConfigMapFromScanned.
private RobotConfigMap buildRobotConfigMapFromScanned(RobotConfigMap existingControllers, ScannedDevices scannedDevices) {
// Initialize deviceControllers using the set of serial numbers in the ScannedDevices. If the serial
// number appears in our existing map, then just carry that configuration over; otherwise, make us
// a new configuration appropriate for the type of the controller.
RobotConfigMap newRobotConfigMap = new RobotConfigMap();
configurationUtility.resetNameUniquifiers();
for (Map.Entry<SerialNumber, DeviceManager.DeviceType> entry : scannedDevices.entrySet()) {
SerialNumber serialNumber = entry.getKey();
ControllerConfiguration controllerConfiguration = null;
if (carryOver(serialNumber, existingControllers)) {
RobotLog.vv(TAG, "carrying over %s", serialNumber);
controllerConfiguration = existingControllers.get(serialNumber);
} else {
switch(entry.getValue()) {
case MODERN_ROBOTICS_USB_DC_MOTOR_CONTROLLER:
controllerConfiguration = configurationUtility.buildNewModernMotorController(serialNumber);
break;
case MODERN_ROBOTICS_USB_SERVO_CONTROLLER:
controllerConfiguration = configurationUtility.buildNewModernServoController(serialNumber);
break;
case MODERN_ROBOTICS_USB_LEGACY_MODULE:
controllerConfiguration = configurationUtility.buildNewLegacyModule(serialNumber);
break;
case MODERN_ROBOTICS_USB_DEVICE_INTERFACE_MODULE:
controllerConfiguration = configurationUtility.buildNewDeviceInterfaceModule(serialNumber);
break;
case LYNX_USB_DEVICE:
try {
RobotLog.vv(TAG, "buildRobotConfigMapFromScanned(%s)...", serialNumber);
HardwareDeviceManager deviceManager = new HardwareDeviceManager(utility.getActivity(), null);
ThreadPool.SingletonResult<LynxModuleMetaList> discoveryFuture = this.usbScanManager.startLynxModuleEnumerationIfNecessary(serialNumber);
controllerConfiguration = configurationUtility.buildNewLynxUsbDevice(serialNumber, deviceManager, discoveryFuture);
RobotLog.vv(TAG, "...buildRobotConfigMapFromScanned(%s)", serialNumber);
} catch (InterruptedException e) {
RobotLog.ee(TAG, "interrupt in buildRobotConfigMapFromScanned(%s)", serialNumber);
Thread.currentThread().interrupt();
} catch (RobotCoreException e) {
RobotLog.ee(TAG, e, "exception in buildRobotConfigMapFromScanned(%s)", serialNumber);
controllerConfiguration = null;
}
break;
}
}
if (controllerConfiguration != null) {
controllerConfiguration.setKnownToBeAttached(true);
newRobotConfigMap.put(serialNumber, controllerConfiguration);
}
}
return newRobotConfigMap;
}
use of com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration in project robotcode by OutoftheBoxFTC.
the class EditLegacyModuleControllerActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCodeValue, int resultCode, Intent data) {
logActivityResult(requestCodeValue, resultCode, data);
if (resultCode == RESULT_OK) {
EditParameters parameters = EditParameters.fromIntent(this, data);
RequestCode requestCode = RequestCode.fromValue(requestCodeValue);
if (requestCode == EditSwapUsbDevices.requestCode) {
completeSwapConfiguration(requestCodeValue, resultCode, data);
} else {
ControllerConfiguration newC = (ControllerConfiguration) parameters.getConfiguration();
setModule(newC);
populatePort(findViewByPort(newC.getPort()), devices.get(newC.getPort()));
}
currentCfgFile.markDirty();
robotConfigFileManager.setActiveConfigAndUpdateUI(currentCfgFile);
}
}
use of com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration in project robotcode by OutoftheBoxFTC.
the class EditLegacyModuleControllerActivity method createController.
/**
* If the drop-down spinner-selected item is a Controller (Motor- or Servo-), we need to create
* an empty Controller with the proper number of motors/servos.
*
* @param port - the port where this controller got added
* @param newType - the type of controller we're creating
*/
private void createController(int port, ConfigurationType newType) {
DeviceConfiguration currentModule = devices.get(port);
String name = currentModule.getName();
SerialNumber serialNumber = new SerialNumber();
ConfigurationType currentType = currentModule.getConfigurationType();
if (!(currentType == newType)) {
// only update the controller if it's a new choice.
ControllerConfiguration newModule;
if (newType == BuiltInConfigurationType.MOTOR_CONTROLLER) {
ArrayList<MotorConfiguration> motors = new ArrayList<MotorConfiguration>();
for (int motorPortNumber = ModernRoboticsConstants.INITIAL_MOTOR_PORT; motorPortNumber <= ModernRoboticsConstants.NUMBER_OF_MOTORS; motorPortNumber++) {
motors.add(new MotorConfiguration(motorPortNumber));
}
newModule = new MotorControllerConfiguration(name, motors, serialNumber);
newModule.setPort(port);
} else if (newType == BuiltInConfigurationType.SERVO_CONTROLLER) {
ArrayList<ServoConfiguration> servos = new ArrayList<ServoConfiguration>();
for (int servoPortNumber = ModernRoboticsConstants.INITIAL_SERVO_PORT; servoPortNumber <= ModernRoboticsConstants.NUMBER_OF_SERVOS; servoPortNumber++) {
servos.add(new ServoConfiguration(servoPortNumber));
}
newModule = new ServoControllerConfiguration(name, servos, serialNumber);
newModule.setPort(port);
} else if (newType == BuiltInConfigurationType.MATRIX_CONTROLLER) {
ArrayList<MotorConfiguration> motors = new ArrayList<MotorConfiguration>();
for (int motorPortNumber = MatrixConstants.INITIAL_MOTOR_PORT; motorPortNumber <= MatrixConstants.NUMBER_OF_MOTORS; motorPortNumber++) {
motors.add(new MotorConfiguration(motorPortNumber));
}
ArrayList<ServoConfiguration> servos = new ArrayList<ServoConfiguration>();
for (int servoPortNumber = MatrixConstants.INITIAL_SERVO_PORT; servoPortNumber <= MatrixConstants.NUMBER_OF_SERVOS; servoPortNumber++) {
servos.add(new ServoConfiguration(servoPortNumber));
}
newModule = new MatrixControllerConfiguration(name, motors, servos, serialNumber);
newModule.setPort(port);
} else {
newModule = null;
}
if (newModule != null) {
newModule.setEnabled(true);
setModule(newModule);
}
}
}
use of com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration in project robotcode by OutoftheBoxFTC.
the class ConfigureFromTemplateActivity method instantiateTemplate.
RobotConfigMap instantiateTemplate(RobotConfigFile templateMeta, XmlPullParser xmlPullParser) throws RobotCoreException {
awaitScannedDevices();
//
ReadXMLFileHandler readXMLFileHandler = new ReadXMLFileHandler();
List<ControllerConfiguration> controllerList = readXMLFileHandler.parse(xmlPullParser);
RobotConfigMap robotConfigMap = new RobotConfigMap(controllerList);
robotConfigMap.bindUnboundControllers(scannedDevices);
//
return robotConfigMap;
}
use of com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration in project robotcode by OutoftheBoxFTC.
the class EditSwapUsbDevices method populateList.
// ------------------------------------------------------------------------------------------------
// Life cycle support
// ------------------------------------------------------------------------------------------------
protected void populateList() {
ListView controllerListView = (ListView) findViewById(R.id.controllersList);
DeviceInfoAdapter adapter = new DeviceInfoAdapter(this, android.R.layout.simple_list_item_2, getRobotConfigMap().getEligibleSwapTargets(targetConfiguration, scannedDevices, this));
controllerListView.setAdapter(adapter);
controllerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View v, int pos, long arg3) {
ControllerConfiguration controllerConfiguration = (ControllerConfiguration) adapterView.getItemAtPosition(pos);
finishOk(new EditParameters(EditSwapUsbDevices.this, controllerConfiguration));
}
});
}
Aggregations