Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_output_report #159

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ extern "C" {
pub fn hid_libusb_wrap_sys_device(sys_dev: intptr_t, interface_num: c_int) -> *mut HidDevice;
#[cfg(all(libusb, not(target_os = "freebsd")))]
pub fn libusb_set_option(ctx: *mut LibusbContext, option: c_int);
pub fn hid_send_output_report(
device: *mut HidDevice,
data: *const c_uchar,
length: size_t,
) -> c_int;
pub fn hid_write(device: *mut HidDevice, data: *const c_uchar, length: size_t) -> c_int;
pub fn hid_read_timeout(
device: *mut HidDevice,
Expand Down
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ trait HidDeviceBackendBase {
#[cfg(hidapi)]
fn check_error(&self) -> HidResult<HidError>;
fn write(&self, data: &[u8]) -> HidResult<usize>;
fn send_output_report(&self, data: &[u8]) -> HidResult<usize>;
fn read(&self, buf: &mut [u8]) -> HidResult<usize>;
fn read_timeout(&self, buf: &mut [u8], timeout: i32) -> HidResult<usize>;
fn send_feature_report(&self, data: &[u8]) -> HidResult<()>;
Expand Down Expand Up @@ -541,6 +542,21 @@ impl HidDevice {
self.inner.write(data)
}

// Output 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 be set
// to 0x0. The remaining bytes contain the report data. Since the
// Report ID is mandatory, calls to hid_send_output_report() 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
// hid_send_output_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.
pub fn send_output_report(&self, data: &[u8]) -> HidResult<usize> {
self.inner.send_output_report(data)
}

/// Read an Input report from a HID device.
///
/// Input reports are returned to the host through the 'INTERRUPT IN'
Expand Down
Loading