Class HidDeviceManager

java.lang.Object
org.hid4java.HidDeviceManager

class HidDeviceManager extends Object

Manager to provide the following to HID services:

  • Access to the underlying JNA and hidapi library
  • Device attach/detach detection
Since:
0.0.1  
  • Field Details

    • hidServicesSpecification

      private final HidServicesSpecification hidServicesSpecification
      The HID services specification providing configuration parameters
    • attachedDevices

      private final Map<String, HidDevice> attachedDevices
      The currently attached devices keyed on ID
    • listenerList

      private final HidServicesListenerList listenerList
      HID services listener list
    • scanThread

      private Thread scanThread
      The device enumeration thread We use a Thread instead of Executor since it may be stopped/paused/restarted frequently and executors are more heavyweight in this regard
  • Constructor Details

    • HidDeviceManager

      HidDeviceManager(HidServicesListenerList listenerList, HidServicesSpecification hidServicesSpecification) throws HidException
      Constructs a new device manager
      Parameters:
      listenerList - The HID services providing access to the event model
      hidServicesSpecification - Provides various parameters for configuring HID services
      Throws:
      HidException - If USB HID initialization fails
  • Method Details

    • start

      public void start()
      Starts the manager If already started (scanning) it will immediately return without doing anything Otherwise this will perform a one-off scan of all devices then if the scan interval is zero will stop there or will start the scanning daemon thread at the required interval.
      Throws:
      HidException - If something goes wrong (such as Hidapi not initialising correctly)
    • stop

      public void stop()
      Stop the scan executor and block until terminated (max 5 seconds)
    • scan

      public void scan()
      Updates the device list by adding newly connected devices to it and by removing no longer connected devices. Will fire attach/detach events as appropriate.
    • isScanning

      public boolean isScanning()
      Returns:
      True if the scan thread is running, false otherwise.
    • getAttachedHidDevices

      public List<HidDevice> getAttachedHidDevices()
      Returns:
      A list of all attached HID devices
    • afterDeviceWrite

      public void afterDeviceWrite()
      Indicate that a device write has occurred which may require a change in scanning frequency
    • configureScanThread

      private void configureScanThread(Runnable scanRunnable)
      Configures the scan executor service to allow recovery from stop or pause
    • getScanRunnable

      private Runnable getScanRunnable()