package com.github.mjdev.libaums.usb;

import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbEndpoint;
import android.os.Build;
import android.util.Log;

/**
 * Created by magnusja on 21/12/16.
 */

public class UsbCommunicationFactory {

    enum UnderlyingUsbCommunication {
        USB_REQUEST,
        DEVICE_CONNECTION
    }

    private static final String TAG = UsbCommunicationFactory.class.getSimpleName();

    private static UnderlyingUsbCommunication underlyingUsbCommunication = UnderlyingUsbCommunication.USB_REQUEST;

    public static UsbCommunication createUsbCommunication(UsbDeviceConnection deviceConnection, UsbEndpoint outEndpoint, UsbEndpoint inEndpoint) {
        UsbCommunication communication;

        if (underlyingUsbCommunication == UnderlyingUsbCommunication.DEVICE_CONNECTION) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                communication = new JellyBeanMr2Communication(deviceConnection, outEndpoint, inEndpoint);
            } else {
                Log.i(TAG, "using workaround usb communication");
                communication = new HoneyCombMr1Communication(deviceConnection, outEndpoint, inEndpoint);
            }
        } else {
            communication = new UsbRequestCommunication(deviceConnection, outEndpoint, inEndpoint);
        }

        return communication;
    }

    public static void setUnderlyingUsbCommunication(UnderlyingUsbCommunication underlyingUsbCommunication) {
        UsbCommunicationFactory.underlyingUsbCommunication = underlyingUsbCommunication;
    }
}

@@ -315,16 +315,22 @@
 _REQUEST
+_ASYNC
 ,%0A      
@@ -348,16 +348,21 @@
 NNECTION
+_SYNC
 %0A    %7D%0A%0A
@@ -549,27 +549,38 @@
 ication.
-USB_REQUEST
+DEVICE_CONNECTION_SYNC
 ;%0A%0A    p
@@ -848,16 +848,21 @@
 NNECTION
+_SYNC
 ) %7B%0A    

Reset to device connection usb communication