Finish up - HID controller filtering backend done

This commit is contained in:
Ash 2017-04-12 15:36:36 +10:00
parent 24bdf92bbc
commit fe8398a4c8
3 changed files with 32 additions and 8 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>3591b7e</version> <version>847db72</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.hid4java</groupId> <groupId>org.hid4java</groupId>

View File

@ -43,13 +43,24 @@ public class HidManager {
for (HidDevice info : backend.enumerateDevices()) { for (HidDevice info : backend.enumerateDevices()) {
if (isGamepad(info)) { if (isGamepad(info)) {
if (Settings.ControllerFiltering.getFilterState(Settings.ControllerFiltering.Type.HIDGAMEPAD)) {
// Skip Xbox controller under windows. We should use XInput instead. // Skip Xbox controller under windows. We should use XInput instead.
if (isXboxController(info) && Settings.isWindows()) { if (isXboxController(info) && Settings.isWindows()) {
continue; continue;
} }
connectedGamepads.add(info); 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);
}
} }
return connectedGamepads; return connectedGamepads;
} }
@ -60,6 +71,18 @@ public class HidManager {
return (usage == 0x05 || usage == 0x04 || isNintendoController(info) || isPlaystationController(info)); 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) { private static boolean isPlaystationController(HidDevice info) {
if (info == null) return false; if (info == null) return false;
return (info.getVendorId() == (short) 0x054c); return (info.getVendorId() == (short) 0x054c);
@ -81,7 +104,7 @@ public class HidManager {
} else if (Settings.isWindows()) { } else if (Settings.isWindows()) {
backend = new PureJavaHidManagerBackend(); backend = new PureJavaHidManagerBackend();
} else if (Settings.isLinux()) { } else if (Settings.isLinux()) {
backend = new Hid4JavaHidManagerBackend(); backend = new PureJavaHidManagerBackend();
} else { } else {
backend = null; backend = null;
} }

View File

@ -204,7 +204,8 @@ public final class Settings {
public static enum Type { public static enum Type {
HIDGAMEPAD (0, "HID Gamepads"), HIDGAMEPAD (0, "HID Gamepads"),
HIDKEYBOARD (1, "HID Keyboards"), HIDKEYBOARD (1, "HID Keyboards"),
HIDOTHER (2, "Other HIDs"); HIDMOUSE (2, "HID Mice"),
HIDOTHER (3, "Other HIDs");
private int index; private int index;
@Getter private String name; @Getter private String name;
@ -231,7 +232,6 @@ public final class Settings {
public static void setFilterState(Type filter, boolean state) { public static void setFilterState(Type filter, boolean state) {
filterStates[filter.index] = state; filterStates[filter.index] = state;
log.info("Just set " + filter + " to " + state);
} }
public static boolean getFilterState(Type filter) { public static boolean getFilterState(Type filter) {
return filterStates[filter.index]; return filterStates[filter.index];
@ -239,6 +239,7 @@ public final class Settings {
public static void setDefaultFilterStates() { public static void setDefaultFilterStates() {
filterStates[Type.HIDGAMEPAD.index] = true; filterStates[Type.HIDGAMEPAD.index] = true;
filterStates[Type.HIDKEYBOARD.index] = false; filterStates[Type.HIDKEYBOARD.index] = false;
filterStates[Type.HIDMOUSE.index] = false;
filterStates[Type.HIDOTHER.index] = false; filterStates[Type.HIDOTHER.index] = false;
} }
} }