usb-hid-relay-java is a simple API for controlling USB HID relays. (Currently only tested with the SainSmart 16-channel USB-HID programmable relay.)
The following projects were used as a reference for understanding the protocol;
- Integrate with JitPack; https://jitpack.io/
- Add dependency;
pom.xml;
<dependencies>
<dependency>
<groupId>com.github.symbioquine</groupId>
<artifactId>usb-hid-relay-java</artifactId>
<version>v1.0.0</version>
</dependency>
</dependencies>
build.gradle;
dependencies {
compile 'com.github.symbioquine:usb-hid-relay-java:v1.0.0'
}
import net.symbioquine.usbhidrelay.UsbHidRelay;
import static net.symbioquine.usbhidrelay.UsbHidRelaySize.SIXTEEN;
UsbHidRelay relay = UsbHidRelay.findAndAcquireFirstRelay(SIXTEEN);
relay.setSwitchOn(0);
import net.symbioquine.usbhidrelay.EnumeratedUsbHidRelay;
import net.symbioquine.usbhidrelay.UsbHidRelaySwitchId;
public enum AwesomeMovieRelaySwitch implements UsbHidRelaySwitchId {
LIGHTS(0),
CAMERA(10),
ACTION(3);
private final int switchId;
MyProjectRelaySwitch(int switchId) {
this.switchId = switchId;
}
@Override
int id() {
return switchId;
}
}
import static AwesomeMovieRelaySwitch.*;
EnumeratedUsbHidRelay<AwesomeMovieRelaySwitch> relay = EnumeratedUsbHidRelay.findAndAcquireFirstRelay(SIXTEEN, AwesomeMovieRelaySwitch.class);
relay.setSwitchOn(LIGHTS);
relay.setSwitchOn(CAMERA);
relay.setSwitchOn(ACTION);