Java 1.6; Mac OSX fixes

This commit is contained in:
Ash 2017-03-21 20:42:26 +11:00
parent ee1ea6ed74
commit 8dffdb84fa
8 changed files with 55 additions and 28 deletions

View File

@ -22,8 +22,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- Generate a jar with dependencies -->

View File

@ -68,7 +68,7 @@ public class GuiControllerList extends JPanel {
List<GuiControllerListItem> newComponents = new ArrayList<GuiControllerListItem>();
Map<Controller,GuiControllerListItem> components = new HashMap<>();
Map<Controller,GuiControllerListItem> components = new HashMap<Controller,GuiControllerListItem>();
for (Component component : innerScrollPanel.getComponents()) {
if (component instanceof GuiControllerListItem) {
GuiControllerListItem comp = (GuiControllerListItem) component;

View File

@ -69,12 +69,12 @@ public class ActiveControllerManager implements Runnable{
}).start();
}
private Map<Controller,NetworkHIDDevice> activeControllers = new HashMap<>();
private Map<Controller,NetworkHIDDevice> activeControllers = new HashMap<Controller,NetworkHIDDevice>();
public void updateControllerStates() {
List<Controller> currentControllers = ControllerManager.getActiveControllers();
List<Controller> toAdd = new ArrayList<>();
List<Controller> toRemove = new ArrayList<>();
List<Controller> toAdd = new ArrayList<Controller>();
List<Controller> toRemove = new ArrayList<Controller>();
synchronized (activeControllers) {
//Adding all missing.

View File

@ -43,11 +43,12 @@ import net.ash.HIDToVPADNetworkClient.controller.XInput13Controller;
import net.ash.HIDToVPADNetworkClient.controller.XInput14Controller;
import net.ash.HIDToVPADNetworkClient.controller.XInputController;
import net.ash.HIDToVPADNetworkClient.exeption.ControllerInitializationFailedException;
import net.ash.HIDToVPADNetworkClient.util.PureJavaHidApiManager;
import purejavahidapi.HidDeviceInfo;
import purejavahidapi.PureJavaHidApi;
public class ControllerManager{
private static Map<String,Controller> attachedControllers = new HashMap<>();
private static Map<String,Controller> attachedControllers = new HashMap<String,Controller>();
/**
* Detects all attached controller.
@ -57,7 +58,7 @@ public class ControllerManager{
String os = System.getProperty("os.name");
//System.out.println("[ControllerDetector] OS: " + os);
Map<String,ControllerType> connectedDevices = new HashMap<>();
Map<String,ControllerType> connectedDevices = new HashMap<String,ControllerType>();
if (os.contains("Linux")) {
connectedDevices.putAll(detectLinuxControllers());
@ -65,10 +66,16 @@ public class ControllerManager{
connectedDevices.putAll(detectWindowsControllers());
}
if (os.contains("Mac OS X")) {
connectedDevices.putAll(detectOSXHIDDevices());
PureJavaHidApiManager.MAC_OS_X = true;
} else {
connectedDevices.putAll(detectHIDDevices());
PureJavaHidApiManager.MAC_OS_X = false;
}
//Remove detached devices
List<String> toRemove = new ArrayList<>();
List<String> toRemove = new ArrayList<String>();
for(String s : attachedControllers.keySet()){
if(!connectedDevices.containsKey(s)){
toRemove.add(s);
@ -135,11 +142,11 @@ public class ControllerManager{
@Synchronized("attachedControllers")
public static List<Controller> getAttachedControllers() {
return new ArrayList<>(attachedControllers.values());
return new ArrayList<Controller>(attachedControllers.values());
}
private static Map<String, ControllerType> detectHIDDevices() {
Map<String,ControllerType> connectedDevices = new HashMap<>();
Map<String,ControllerType> connectedDevices = new HashMap<String,ControllerType>();
for (HidDeviceInfo info : PureJavaHidApi.enumerateDevices()) {
if(info.getUsagePage() == 0x05 || info.getUsagePage() == 0x04 || (info.getVendorId() == 0x57e) || (info.getVendorId() == 0x054c) ){
@ -150,8 +157,20 @@ public class ControllerManager{
return connectedDevices;
}
private static Map<String, ControllerType> detectOSXHIDDevices() {
Map<String,ControllerType> connectedDevices = new HashMap<String,ControllerType>();
for (HidDeviceInfo info : PureJavaHidApi.enumerateDevices()) {
if(info.getUsagePage() == 0x05 || info.getUsagePage() == 0x04 || (info.getVendorId() == 0x57e) || (info.getVendorId() == 0x054c) ){
connectedDevices.put(info.getPath().substring(0, 13),ControllerType.PureJAVAHid);
}
}
return connectedDevices;
}
private static Map<String, ControllerType> detectWindowsControllers() {
Map<String,ControllerType> result = new HashMap<>();
Map<String,ControllerType> result = new HashMap<String,ControllerType>();
ControllerType type = ControllerType.XINPUT13;
if(XInputDevice.isAvailable() || XInputDevice14.isAvailable()) {
if(XInputDevice14.isAvailable()){
@ -175,7 +194,7 @@ public class ControllerManager{
}
private static Map<String, ControllerType> detectLinuxControllers() {
Map<String,ControllerType> result = new HashMap<>();
Map<String,ControllerType> result = new HashMap<String,ControllerType>();
File devInput = new File("/dev/input");
if (!devInput.exists()) return result;
@ -194,7 +213,7 @@ public class ControllerManager{
@Synchronized("attachedControllers")
public static List<Controller> getActiveControllers() {
List<Controller> active = new ArrayList<>();
List<Controller> active = new ArrayList<Controller>();
for(Controller c : attachedControllers.values()){
if(c.isActive()){
active.add(c);

View File

@ -45,7 +45,7 @@ public class NetworkHIDDevice {
@Getter @Setter private byte padslot;
@Getter private int hidHandle = HandleFoundry.next();
@Getter(AccessLevel.PRIVATE) private List<DeviceCommand> commands = new ArrayList<>();
@Getter(AccessLevel.PRIVATE) private List<DeviceCommand> commands = new ArrayList<DeviceCommand>();
@Getter(AccessLevel.PRIVATE) @Setter(AccessLevel.PRIVATE) private ReadCommand latestRead;
@ -83,7 +83,7 @@ public class NetworkHIDDevice {
}
public Collection<? extends DeviceCommand> getCommandList() {
List<DeviceCommand> commands = new ArrayList<>();
List<DeviceCommand> commands = new ArrayList<DeviceCommand>();
commands.addAll(getCommands());
DeviceCommand lastRead;

View File

@ -43,7 +43,7 @@ public class NetworkManager implements Runnable{
private static NetworkManager instance = null;
private List<DeviceCommand> ownCommands = new ArrayList<>();
private List<DeviceCommand> ownCommands = new ArrayList<DeviceCommand>();
private NetworkManager() {
@ -56,7 +56,7 @@ public class NetworkManager implements Runnable{
return instance;
}
@Getter private List<NetworkHIDDevice> devices = new ArrayList<>();
@Getter private List<NetworkHIDDevice> devices = new ArrayList<NetworkHIDDevice>();
public void addHIDDevice(NetworkHIDDevice device){
if(!getDevices().contains(device)){
@ -69,7 +69,7 @@ public class NetworkManager implements Runnable{
/*
* We want to remove them at the end of a cycle. To make sure the detach was send before removing.
*/
@Getter private List<NetworkHIDDevice> toRemove = new ArrayList<>();
@Getter private List<NetworkHIDDevice> toRemove = new ArrayList<NetworkHIDDevice>();
@Synchronized("toRemove")
public void removeHIDDevice(NetworkHIDDevice device) {
device.sendDetach();
@ -94,7 +94,7 @@ public class NetworkManager implements Runnable{
}
public void proccessCommands(){
List<DeviceCommand> commands = new ArrayList<>();
List<DeviceCommand> commands = new ArrayList<DeviceCommand>();
commands.addAll(ownCommands); //TODO: Does this need a synchronized block? It _should_ be only access from this thread. Need to think about it
ownCommands.clear();
synchronized (toRemove) {
@ -108,7 +108,7 @@ public class NetworkManager implements Runnable{
if(commands.isEmpty())return;
//Split up into "read commands" and other commands.
List<ReadCommand> readCommands = new ArrayList<>();
List<ReadCommand> readCommands = new ArrayList<ReadCommand>();
{
for(DeviceCommand command : commands){
if(command instanceof ReadCommand){

View File

@ -25,11 +25,11 @@
package net.ash.HIDToVPADNetworkClient.util;
import java.util.concurrent.ThreadLocalRandom;
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 = ThreadLocalRandom.current().nextInt(1, 10000);
private static int h = new Random().nextInt();
private HandleFoundry(){}

View File

@ -32,6 +32,8 @@ public class PureJavaHidApiManager {
private PureJavaHidApiManager(){}
public static boolean MAC_OS_X;
/**
* Searches the corresponding HIDDevice for the given path
* @param path Path of the HIDDevice
@ -41,10 +43,16 @@ public class PureJavaHidApiManager {
public static HidDevice getDeviceByPath(String path) throws IOException{
List<HidDeviceInfo> devList = PureJavaHidApi.enumerateDevices();
for (HidDeviceInfo info : devList) {
if (MAC_OS_X) {
if(info.getPath().substring(0, 13).equals(path)){
return PureJavaHidApi.openDevice(info);
}
} else {
if(info.getPath().equals(path)){
return PureJavaHidApi.openDevice(info);
}
}
}
return null;
}
}