mirror of
https://github.com/Maschell/HIDtoVPADNetworkClient.git
synced 2024-11-14 19:05: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
|
||||
if (getVID() == 0x57e) {
|
||||
if (getPID() == 0x2006) {
|
||||
return "Joy-Con (L) (57e:2006) on " + getIdentifier();
|
||||
return "Joy-Con (L) (0x057e:0x2006) on " + getIdentifier();
|
||||
} else if (getPID() == 0x2007) {
|
||||
return "Joy-Con (R) (57e:2007) on " + getIdentifier();
|
||||
return "Joy-Con (R) (0x057e:0x2007) on " + getIdentifier();
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
@ -41,10 +41,10 @@ public class LinuxDevInputController extends Controller implements Runnable {
|
||||
private static final byte JS_EVENT_AXIS = 0x02;
|
||||
|
||||
private DataInputStream controller;
|
||||
|
||||
|
||||
@Getter private short VID;
|
||||
@Getter private short PID;
|
||||
|
||||
|
||||
private String name;
|
||||
|
||||
private long buttonState = 0;
|
||||
@ -70,7 +70,7 @@ public class LinuxDevInputController extends Controller implements Runnable {
|
||||
e.printStackTrace();
|
||||
System.err.println("oops");
|
||||
}
|
||||
|
||||
|
||||
if (VID == 0 || PID == 0) {
|
||||
VID = ((short) (identifier.hashCode() & 0xFFFF));
|
||||
PID = ((short) ((identifier.hashCode() >> (Short.SIZE / Byte.SIZE)) & 0xFFFF));
|
||||
@ -81,29 +81,29 @@ public class LinuxDevInputController extends Controller implements Runnable {
|
||||
return true;
|
||||
}
|
||||
|
||||
//This could probably do with some cleanup
|
||||
// This could probably do with some cleanup
|
||||
public void doSysFs(String identifier) throws Exception {
|
||||
Process querySysFs = Runtime.getRuntime().exec("udevadm info -q path " + identifier);
|
||||
querySysFs.waitFor();
|
||||
|
||||
|
||||
String sysfs_path = "/sys" + Utilities.getStringFromInputStream(querySysFs.getInputStream()).trim() + "/device";
|
||||
querySysFs.destroy();
|
||||
File sysfs = new File(sysfs_path);
|
||||
if (!sysfs.exists()) return;
|
||||
|
||||
|
||||
char[] nameBuf = new char[1024];
|
||||
FileReader nameGet = new FileReader(sysfs_path + "/name");
|
||||
nameGet.read(nameBuf);
|
||||
nameGet.close();
|
||||
name = new String(nameBuf).trim();
|
||||
|
||||
|
||||
char[] vidBuf = new char[6];
|
||||
FileReader vidGet = new FileReader(sysfs_path + "/id/vendor");
|
||||
vidGet.read(vidBuf);
|
||||
vidGet.close();
|
||||
short vid = Short.parseShort(new String(vidBuf).trim(), 16);
|
||||
this.VID = vid;
|
||||
|
||||
|
||||
char[] pidBuf = new char[6];
|
||||
FileReader pidGet = new FileReader(sysfs_path + "/id/product");
|
||||
pidGet.read(pidBuf);
|
||||
@ -111,7 +111,7 @@ public class LinuxDevInputController extends Controller implements Runnable {
|
||||
short pid = Short.parseShort(new String(pidBuf).trim(), 16);
|
||||
this.PID = pid;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public byte[] pollLatestData() {
|
||||
DataInputStream inputStream = this.controller;
|
||||
@ -125,7 +125,7 @@ public class LinuxDevInputController extends Controller implements Runnable {
|
||||
type = inputStream.readByte();
|
||||
number = inputStream.readByte();
|
||||
} 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!");
|
||||
e.printStackTrace();
|
||||
System.out.println("[LinuxDevInputController] Detaching...");
|
||||
@ -169,14 +169,13 @@ public class LinuxDevInputController extends Controller implements Runnable {
|
||||
for (int i = (Long.SIZE / Byte.SIZE); i < CONTROLLER_DATA_SIZE; i++) {
|
||||
newData[i] = axisState[i - (Long.SIZE / Byte.SIZE)];
|
||||
}
|
||||
|
||||
|
||||
return newData;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doSleepAfterPollingData() {
|
||||
// This is event driven (aka pollLatestData() is blocking anyway until
|
||||
// we have data), we don't need to sleep it all.
|
||||
// This is event driven (aka pollLatestData() is blocking anyway until we have data), we don't need to sleep it all.
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -195,6 +194,6 @@ public class LinuxDevInputController extends Controller implements Runnable {
|
||||
|
||||
@Override
|
||||
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
|
||||
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
|
||||
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
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ 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.
|
||||
// Skip Xbox controller under windows. We should use XInput instead.
|
||||
if (isXboxController(info) && Settings.isWindows()) {
|
||||
continue;
|
||||
}
|
||||
@ -72,7 +72,7 @@ public class HidManager {
|
||||
public static boolean isGamepad(HidDevice info) {
|
||||
if (info == null) return false;
|
||||
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) {
|
||||
|
@ -113,7 +113,7 @@ class PureJavaHidDevice implements HidDevice, InputReportListener {
|
||||
|
||||
@Override
|
||||
public String getProductString() {
|
||||
return myDeviceInfo.getProductString();
|
||||
return myDeviceInfo.getProductString().trim();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -209,11 +209,12 @@ public final class Settings {
|
||||
public static class ControllerFiltering {
|
||||
public static enum Type {
|
||||
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),
|
||||
HIDMOUSE (2, "HID Mice", Platform.LINUX.mask),
|
||||
HIDOTHER (3, "Other HIDs", Platform.LINUX.mask | Platform.WINDOWS.mask | Platform.MAC_OS_X.mask),
|
||||
LINUX (4, "Linux controllers", Platform.LINUX.mask),
|
||||
XINPUT (5, "XInput controllers", Platform.WINDOWS.mask);
|
||||
;
|
||||
|
||||
private int index;
|
||||
@Getter private String name;
|
||||
|
@ -8,32 +8,33 @@ import net.ash.HIDToVPADNetworkClient.network.NetworkManager;
|
||||
|
||||
public class StatusReport {
|
||||
public static String generateStatusReport() {
|
||||
String report = "HID to VPAD Network Client\n\nRunning on ";
|
||||
report += Settings.getPlattform();
|
||||
StringBuilder report = new StringBuilder();
|
||||
report.append("HID to VPAD Network Client\n\nRunning on ");
|
||||
report.append(Settings.getPlattform());
|
||||
|
||||
report += "\nHID Backend: ";
|
||||
report += HidManager.getBackendType();
|
||||
report.append(System.lineSeparator()).append("HID Backend: ");
|
||||
report.append(HidManager.getBackendType());
|
||||
|
||||
report += "\nCurrently ";
|
||||
report += (NetworkManager.getInstance().isConnected()) ? "Connected.\n" : "Disconnected.\n";
|
||||
report += (NetworkManager.getInstance().isReconnecting()) ? "" : "Not ";
|
||||
report += "Reconnecting.";
|
||||
report.append(System.lineSeparator()).append("Currently ");
|
||||
report.append((NetworkManager.getInstance().isConnected()) ? "Connected.\n" : "Disconnected.").append(System.lineSeparator());
|
||||
report.append((NetworkManager.getInstance().isReconnecting()) ? "" : "Not ");
|
||||
report.append("Reconnecting.");
|
||||
|
||||
report += "\n\nCurrently attached controllers:";
|
||||
report.append(System.lineSeparator()).append(System.lineSeparator()).append("Currently attached controllers:");
|
||||
for (Controller c : ControllerManager.getAttachedControllers()) {
|
||||
report += "\n";
|
||||
report += c.toString();
|
||||
report.append(System.lineSeparator());
|
||||
report.append(c.toString());
|
||||
}
|
||||
|
||||
report += "\n\nFiltering settings:\n";
|
||||
report += Settings.ControllerFiltering.getFilterStates();
|
||||
report.append(System.lineSeparator()).append(System.lineSeparator()).append("Filtering settings:").append(System.lineSeparator());
|
||||
report.append(Settings.ControllerFiltering.getFilterStates());
|
||||
|
||||
report += "\n\nAll HIDs:";
|
||||
report.append(System.lineSeparator()).append(System.lineSeparator()).append("All HIDs:");
|
||||
for (HidDevice d : HidManager.getAllAttachedControllers()) {
|
||||
report += "\n";
|
||||
report += d.toString();
|
||||
report.append(System.lineSeparator());
|
||||
report.append(d.toString());
|
||||
}
|
||||
|
||||
return report;
|
||||
return report.toString();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user