Class HidDeviceManager
java.lang.Object
org.hid4java.HidDeviceManager
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 Summary
FieldsModifier and TypeFieldDescriptionThe currently attached devices keyed on IDprivate final HidServicesSpecificationThe HID services specification providing configuration parametersprivate final HidServicesListenerListHID services listener listprivate ThreadThe 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 Summary
ConstructorsConstructorDescriptionHidDeviceManager(HidServicesListenerList listenerList, HidServicesSpecification hidServicesSpecification) Constructs a new device manager -
Method Summary
Modifier and TypeMethodDescriptionvoidIndicate that a device write has occurred which may require a change in scanning frequencyprivate voidconfigureScanThread(Runnable scanRunnable) Configures the scan executor service to allow recovery from stop or pauseprivate Runnablebooleanvoidscan()Updates the device list by adding newly connected devices to it and by removing no longer connected devices.voidstart()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.voidstop()Stop the scan executor and block until terminated (max 5 seconds)
-
Field Details
-
hidServicesSpecification
The HID services specification providing configuration parameters -
attachedDevices
-
listenerList
HID services listener list -
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 modelhidServicesSpecification- 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
-
afterDeviceWrite
public void afterDeviceWrite()Indicate that a device write has occurred which may require a change in scanning frequency -
configureScanThread
Configures the scan executor service to allow recovery from stop or pause -
getScanRunnable
-