From fe8398a4c8e7640f832993d6586ac2255c0cbc28 Mon Sep 17 00:00:00 2001 From: Ash Date: Wed, 12 Apr 2017 15:36:36 +1000 Subject: [PATCH] Finish up - HID controller filtering backend done --- pom.xml | 2 +- .../hid/HidManager.java | 33 ++++++++++++++++--- .../HIDToVPADNetworkClient/util/Settings.java | 5 +-- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 2d630d7..629be40 100644 --- a/pom.xml +++ b/pom.xml @@ -140,7 +140,7 @@ com.github.QuarkTheAwesome purejavahidapi - 3591b7e + 847db72 org.hid4java diff --git a/src/net/ash/HIDToVPADNetworkClient/hid/HidManager.java b/src/net/ash/HIDToVPADNetworkClient/hid/HidManager.java index 5ee6d49..7eaaab6 100644 --- a/src/net/ash/HIDToVPADNetworkClient/hid/HidManager.java +++ b/src/net/ash/HIDToVPADNetworkClient/hid/HidManager.java @@ -43,11 +43,22 @@ public class HidManager { for (HidDevice info : backend.enumerateDevices()) { if (isGamepad(info)) { - - // Skip Xbox controller under windows. We should use XInput instead. - if (isXboxController(info) && Settings.isWindows()) { - continue; + if (Settings.ControllerFiltering.getFilterState(Settings.ControllerFiltering.Type.HIDGAMEPAD)) { + // Skip Xbox controller under windows. We should use XInput instead. + if (isXboxController(info) && Settings.isWindows()) { + continue; + } + connectedGamepads.add(info); } + } else if (isKeyboard(info)) { + if (Settings.ControllerFiltering.getFilterState(Settings.ControllerFiltering.Type.HIDKEYBOARD)) { + connectedGamepads.add(info); + } + } else if (isMouse(info)) { + if (Settings.ControllerFiltering.getFilterState(Settings.ControllerFiltering.Type.HIDMOUSE)) { + connectedGamepads.add(info); + } + } else if (Settings.ControllerFiltering.getFilterState(Settings.ControllerFiltering.Type.HIDOTHER)) { connectedGamepads.add(info); } } @@ -59,6 +70,18 @@ public class HidManager { short usage = info.getUsage(); return (usage == 0x05 || usage == 0x04 || isNintendoController(info) || isPlaystationController(info)); } + + public static boolean isKeyboard(HidDevice info) { + if (info == null) return false; + short usage = info.getUsage(); + return (usage == 0x06); + } + + public static boolean isMouse(HidDevice info) { + if (info == null) return false; + short usage = info.getUsage(); + return (usage == 0x02); + } private static boolean isPlaystationController(HidDevice info) { if (info == null) return false; @@ -81,7 +104,7 @@ public class HidManager { } else if (Settings.isWindows()) { backend = new PureJavaHidManagerBackend(); } else if (Settings.isLinux()) { - backend = new Hid4JavaHidManagerBackend(); + backend = new PureJavaHidManagerBackend(); } else { backend = null; } diff --git a/src/net/ash/HIDToVPADNetworkClient/util/Settings.java b/src/net/ash/HIDToVPADNetworkClient/util/Settings.java index b01a3a0..2e09137 100644 --- a/src/net/ash/HIDToVPADNetworkClient/util/Settings.java +++ b/src/net/ash/HIDToVPADNetworkClient/util/Settings.java @@ -204,7 +204,8 @@ public final class Settings { public static enum Type { HIDGAMEPAD (0, "HID Gamepads"), HIDKEYBOARD (1, "HID Keyboards"), - HIDOTHER (2, "Other HIDs"); + HIDMOUSE (2, "HID Mice"), + HIDOTHER (3, "Other HIDs"); private int index; @Getter private String name; @@ -231,7 +232,6 @@ public final class Settings { public static void setFilterState(Type filter, boolean state) { filterStates[filter.index] = state; - log.info("Just set " + filter + " to " + state); } public static boolean getFilterState(Type filter) { return filterStates[filter.index]; @@ -239,6 +239,7 @@ public final class Settings { public static void setDefaultFilterStates() { filterStates[Type.HIDGAMEPAD.index] = true; filterStates[Type.HIDKEYBOARD.index] = false; + filterStates[Type.HIDMOUSE.index] = false; filterStates[Type.HIDOTHER.index] = false; } }