Search in sources :

Example 1 with ConfigurationType

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

the class EditActivity method localizeConfigTypeSpinnerTypes.

protected void localizeConfigTypeSpinnerTypes(ConfigurationType.DisplayNameFlavor flavor, Spinner spinner, List<ConfigurationType> types, @Nullable Comparator<ConfigurationType> comparator) // Localize the strings in the spinner
{
    ConfigurationTypeAndDisplayName[] pairs = new ConfigurationTypeAndDisplayName[types.size()];
    for (int i = 0; i < types.size(); i++) {
        ConfigurationType type = types.get(i);
        pairs[i] = new ConfigurationTypeAndDisplayName(flavor, type, comparator);
    }
    // Sort the spinner alphabetically
    Arrays.sort(pairs);
    ArrayAdapter<ConfigurationTypeAndDisplayName> newAdapter = new ArrayAdapter<ConfigurationTypeAndDisplayName>(this, android.R.layout.simple_spinner_dropdown_item, pairs);
    spinner.setAdapter(newAdapter);
}
Also used : ConfigurationType(com.qualcomm.robotcore.hardware.configuration.ConfigurationType) BuiltInConfigurationType(com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType) ArrayAdapter(android.widget.ArrayAdapter)

Example 2 with ConfigurationType

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

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

the class RobotConfigMap method bindUnboundControllers.

/**
 * For each controller in this map that currently lacks a real serial number, try to choose
 * an unused selection from the scanned devices to associate with same.
 */
public void bindUnboundControllers(ScannedDevices scannedDevices) {
    // First, find out whom we have to choose from that's not already used
    ScannedDevices extraDevices = new ScannedDevices(scannedDevices);
    for (ControllerConfiguration controllerConfiguration : this.controllerConfigurations()) {
        extraDevices.remove(controllerConfiguration.getSerialNumber());
    }
    // Invert the map, so we can easily lookup (ConfigurationType -> extra controllers)
    Map<ConfigurationType, List<SerialNumber>> extraByType = new HashMap<ConfigurationType, List<SerialNumber>>();
    for (Map.Entry<SerialNumber, DeviceManager.DeviceType> pair : extraDevices.entrySet()) {
        ConfigurationType configurationType = BuiltInConfigurationType.fromUSBDeviceType(pair.getValue());
        if (configurationType != BuiltInConfigurationType.UNKNOWN) {
            List<SerialNumber> list = extraByType.get(configurationType);
            if (list == null) {
                list = new LinkedList<SerialNumber>();
                extraByType.put(configurationType, list);
            }
            list.add(pair.getKey());
        }
    }
    // Figure out who's missing, and assign. Be careful about updating while iterating.
    for (ControllerConfiguration controllerConfiguration : this.controllerConfigurations()) {
        if (controllerConfiguration.getSerialNumber().isFake()) {
            List<SerialNumber> list = extraByType.get(controllerConfiguration.getConfigurationType());
            if (list != null && !list.isEmpty()) {
                // Use the first available controller of the right type, and bind to it
                SerialNumber newSerialNumber = list.remove(0);
                controllerConfiguration.setSerialNumber(newSerialNumber);
            }
        }
    }
    // Make sure we're accurate on the way out
    Collection<ControllerConfiguration> controllers = new ArrayList<ControllerConfiguration>(this.controllerConfigurations());
    map.clear();
    for (ControllerConfiguration controllerConfiguration : controllers) {
        put(controllerConfiguration.getSerialNumber(), controllerConfiguration);
    }
}
Also used : ConfigurationType(com.qualcomm.robotcore.hardware.configuration.ConfigurationType) BuiltInConfigurationType(com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SerialNumber(com.qualcomm.robotcore.util.SerialNumber) ControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with ConfigurationType

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

the class RobotConfigMap method getEligibleSwapTargets.

/**
 * Returns a list of the candidate configurations with which the target may be swapped.
 * Candidates must be of the same configuration type as the target but must not be the
 * target itself. We pull candidates both from what's in this {@link RobotConfigMap} and
 * what's currently attached to the USB bus: those are possibly intersecting sets, but each
 * may have members which are not in the other.
 */
public List<ControllerConfiguration> getEligibleSwapTargets(ControllerConfiguration target, ScannedDevices scannedDevices, Context context) {
    List<ControllerConfiguration> result = new LinkedList<ControllerConfiguration>();
    // Only our USB-attached devices are swappable
    ConfigurationType type = target.getConfigurationType();
    if (!(type == BuiltInConfigurationType.MOTOR_CONTROLLER || type == BuiltInConfigurationType.SERVO_CONTROLLER || type == BuiltInConfigurationType.DEVICE_INTERFACE_MODULE || type == BuiltInConfigurationType.LEGACY_MODULE_CONTROLLER)) {
        return result;
    }
    if (target.getSerialNumber().isFake()) {
        return result;
    }
    // First snarf candidates that are already in this robot configuration
    for (ControllerConfiguration other : this.controllerConfigurations()) {
        SerialNumber serialNumber = other.getSerialNumber();
        if (serialNumber.isFake()) {
            continue;
        }
        if (serialNumber.equals(target.getSerialNumber())) {
            continue;
        }
        if (containsSerialNumber(result, serialNumber)) {
            // shouldn't need this test, but it's harmless
            continue;
        }
        if (other.getConfigurationType() == target.getConfigurationType()) {
            result.add(other);
        }
    }
    // Then add others we know about from scanning but haven't added yet
    for (Map.Entry<SerialNumber, DeviceManager.DeviceType> entry : scannedDevices.entrySet()) {
        SerialNumber serialNumber = entry.getKey();
        if (serialNumber.isFake()) {
            continue;
        }
        if (serialNumber.equals(target.getSerialNumber())) {
            continue;
        }
        if (containsSerialNumber(result, serialNumber)) {
            continue;
        }
        if (entry.getValue() == target.toUSBDeviceType()) {
            String name = generateName(context, target.getConfigurationType(), result);
            ControllerConfiguration controllerConfiguration = ControllerConfiguration.forType(name, entry.getKey(), target.getConfigurationType());
            controllerConfiguration.setKnownToBeAttached(scannedDevices.containsKey(controllerConfiguration.getSerialNumber()));
            result.add(controllerConfiguration);
        }
    }
    return result;
}
Also used : ConfigurationType(com.qualcomm.robotcore.hardware.configuration.ConfigurationType) BuiltInConfigurationType(com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType) SerialNumber(com.qualcomm.robotcore.util.SerialNumber) ControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration) HashMap(java.util.HashMap) Map(java.util.Map) LinkedList(java.util.LinkedList)

