Skip to content

Commit

Permalink
Merge pull request #8 from oci-labs/JNA550
Browse files Browse the repository at this point in the history
Bug fix in setOutputReport
  • Loading branch information
kuznetsovmoci authored Dec 13, 2019
2 parents 655530b + 065e8b8 commit f98da3a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Binary file modified bin/purejavahidapi-src.jar
Binary file not shown.
Binary file modified bin/purejavahidapi.jar
Binary file not shown.
14 changes: 9 additions & 5 deletions src/purejavahidapi/windows/HidDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Arrays;

public class HidDevice extends purejavahidapi.HidDevice {
private WindowsBackend m_Backend;
Expand All @@ -73,6 +74,7 @@ public class HidDevice extends purejavahidapi.HidDevice {
private SyncPoint m_SyncShutdown;
private boolean m_StopThread;
private boolean m_ForceControlOutput;
private byte[] m_OutputReportArray;

/* package */ HidDevice(purejavahidapi.HidDeviceInfo deviceInfo, WindowsBackend backend) {
HANDLE handle = WindowsBackend.openDeviceHandle(deviceInfo.getPath(), false);
Expand Down Expand Up @@ -100,8 +102,10 @@ public class HidDevice extends purejavahidapi.HidDevice {
return;
}
m_OutputReportLength = caps.OutputReportByteLength;
if (m_OutputReportLength > 0)
if (m_OutputReportLength > 0) {
m_OutputReportMemory = new Memory(m_OutputReportLength);
m_OutputReportArray = new byte[m_OutputReportLength];
}
m_OutputReportOverlapped = new OVERLAPPED();
m_OutputReportBytesWritten = new int[] {
0
Expand Down Expand Up @@ -161,9 +165,9 @@ synchronized public int setOutputReport(byte reportID, byte[] data, int length)
throw new IllegalArgumentException("this device supports no output reports");
// In Windows writeFile() to HID device data has to be preceded with the report
// number, regardless
byte[] abOutput = new byte[length + 1];
abOutput[0] = reportID;
System.arraycopy(data, 0, abOutput, 1, length);
Arrays.fill(m_OutputReportArray, (byte)0);
m_OutputReportArray[0] = reportID;
System.arraycopy(data, 0, m_OutputReportArray, 1, length);


if (!m_ForceControlOutput) {
Expand All @@ -175,7 +179,7 @@ synchronized public int setOutputReport(byte reportID, byte[] data, int length)

// In windows always attempt to write as many bytes as there are in the longest
// report plus one for the report number (even if zero ie not used)
if (!Kernel32.INSTANCE.WriteFile(m_Handle, abOutput, m_OutputReportLength, null, m_OutputReportOverlapped)) {
if (!Kernel32.INSTANCE.WriteFile(m_Handle, m_OutputReportArray, m_OutputReportLength, null, m_OutputReportOverlapped)) {
if (Kernel32.INSTANCE.GetLastError() != ERROR_IO_PENDING) {
// WriteFile() failed. Return error.
// register_error(dev, "WriteFile");
Expand Down

0 comments on commit f98da3a

Please sign in to comment.