Search in sources :

Example 6 with ConfigurationType

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

the class HardwareFactory method buildI2cDevices.

private void buildI2cDevices(List<DeviceConfiguration> list, HardwareMap map, DeviceManager deviceMgr, I2cController i2cController) {
    for (DeviceConfiguration deviceConfiguration : list) {
        ConfigurationType devType = deviceConfiguration.getConfigurationType();
        if (devType == BuiltInConfigurationType.I2C_DEVICE) {
            mapI2cDevice(map, deviceMgr, i2cController, deviceConfiguration);
            continue;
        }
        if (devType == BuiltInConfigurationType.I2C_DEVICE_SYNCH) {
            mapI2cDeviceSynch(map, deviceMgr, i2cController, deviceConfiguration);
            continue;
        }
        if (devType == BuiltInConfigurationType.IR_SEEKER_V3) {
            mapIrSeekerV3Device(map, deviceMgr, i2cController, deviceConfiguration);
            continue;
        }
        if (devType == BuiltInConfigurationType.ADAFRUIT_COLOR_SENSOR) {
            mapAdafruitColorSensor(map, deviceMgr, i2cController, deviceConfiguration);
            continue;
        }
        if (devType == BuiltInConfigurationType.COLOR_SENSOR) {
            mapModernRoboticsColorSensor(map, deviceMgr, i2cController, deviceConfiguration);
            continue;
        }
        if (devType == BuiltInConfigurationType.GYRO) {
            mapModernRoboticsGyro(map, deviceMgr, i2cController, deviceConfiguration);
            continue;
        }
        if (devType == BuiltInConfigurationType.NOTHING) {
            // nothing to do
            continue;
        }
        if (devType.isDeviceFlavor(UserConfigurationType.Flavor.I2C)) {
            if (devType instanceof UserI2cSensorType) {
                mapUserI2cDevice(map, deviceMgr, i2cController, deviceConfiguration);
                continue;
            }
        }
        RobotLog.w("Unexpected device type connected to I2c Controller while parsing XML: " + devType.toString());
    }
}
Also used : ConfigurationType(com.qualcomm.robotcore.hardware.configuration.ConfigurationType) BuiltInConfigurationType(com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType) UserConfigurationType(com.qualcomm.robotcore.hardware.configuration.UserConfigurationType) UserI2cSensorType(com.qualcomm.robotcore.hardware.configuration.UserI2cSensorType) LynxUsbDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxUsbDeviceConfiguration) LynxI2cDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxI2cDeviceConfiguration) DeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration)

Example 7 with ConfigurationType

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

the class EditMotorListActivity method localizeSpinner.

@Override
protected void localizeSpinner(View itemView) {
    Spinner spinner = (Spinner) itemView.findViewById(this.idItemSpinner);
    Comparator<ConfigurationType> comparator = new Comparator<ConfigurationType>() {

        @Override
        public int compare(ConfigurationType lhs, ConfigurationType rhs) {
            // Make sure 'nothing' is first, and 'unspecified' is second
            if (lhs == rhs) {
                return 0;
            }
            if (lhs == BuiltInConfigurationType.NOTHING) {
                return -1;
            }
            if (rhs == BuiltInConfigurationType.NOTHING) {
                return 1;
            }
            if (lhs == unspecifiedMotorType) {
                return -1;
            }
            if (rhs == unspecifiedMotorType) {
                return 1;
            }
            // they'll be distinguished using an outer level comparator
            return 0;
        }
    };
    localizeConfigTypeSpinnerTypes(ConfigurationType.DisplayNameFlavor.Normal, spinner, Arrays.asList(this.configurationTypes), comparator);
}
Also used : ConfigurationType(com.qualcomm.robotcore.hardware.configuration.ConfigurationType) MotorConfigurationType(com.qualcomm.robotcore.hardware.configuration.MotorConfigurationType) BuiltInConfigurationType(com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType) Spinner(android.widget.Spinner) Comparator(java.util.Comparator)

Example 8 with ConfigurationType

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

the class HardwareFactory method mapUsbLegacyModule.

