mirror of
https://github.com/Maschell/HIDtoVPADNetworkClient.git
synced 2024-11-15 03:15:05 +01:00
Minor code clean up
This commit is contained in:
parent
b94ed1cc9a
commit
f5f1d42d1b
@ -113,13 +113,13 @@ public class HidController extends Controller {
|
|||||||
// TODO: own class for joycons
|
// TODO: own class for joycons
|
||||||
if (getVID() == 0x57e) {
|
if (getVID() == 0x57e) {
|
||||||
if (getPID() == 0x2006) {
|
if (getPID() == 0x2006) {
|
||||||
return "Joy-Con (L) (57e:2006) on " + getIdentifier();
|
return "Joy-Con (L) (0x057e:0x2006) on " + getIdentifier();
|
||||||
} else if (getPID() == 0x2007) {
|
} else if (getPID() == 0x2007) {
|
||||||
return "Joy-Con (R) (57e:2007) on " + getIdentifier();
|
return "Joy-Con (R) (0x057e:0x2007) on " + getIdentifier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = getHidDevice().getProductString();
|
String name = getHidDevice().getProductString();
|
||||||
return ((name != null) ? name : "USB HID") + " (" + Integer.toHexString((int)getVID() & 0xFFFF) + ":" + Integer.toHexString((int)getPID() & 0xFFFF) + ") on " + getIdentifier();
|
return String.format("%s (0x%04X:0x%04X) on %s",(name != null) ? name: "USB HID", getVID(),getPID(),getIdentifier());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -81,7 +81,7 @@ public class LinuxDevInputController extends Controller implements Runnable {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//This could probably do with some cleanup
|
// This could probably do with some cleanup
|
||||||
public void doSysFs(String identifier) throws Exception {
|
public void doSysFs(String identifier) throws Exception {
|
||||||
Process querySysFs = Runtime.getRuntime().exec("udevadm info -q path " + identifier);
|
Process querySysFs = Runtime.getRuntime().exec("udevadm info -q path " + identifier);
|
||||||
querySysFs.waitFor();
|
querySysFs.waitFor();
|
||||||
@ -125,7 +125,7 @@ public class LinuxDevInputController extends Controller implements Runnable {
|
|||||||
type = inputStream.readByte();
|
type = inputStream.readByte();
|
||||||
number = inputStream.readByte();
|
number = inputStream.readByte();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (!isActive()) return null; //"Stream closed" when removing
|
if (!isActive()) return null; // "Stream closed" when removing
|
||||||
System.err.println("[LinuxDevInputController] Couldn't read from controller!");
|
System.err.println("[LinuxDevInputController] Couldn't read from controller!");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.out.println("[LinuxDevInputController] Detaching...");
|
System.out.println("[LinuxDevInputController] Detaching...");
|
||||||
@ -175,8 +175,7 @@ public class LinuxDevInputController extends Controller implements Runnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doSleepAfterPollingData() {
|
protected void doSleepAfterPollingData() {
|
||||||
// This is event driven (aka pollLatestData() is blocking anyway until
|
// This is event driven (aka pollLatestData() is blocking anyway until we have data), we don't need to sleep it all.
|
||||||
// we have data), we don't need to sleep it all.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -195,6 +194,6 @@ public class LinuxDevInputController extends Controller implements Runnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInfoText() {
|
public String getInfoText() {
|
||||||
return ((name != null) ? name : "Linux controller") + " (" + Integer.toHexString((int)getVID() & 0xFFFF) + ":" + Integer.toHexString((int)getPID() & 0xFFFF) + ") on " + getIdentifier();
|
return String.format("%s (0x%04X:0x%04X) on %s", (name != null) ? name : "Linux Controller", getVID(), getPID(), getIdentifier());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,6 @@ public class XInput13Controller extends XInputController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInfoText() {
|
public String getInfoText() {
|
||||||
return "XInput 1.3 (" + Integer.toHexString((int)getVID() & 0xFFFF) + ":" + Integer.toHexString((int)getPID() & 0xFFFF) + ") on " + getIdentifier();
|
return String.format("XInput 1.3 (0x%04X:0x%04X) on ", getVID(),getPID()) + getIdentifier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,6 @@ public class XInput14Controller extends XInputController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInfoText() {
|
public String getInfoText() {
|
||||||
return "XInput 1.4 (" + Integer.toHexString((int)getVID() & 0xFFFF) + ":" + Integer.toHexString((int)getPID() & 0xFFFF) + ") on " + getIdentifier();
|
return String.format("XInput 1.4 (0x%04X:0x%04X) on ", getVID(),getPID()) + getIdentifier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,6 +139,6 @@ public class XInputController extends Controller {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInfoText() {
|
public String getInfoText() {
|
||||||
return "XInput (" + Integer.toHexString((int)getVID() & 0xFFFF) + ":" + Integer.toHexString((int)getPID() & 0xFFFF) + ") on " + getIdentifier();
|
return String.format("XInput (0x%04X:%0x04X) on ", getVID(),getPID()) + getIdentifier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ public class HidManager {
|
|||||||
public static boolean isGamepad(HidDevice info) {
|
public static boolean isGamepad(HidDevice info) {
|
||||||
if (info == null) return false;
|
if (info == null) return false;
|
||||||
short usage = info.getUsageID();
|
short usage = info.getUsageID();
|
||||||
return (usage == 0x05 || usage == 0x04 || isNintendoController(info) || isPlaystationController(info));
|
return (info.getProductString().toLowerCase().contains("gamepad") || usage == 0x05 || usage == 0x04 || isNintendoController(info) || isPlaystationController(info));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isKeyboard(HidDevice info) {
|
public static boolean isKeyboard(HidDevice info) {
|
||||||
|
@ -113,7 +113,7 @@ class PureJavaHidDevice implements HidDevice, InputReportListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProductString() {
|
public String getProductString() {
|
||||||
return myDeviceInfo.getProductString();
|
return myDeviceInfo.getProductString().trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -209,11 +209,12 @@ public final class Settings {
|
|||||||
public static class ControllerFiltering {
|
public static class ControllerFiltering {
|
||||||
public static enum Type {
|
public static enum Type {
|
||||||
HIDGAMEPAD (0, "HID Gamepads", Platform.LINUX.mask | Platform.WINDOWS.mask | Platform.MAC_OS_X.mask),
|
HIDGAMEPAD (0, "HID Gamepads", Platform.LINUX.mask | Platform.WINDOWS.mask | Platform.MAC_OS_X.mask),
|
||||||
|
XINPUT (5, "XInput controllers", Platform.WINDOWS.mask),
|
||||||
HIDKEYBOARD (1, "HID Keyboards", Platform.LINUX.mask | Platform.MAC_OS_X.mask),
|
HIDKEYBOARD (1, "HID Keyboards", Platform.LINUX.mask | Platform.MAC_OS_X.mask),
|
||||||
HIDMOUSE (2, "HID Mice", Platform.LINUX.mask),
|
HIDMOUSE (2, "HID Mice", Platform.LINUX.mask),
|
||||||
HIDOTHER (3, "Other HIDs", Platform.LINUX.mask | Platform.WINDOWS.mask | Platform.MAC_OS_X.mask),
|
HIDOTHER (3, "Other HIDs", Platform.LINUX.mask | Platform.WINDOWS.mask | Platform.MAC_OS_X.mask),
|
||||||
LINUX (4, "Linux controllers", Platform.LINUX.mask),
|
LINUX (4, "Linux controllers", Platform.LINUX.mask),
|
||||||
XINPUT (5, "XInput controllers", Platform.WINDOWS.mask);
|
;
|
||||||
|
|
||||||
private int index;
|
private int index;
|
||||||
@Getter private String name;
|
@Getter private String name;
|
||||||
|
@ -8,32 +8,33 @@ import net.ash.HIDToVPADNetworkClient.network.NetworkManager;
|
|||||||
|
|
||||||
public class StatusReport {
|
public class StatusReport {
|
||||||
public static String generateStatusReport() {
|
public static String generateStatusReport() {
|
||||||
String report = "HID to VPAD Network Client\n\nRunning on ";
|
StringBuilder report = new StringBuilder();
|
||||||
report += Settings.getPlattform();
|
report.append("HID to VPAD Network Client\n\nRunning on ");
|
||||||
|
report.append(Settings.getPlattform());
|
||||||
|
|
||||||
report += "\nHID Backend: ";
|
report.append(System.lineSeparator()).append("HID Backend: ");
|
||||||
report += HidManager.getBackendType();
|
report.append(HidManager.getBackendType());
|
||||||
|
|
||||||
report += "\nCurrently ";
|
report.append(System.lineSeparator()).append("Currently ");
|
||||||
report += (NetworkManager.getInstance().isConnected()) ? "Connected.\n" : "Disconnected.\n";
|
report.append((NetworkManager.getInstance().isConnected()) ? "Connected.\n" : "Disconnected.").append(System.lineSeparator());
|
||||||
report += (NetworkManager.getInstance().isReconnecting()) ? "" : "Not ";
|
report.append((NetworkManager.getInstance().isReconnecting()) ? "" : "Not ");
|
||||||
report += "Reconnecting.";
|
report.append("Reconnecting.");
|
||||||
|
|
||||||
report += "\n\nCurrently attached controllers:";
|
report.append(System.lineSeparator()).append(System.lineSeparator()).append("Currently attached controllers:");
|
||||||
for (Controller c : ControllerManager.getAttachedControllers()) {
|
for (Controller c : ControllerManager.getAttachedControllers()) {
|
||||||
report += "\n";
|
report.append(System.lineSeparator());
|
||||||
report += c.toString();
|
report.append(c.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
report += "\n\nFiltering settings:\n";
|
report.append(System.lineSeparator()).append(System.lineSeparator()).append("Filtering settings:").append(System.lineSeparator());
|
||||||
report += Settings.ControllerFiltering.getFilterStates();
|
report.append(Settings.ControllerFiltering.getFilterStates());
|
||||||
|
|
||||||
report += "\n\nAll HIDs:";
|
report.append(System.lineSeparator()).append(System.lineSeparator()).append("All HIDs:");
|
||||||
for (HidDevice d : HidManager.getAllAttachedControllers()) {
|
for (HidDevice d : HidManager.getAllAttachedControllers()) {
|
||||||
report += "\n";
|
report.append(System.lineSeparator());
|
||||||
report += d.toString();
|
report.append(d.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return report;
|
return report.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user