Skip to content

Commit

Permalink
Merge pull request #139 from YgorSouza/improve-docs
Browse files Browse the repository at this point in the history
Document what read and write methods return
  • Loading branch information
ruabmbua committed Jan 14, 2024
2 parents b69e5db + ee7538e commit 8972305
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@ impl HidDevice {
self.inner.check_error()
}

/// 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
Expand All @@ -546,26 +548,37 @@ impl HidDevice {
/// `write()` 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).
///
/// If successful, returns the actual number of bytes written.
pub fn write(&self, data: &[u8]) -> HidResult<usize> {
self.inner.write(data)
}

/// 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.
///
/// If successful, returns the actual number of bytes read.
pub fn read(&self, buf: &mut [u8]) -> HidResult<usize> {
self.inner.read(buf)
}

/// 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. Timeout measured in milliseconds, set -1 for
/// blocking wait.
///
/// If successful, returns the actual number of bytes read.
pub fn read_timeout(&self, buf: &mut [u8], timeout: i32) -> HidResult<usize> {
self.inner.read_timeout(buf, timeout)
}

/// 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 support a single report, this must
Expand All @@ -576,13 +589,20 @@ impl HidDevice {
/// `send_feature_report()`: 'the Report ID' (or 0x0, for devices which
/// do not use numbered reports), followed by the report data (16 bytes).
/// In this example, the length passed in would be 17.
///
/// If successful, returns the actual number of bytes written.
pub fn send_feature_report(&self, data: &[u8]) -> HidResult<()> {
self.inner.send_feature_report(data)
}

/// Get a feature report from a HID device.
///
/// Set the first byte of `buf` to the 'Report ID' of the report to be read.
/// Upon return, the first byte will still contain the Report ID, and the
/// report data will start in `buf[1]`.
///
/// If successful, returns the number of bytes read plus one for the report ID (which is still
/// in the first byte).
pub fn get_feature_report(&self, buf: &mut [u8]) -> HidResult<usize> {
self.inner.get_feature_report(buf)
}
Expand Down

0 comments on commit 8972305

Please sign in to comment.