hid-0.2: Interface to hidapi library

Copyright(C) 2015 Dimitri Sabadie
LicenseBSD3
MaintainerDimitri Sabadie <dimitri.sabadie@gmail.com>
Stabilityexperimental
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

System.HID

Contents

Description

 

Synopsis

Initialization and finalization

init :: MonadIO m => m Bool Source

Initialize the library.

This function initializes the library. Calling it is not strictly necessary, as it will be called automatically when enumerating or opening devices if it’s needed. This function should be called at the beginning of execution however, if there is a chance of handles being opened by different threads simultaneously.

exit :: MonadIO m => m Bool Source

Finalize the library.

This function frees all of the static data associated with the library. It should be called at the end of execution to avoid memory leaks.

Getting devices information

data DeviceInfo Source

Information on a device.

enumerate :: MonadIO m => Word32 -> Word32 -> m [DeviceInfo] Source

Enumerate all devices for a given vendor ID and product ID. If you need to get all available devices, use detectDevices.

detectDevices :: MonadIO m => m [DeviceInfo] Source

Enumerate all plugged in devices.

Accessing devices

data Device Source

An opaque device.

vendorProductSerialDevice :: MonadIO m => Word16 -> Word16 -> Maybe String -> m (Maybe Device) Source

Get a Device from the vendor ID, product ID and an optional serial number.

pathDevice :: MonadIO m => String -> m (Maybe Device) Source

Get a Device from a path.

Sending data to devices

writeOutputReport :: MonadIO m => Device -> ByteString -> m Int Source

Write an Output report to a HID device.

The first byte of data must contain the Report ID. For devices which only support a single report, this must be set to 0x0. The remaining bytes contain the report data. Since the Report ID is mandatory, calls to writeOutputReport will always contain one more byte(s) than the report contains. For example, if a hid report is 16 bytes long, 17 bytes must be passed to writeOutputReport, the Report ID (or 0x0, for devices with a single report), followed by the report data (16 bytes). In that example, the length passed in would be 17.

writeOutputReport will send the data on the first OUT endpoint, if one exists. If it does not, it will send the data through the Control Endpoint Endpoint 0).

sendFeatureReport :: MonadIO m => Device -> ByteString -> m Int Source

Send a Feature report to the device.

Feature reports are sent over the Control endpoint as a Set_Report transfer. The first byte of data must contain the Report ID. For devices which only upport a single report, this must be set to 0x0. The remaining bytes contain the report data. Since the Report ID is mandatory, calls to sendFeatureReport will always contain one more byte than the report contains. For example, if a hid report is 16 bytes long, 17 bytes must be passed to sendFeatureReport: the Report ID (or 0x0, for devices which do not use numbered reports), followed by the report data (16 bytes). In that example, the length passed in would be 17.

Receiving data from devices

readInputReport :: MonadIO m => Device -> m (Maybe ByteString) Source

Read an Input report from a HID device.

Input reports are returned to the host through the INTERRUPT IN endpoint. The first byte will contain the Report number if the device uses numbered reports.

readInputReportTimeout :: MonadIO m => Device -> Int -> m (Maybe ByteString) Source

Read an Input report from a HID device with timeout.

Input reports are returned to the host through the INTERRUPT IN endpoint. The first byte will contain the Report number if the device uses numbered reports.

getFeatureReport :: MonadIO m => Device -> m (Maybe ByteString) Source

Get a feature report from a HID device.

Set the first byte of data to the Report ID of the report to be read. Make sure to allow space for this extra byte in data. Upon return, the first byte will still contain the Report ID, and the report data will start in data[1].

getManufacturer :: MonadIO m => Device -> m String Source

Get the manufacturer string from a HID device.

getProductName :: MonadIO m => Device -> m String Source

Get the product name from a HID device.

getSerialNumber :: MonadIO m => Device -> m String Source

Get the serial number string from a HID device.

getIndexedString :: MonadIO m => Device -> Int -> m String Source

Get an indexed string from a HID device.

Blocking mode for devices

setBlocking :: MonadIO m => Device -> Bool -> m Bool Source

Set the blocking mode of a device.