usbinputdevicetodrivermapper.java

来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 75 行

JAVA
75
字号
/*
 * $Id: USBInputDeviceToDriverMapper.java,v 1.1 2003/11/25 11:51:35 epr Exp $
 */
package org.jnode.driver.usb.input;

import org.jnode.driver.Device;
import org.jnode.driver.DeviceToDriverMapper;
import org.jnode.driver.Driver;
import org.jnode.driver.usb.InterfaceDescriptor;
import org.jnode.driver.usb.USBConfiguration;
import org.jnode.driver.usb.USBConstants;
import org.jnode.driver.usb.USBDevice;
import org.jnode.driver.usb.USBInterface;

/**
 * @author Ewout Prangsma (epr@users.sourceforge.net)
 */
public class USBInputDeviceToDriverMapper implements DeviceToDriverMapper, USBConstants {

	/**
	 * @see org.jnode.driver.DeviceToDriverMapper#findDriver(org.jnode.driver.Device)
	 */
	public Driver findDriver(Device device) {
		if (!(device instanceof USBDevice)) {
			return null;
		}
		
		final USBDevice dev = (USBDevice) device;
		if (dev.getDescriptor().getDeviceClass() != USB_CLASS_PER_INTERFACE) {
			return null;
		}

		final USBConfiguration conf = dev.getConfiguration(0);
		final USBInterface intf = conf.getInterface(0);
		final InterfaceDescriptor descr = intf.getDescriptor();

		if (descr.getInterfaceClass() != USB_CLASS_HID) {
			return null;
		}
		
		// SubClass: 1 = boot interface subclass
		if (descr.getInterfaceSubClass() != 1) {
			return null;
		}
		
		// Protocol: 1 = keyboard, 2 = mouse
		switch (descr.getInterfaceProtocol()) {
			case 1 :
				// We found an USB keyboard
				return new USBKeyboardDriver();
			case 2 :
				// We found an USB mouse
				return new USBMouseDriver();
			default :
				return null;
		}
	}
	
	/**
	 * Gets the matching level of this mapper.
	 * The mappers are queried in order of match level. This will ensure
	 * the best available driver for a device.
	 * 
	 * @return One of the MATCH_xxx constants.
	 * @see #MATCH_DEVICE_REVISION
	 * @see #MATCH_DEVICE
	 * @see #MATCH_DEVCLASS
	 */
	public int getMatchLevel() {
		return MATCH_DEVCLASS;
	}
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?