• Stars
    star
    228
  • Rank 175,267 (Top 4 %)
  • Language
    Java
  • License
    MIT License
  • Created about 10 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A cross-platform Java Native Access (JNA) wrapper for the libusb/hidapi library. Works out of the box on Windows/Mac/Linux.

Project status

Build Status Maven Central Javadocs

🌟 Summary

The hid4java project supports USB HID devices through a common API which is provided here under the MIT license. The API is very simple but provides great flexibility such as support for feature reports and blocking reads with timeouts. Attach/detach events are provided to allow applications to respond instantly to device availability.

Telegram group

If you want to discuss hid4java in general please use the Telegram chat. I can't guarantee an instant response but I'm usually active on Telegram during office hours in the GMT timezone.

Remember to check the Wiki first before asking questions to avoid causing frustration!

Technologies

  • hidapi - Native USB HID library for multiple platforms
  • JNA - to remove the need for Java Native Interface (JNI) and greatly simplify the project
  • dockcross - Cross-compilation environments for multiple platforms to create hidapi libraries
  • Java 7+ - to remove dependencies on JVMs that have reached end of life

Maven dependency

<dependencies>

  <!-- hid4java for cross-platform HID USB -->
  <dependency>
    <groupId>org.hid4java</groupId>
    <artifactId>hid4java</artifactId>
    <version>0.7.0</version>
  </dependency>

</dependencies>

Gradle dependency

repositories {
    mavenCentral()
}

dependencies {
    implementation('org.hid4java:hid4java')
}

πŸš€ Code example

Taken from UsbHidEnumerationExample which provides more details.

// Configure to use custom specification
HidServicesSpecification hidServicesSpecification = new HidServicesSpecification();

// Use the v0.7.0 manual start feature to get immediate attach events
hidServicesSpecification.setAutoStart(false);

// Get HID services using custom specification
HidServices hidServices = HidManager.getHidServices(hidServicesSpecification);
hidServices.addHidServicesListener(this);

// Manually start the services to get attachment event
hidServices.start();

// Provide a list of attached devices
for (HidDevice hidDevice : hidServices.getAttachedHidDevices()) {
  System.out.println(hidDevice);
}
    

βš™ Local build

If you're unfamiliar with Maven and git the wiki provides an easy guide to creating a development environment.

The project uses the standard Maven build process and can be used without having external hardware attached. Just do the usual

cd <workspace>
git clone https://github.com/gary-rowe/hid4java.git
cd hid4java

# Maven build
mvn clean install

and you're good to go.

πŸ€” More information

Much of the information previously in this README has been migrated to the project Wiki as it was getting rather long. Here are some useful jumping off points that should help:

  • Home - The wiki Home page with lots of useful launch points
  • FAQ - Frequently asked questions
  • Examples - Using the examples to kickstart your own project
  • Troubleshooting - A comprehensive troubleshooting guide

πŸ“• Closing notes

All trademarks and copyrights are acknowledged.

Many thanks to victorix who provided the basis for this library. Please see the inspiration on the mbed.org site.

Thanks also go to everyone who has contributed their knowledge and advice during the creation and subsequent improvement of this library.

More Repositories

1

multibit-merchant

⚠️ OBSOLETE. DO NOT USE! A free and open source Bitcoin ecommerce platform, with several representative clients (online shop, admin etc). Uses Dropwizard, HAL, MongoDB etc
Java
150
star
2

DropwizardOpenID

⚠️ OBSOLETE. DO NOT USE! Template project demonstrating Dropwizard with OpenID authentication against a few providers (Google, Yahoo etc) and User/Authority annotation support.
Java
65
star
3

SimpleScaffolding

⚠️ OBSOLETE. DO NOT USE! Quickly generate large blocks of scaffolding for your applications. Generate templates from your own projects and apply them to new ones.
Java
27
star
4

BitcoinjEnforcerRules

⚠️ OBSOLETE. DO NOT USE! Verifies Maven SHA1 hashes against a known list to deter dependency-chain attack vectors
Java
24
star
5

DropwizardEmberData

⚠️ OBSOLETE. DO NOT USE! A simple demonstrator of Ember Data against a Dropwizard RESTful API
JavaScript
21
star
6

MultiBitStore

⚠️ OBSOLETE. DO NOT USE! A MultiBit Merchant client providing a complete online store using Bitcoin. Fully customisable.
Java
10
star
7

MultiBitMerchantSite

⚠️ OBSOLETE. DO NOT USE!
Java
6
star
8

trezor-java

⚠️ OBSOLETE. DO NOT USE! Integrate Trezor devices into your project using this library
Java
6
star
9

ember-data-starter-kit

⚠️ OBSOLETE. DO NOT USE! A very simple Ember Data starter kit showing how to make a simple GET request through the RESTAdapter.
JavaScript
5
star
10

GarysWPAccount

Various short stories I've submitted to Reddit Writing Prompts
1
star