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> <dependency>
<groupId>com.github.QuarkTheAwesome</groupId> <groupId>com.github.QuarkTheAwesome</groupId>
<artifactId>purejavahidapi</artifactId> <artifactId>purejavahidapi</artifactId>
<version>847db72</version> <version>f877704</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.hid4java</groupId> <groupId>org.hid4java</groupId>

View File

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

View File

@ -57,11 +57,18 @@ public interface HidDevice {
byte[] getLatestData(); 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 * Returns the path of this HidDevice

View File

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

View File

@ -68,11 +68,16 @@ class Hid4JavaHidDevice implements HidDevice {
@Override @Override
public String toString() { 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 @Override
public short getUsage() { public short getUsageID() {
return (short) myDevice.getUsage(); return (short) myDevice.getUsage();
} }
@Override
public short getUsagePage() {
return (short) myDevice.getUsagePage();
}
} }

View File

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