private void mapUsbLegacyModule(HardwareMap map, DeviceManager deviceMgr, LegacyModuleControllerConfiguration ctrlConf) throws RobotCoreException, InterruptedException {
    if (!ctrlConf.isEnabled()) {
        return;
    }
    LegacyModule legacyModule = deviceMgr.createUsbLegacyModule(ctrlConf.getSerialNumber(), ctrlConf.getName());
    map.legacyModule.put(ctrlConf.getName(), legacyModule);
    for (DeviceConfiguration devConf : ctrlConf.getDevices()) {
        ConfigurationType devType = devConf.getConfigurationType();
        if (devType == BuiltInConfigurationType.GYRO) {
            mapNxtGyroSensor(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.COMPASS) {
            mapNxtCompassSensor(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.IR_SEEKER) {
            mapNxtIrSeekerSensor(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.LIGHT_SENSOR) {
            mapNxtLightSensor(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.ACCELEROMETER) {
            mapNxtAccelerationSensor(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.MOTOR_CONTROLLER) {
            mapNxtDcMotorController(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.SERVO_CONTROLLER) {
            mapNxtServoController(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.TOUCH_SENSOR) {
            mapNxtTouchSensor(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.TOUCH_SENSOR_MULTIPLEXER) {
            mapNxtTouchSensorMultiplexer(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.ULTRASONIC_SENSOR) {
            mapSonarSensor(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.COLOR_SENSOR) {
            mapNxtColorSensor(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.MATRIX_CONTROLLER) {
            mapMatrixController(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.NOTHING) {
        // nothing to do
        } else {
            RobotLog.w("Unexpected device type connected to Legacy Module while parsing XML: " + devType.toString());
        }
    }
}
Also used : ConfigurationType(com.qualcomm.robotcore.hardware.configuration.ConfigurationType) BuiltInConfigurationType(com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType) UserConfigurationType(com.qualcomm.robotcore.hardware.configuration.UserConfigurationType) LegacyModule(com.qualcomm.robotcore.hardware.LegacyModule) ModernRoboticsUsbLegacyModule(com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbLegacyModule) LynxUsbDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxUsbDeviceConfiguration) LynxI2cDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxI2cDeviceConfiguration) DeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration)

Example 9 with ConfigurationType

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

the class FtcConfigurationActivity method populateList.

/**
 * Populates the list with the relevant controllers from the deviceControllers variable.
 * That variable is either from scanned devices, or read in from an xml file.
 */
private void populateList() {
    ListView controllerListView = (ListView) findViewById(R.id.controllersList);
    // Before we launch, we want the scan to have completed
    try {
        scannedDevices = usbScanManager.awaitScannedDevices();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    // Make sure we'll report serial numbers correctly as attached or not
    tellControllersAboutAttachment();
    DeviceInfoAdapter adapter = new DeviceInfoAdapter(this, android.R.layout.simple_list_item_2, new LinkedList<ControllerConfiguration>(getRobotConfigMap().controllerConfigurations()));
    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);
            ConfigurationType itemType = controllerConfiguration.getConfigurationType();
            if (itemType == BuiltInConfigurationType.MOTOR_CONTROLLER) {
                EditParameters parameters = initParameters(ModernRoboticsConstants.INITIAL_MOTOR_PORT, MotorConfiguration.class, controllerConfiguration, ((MotorControllerConfiguration) controllerConfiguration).getMotors());
                parameters.setConfigurationTypes(MotorConfiguration.getAllMotorConfigurationTypes());
                handleLaunchEdit(EditMotorControllerActivity.requestCode, EditMotorControllerActivity.class, parameters);
            } else if (itemType == BuiltInConfigurationType.SERVO_CONTROLLER) {
                EditParameters parameters = initParameters(ModernRoboticsConstants.INITIAL_SERVO_PORT, ServoConfiguration.class, controllerConfiguration, ((ServoControllerConfiguration) controllerConfiguration).getServos());
                handleLaunchEdit(EditServoControllerActivity.requestCode, EditServoControllerActivity.class, parameters);
            } else if (itemType == BuiltInConfigurationType.LEGACY_MODULE_CONTROLLER) {
                EditParameters parameters = initParameters(0, DeviceConfiguration.class, controllerConfiguration, ((LegacyModuleControllerConfiguration) controllerConfiguration).getDevices());
                handleLaunchEdit(EditLegacyModuleControllerActivity.requestCode, EditLegacyModuleControllerActivity.class, parameters);
            } else if (itemType == BuiltInConfigurationType.DEVICE_INTERFACE_MODULE) {
                EditParameters parameters = initParameters(0, DeviceConfiguration.class, controllerConfiguration, ((DeviceInterfaceModuleConfiguration) controllerConfiguration).getDevices());
                handleLaunchEdit(EditDeviceInterfaceModuleActivity.requestCode, EditDeviceInterfaceModuleActivity.class, parameters);
            } else if (itemType == BuiltInConfigurationType.LYNX_USB_DEVICE) {
                EditParameters parameters = initParameters(0, LynxModuleConfiguration.class, controllerConfiguration, ((LynxUsbDeviceConfiguration) controllerConfiguration).getDevices());
                handleLaunchEdit(EditLynxUsbDeviceActivity.requestCode, EditLynxUsbDeviceActivity.class, parameters);
            }
        }
    });
}
Also used : ConfigurationType(com.qualcomm.robotcore.hardware.configuration.ConfigurationType) BuiltInConfigurationType(com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType) LynxUsbDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxUsbDeviceConfiguration) MotorControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) ListView(android.widget.ListView) 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) AdapterView(android.widget.AdapterView) MotorConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorConfiguration) LegacyModuleControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.LegacyModuleControllerConfiguration) LynxUsbDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxUsbDeviceConfiguration) DeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration) LynxModuleConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxModuleConfiguration)

Example 10 with ConfigurationType

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

the class EditI2cDevicesActivityAbstract method localizeSpinner.

@Override
protected void localizeSpinner(View itemView) {
    Spinner spinner = (Spinner) itemView.findViewById(this.idItemSpinner);
    Comparator<ConfigurationType> comparator = new Comparator<ConfigurationType>() {

        @Override
        public int compare(ConfigurationType lhs, ConfigurationType rhs) {
            // Make sure 'nothing' is first
            if (lhs == rhs) {
                return 0;
            }
            if (lhs == BuiltInConfigurationType.NOTHING) {
                return -1;
            }
            if (rhs == BuiltInConfigurationType.NOTHING) {
                return 1;
            }
            // they'll be distinguished using an outer level comparator
            return 0;
        }
    };
    localizeConfigTypeSpinnerTypes(ConfigurationType.DisplayNameFlavor.Normal, spinner, Arrays.asList(this.configurationTypes), comparator);
}
Also used : ConfigurationType(com.qualcomm.robotcore.hardware.configuration.ConfigurationType) BuiltInConfigurationType(com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType) Spinner(android.widget.Spinner) Comparator(java.util.Comparator)

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