mirror of
https://github.com/Maschell/HIDtoVPADNetworkClient.git
synced 2024-11-22 14:09:17 +01:00
Fixed the equals methods + more refactoring
This commit is contained in:
parent
1c98eaffbb
commit
d0e7928ed2
@ -92,7 +92,7 @@ public abstract class Controller implements Runnable {
|
|||||||
public byte[] getLatestData() {
|
public byte[] getLatestData() {
|
||||||
if (latestData == null) {
|
if (latestData == null) {
|
||||||
return new byte[0];
|
return new byte[0];
|
||||||
}else{
|
} else {
|
||||||
byte[] data = this.latestData.clone();
|
byte[] data = this.latestData.clone();
|
||||||
this.latestData = null;
|
this.latestData = null;
|
||||||
return data;
|
return data;
|
||||||
@ -183,7 +183,7 @@ public abstract class Controller implements Runnable {
|
|||||||
if (identifier == null) {
|
if (identifier == null) {
|
||||||
if (other.identifier != null) return false;
|
if (other.identifier != null) return false;
|
||||||
} else if (!identifier.equals(other.identifier)) return false;
|
} else if (!identifier.equals(other.identifier)) return false;
|
||||||
return (type != other.type);
|
return (type == other.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized("rumbleLock")
|
@Synchronized("rumbleLock")
|
||||||
|
@ -100,7 +100,7 @@ public class LinuxDevInputController extends Controller implements Runnable {
|
|||||||
if (value == 0) {
|
if (value == 0) {
|
||||||
// Clear bit with button number
|
// Clear bit with button number
|
||||||
buttonState &= ~(1 << number);
|
buttonState &= ~(1 << number);
|
||||||
}else{
|
} else {
|
||||||
// Set bit with button number
|
// Set bit with button number
|
||||||
buttonState |= (1 << number);
|
buttonState |= (1 << number);
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ import java.util.List;
|
|||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import lombok.Synchronized;
|
||||||
import net.ash.HIDToVPADNetworkClient.util.HandleFoundry;
|
import net.ash.HIDToVPADNetworkClient.util.HandleFoundry;
|
||||||
import net.ash.HIDToVPADNetworkClient.util.Settings;
|
import net.ash.HIDToVPADNetworkClient.util.Settings;
|
||||||
|
|
||||||
@ -46,8 +47,9 @@ public class NetworkHIDDevice {
|
|||||||
|
|
||||||
@Getter private final int hidHandle = HandleFoundry.next();
|
@Getter private final int hidHandle = HandleFoundry.next();
|
||||||
|
|
||||||
private Object readCommandLock = new Object();
|
private final Object readCommandLock = new Object();
|
||||||
@Getter(AccessLevel.PRIVATE) private final List<DeviceCommand> commands = new ArrayList<DeviceCommand>();
|
private final Object pullCommandsLock = new Object();
|
||||||
|
private final List<DeviceCommand> commands = new ArrayList<DeviceCommand>();
|
||||||
@Getter(AccessLevel.PRIVATE) @Setter(AccessLevel.PRIVATE) private ReadCommand latestRead;
|
@Getter(AccessLevel.PRIVATE) @Setter(AccessLevel.PRIVATE) private ReadCommand latestRead;
|
||||||
|
|
||||||
public NetworkHIDDevice(short vid, short pid) {
|
public NetworkHIDDevice(short vid, short pid) {
|
||||||
@ -55,10 +57,12 @@ public class NetworkHIDDevice {
|
|||||||
this.pid = pid;
|
this.pid = pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Synchronized("commands")
|
||||||
private void addCommand(DeviceCommand command) {
|
private void addCommand(DeviceCommand command) {
|
||||||
this.commands.add(command);
|
this.commands.add(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Synchronized("commands")
|
||||||
private void clearCommands() {
|
private void clearCommands() {
|
||||||
this.commands.clear();
|
this.commands.clear();
|
||||||
}
|
}
|
||||||
@ -85,17 +89,24 @@ public class NetworkHIDDevice {
|
|||||||
|
|
||||||
protected Collection<? extends DeviceCommand> getCommandList() {
|
protected Collection<? extends DeviceCommand> getCommandList() {
|
||||||
List<DeviceCommand> commands = new ArrayList<DeviceCommand>();
|
List<DeviceCommand> commands = new ArrayList<DeviceCommand>();
|
||||||
commands.addAll(getCommands());
|
synchronized (pullCommandsLock) {
|
||||||
DeviceCommand lastRead;
|
commands.addAll(getCommands());
|
||||||
|
clearCommands();
|
||||||
|
}
|
||||||
|
|
||||||
synchronized (readCommandLock) {
|
synchronized (readCommandLock) {
|
||||||
if ((lastRead = getLatestRead()) != null) {
|
DeviceCommand lastRead = getLatestRead();
|
||||||
|
if (lastRead != null) {
|
||||||
commands.add(lastRead);
|
commands.add(lastRead);
|
||||||
setLatestRead(null);
|
setLatestRead(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clearCommands();
|
return commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized("commands")
|
||||||
|
private List<DeviceCommand> getCommands() {
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,6 +124,6 @@ public class NetworkHIDDevice {
|
|||||||
if (obj == null) return false;
|
if (obj == null) return false;
|
||||||
if (getClass() != obj.getClass()) return false;
|
if (getClass() != obj.getClass()) return false;
|
||||||
NetworkHIDDevice other = (NetworkHIDDevice) obj;
|
NetworkHIDDevice other = (NetworkHIDDevice) obj;
|
||||||
return (hidHandle != other.hidHandle);
|
return (hidHandle == other.hidHandle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,9 +57,9 @@ public final class NetworkManager implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addHIDDevice(NetworkHIDDevice device) {
|
public void addHIDDevice(NetworkHIDDevice device) {
|
||||||
if (!getDevices().contains(device)) {
|
if (!devices.contains(device)) {
|
||||||
synchronized (devices) {
|
synchronized (devices) {
|
||||||
getDevices().add(device);
|
devices.add(device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,8 +40,7 @@ import net.ash.HIDToVPADNetworkClient.util.Settings;
|
|||||||
@Log
|
@Log
|
||||||
final class TCPClient {
|
final class TCPClient {
|
||||||
private final Object lock = new Object();
|
private final Object lock = new Object();
|
||||||
@Getter
|
@Getter private static TCPClient instance = new TCPClient();
|
||||||
private static TCPClient instance = new TCPClient();
|
|
||||||
private Socket sock;
|
private Socket sock;
|
||||||
private DataInputStream in;
|
private DataInputStream in;
|
||||||
private DataOutputStream out;
|
private DataOutputStream out;
|
||||||
|
@ -27,6 +27,7 @@ import java.net.DatagramSocket;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
final class UDPClient {
|
final class UDPClient {
|
||||||
private final DatagramSocket sock;
|
private final DatagramSocket sock;
|
||||||
private final InetAddress host;
|
private final InetAddress host;
|
||||||
|
Loading…
Reference in New Issue
Block a user