Search in sources :

Example 11 with ConfigurationType

use of com.qualcomm.robotcore.hardware.configuration.ConfigurationType 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);
        }
    }
}
Also used : ConfigurationType(com.qualcomm.robotcore.hardware.configuration.ConfigurationType) BuiltInConfigurationType(com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType) MotorControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration) ArrayList(java.util.ArrayList) MatrixControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration) SerialNumber(com.qualcomm.robotcore.util.SerialNumber) ServoConfiguration(com.qualcomm.robotcore.hardware.configuration.ServoConfiguration) ServoControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration) MotorControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration) ControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration) ServoControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration) MatrixControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration) MotorConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorConfiguration) DeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration)

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