From 725d23de721cc8e7b5ddc54d767b36e70cd867ac Mon Sep 17 00:00:00 2001 From: Ash Date: Wed, 12 Apr 2017 21:32:17 +1000 Subject: [PATCH] Differentiate usagePage and usageID, fix whitespace bugs --- pom.xml | 2 +- .../controller/Controller.java | 2 +- .../ash/HIDToVPADNetworkClient/hid/HidDevice.java | 13 ++++++++++--- .../ash/HIDToVPADNetworkClient/hid/HidManager.java | 6 +++--- .../hid/hid4java/Hid4JavaHidDevice.java | 9 +++++++-- .../hid/purejavahid/PureJavaHidDevice.java | 11 ++++++++--- 6 files changed, 30 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 629be40..c8fb408 100644 --- a/pom.xml +++ b/pom.xml @@ -140,7 +140,7 @@ com.github.QuarkTheAwesome purejavahidapi - 847db72 + f877704 org.hid4java diff --git a/src/net/ash/HIDToVPADNetworkClient/controller/Controller.java b/src/net/ash/HIDToVPADNetworkClient/controller/Controller.java index af5d1e5..e1dfb6f 100644 --- a/src/net/ash/HIDToVPADNetworkClient/controller/Controller.java +++ b/src/net/ash/HIDToVPADNetworkClient/controller/Controller.java @@ -170,7 +170,7 @@ public abstract class Controller implements Runnable { @Override public String toString() { - return getType() + " " + getIdentifier(); + return getType() + " " + getIdentifier().trim(); } @Override diff --git a/src/net/ash/HIDToVPADNetworkClient/hid/HidDevice.java b/src/net/ash/HIDToVPADNetworkClient/hid/HidDevice.java index 9d6fb38..a267694 100644 --- a/src/net/ash/HIDToVPADNetworkClient/hid/HidDevice.java +++ b/src/net/ash/HIDToVPADNetworkClient/hid/HidDevice.java @@ -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 diff --git a/src/net/ash/HIDToVPADNetworkClient/hid/HidManager.java b/src/net/ash/HIDToVPADNetworkClient/hid/HidManager.java index 6291b2d..f4bf2bb 100644 --- a/src/net/ash/HIDToVPADNetworkClient/hid/HidManager.java +++ b/src/net/ash/HIDToVPADNetworkClient/hid/HidManager.java @@ -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); } diff --git a/src/net/ash/HIDToVPADNetworkClient/hid/hid4java/Hid4JavaHidDevice.java b/src/net/ash/HIDToVPADNetworkClient/hid/hid4java/Hid4JavaHidDevice.java index b959153..4ccb8d4 100644 --- a/src/net/ash/HIDToVPADNetworkClient/hid/hid4java/Hid4JavaHidDevice.java +++ b/src/net/ash/HIDToVPADNetworkClient/hid/hid4java/Hid4JavaHidDevice.java @@ -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(); + } } diff --git a/src/net/ash/HIDToVPADNetworkClient/hid/purejavahid/PureJavaHidDevice.java b/src/net/ash/HIDToVPADNetworkClient/hid/purejavahid/PureJavaHidDevice.java index 73bab45..5750489 100644 --- a/src/net/ash/HIDToVPADNetworkClient/hid/purejavahid/PureJavaHidDevice.java +++ b/src/net/ash/HIDToVPADNetworkClient/hid/purejavahid/PureJavaHidDevice.java @@ -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) + "]"; } }