Skip to content

Commit

Permalink
Merge pull request qzind#732 from qzind/jna-update
Browse files Browse the repository at this point in the history
Update JNA to 5.6.0
  • Loading branch information
tresf authored Dec 4, 2020
2 parents 69aa15b + 3d79db3 commit 59b8116
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 30 deletions.
Binary file removed lib/communication/hid4java-0.5.0-qz.jar
Binary file not shown.
Binary file added lib/communication/hid4java-0.7.0.jar
Binary file not shown.
Binary file removed lib/communication/jna-4.5.2.jar
Binary file not shown.
Binary file added lib/communication/jna-5.6.0.jar
Binary file not shown.
Binary file not shown.
Binary file removed lib/communication/purejavahidapi-0.0.1-1.jar
Binary file not shown.
Binary file not shown.
18 changes: 9 additions & 9 deletions src/qz/communication/DeviceOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public static DeviceMode parse(String callName) {

private DeviceMode deviceMode;

private Short vendorId;
private Short productId;
private Integer vendorId;
private Integer productId;

//usb specific
private Byte interfaceId;
Expand All @@ -34,14 +34,14 @@ public static DeviceMode parse(String callName) {
private int responseSize;

//hid specific
private Short usagePage;
private Integer usagePage;
private String serial;

public DeviceOptions(JSONObject parameters, DeviceMode deviceMode) {
this.deviceMode = deviceMode;

vendorId = UsbUtilities.hexToShort(parameters.optString("vendorId"));
productId = UsbUtilities.hexToShort(parameters.optString("productId"));
vendorId = UsbUtilities.hexToInt(parameters.optString("vendorId"));
productId = UsbUtilities.hexToInt(parameters.optString("productId"));

if (!parameters.isNull("interface")) {
interfaceId = UsbUtilities.hexToByte(parameters.optString("interface"));
Expand All @@ -55,19 +55,19 @@ public DeviceOptions(JSONObject parameters, DeviceMode deviceMode) {
responseSize = parameters.optInt("responseSize");

if (!parameters.isNull("usagePage")) {
usagePage = UsbUtilities.hexToShort(parameters.optString("usagePage"));
usagePage = UsbUtilities.hexToInt(parameters.optString("usagePage"));
}
if (!parameters.isNull("serial")) {
serial = parameters.optString("serial", "");
serial = serial.isEmpty() ? null : serial;
}
}

public Short getVendorId() {
public Integer getVendorId() {
return vendorId;
}

public Short getProductId() {
public Integer getProductId() {
return productId;
}

Expand All @@ -87,7 +87,7 @@ public int getResponseSize() {
return responseSize;
}

public Short getUsagePage() {
public Integer getUsagePage() {
return usagePage;
}

Expand Down
2 changes: 1 addition & 1 deletion src/qz/communication/H4J_HidIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class H4J_HidIO implements DeviceIO {


public H4J_HidIO(DeviceOptions dOpts) throws DeviceException {
this(H4J_HidUtilities.findDevice(dOpts.getVendorId(), dOpts.getProductId(), dOpts.getUsagePage(), dOpts.getSerial()));
this(H4J_HidUtilities.findDevice(dOpts));
}

public H4J_HidIO(HidDevice device) throws DeviceException {
Expand Down
2 changes: 1 addition & 1 deletion src/qz/communication/H4J_HidListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private StreamEvent createStreamAction(HidDevice device, String action) {

@Override
public void close() {
HidManager.getHidServices().removeUsbServicesListener(this);
HidManager.getHidServices().removeHidServicesListener(this);
}

}
11 changes: 5 additions & 6 deletions src/qz/communication/H4J_HidUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,18 @@ public static JSONArray getHidDevicesJSON() throws JSONException {
return devicesJSON;
}


public static HidDevice findDevice(Short vendorId, Short productId, Short usagePage, String serial) {
if (vendorId == null) {
public static HidDevice findDevice(DeviceOptions dOpts) {
if (dOpts.getVendorId() == null) {
throw new IllegalArgumentException("Vendor ID cannot be null");
}
if (productId == null) {
if (dOpts.getProductId() == null) {
throw new IllegalArgumentException("Product ID cannot be null");
}

List<HidDevice> devices = getHidDevices();
for(HidDevice device : devices) {
if (device.isVidPidSerial(vendorId, productId, serial)
&& (usagePage == null || usagePage == (short)device.getUsagePage())) {
if (device.isVidPidSerial(dOpts.getVendorId(), dOpts.getProductId(), dOpts.getSerial())
&& (dOpts.getUsagePage() == null || dOpts.getUsagePage() == device.getUsagePage())) {
return device;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/qz/communication/PJHA_HidIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class PJHA_HidIO implements DeviceIO {


public PJHA_HidIO(DeviceOptions dOpts) throws DeviceException {
this(PJHA_HidUtilities.findDevice(dOpts.getVendorId(), dOpts.getProductId(), dOpts.getUsagePage(), dOpts.getSerial()));
this(PJHA_HidUtilities.findDevice(dOpts));
}

public PJHA_HidIO(HidDeviceInfo deviceInfo) throws DeviceException {
Expand Down
4 changes: 3 additions & 1 deletion src/qz/communication/PJHA_HidListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ private StreamEvent createStreamAction(HidDevice device, String action) {

@Override
public void close() {
device.setDeviceRemovalListener(null);
if (device != null) {
device.setDeviceRemovalListener(null);
}
}

@Override
Expand Down
12 changes: 6 additions & 6 deletions src/qz/communication/PJHA_HidUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ public static JSONArray getHidDevicesJSON() throws JSONException {
return devicesJSON;
}

public static HidDeviceInfo findDevice(Short vendorId, Short productId, Short usagePage, String serial) {
if (vendorId == null) {
public static HidDeviceInfo findDevice(DeviceOptions dOpts) {
if (dOpts.getVendorId() == null) {
throw new IllegalArgumentException("Vendor ID cannot be null");
}
if (productId == null) {
if (dOpts.getProductId() == null) {
throw new IllegalArgumentException("Product ID cannot be null");
}


List<HidDeviceInfo> devList = PureJavaHidApi.enumerateDevices();
for(HidDeviceInfo device : devList) {
if (device.getVendorId() == vendorId && device.getProductId() == productId
&& (usagePage == null || usagePage == device.getUsagePage())
&& (serial == null || serial.equals(device.getSerialNumberString()))) {
if (device.getVendorId() == dOpts.getVendorId().shortValue() && device.getProductId() == dOpts.getProductId().shortValue()
&& (dOpts.getUsagePage() == null || dOpts.getUsagePage().shortValue() == device.getUsagePage())
&& (dOpts.getSerial() == null || dOpts.getSerial().equals(device.getSerialNumberString()))) {
return device;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/qz/communication/UsbIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class UsbIO implements DeviceIO {


public UsbIO(DeviceOptions dOpts) throws DeviceException {
UsbDevice device = UsbUtilities.findDevice(dOpts.getVendorId(), dOpts.getProductId());
UsbDevice device = UsbUtilities.findDevice(dOpts.getVendorId().shortValue(), dOpts.getProductId().shortValue());

if (device == null) {
throw new DeviceException("USB device could not be found");
Expand Down
8 changes: 4 additions & 4 deletions src/qz/utils/UsbUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ public class UsbUtilities {

private static final Logger log = LoggerFactory.getLogger(UsbUtilities.class);

public static Short hexToShort(String hex) {
public static Integer hexToInt(String hex) {
if (hex == null || hex.isEmpty()) {
return null;
}

if (hex.startsWith("0x")) { hex = hex.substring(2); }
return (short)Integer.parseInt(hex, 16);
return Integer.parseInt(hex, 16);
}

public static Byte hexToByte(String hex) {
Expand Down Expand Up @@ -132,7 +132,7 @@ public static List getDeviceInterfaces(Short vendorId, Short productId) throws D
public static JSONArray getDeviceInterfacesJSON(DeviceOptions dOpts) throws DeviceException {
JSONArray ifaceJSON = new JSONArray();

List ifaces = getDeviceInterfaces(dOpts.getVendorId(), dOpts.getProductId());
List ifaces = getDeviceInterfaces(dOpts.getVendorId().shortValue(), dOpts.getProductId().shortValue());
for(Object o : ifaces) {
UsbInterface iface = (UsbInterface)o;
UsbInterfaceDescriptor desc = iface.getUsbInterfaceDescriptor();
Expand All @@ -154,7 +154,7 @@ public static List getInterfaceEndpoints(Short vendorId, Short productId, Byte i
public static JSONArray getInterfaceEndpointsJSON(DeviceOptions dOpts) throws DeviceException {
JSONArray endJSON = new JSONArray();

List endpoints = getInterfaceEndpoints(dOpts.getVendorId(), dOpts.getProductId(), dOpts.getInterfaceId());
List endpoints = getInterfaceEndpoints(dOpts.getVendorId().shortValue(), dOpts.getProductId().shortValue(), dOpts.getInterfaceId());
for(Object o : endpoints) {
UsbEndpoint endpoint = (UsbEndpoint)o;
UsbEndpointDescriptor desc = endpoint.getUsbEndpointDescriptor();
Expand Down

0 comments on commit 59b8116

Please sign in to comment.