Skip to content

symbioquine/usb-hid-relay-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

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;

Getting started

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'
}

Simple use

import net.symbioquine.usbhidrelay.UsbHidRelay;
import static net.symbioquine.usbhidrelay.UsbHidRelaySize.SIXTEEN;
UsbHidRelay relay = UsbHidRelay.findAndAcquireFirstRelay(SIXTEEN);

relay.setSwitchOn(0);

Enumerated switches

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);