Search in sources :

Example 1 with ModernRoboticsUsbDeviceInterfaceModule

use of com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDeviceInterfaceModule in project robotcode by OutoftheBoxFTC.

the class HardwareDeviceManager method createDeviceInterfaceModule.

@Override
public DeviceInterfaceModule createDeviceInterfaceModule(final SerialNumber serialNumber, String name) throws RobotCoreException, InterruptedException {
    HardwareFactory.noteSerialNumberType(context, serialNumber, context.getString(R.string.moduleDisplayNameCDIM));
    RobotLog.v("Creating %s", HardwareFactory.getDeviceDisplayName(context, serialNumber));
    ModernRoboticsUsbDevice.OpenRobotUsbDevice openRobotUsbDevice = new ModernRoboticsUsbDevice.OpenRobotUsbDevice() {

        @Override
        public RobotUsbDevice open() throws RobotCoreException, InterruptedException {
            RobotUsbDevice dev = null;
            try {
                dev = ModernRoboticsUsbUtil.openUsbDevice(true, usbManager, serialNumber);
                byte[] deviceHeader = getModernRoboticsDeviceHeader(dev);
                DeviceType type = getModernRoboticsDeviceType(dev, deviceHeader);
                if (type != DeviceType.MODERN_ROBOTICS_USB_DEVICE_INTERFACE_MODULE) {
                    closeAndThrowOnFailedDeviceTypeCheck(dev, serialNumber);
                }
                dev.setFirmwareVersion(getModernRoboticsFirmwareVersion(deviceHeader));
            } catch (RobotCoreException e) {
                if (dev != null) {
                    // avoid leakage of open FT_Devices
                    dev.close();
                }
                throw e;
            } catch (RuntimeException e) {
                if (dev != null) {
                    // avoid leakage of open FT_Devices
                    dev.close();
                }
                throw e;
            }
            return dev;
        }
    };
    ModernRoboticsUsbDeviceInterfaceModule deviceInterfaceModule = new ModernRoboticsUsbDeviceInterfaceModule(context, serialNumber, openRobotUsbDevice, manager);
    deviceInterfaceModule.armOrPretend();
    deviceInterfaceModule.initializeHardware();
    return deviceInterfaceModule;
}
Also used : ModernRoboticsUsbDevice(com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDevice) ModernRoboticsUsbDeviceInterfaceModule(com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDeviceInterfaceModule) RobotCoreException(com.qualcomm.robotcore.exception.RobotCoreException) RobotUsbDevice(com.qualcomm.robotcore.hardware.usb.RobotUsbDevice)

Aggregations

ModernRoboticsUsbDevice (com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDevice)1 ModernRoboticsUsbDeviceInterfaceModule (com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDeviceInterfaceModule)1 RobotCoreException (com.qualcomm.robotcore.exception.RobotCoreException)1 RobotUsbDevice (com.qualcomm.robotcore.hardware.usb.RobotUsbDevice)1