Skip to content

Commit

Permalink
Merge pull request #3 from umjammer/0.0.16v
Browse files Browse the repository at this point in the history
0.0.16v
  • Loading branch information
umjammer committed Jan 30, 2024
2 parents b4aaa2a + af5a260 commit a65fb24
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>purejavahidapi</groupId>
<artifactId>purejavahidapi</artifactId>
<version>0.0.15v</version>
<version>0.0.16v</version>

<packaging>jar</packaging>
<name>Pure Java HID-API</name>
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/purejavahidapi/linux/HidDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

import com.sun.jna.Native;
import purejavahidapi.DeviceRemovalListener;
import purejavahidapi.InputReportListener;
import purejavahidapi.shared.SyncPoint;

import static purejavahidapi.linux.CLibrary.EACCES;
Expand Down Expand Up @@ -166,8 +165,12 @@ private void runReadOnBackground() throws IOException {
// the HID descriptor AND parse it. I like the Mac OS and Windows ways better, what a mess the world is!
int bytes_read = read(m_DeviceHandle, m_InputReportBytes, m_InputReportBytes.length);
if (m_InputReportListener != null) {
byte reportID = m_UsesNumberedReports ? m_InputReportBytes[0] : 0;
System.arraycopy(m_InputReportBytes, 0, m_InputReportBytes, 0, bytes_read);
byte reportID = 0;
if (m_UsesNumberedReports) {
reportID = m_InputReportBytes[0];
bytes_read--;
System.arraycopy(m_InputReportBytes, 1, m_InputReportBytes, 0, bytes_read);
}
m_InputReportListener.onInputReport(this, reportID, m_InputReportBytes, bytes_read);
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/purejavahidapi/macosx/HidDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@
import com.sun.jna.Memory;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import purejavahidapi.DeviceRemovalListener;
import purejavahidapi.InputReportListener;
import purejavahidapi.shared.SyncPoint;
import vavi.util.Debug;
import vavi.util.StringUtil;

import static purejavahidapi.macosx.CoreFoundationLibrary.*;
import static purejavahidapi.macosx.IOHIDManagerLibrary.IOHIDDeviceCallback;
Expand Down Expand Up @@ -272,8 +269,14 @@ public void callback(Pointer context, int result, Pointer sender, int reportType
HidDevice dev = m_DevFromCallback.get(this);
if (dev != null) {
if (dev.m_InputReportListener != null) {
int length = report_length.intValue();
int length;
if (reportId == 0) {
length = report_length.intValue();
report.read(0, dev.m_InputReportData, 0, length);
} else {
length = report_length.intValue() - 1;
report.read(1, dev.m_InputReportData, 0, length);
}
dev.m_InputReportListener.onInputReport(dev, (byte) reportId, dev.m_InputReportData, length);
}
} else
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/purejavahidapi/windows/HidDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,17 @@ private void runReadOnBackground() {
}
}

byte reportId = m_Transfrd[INPUT][0] > 0 ? m_Buffer[INPUT].getByte(0) : 0;
m_Buffer[INPUT].read(0, m_InputReportBytes, 0, m_Transfrd[INPUT][0]);
if (m_Transfrd[INPUT][0] > 0) {
byte reportId = m_Buffer[INPUT].getByte(0);
m_Transfrd[INPUT][0]--;

m_Buffer[INPUT].read(1, m_InputReportBytes, 0, m_Transfrd[INPUT][0]);

if (m_InputReportListener != null)
m_InputReportListener.onInputReport(this, reportId, m_InputReportBytes, m_Transfrd[INPUT][0]);
}

}
m_SyncShutdown.waitAndSync();
}

Expand Down

0 comments on commit a65fb24

Please sign in to comment.