Skip to content

Commit

Permalink
Log Operating System details and present controllers on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
bwRavencl committed May 25, 2024
1 parent b29ebd4 commit 4e7ad00
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 25 deletions.
20 changes: 15 additions & 5 deletions src/main/java/de/bwravencl/controllerbuddy/gui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -970,11 +970,17 @@ public void windowOpened(final WindowEvent e) {

final var presentControllers = taskRunner.run(Main::getPresentControllers);
if (presentControllers != null && !presentControllers.isEmpty()) {
log.log(Level.INFO,
"Present controllers:" + presentControllers.stream()
.map(controllerInfo -> assembleControllerLoggingMessage("\n\t", controllerInfo))
.collect(Collectors.joining()));

final var lastControllerGuid = preferences.get(PREFERENCES_LAST_CONTROLLER, null);
if (lastControllerGuid != null) {
presentControllers.stream().filter(controller -> lastControllerGuid.equals(controller.guid)).findFirst()
.ifPresentOrElse(controller -> {
log.log(Level.INFO, assembleControllerLoggingMessage("Found previously used", controller));
log.log(Level.INFO,
assembleControllerLoggingMessage("Found previously used controller ", controller));
setSelectedController(controller);
}, () -> {
log.log(Level.INFO, "Previously used controller is not present");
Expand All @@ -997,7 +1003,8 @@ public void windowOpened(final WindowEvent e) {
if (disconnected || GLFW.glfwJoystickIsGamepad(jid)) {
if (disconnected && presentControllers != null
&& presentControllers.stream().anyMatch(controller -> controller.jid == jid)) {
log.log(Level.INFO, assembleControllerLoggingMessage("Disconnected", new ControllerInfo(jid)));
log.log(Level.INFO,
assembleControllerLoggingMessage("Disconnected controller ", new ControllerInfo(jid)));

if (selectedController != null && selectedController.jid == jid) {
if (!isMac) {
Expand All @@ -1006,7 +1013,8 @@ public void windowOpened(final WindowEvent e) {
input.deInit(true);
}
} else if (event == GLFW.GLFW_CONNECTED) {
log.log(Level.INFO, assembleControllerLoggingMessage("Connected", new ControllerInfo(jid)));
log.log(Level.INFO,
assembleControllerLoggingMessage("Connected controller ", new ControllerInfo(jid)));
}

EventQueue.invokeLater(() -> onControllersChanged(getPresentControllers(), false));
Expand Down Expand Up @@ -1051,7 +1059,7 @@ private static void addGlueToSettingsPanel(final JPanel settingsPanel) {

public static String assembleControllerLoggingMessage(final String prefix, final ControllerInfo controller) {
final var sb = new StringBuilder();
sb.append(prefix).append(" controller ");
sb.append(prefix);

final var appendGamepadName = controller.name != null;

Expand Down Expand Up @@ -1163,6 +1171,8 @@ private static boolean isModalDialogShowing() {

public static void main(final String[] args) {
log.log(Level.INFO, "Launching " + Metadata.APPLICATION_NAME + " " + Metadata.VERSION);
log.log(Level.INFO, "Operating System: " + System.getProperty("os.name") + " "
+ System.getProperty("os.version") + " " + System.getProperty("os.arch"));

Thread.setDefaultUncaughtExceptionHandler((_, e) -> {
log.log(Level.SEVERE, e.getMessage(), e);
Expand Down Expand Up @@ -2379,7 +2389,7 @@ private void setSelectedController(final ControllerInfo controller) {
selectedController = controller;

if (controller != null) {
log.log(Level.INFO, assembleControllerLoggingMessage("Selected controller", controller));
log.log(Level.INFO, assembleControllerLoggingMessage("Selected controller ", controller));

if (controller.guid != null) {
preferences.put(PREFERENCES_LAST_CONTROLLER, controller.guid);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/bwravencl/controllerbuddy/input/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ public boolean poll() {
if (state.buttons(hotSwappingButtonId) != 0) {
hotSwappingButtonDownJids.add(controller.jid());
} else if (hotSwappingButtonDownJids.contains(controller.jid())) {
log.log(Level.INFO,
Main.assembleControllerLoggingMessage("Initiating hot swap to ", controller));
log.log(Level.INFO, Main.assembleControllerLoggingMessage(
"Initiating hot swap to controller ", controller));

hotSwappingButtonId = HotSwappingButton.None.id;
EventQueue.invokeLater(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private EvdevDriver(final Input input, final ControllerInfo controller, final Ev
strongRumbleEffectId = createRumbleEffect((short) 90);
lightRumbleEffectId = createRumbleEffect((short) 60);

log.log(Level.INFO, Main.assembleControllerLoggingMessage("Using evdev driver for controller", controller));
log.log(Level.INFO, Main.assembleControllerLoggingMessage("Using evdev driver for controller ", controller));
}

private static void closeFileDescriptor(final int fd) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ private XInputDriver(final Input input, final ControllerInfo controller) throws
}

log.log(Level.INFO,
Main.assembleControllerLoggingMessage(
"Using XInput " + XInputDevice.getLibraryVersion().name().substring("XINPUT_".length())
.replace('_', '.') + " controller with ID " + xinputDevice.getPlayerNum() + " as",
controller));
Main.assembleControllerLoggingMessage("Using XInput controller "
+ XInputDevice.getLibraryVersion().name().substring("XINPUT_".length()).replace('_', '.')
+ " controller with ID " + xinputDevice.getPlayerNum() + " as", controller));
}

private static boolean isXInputController(final ControllerInfo controller) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,12 @@ public abstract class SonyDriver extends Driver implements IGamepadStateProvider
final var reportId = reportData[0];
if (reportId != connection.inputReportId || (bluetooth ? reportLength < BLUETOOTH_REPORT_LENGTH
: reportLength != USB_REPORT_LENGTH)) {
getLogger().log(Level.WARNING,
Main.assembleControllerLoggingMessage("Received unexpected HID input report with ID "
+ reportId + " and length " + reportLength + " from", controller));
getLogger()
.log(Level.WARNING,
Main.assembleControllerLoggingMessage(
"Received unexpected HID input report with ID " + reportId
+ " and length " + reportLength + " from controller ",
controller));

continue;
}
Expand All @@ -168,7 +171,7 @@ public abstract class SonyDriver extends Driver implements IGamepadStateProvider

if (receivedCrc32Value != calculatedCrc32Value) {
getLogger().log(Level.WARNING, Main.assembleControllerLoggingMessage(
"Received faulty HID input report from", controller));
"Received faulty HID input report from controller ", controller));
continue;
}
}
Expand Down Expand Up @@ -362,15 +365,15 @@ static HidDevice getHidDevice(final List<ControllerInfo> presentControllers,
final var hidDevice = devices.get(deviceIndex);

if (!hidDevice.open()) {
log.log(Level.WARNING, Main.assembleControllerLoggingMessage("Could not open HID device "
+ humanReadableName + " with path " + hidDevice.getPath() + " to use as", selectedController));
log.log(Level.WARNING,
Main.assembleControllerLoggingMessage("Could not open HID device " + humanReadableName
+ " with path " + hidDevice.getPath() + " to use as controller ", selectedController));
return null;
}

log.log(Level.INFO,
Main.assembleControllerLoggingMessage(
"Using " + humanReadableName + " controller with path " + hidDevice.getPath() + " as",
selectedController));
log.log(Level.INFO, Main.assembleControllerLoggingMessage(
"Using " + humanReadableName + " controller with path " + hidDevice.getPath() + " as controller ",
selectedController));

hidServices = null;
return hidDevice;
Expand Down Expand Up @@ -444,7 +447,7 @@ public boolean getGamepadState(final GLFWGamepadState state) {

if (System.currentTimeMillis() - lastInputReportTime > INPUT_REPORT_TIMEOUT) {
getLogger().log(Level.WARNING, Main.assembleControllerLoggingMessage(
"No new input report for more than " + INPUT_REPORT_TIMEOUT + " ms from", controller));
"No new input report for more than " + INPUT_REPORT_TIMEOUT + " ms from controller ", controller));

return false;
}
Expand Down Expand Up @@ -584,7 +587,7 @@ boolean sendHidReport() {

if (!success) {
getLogger().log(Level.WARNING,
Main.assembleControllerLoggingMessage("Error while sending HID packet to", controller));
Main.assembleControllerLoggingMessage("Error while sending HID packet to controller ", controller));
}

return success;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ final void controllerDisconnected() {

Thread.startVirtualThread(() -> main.stopAll(true, !main.isAutoRestartOutput(), true));

log.log(Level.WARNING, Main.assembleControllerLoggingMessage("Could not read from", input.getController()));
log.log(Level.WARNING,
Main.assembleControllerLoggingMessage("Could not read from controller ", input.getController()));
if (!main.isSkipControllerDialogs()) {
EventQueue.invokeLater(() -> GuiUtils.showMessageDialog(main, main.getFrame(),
Main.strings.getString("COULD_NOT_READ_FROM_CONTROLLER_DIALOG_TEXT"),
Expand Down

0 comments on commit 4e7ad00

Please sign in to comment.