Search in sources :

Example 1 with RobotUsbDeviceFtdi

use of com.qualcomm.robotcore.hardware.usb.ftdi.RobotUsbDeviceFtdi in project robotcode by OutoftheBoxFTC.

the class LynxUsbDeviceImpl method resetDevice.

/**
 * Issues a hardware reset to the lynx module.
 */
public static void resetDevice(RobotUsbDevice robotUsbDevice) {
    RobotLog.vv(LynxModule.TAG, "resetDevice() serial=%s", robotUsbDevice.getSerialNumber());
    int msDelay = msCbusWiggle;
    try {
        if (LynxConstants.isEmbeddedSerialNumber(robotUsbDevice.getSerialNumber())) {
            boolean prevState = DragonboardLynxDragonboardIsPresentPin.getInstance().getState();
            RobotLog.vv(LynxModule.TAG, "resetting embedded usb device: isPresent: was=%s", prevState);
            // Make sure we're 'present'. Our reset pin won't operate unless we are
            if (!prevState) {
                DragonboardLynxDragonboardIsPresentPin.getInstance().setState(true);
                Thread.sleep(msDelay);
            }
            DragonboardLynxResetPin.getInstance().setState(true);
            Thread.sleep(msDelay);
            DragonboardLynxResetPin.getInstance().setState(false);
            Thread.sleep(msDelay);
            // ALWAYS remain 'present' unless we're explicitly configured not to
            if (LynxConstants.isRevControlHub() && LynxConstants.disableDragonboard()) {
                DragonboardLynxDragonboardIsPresentPin.getInstance().setState(false);
                Thread.sleep(msDelay);
            }
        } else {
            RobotUsbDeviceFtdi deviceFtdi = accessCBus(robotUsbDevice);
            if (deviceFtdi != null) {
                // Initialize with both lines deasserted
                deviceFtdi.cbus_setup(cbusMask, cbusNeitherAsserted);
                Thread.sleep(msDelay);
                // Assert reset
                deviceFtdi.cbus_write(cbusResetAsserted);
                Thread.sleep(msDelay);
                // Deassert reset
                deviceFtdi.cbus_write(cbusNeitherAsserted);
            }
        }
        // give the board a chance to recover
        // totally a finger in the wind
        Thread.sleep(msResetRecovery);
    } catch (InterruptedException | RobotUsbException e) {
        exceptionHandler.handleException(e);
    }
}
Also used : RobotUsbDeviceFtdi(com.qualcomm.robotcore.hardware.usb.ftdi.RobotUsbDeviceFtdi) RobotUsbException(org.firstinspires.ftc.robotcore.internal.usb.exception.RobotUsbException)

Example 2 with RobotUsbDeviceFtdi

use of com.qualcomm.robotcore.hardware.usb.ftdi.RobotUsbDeviceFtdi in project robotcode by OutoftheBoxFTC.

the class LynxUsbDeviceImpl method enterFirmwareUpdateModeUSB.

/**
 * If we are a USB-attached Lynx, then cause us to enter firmware update mode
 */
public static void enterFirmwareUpdateModeUSB(RobotUsbDevice robotUsbDevice) {
    RobotLog.vv(LynxModule.TAG, "enterFirmwareUpdateModeUSB() serial=%s", robotUsbDevice.getSerialNumber());
    RobotUsbDeviceFtdi deviceFtdi = accessCBus(robotUsbDevice);
    if (deviceFtdi != null) {
        try {
            int msDelay = msCbusWiggle;
            // Initialize with both lines deasserted
            deviceFtdi.cbus_setup(cbusMask, cbusNeitherAsserted);
            Thread.sleep(msDelay);
            // Assert nProg
            deviceFtdi.cbus_write(cbusProgAsserted);
            Thread.sleep(msDelay);
            // Assert nProg and nReset
            deviceFtdi.cbus_write(cbusBothAsserted);
            Thread.sleep(msDelay);
            // Deassert nReset
            deviceFtdi.cbus_write(cbusProgAsserted);
            Thread.sleep(msDelay);
            // Deassert nProg
            deviceFtdi.cbus_write(cbusNeitherAsserted);
            Thread.sleep(msResetRecovery);
        } catch (InterruptedException | RobotUsbException e) {
            exceptionHandler.handleException(e);
        }
    }
}
Also used : RobotUsbDeviceFtdi(com.qualcomm.robotcore.hardware.usb.ftdi.RobotUsbDeviceFtdi) RobotUsbException(org.firstinspires.ftc.robotcore.internal.usb.exception.RobotUsbException)

Aggregations

RobotUsbDeviceFtdi (com.qualcomm.robotcore.hardware.usb.ftdi.RobotUsbDeviceFtdi)2 RobotUsbException (org.firstinspires.ftc.robotcore.internal.usb.exception.RobotUsbException)2