78 lines
3.1 KiB
Java
78 lines
3.1 KiB
Java
package com.unity3d.player;
|
|
|
|
import android.content.Context;
|
|
import android.hardware.usb.UsbDevice;
|
|
import android.hardware.usb.UsbManager;
|
|
import android.util.Log;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
|
|
public class USBCamUtil {
|
|
static String RGBCamDeviceName = "";
|
|
static String TargetCamName0 = "WN-Camera-RGB";
|
|
static String TargetCamName1 = "RGB Camera";
|
|
|
|
static String IRCamDeviceName = "";
|
|
static String TargetCamName2 = "WN-Camera-IR";
|
|
static String TargetCamName3 = "IR Camera";
|
|
|
|
public static boolean CamIsRGB(String deviceName)
|
|
{
|
|
if(RGBCamDeviceName.isEmpty())
|
|
{
|
|
UsbManager usbManager = (UsbManager)UnityPlayer.currentActivity.getSystemService(Context.USB_SERVICE);
|
|
HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
|
|
Log.d("USBCamUtil", "device count: "+deviceList.size());
|
|
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
|
|
while (deviceIterator.hasNext()) {
|
|
UsbDevice device = deviceIterator.next();
|
|
if(device.getProductName().equalsIgnoreCase(TargetCamName0) || device.getProductName().equalsIgnoreCase(TargetCamName1))
|
|
{
|
|
RGBCamDeviceName = device.getDeviceName();
|
|
}
|
|
Log.d("USBCamUtil", "ProductName: " + device.getProductName()+"-DeviceName:"+device.getDeviceName());
|
|
}
|
|
}
|
|
return (deviceName.equalsIgnoreCase(RGBCamDeviceName));
|
|
|
|
}
|
|
|
|
public static boolean CamIsIR(String deviceName)
|
|
{
|
|
if(IRCamDeviceName.isEmpty())
|
|
{
|
|
UsbManager usbManager = (UsbManager)UnityPlayer.currentActivity.getSystemService(Context.USB_SERVICE);
|
|
HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
|
|
Log.d("USBCamUtil", "device count: "+deviceList.size());
|
|
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
|
|
while (deviceIterator.hasNext()) {
|
|
UsbDevice device = deviceIterator.next();
|
|
if(device.getProductName().equalsIgnoreCase(TargetCamName2) || device.getProductName().equalsIgnoreCase(TargetCamName3))
|
|
{
|
|
IRCamDeviceName = device.getDeviceName();
|
|
}
|
|
}
|
|
}
|
|
return (deviceName.equalsIgnoreCase(IRCamDeviceName));
|
|
}
|
|
|
|
public static String[] GetAllDevice()
|
|
{
|
|
UsbManager usbManager = (UsbManager)UnityPlayer.currentActivity.getSystemService(Context.USB_SERVICE);
|
|
HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
|
|
String[] sts = new String[deviceList.size()];
|
|
|
|
int index = 0;
|
|
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
|
|
while (deviceIterator.hasNext()) {
|
|
UsbDevice device = deviceIterator.next();
|
|
|
|
sts[index] = ("deviceName:"+device.getDeviceName()+" productname:"+device.getProductName());
|
|
index++;
|
|
Log.d("USBCamUtil", "ProductName: " + device.getProductName()+"-DeviceName:"+device.getDeviceName());
|
|
}
|
|
return sts;
|
|
}
|
|
}
|