mirror of
https://github.com/Maschell/HIDtoVPADNetworkClient.git
synced 2024-11-22 05:59:16 +01:00
Finish up - HID controller filtering backend done
This commit is contained in:
parent
24bdf92bbc
commit
fe8398a4c8
2
pom.xml
2
pom.xml
@ -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>
|
||||
|
@ -43,13 +43,24 @@ public class HidManager {
|
||||
|
||||
for (HidDevice info : backend.enumerateDevices()) {
|
||||
if (isGamepad(info)) {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
return connectedGamepads;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user