mirror of
https://github.com/Maschell/HIDtoVPADNetworkClient.git
synced 2024-11-25 23:34:15 +01:00
Fixed bug with the connecting when auto activating is enabled
- Force the controller to send their data once after they connected. - Limiting the maximum handle size to (2^15)-1.
This commit is contained in:
parent
72fd042a3a
commit
5f9da81af9
@ -31,6 +31,7 @@ import lombok.extern.java.Log;
|
||||
import net.ash.HIDToVPADNetworkClient.controller.Controller;
|
||||
import net.ash.HIDToVPADNetworkClient.network.NetworkHIDDevice;
|
||||
import net.ash.HIDToVPADNetworkClient.network.NetworkManager;
|
||||
import net.ash.HIDToVPADNetworkClient.network.TCPClient;
|
||||
import net.ash.HIDToVPADNetworkClient.util.Settings;
|
||||
import net.ash.HIDToVPADNetworkClient.util.Utilities;
|
||||
|
||||
@ -113,7 +114,8 @@ public class ActiveControllerManager implements Runnable {
|
||||
synchronized (activeControllers) {
|
||||
for (Controller c : toAdd) {
|
||||
NetworkHIDDevice hiddevice = new NetworkHIDDevice(c.getVID(), c.getPID());
|
||||
hiddevice.sendAttach();
|
||||
if (NetworkManager.getInstance().isConnected()) hiddevice.sendAttach(); // Only send the attach when we're connected. Because on connecting the
|
||||
// TCPClient will automatically attach all active controller
|
||||
NetworkManager.getInstance().addHIDDevice(hiddevice);
|
||||
activeControllers.put(c, hiddevice);
|
||||
}
|
||||
@ -141,6 +143,15 @@ public class ActiveControllerManager implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
public void detachAllActiveControllers() {
|
||||
synchronized (activeControllers) {
|
||||
for (Entry<Controller, NetworkHIDDevice> entry : activeControllers.entrySet()) {
|
||||
NetworkHIDDevice device = entry.getValue();
|
||||
device.sendDetach();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param HIDhandle
|
||||
@ -154,4 +165,5 @@ public class ActiveControllerManager implements Runnable {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,6 +43,8 @@ public class NetworkHIDDevice {
|
||||
@Getter @Setter private short deviceslot;
|
||||
@Getter @Setter private byte padslot;
|
||||
|
||||
@Getter @Setter private boolean needFirstData = false;
|
||||
|
||||
@Getter private int hidHandle = HandleFoundry.next();
|
||||
@Getter(AccessLevel.PRIVATE) private List<DeviceCommand> commands = new ArrayList<DeviceCommand>();
|
||||
|
||||
@ -74,11 +76,14 @@ public class NetworkHIDDevice {
|
||||
private byte[] lastdata = null;
|
||||
|
||||
public void sendRead(byte[] data) {
|
||||
if (!Arrays.equals(lastdata, data)) {
|
||||
if (!Arrays.equals(lastdata, data) || isNeedFirstData()) {
|
||||
synchronized (readCommandLock) {
|
||||
setLatestRead(new ReadCommand(getHidHandle(), data, this)); // Only get the latest Value.
|
||||
}
|
||||
lastdata = data.clone();
|
||||
if (isNeedFirstData()) {
|
||||
setNeedFirstData(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -262,11 +262,12 @@ public class NetworkManager implements Runnable {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Let's save them for later.
|
||||
// Let's save them for later and demand the first data packet.
|
||||
NetworkHIDDevice sender = command.getSender();
|
||||
if (sender != null) {
|
||||
sender.setDeviceslot(deviceslot);
|
||||
sender.setPadslot(padslot);
|
||||
sender.setNeedFirstData(true); // Please send data after connecting.
|
||||
} else {
|
||||
log.info("Something really went wrong. Got an attach event with out an " + NetworkHIDDevice.class.getSimpleName());
|
||||
return false;
|
||||
|
@ -29,7 +29,7 @@ import java.util.Random;
|
||||
|
||||
public class HandleFoundry {
|
||||
// We start with a random value, so we have at each startup a different clientID!
|
||||
private static int h = new Random().nextInt(100000);
|
||||
private static int h = new Random().nextInt(Short.MAX_VALUE);
|
||||
|
||||
private HandleFoundry() {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user