mirror of
https://github.com/Maschell/HIDtoVPADNetworkClient.git
synced 2024-11-22 14:09:17 +01:00
Improved behaviour if no valid config file is found.
It should show a message and deactivate the controller, but sometimes it also disconnects. I don't know if it's currently worth it to fix the disconnecting problem, as you reconnect without any problems (and need to add/create the config anyway).
This commit is contained in:
parent
7914c8d633
commit
59c328c194
@ -48,6 +48,7 @@ public abstract class Controller implements Runnable {
|
||||
|
||||
private Object rumbleLock = new Object();
|
||||
private boolean rumble = false;
|
||||
private boolean hasConfig = true; // Let's be optimistic
|
||||
|
||||
public Controller(ControllerType type, String identifier) throws ControllerInitializationFailedException {
|
||||
this.type = type;
|
||||
@ -206,4 +207,12 @@ public abstract class Controller implements Runnable {
|
||||
}
|
||||
|
||||
public abstract String getInfoText();
|
||||
|
||||
public boolean hasConfig() {
|
||||
return this.hasConfig;
|
||||
}
|
||||
|
||||
public void setHasConfig(boolean b) {
|
||||
this.hasConfig = b;
|
||||
}
|
||||
}
|
@ -33,6 +33,7 @@ import javax.swing.Timer;
|
||||
import lombok.Getter;
|
||||
import net.ash.HIDToVPADNetworkClient.controller.Controller;
|
||||
import net.ash.HIDToVPADNetworkClient.network.NetworkManager;
|
||||
import net.ash.HIDToVPADNetworkClient.util.Utilities;
|
||||
|
||||
public class GuiControllerListItem extends JPanel implements ActionListener {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ -40,6 +41,9 @@ public class GuiControllerListItem extends JPanel implements ActionListener {
|
||||
@Getter private final Controller controller;
|
||||
private JCheckBox checkbox;
|
||||
|
||||
private boolean clicked = false;
|
||||
private boolean hasConfigCache = true;
|
||||
|
||||
public GuiControllerListItem(Controller data) {
|
||||
super(new BorderLayout());
|
||||
|
||||
@ -57,6 +61,11 @@ public class GuiControllerListItem extends JPanel implements ActionListener {
|
||||
int delay = 100; // milliseconds
|
||||
ActionListener taskPerformer = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
if (hasConfigCache != controller.hasConfig()) {
|
||||
hasConfigCache = controller.hasConfig();
|
||||
checkIfDisplayNoConfigMessage();
|
||||
}
|
||||
|
||||
checkbox.setEnabled(NetworkManager.getInstance().isConnected());
|
||||
checkbox.setSelected(controller.isActive());
|
||||
}
|
||||
@ -68,8 +77,15 @@ public class GuiControllerListItem extends JPanel implements ActionListener {
|
||||
return controller.getInfoText();
|
||||
}
|
||||
|
||||
private void checkIfDisplayNoConfigMessage() {
|
||||
if (hasConfigCache == false) {
|
||||
Utilities.messageBox("No configuration for this controller found on the console.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
checkIfDisplayNoConfigMessage();
|
||||
boolean selected = ((JCheckBox) e.getSource()).isSelected();
|
||||
controller.setActive(selected);
|
||||
checkbox.setSelected(controller.isActive());
|
||||
|
@ -103,7 +103,7 @@ public class ActiveControllerManager implements Runnable {
|
||||
synchronized (activeControllers) {
|
||||
for (Controller c : toRemove) {
|
||||
NetworkManager.getInstance().removeHIDDevice(activeControllers.get(c));
|
||||
//c.destroyDriver(); Removing it from the list doesn't require to close the connection.
|
||||
// c.destroyDriver(); Removing it from the list doesn't require to close the connection.
|
||||
activeControllers.remove(c);
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ public class ControllerManager {
|
||||
public static List<Controller> getAttachedControllers() {
|
||||
return new ArrayList<Controller>(attachedControllers.values());
|
||||
}
|
||||
|
||||
|
||||
private static Map<String, ControllerType> detectHIDDevices() {
|
||||
Map<String, ControllerType> connectedDevices = new HashMap<String, ControllerType>();
|
||||
|
||||
|
@ -29,6 +29,8 @@ import java.util.List;
|
||||
import lombok.Getter;
|
||||
import lombok.Synchronized;
|
||||
import lombok.extern.java.Log;
|
||||
import net.ash.HIDToVPADNetworkClient.controller.Controller;
|
||||
import net.ash.HIDToVPADNetworkClient.manager.ActiveControllerManager;
|
||||
import net.ash.HIDToVPADNetworkClient.network.commands.AttachCommand;
|
||||
import net.ash.HIDToVPADNetworkClient.network.commands.DetachCommand;
|
||||
import net.ash.HIDToVPADNetworkClient.network.commands.DeviceCommand;
|
||||
@ -206,13 +208,20 @@ public class NetworkManager implements Runnable {
|
||||
try {
|
||||
configFound = recvTCPByte();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
log.info("Failed to get byte.");
|
||||
disconnect();
|
||||
return false;
|
||||
}
|
||||
if (configFound == Protocol.TCP_CMD_ATTACH_CONFIG_FOUND) {
|
||||
// log.info("Config on the console found!");
|
||||
} else if (configFound == Protocol.TCP_CMD_ATTACH_CONFIG_NOT_FOUND) {
|
||||
log.info("NO CONFIG FOUND.");
|
||||
return false;
|
||||
Controller c = ActiveControllerManager.getInstance().getControllerByHIDHandle(command.getSender().getHidHandle());
|
||||
if (c != null) {
|
||||
c.setHasConfig(false);
|
||||
c.setActive(false);
|
||||
}
|
||||
return true;
|
||||
} else if (configFound == 0) {
|
||||
log.info("Failed to get byte.");
|
||||
disconnect();
|
||||
|
@ -58,9 +58,9 @@ public class Protocol {
|
||||
}
|
||||
|
||||
public enum HandshakeReturnCode {
|
||||
GOOD_HANDSHAKE,BAD_HANDSHAKE
|
||||
GOOD_HANDSHAKE, BAD_HANDSHAKE
|
||||
}
|
||||
|
||||
|
||||
public static byte[] getRawAttachDataToSend(AttachCommand command) throws IOException {
|
||||
return ByteBuffer.allocate(9).put(Protocol.TCP_CMD_ATTACH).putInt(command.getHandle()).putShort(command.getVid()).putShort(command.getPid()).array();
|
||||
}
|
||||
@ -99,5 +99,5 @@ public class Protocol {
|
||||
|
||||
return bos.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -55,20 +55,20 @@ public class TCPClient {
|
||||
sock.connect(new InetSocketAddress(ip, Protocol.TCP_PORT), 2000);
|
||||
in = new DataInputStream(sock.getInputStream());
|
||||
out = new DataOutputStream(sock.getOutputStream());
|
||||
|
||||
HandshakeReturnCode resultHandshake = HandshakeReturnCode.GOOD_HANDSHAKE;
|
||||
if (recvByte() != Protocol.TCP_HANDSHAKE) resultHandshake = HandshakeReturnCode.BAD_HANDSHAKE;
|
||||
|
||||
|
||||
HandshakeReturnCode resultHandshake = HandshakeReturnCode.GOOD_HANDSHAKE;
|
||||
if (recvByte() != Protocol.TCP_HANDSHAKE) resultHandshake = HandshakeReturnCode.BAD_HANDSHAKE;
|
||||
|
||||
if (resultHandshake == HandshakeReturnCode.GOOD_HANDSHAKE) {
|
||||
ActiveControllerManager.getInstance().attachAllActiveControllers();
|
||||
this.ip = ip;
|
||||
shouldRetry = 0;
|
||||
}else{
|
||||
} else {
|
||||
log.info("[TCP] Handshaking failed");
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public synchronized boolean abort() {
|
||||
try {
|
||||
shouldRetry = Settings.MAXIMUM_TRIES_FOR_RECONNECTING;
|
||||
@ -104,12 +104,7 @@ public class TCPClient {
|
||||
}
|
||||
|
||||
public synchronized byte recvByte() throws IOException {
|
||||
try {
|
||||
return in.readByte();
|
||||
} catch (IOException e) {
|
||||
log.info(e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
return in.readByte();
|
||||
}
|
||||
|
||||
public synchronized short recvShort() throws IOException {
|
||||
|
@ -58,10 +58,10 @@ public class PureJavaHidApiManager {
|
||||
|
||||
if (Settings.isMacOSX()) real_path = real_path.substring(0, 13);
|
||||
|
||||
if (real_path.equals(expected_path)){
|
||||
if (real_path.equals(expected_path)) {
|
||||
return PureJavaHidApi.openDevice(info);
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,9 @@
|
||||
*******************************************************************************/
|
||||
package net.ash.HIDToVPADNetworkClient.util;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
public class Utilities {
|
||||
|
||||
private Utilities() {
|
||||
@ -76,4 +79,8 @@ public class Utilities {
|
||||
public static short signedShortToByte(short value) {
|
||||
return signedShortToByte((int) value);
|
||||
}
|
||||
|
||||
public static void messageBox(String string) {
|
||||
JOptionPane.showMessageDialog(new JFrame(), string);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user