Differentiate usagePage and usageID, fix whitespace bugs

This commit is contained in:
Ash 2017-04-12 21:32:17 +10:00
parent fdf74a0f55
commit 725d23de72
6 changed files with 30 additions and 13 deletions

View File

@ -140,7 +140,7 @@
<dependency>
<groupId>com.github.QuarkTheAwesome</groupId>
<artifactId>purejavahidapi</artifactId>
<version>847db72</version>
<version>f877704</version>
</dependency>
<dependency>
<groupId>org.hid4java</groupId>

View File

@ -170,7 +170,7 @@ public abstract class Controller implements Runnable {
@Override
public String toString() {
return getType() + " " + getIdentifier();
return getType() + " " + getIdentifier().trim();
}
@Override

View File

@ -57,11 +57,18 @@ public interface HidDevice {
byte[] getLatestData();
/**
* Retuns the Usage of this HID-Device
* Retuns the Usage Page of this HID-Device
*
* @return usage
* @return usage page
*/
short getUsage();
short getUsagePage();
/**
* Retuns the Usage ID of this HID-Device
*
* @return usage id
*/
short getUsageID();
/**
* Returns the path of this HidDevice

View File

@ -71,19 +71,19 @@ public class HidManager {
public static boolean isGamepad(HidDevice info) {
if (info == null) return false;
short usage = info.getUsage();
short usage = info.getUsageID();
return (usage == 0x05 || usage == 0x04 || isNintendoController(info) || isPlaystationController(info));
}
public static boolean isKeyboard(HidDevice info) {
if (info == null) return false;
short usage = info.getUsage();
short usage = info.getUsageID();
return (usage == 0x06);
}
public static boolean isMouse(HidDevice info) {
if (info == null) return false;
short usage = info.getUsage();
short usage = info.getUsageID();
return (usage == 0x02);
}

View File

@ -68,11 +68,16 @@ class Hid4JavaHidDevice implements HidDevice {
@Override
public String toString() {
return "Hid4JavaHidDevice [vid= " + getVendorId() + ", pid= " + getProductId() + ", usage= " + String.format("%04X", getUsage()) + ", data=" + Arrays.toString(data) + "]";
return "Hid4JavaHidDevice [vid= " + getVendorId() + ", pid= " + getProductId() + ", usage= " + String.format("%04X:%04X", getUsagePage(), getUsageID()) + ", data=" + Arrays.toString(data) + "]";
}
@Override
public short getUsage() {
public short getUsageID() {
return (short) myDevice.getUsage();
}
@Override
public short getUsagePage() {
return (short) myDevice.getUsagePage();
}
}

View File

@ -81,9 +81,14 @@ class PureJavaHidDevice implements HidDevice, InputReportListener {
}
@Override
public short getUsage() {
public short getUsagePage() {
return myDeviceInfo.getUsagePage();
}
@Override
public short getUsageID() {
return myDeviceInfo.getUsageID();
}
@Override
public String getPath() {
@ -92,7 +97,7 @@ class PureJavaHidDevice implements HidDevice, InputReportListener {
@Override
public String toString() {
return "PureJavaHidDevice [vid= " + String.format("%04X", getVendorId()) + ", pid= " + String.format("%04X", getProductId()) + ", path= " + getPath()
+ ", usage= " + String.format("%04X", getUsage()) + ", data=" + Arrays.toString(currentData) + "]";
return "PureJavaHidDevice [vid= " + String.format("%04X", getVendorId()) + ", pid= " + String.format("%04X", getProductId()) + ", path= " + getPath().trim()
+ ", usage= " + String.format("%04X:%04X", getUsagePage(), getUsageID()) + ", data=" + Arrays.toString(currentData) + "]";
}
}