Search in sources :

Example 6 with DeviceConfiguration

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

the class EditPortListCheckboxActivity method addCheckBoxListenerOnIndex.

protected void addCheckBoxListenerOnIndex(final int index) {
    View itemView = findViewByIndex(index);
    final EditText name;
    name = (EditText) itemView.findViewById(this.idItemEditTextResult);
    final DeviceConfiguration device;
    device = this.itemList.get(index);
    CheckBox checkbox = (CheckBox) itemView.findViewById(this.idItemCheckbox);
    checkbox.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (((CheckBox) view).isChecked()) {
                name.setEnabled(true);
                name.setText("");
                device.setEnabled(true);
                device.setName("");
            } else {
                name.setEnabled(false);
                name.setText(disabledDeviceName());
                device.setEnabled(false);
                device.setName(disabledDeviceName());
            }
        }
    });
}
Also used : EditText(android.widget.EditText) CheckBox(android.widget.CheckBox) View(android.view.View) DeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration)

Example 7 with DeviceConfiguration

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

the class EditPortListSpinnerActivity method changeDevice.

@Override
protected void changeDevice(View itemView, ConfigurationType type) {
    TextView textViewPortNumber = (TextView) itemView.findViewById(this.idItemPortNumber);
    int portNumber = Integer.parseInt(textViewPortNumber.getText().toString());
    EditText nameText = (EditText) itemView.findViewById(this.idItemEditTextResult);
    nameText.setEnabled(true);
    DeviceConfiguration config = findConfigByPort(portNumber);
    clearNameIfNecessary(nameText, config);
    config.setConfigurationType(type);
    config.setEnabled(true);
}
Also used : EditText(android.widget.EditText) TextView(android.widget.TextView) DeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration)

Example 8 with DeviceConfiguration

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

the class HardwareFactory method mapCoreInterfaceDeviceModule.

private void mapCoreInterfaceDeviceModule(HardwareMap map, DeviceManager deviceMgr, DeviceInterfaceModuleConfiguration ctrlConf) throws RobotCoreException, InterruptedException {
    if (!ctrlConf.isEnabled()) {
        return;
    }
    DeviceInterfaceModule deviceInterfaceModule = deviceMgr.createDeviceInterfaceModule(ctrlConf.getSerialNumber(), ctrlConf.getName());
    map.deviceInterfaceModule.put(ctrlConf.getName(), deviceInterfaceModule);
    List<DeviceConfiguration> pwmDevices = ctrlConf.getPwmOutputs();
    buildDevices(pwmDevices, map, deviceMgr, deviceInterfaceModule);
    List<DeviceConfiguration> i2cDevices = ctrlConf.getI2cDevices();
    buildI2cDevices(i2cDevices, map, deviceMgr, deviceInterfaceModule);
    List<DeviceConfiguration> analogInputDevices = ctrlConf.getAnalogInputDevices();
    buildDevices(analogInputDevices, map, deviceMgr, deviceInterfaceModule);
    List<DeviceConfiguration> digitalDevices = ctrlConf.getDigitalDevices();
    buildDevices(digitalDevices, map, deviceMgr, deviceInterfaceModule);
    List<DeviceConfiguration> analogOutputDevices = ctrlConf.getAnalogOutputDevices();
    buildDevices(analogOutputDevices, map, deviceMgr, deviceInterfaceModule);
}
Also used : DeviceInterfaceModule(com.qualcomm.robotcore.hardware.DeviceInterfaceModule) LynxUsbDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxUsbDeviceConfiguration) LynxI2cDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxI2cDeviceConfiguration) DeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration)

Example 9 with DeviceConfiguration

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

the class HardwareFactory method mapNxtServoController.

private void mapNxtServoController(HardwareMap map, DeviceManager deviceMgr, LegacyModule legacyModule, DeviceConfiguration devConf) {
    if (!devConf.isEnabled()) {
        return;
    }
    ServoController sc = deviceMgr.createHTServoController(legacyModule, devConf.getPort(), devConf.getName());
    map.servoController.put(devConf.getName(), sc);
    for (DeviceConfiguration servoConf : ((ServoControllerConfiguration) devConf).getServos()) {
        mapServo(map, deviceMgr, servoConf, sc);
    }
}
Also used : ServoControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration) LynxServoController(com.qualcomm.hardware.lynx.LynxServoController) MatrixServoController(com.qualcomm.hardware.matrix.MatrixServoController) ServoController(com.qualcomm.robotcore.hardware.ServoController) LynxUsbDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxUsbDeviceConfiguration) LynxI2cDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxI2cDeviceConfiguration) DeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration)

Example 10 with DeviceConfiguration

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

the class HardwareFactory method mapLynxUsbDevice.

