use of com.qualcomm.hardware.HardwareDeviceManager 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;
}
Aggregations