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

View File

@ -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);
}
}
@ -60,6 +71,18 @@ public class HidManager {
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;
return (info.getVendorId() == (short) 0x054c);
@ -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;
}

View File

@ -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;
}
}