private void mapLynxUsbDevice(HardwareMap map, DeviceManager deviceMgr, LynxUsbDeviceConfiguration lynxUsbDeviceConfiguration) throws RobotCoreException, InterruptedException {
    if (!lynxUsbDeviceConfiguration.isEnabled()) {
        return;
    }
    // Make a new LynxUsbDevice
    LynxUsbDevice lynxUsbDevice = (LynxUsbDevice) deviceMgr.createLynxUsbDevice(lynxUsbDeviceConfiguration.getSerialNumber(), lynxUsbDeviceConfiguration.getName());
    try {
        // If the system made up this device, let the live device know that too
        if (lynxUsbDeviceConfiguration.isSystemSynthetic()) {
            lynxUsbDevice.setSystemSynthetic(true);
        }
        // Are we the first USB-attached (as opposed to embedded) LynxUsbDevice?
        boolean isFirstLynxUsbDevice = !LynxConstants.isEmbeddedSerialNumber(lynxUsbDeviceConfiguration.getSerialNumber());
        for (LynxUsbDevice usbDevice : map.getAll(LynxUsbDevice.class)) {
            if (!LynxConstants.isEmbeddedSerialNumber(usbDevice.getSerialNumber())) {
                isFirstLynxUsbDevice = false;
                break;
            }
        }
        // Make all the modules first, since we need to ping the parent before pinging anyone else,
        // and so we need to figure out who that is.
        // 
        List<LynxModule> potentialModules = new ArrayList<LynxModule>();
        Map<Integer, String> moduleNames = new HashMap<Integer, String>();
        final int parentModuleAddress = lynxUsbDeviceConfiguration.getParentModuleAddress();
        for (DeviceConfiguration moduleConfiguration : lynxUsbDeviceConfiguration.getModules()) {
            int moduleAddress = moduleConfiguration.getPort();
            moduleNames.put(moduleAddress, moduleConfiguration.getName());
            // 
            LynxModule module = (LynxModule) deviceMgr.createLynxModule(lynxUsbDevice, moduleAddress, parentModuleAddress == moduleAddress, moduleConfiguration.getName());
            potentialModules.add(module);
            // If the system made up this device, let the live device know that too
            if (((LynxModuleConfiguration) moduleConfiguration).isSystemSynthetic()) {
                module.setSystemSynthetic(true);
            }
        }
        // Attach all the LynxModules to that LynxUsbDevice, parents first, so that parents get pinged first. Note that if some
        // modules aren't actually there, or are there but are wedged, these may throw exceptions.
        Map<Integer, LynxModule> connectedModules = new HashMap<Integer, LynxModule>();
        for (LynxModule module : potentialModules) {
            if (module.isParent()) {
                // nb: there should be only one parent
                connectModule(lynxUsbDevice, module, moduleNames, connectedModules, isFirstLynxUsbDevice && connectedModules.isEmpty());
            }
        }
        for (LynxModule module : potentialModules) {
            if (!module.isParent()) {
                connectModule(lynxUsbDevice, module, moduleNames, connectedModules, false);
            }
        }
        // Finish adding all the pieces to the modules we successfully talked to
        mapLynxModuleComponents(map, deviceMgr, lynxUsbDeviceConfiguration, lynxUsbDevice, connectedModules);
        // For the things that worked, remember the module names in the hwmap
        for (Map.Entry<Integer, LynxModule> pair : connectedModules.entrySet()) {
            int moduleAddress = pair.getKey();
            map.put(moduleNames.get(moduleAddress), pair.getValue());
        }
        // Remember the LynxUsbDevice too, so we we'll only enable one to charge the RC battery
        map.put(lynxUsbDeviceConfiguration.getName(), lynxUsbDevice);
    } catch (LynxNackException e) {
        throw e.wrap();
    } catch (RobotCoreException | RuntimeException e) {
        lynxUsbDevice.close();
        map.remove(lynxUsbDeviceConfiguration.getName(), lynxUsbDevice);
        throw e;
    }
}
Also used : LynxModule(com.qualcomm.hardware.lynx.LynxModule) LynxUsbDevice(com.qualcomm.hardware.lynx.LynxUsbDevice) LynxNackException(com.qualcomm.hardware.lynx.LynxNackException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RobotCoreException(com.qualcomm.robotcore.exception.RobotCoreException) LynxUsbDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxUsbDeviceConfiguration) LynxI2cDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxI2cDeviceConfiguration) DeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration) LynxModuleConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxModuleConfiguration) HardwareMap(com.qualcomm.robotcore.hardware.HardwareMap) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

DeviceConfiguration (com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration)21 EditText (android.widget.EditText)8 LynxI2cDeviceConfiguration (com.qualcomm.robotcore.hardware.configuration.LynxI2cDeviceConfiguration)8 LynxUsbDeviceConfiguration (com.qualcomm.robotcore.hardware.configuration.LynxUsbDeviceConfiguration)8 TextView (android.widget.TextView)7 View (android.view.View)4 CheckBox (android.widget.CheckBox)4 LynxServoController (com.qualcomm.hardware.lynx.LynxServoController)4 MatrixServoController (com.qualcomm.hardware.matrix.MatrixServoController)3 ServoController (com.qualcomm.robotcore.hardware.ServoController)3 BuiltInConfigurationType (com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType)3 ConfigurationType (com.qualcomm.robotcore.hardware.configuration.ConfigurationType)3 LynxDcMotorController (com.qualcomm.hardware.lynx.LynxDcMotorController)2 LynxModule (com.qualcomm.hardware.lynx.LynxModule)2 LynxModuleConfiguration (com.qualcomm.robotcore.hardware.configuration.LynxModuleConfiguration)2 MatrixControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration)2 MotorConfiguration (com.qualcomm.robotcore.hardware.configuration.MotorConfiguration)2 ServoControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration)2 ArrayList (java.util.ArrayList)2 LinearLayout (android.widget.LinearLayout)1