forked from gary-rowe/hid4java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from umjammer/0.14.6v
0.14.6v
- Loading branch information
Showing
16 changed files
with
1,259 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,10 @@ | |
|
||
<groupId>org.hid4java</groupId> | ||
<artifactId>hid4java</artifactId> | ||
<version>0.14.5v</version> | ||
<version>0.14.6v</version> | ||
|
||
<name>hid4java</name> | ||
<description>A cross-platform Java Native Access (JNA) wrapper for the libusb/hidapi library</description> | ||
<description>A cross-platform hidapi like library (depends on jna but hidapi native library)</description> | ||
<url>https://github.com/umjammer/hid4java</url> | ||
<inceptionYear>2014</inceptionYear> | ||
<developers> | ||
|
@@ -34,22 +34,69 @@ | |
<url>[email protected]:umjammer/hid4java.git</url> | ||
</scm> | ||
|
||
<distributionManagement> | ||
<repository> | ||
<id>sonatype-nexus-staging</id> | ||
<name>Nexus Release Repository</name> | ||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url> | ||
</repository> | ||
</distributionManagement> | ||
|
||
<properties> | ||
<jinput.groupId>com.github.umjammer.jinput</jinput.groupId> <!-- net.java.jinput / com.github.umjammer.jinput --> | ||
<jinput.version>2.0.14v</jinput.version> | ||
<jinput.version>2.0.15v</jinput.version> | ||
</properties> | ||
|
||
|
||
<profiles> | ||
<profile> | ||
<!-- mvn -P jnaerator jnaerator:generate --> | ||
<id>jnaerator</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.nativelibs4java</groupId> | ||
<artifactId>maven-jnaerator-plugin</artifactId> | ||
<version>0.12</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>generate</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<javaOutputDirectory>${project.build.testSourceDirectory}</javaOutputDirectory> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
|
||
<profile> | ||
<!-- mvn -P run antrun:run -Dfoo='bar' --> | ||
<id>run</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<!-- GOOD: fork: OK, test jars: OK, user args, default args: OK --> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-antrun-plugin</artifactId> | ||
<version>3.1.0</version> | ||
<goals> | ||
<goal>run</goal> | ||
</goals> | ||
<configuration> | ||
<target> | ||
<java classname="vavi.games.input.hid4java.spi.GamepadTest" fork="true"> | ||
<classpath> | ||
<path refid="maven.compile.classpath"/> | ||
<path refid="maven.test.classpath"/> | ||
</classpath> | ||
<jvmarg value="-Djava.util.logging.config.file=${project.build.testOutputDirectory}/logging.properties" /> | ||
</java> | ||
</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
|
||
<build> | ||
<plugins> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
|
@@ -128,7 +175,6 @@ | |
</archive> | ||
</configuration> | ||
</plugin> | ||
|
||
</plugins> | ||
</build> | ||
|
||
|
@@ -152,6 +198,12 @@ | |
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.github.umjammer</groupId> | ||
<artifactId>vavi-commons</artifactId> | ||
<version>1.1.9</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${jinput.groupId}</groupId> | ||
<artifactId>osx-plugin</artifactId> | ||
|
@@ -178,38 +230,5 @@ | |
<artifactId>junit-platform-commons</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.github.umjammer</groupId> | ||
<artifactId>vavi-commons</artifactId> | ||
<version>1.1.9</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<profiles> | ||
<profile> | ||
<!-- mvn -P jnaerator jnaerator:generate --> | ||
<id>jnaerator</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.nativelibs4java</groupId> | ||
<artifactId>maven-jnaerator-plugin</artifactId> | ||
<version>0.12</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>generate</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<javaOutputDirectory>${project.build.testSourceDirectory}</javaOutputDirectory> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/main/java/vavi/games/input/hid4java/spi/Hid4JavaComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright (c) 2023 by Naohide Sano, All rights reserved. | ||
* | ||
* Programmed by Naohide Sano | ||
*/ | ||
|
||
package vavi.games.input.hid4java.spi; | ||
|
||
import java.util.function.Function; | ||
|
||
import net.java.games.input.AbstractComponent; | ||
import net.java.games.input.WrappedComponent; | ||
import net.java.games.input.usb.HidComponent; | ||
import net.java.games.input.usb.parser.Field; | ||
import net.java.games.input.usb.parser.HidParser.Feature; | ||
|
||
import static net.java.games.input.usb.parser.HidParser.Feature.RELATIVE; | ||
|
||
|
||
/** | ||
* Hid4JavaComponent. | ||
* | ||
* @author <a href="mailto:[email protected]">Naohide Sano</a> (nsano) | ||
* @version 0.00 2023-11-06 nsano initial version <br> | ||
*/ | ||
public class Hid4JavaComponent extends AbstractComponent implements HidComponent, WrappedComponent<Field> { | ||
|
||
/** an input report definition */ | ||
private final Field field; | ||
|
||
/** special data picker (e.g. for touch x, y) */ | ||
private Function<byte[], Integer> function; | ||
|
||
/** | ||
* Protected constructor | ||
* | ||
* @param name A name for the axis | ||
* @param field an input report descriptor fragment. | ||
*/ | ||
protected Hid4JavaComponent(String name, Identifier id, Field field) { | ||
super(name, id); | ||
this.field = field; | ||
} | ||
|
||
/** | ||
* @param offset bits (must be excluded first one byte (8 bits) for report id) | ||
* @param size bit length | ||
*/ | ||
public Hid4JavaComponent(String name, Identifier id, int offset, int size) { | ||
this(name, id, offset, size, null); | ||
} | ||
|
||
/** | ||
* @param offset bits (must be excluded first one byte (8 bits) for report id) | ||
* @param size bit length | ||
*/ | ||
public Hid4JavaComponent(String name, Identifier id, int offset, int size, Function<byte[], Integer> function) { | ||
super(name, id); | ||
this.field = new Field(offset, size); | ||
this.function = function; | ||
} | ||
|
||
@Override | ||
public boolean isRelative() { | ||
return field != null && Feature.containsIn(RELATIVE, field.getFeature()); | ||
} | ||
|
||
@Override | ||
public boolean isValueChanged(byte[] data) { | ||
return getEventValue() != getValue(data); | ||
} | ||
|
||
@Override | ||
public float getValue() { | ||
return getEventValue(); | ||
} | ||
|
||
/** by hid input report */ | ||
private int getValue(byte[] data) { | ||
int value = field.getValue(data); | ||
return function != null ? function.apply(data) : value; | ||
} | ||
|
||
@Override | ||
public void setValue(byte[] data) { | ||
setEventValue(field.getValue(data)); | ||
} | ||
|
||
@Override | ||
public Field getWrappedObject() { | ||
return field; | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
src/main/java/vavi/games/input/hid4java/spi/Hid4JavaController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright (c) 2023 by Naohide Sano, All rights reserved. | ||
* | ||
* Programmed by Naohide Sano | ||
*/ | ||
|
||
package vavi.games.input.hid4java.spi; | ||
|
||
import java.io.IOException; | ||
import java.util.logging.Level; | ||
|
||
import net.java.games.input.AbstractController; | ||
import net.java.games.input.Component; | ||
import net.java.games.input.Controller; | ||
import net.java.games.input.Rumbler; | ||
import net.java.games.input.usb.HidController; | ||
import org.hid4java.HidDevice; | ||
import vavi.util.Debug; | ||
import vavi.util.StringUtil; | ||
|
||
|
||
/** | ||
* Hid4JavaController. | ||
* | ||
* @author <a href="mailto:[email protected]">Naohide Sano</a> (nsano) | ||
* @version 0.00 2023-09-18 nsano initial version <br> | ||
*/ | ||
public class Hid4JavaController extends AbstractController implements HidController { | ||
|
||
/** */ | ||
private final HidDevice device; | ||
|
||
/** | ||
* Protected constructor for a controller containing the specified | ||
* axes, child controllers, and rumblers | ||
* | ||
* @param device the controller | ||
* @param components components for the controller | ||
* @param children child controllers for the controller | ||
* @param rumblers rumblers for the controller | ||
*/ | ||
protected Hid4JavaController(HidDevice device, Component[] components, Controller[] children, Rumbler[] rumblers) { | ||
super(device.getManufacturer() + "/" + device.getProduct(), components, children, rumblers); | ||
this.device = device; | ||
Debug.println("device: " + device + ", " + device.isOpen()); | ||
} | ||
|
||
@Override | ||
public int getVendorId() { | ||
return device.getVendorId(); | ||
} | ||
|
||
@Override | ||
public int getProductId() { | ||
return device.getProductId(); | ||
} | ||
|
||
@Override | ||
public void open() throws IOException { | ||
super.open(); | ||
|
||
device.open(); | ||
device.addInputReportListener(event -> { | ||
byte[] data = event.getReport(); | ||
fireOnInput(new Hid4JavaInputEvent(Hid4JavaController.this, getComponents(), data)); | ||
}); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
device.close(); | ||
super.close(); | ||
} | ||
|
||
@Override | ||
public Type getType() { | ||
return Type.GAMEPAD; | ||
} | ||
|
||
@Override | ||
public void output(Report report) throws IOException { | ||
((HidReport) report).setup(getRumblers()); | ||
|
||
int reportId = ((HidReport) report).getReportId(); | ||
byte[] data = ((HidReport) report).getData(); | ||
Debug.println(Level.FINER, "reportId: " + reportId + "\n" + StringUtil.getDump(data)); | ||
int r = device.write(data, data.length, reportId); | ||
if (r == -1) { | ||
throw new IOException("write returns -1"); | ||
} | ||
} | ||
} |
Oops, something went wrong.