Search in sources :

Example 1 with HardwareDeviceManager

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;
}
Also used : SerialNumber(com.qualcomm.robotcore.util.SerialNumber) ThreadPool(com.qualcomm.robotcore.util.ThreadPool) RobotCoreException(com.qualcomm.robotcore.exception.RobotCoreException) LegacyModuleControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.LegacyModuleControllerConfiguration) ControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration) ServoControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration) MotorControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration) Map(java.util.Map) HardwareDeviceManager(com.qualcomm.hardware.HardwareDeviceManager) LynxModuleMetaList(com.qualcomm.robotcore.hardware.LynxModuleMetaList)

Aggregations

HardwareDeviceManager (com.qualcomm.hardware.HardwareDeviceManager)1 RobotCoreException (com.qualcomm.robotcore.exception.RobotCoreException)1 LynxModuleMetaList (com.qualcomm.robotcore.hardware.LynxModuleMetaList)1 ControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration)1 LegacyModuleControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.LegacyModuleControllerConfiguration)1 MotorControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration)1 ServoControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration)1 SerialNumber (com.qualcomm.robotcore.util.SerialNumber)1 ThreadPool (com.qualcomm.robotcore.util.ThreadPool)1 Map (java.util.Map)1