Example 5 with ConfigurationType

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

the class HardwareFactory method createHardwareMap.

// ------------------------------------------------------------------------------------------------
// Hardware management
// ------------------------------------------------------------------------------------------------
/**
 * Create a hardware map
 *
 * @return HardwareMap
 */
public HardwareMap createHardwareMap(EventLoopManager manager) throws RobotCoreException, InterruptedException {
    // We synchronize with scanning so that there's only one thread trying to open *new* FTDI devices at a time
    synchronized (HardwareDeviceManager.scanDevicesLock) {
        RobotLog.vv(TAG, "createHardwareMap()");
        // Clear notion of embedded lynx module that we currently have. We'll discovery a new one,
        // if he's there, when we go through the below.
        WifiDirectInviteDialogMonitor.clearUILynxModule();
        HardwareMap map = new HardwareMap(context);
        if (xmlPullParser != null) {
            DeviceManager deviceMgr = new HardwareDeviceManager(context, manager);
            ReadXMLFileHandler readXmlFileHandler = new ReadXMLFileHandler();
            List<ControllerConfiguration> ctrlConfList = readXmlFileHandler.parse(xmlPullParser);
            for (ControllerConfiguration ctrlConf : ctrlConfList) {
                ConfigurationType type = ctrlConf.getConfigurationType();
                if (type == BuiltInConfigurationType.MOTOR_CONTROLLER) {
                    mapUsbMotorController(map, deviceMgr, (MotorControllerConfiguration) ctrlConf);
                } else if (type == BuiltInConfigurationType.SERVO_CONTROLLER) {
                    mapUsbServoController(map, deviceMgr, (ServoControllerConfiguration) ctrlConf);
                } else if (type == BuiltInConfigurationType.LEGACY_MODULE_CONTROLLER) {
                    mapUsbLegacyModule(map, deviceMgr, (LegacyModuleControllerConfiguration) ctrlConf);
                } else if (type == BuiltInConfigurationType.DEVICE_INTERFACE_MODULE) {
                    mapCoreInterfaceDeviceModule(map, deviceMgr, (DeviceInterfaceModuleConfiguration) ctrlConf);
                } else if (type == BuiltInConfigurationType.LYNX_USB_DEVICE) {
                    mapLynxUsbDevice(map, deviceMgr, (LynxUsbDeviceConfiguration) ctrlConf);
                } else {
                    RobotLog.ee(TAG, "Unexpected controller type while parsing XML: " + type.toString());
                }
            }
        } else {
            // no XML to parse, just return empty map
            RobotLog.vv(TAG, "no xml to parse: using empty map");
        }
        return map;
    }
}
Also used : ConfigurationType(com.qualcomm.robotcore.hardware.configuration.ConfigurationType) BuiltInConfigurationType(com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType) UserConfigurationType(com.qualcomm.robotcore.hardware.configuration.UserConfigurationType) HardwareMap(com.qualcomm.robotcore.hardware.HardwareMap) ReadXMLFileHandler(com.qualcomm.robotcore.hardware.configuration.ReadXMLFileHandler) DeviceInterfaceModuleConfiguration(com.qualcomm.robotcore.hardware.configuration.DeviceInterfaceModuleConfiguration) ServoControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration) DeviceManager(com.qualcomm.robotcore.hardware.DeviceManager) 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) MatrixControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration)

Aggregations

BuiltInConfigurationType (com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType)11 ConfigurationType (com.qualcomm.robotcore.hardware.configuration.ConfigurationType)11 ControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration)5 DeviceConfiguration (com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration)4 UserConfigurationType (com.qualcomm.robotcore.hardware.configuration.UserConfigurationType)4 LynxUsbDeviceConfiguration (com.qualcomm.robotcore.hardware.configuration.LynxUsbDeviceConfiguration)3 MotorControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration)3 ServoControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration)3 SerialNumber (com.qualcomm.robotcore.util.SerialNumber)3 LinkedList (java.util.LinkedList)3 Spinner (android.widget.Spinner)2 LegacyModuleControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.LegacyModuleControllerConfiguration)2 LynxI2cDeviceConfiguration (com.qualcomm.robotcore.hardware.configuration.LynxI2cDeviceConfiguration)2 MatrixControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration)2 MotorConfiguration (com.qualcomm.robotcore.hardware.configuration.MotorConfiguration)2 ArrayList (java.util.ArrayList)2 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 View (android.view.View)1