hidapi-sys-0.1.4/.gitignore01006000001750000175000000000022127216740010013761 0ustar0000000000000000target Cargo.lock hidapi-sys-0.1.4/Cargo.toml.orig01006000001750000175000000000722132110100500014646 0ustar0000000000000000[package] name = "hidapi-sys" version = "0.1.4" build = "build.rs" links = "hidapi" authors = ["meh. "] license = "WTFPL" description = "FFI bindings to hidapi" repository = "https://github.com/meh/rust-hidapi-sys" keywords = ["hid"] categories = ["external-ffi-bindings", "hardware-support", "os"] [features] static = [] build = ["static"] [dependencies] libc = "0.2" [build-dependencies] cc = "1.0" pkg-config = "0.3" hidapi-sys-0.1.4/Cargo.toml0000644000000017630010134 0ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g. crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] name = "hidapi-sys" version = "0.1.4" authors = ["meh. "] build = "build.rs" links = "hidapi" description = "FFI bindings to hidapi" keywords = ["hid"] categories = ["external-ffi-bindings", "hardware-support", "os"] license = "WTFPL" repository = "https://github.com/meh/rust-hidapi-sys" [dependencies.libc] version = "0.2" [build-dependencies.cc] version = "1.0" [build-dependencies.pkg-config] version = "0.3" [features] build = ["static"] static = [] hidapi-sys-0.1.4/README.md01006000001750000175000000000575132110077770013272 0ustar0000000000000000hidapi-sys [![WTFPL](http://img.shields.io/badge/license-WTFPL-blue.svg)](http://www.wtfpl.net/txt/copying) ========== Bindings for hidapi with support for building sources automatically. Requirements ------------ `gcc` and `pkg-config` are required for building source automatically. `git` is required unless `HIDAPI_PATH` is exported to an existing checkout of hidapi sources. hidapi-sys-0.1.4/build.rs01006000001750000175000000003514132110074540013444 0ustar0000000000000000extern crate cc; extern crate pkg_config; use std::env; use std::io; use std::path::PathBuf; use std::process::Command; fn main() { if env::var("CARGO_FEATURE_BUILD").is_err() { return; } fetch().expect("failed to checkout hidapi sources, internet connection and git are needed"); build().expect("failed to build hidapi sources"); println!("cargo:rustc-link-search=native={}", output().to_string_lossy()); } fn output() -> PathBuf { PathBuf::from(env::var("OUT_DIR").unwrap()) } fn source() -> PathBuf { if let Ok(path) = env::var("HIDAPI_PATH") { path.into() } else { output().join("hidapi") } } fn fetch() -> io::Result<()> { if env::var("HIDAPI_PATH").is_ok() { return Ok(()); } Command::new("git") .current_dir(&output()) .arg("clone") .arg("https://github.com/signal11/hidapi.git") .arg("hidapi") .status()?; Ok(()) } #[cfg(target_os = "linux")] fn build() -> io::Result<()> { let mut build = cc::Build::new(); build.file(source().join("libusb/hid.c")); build.include(source().join("hidapi")); build.static_flag(true); for path in pkg_config::find_library("libusb-1.0").unwrap().include_paths { build.include(path.to_str().unwrap()); } build.compile("libhidapi-libusb.a"); Ok(()) } #[cfg(target_os = "macos")] fn build() -> io::Result<()> { let mut build = cc::Build::new(); build.file(source().join("libusb/hid.c")); build.include(source().join("hidapi")); build.static_flag(true); for path in pkg_config::find_library("libusb-1.0").unwrap().include_paths { build.include(path.to_str().unwrap()); } build.compile("libhidapi.a"); Ok(()) } #[cfg(target_os = "windows")] fn build() -> io::Result<()> { let mut build = cc::Build::new(); build.file(source().join("windows/hid.c")); build.include(source().join("hidapi")); build.static_flag(true); build.compile("libhidapi.a"); Ok(()) } hidapi-sys-0.1.4/src/lib.rs01006000001750000175000000005151127216740010013704 0ustar0000000000000000#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] extern crate libc; use libc::{c_void, c_ushort, wchar_t, c_int, c_uchar, size_t, c_char}; pub type hid_device = c_void; #[repr(C)] pub struct hid_device_info { pub path: *mut c_char, pub vendor_id: c_ushort, pub product_id: c_ushort, pub serial_number: *mut wchar_t, pub release_number: c_ushort, pub manufacturer_string: *mut wchar_t, pub product_string: *mut wchar_t, pub usage_page: c_ushort, pub usage: c_ushort, pub interface_number: c_int, pub next: *mut hid_device_info, } #[cfg_attr(target_os = "linux", link(name = "udev"))] extern "C" { } #[cfg_attr(target_os = "windows", link(name = "setupapi"))] extern "C" { } #[cfg_attr(all(feature = "static", target_os = "linux"), link(name = "hidapi-libusb", kind = "static"))] #[cfg_attr(all(not(feature = "static"), target_os = "linux"), link(name = "hidapi-libusb"))] #[cfg_attr(all(feature = "static", not(target_os = "linux")), link(name = "hidapi", kind = "static"))] #[cfg_attr(all(not(feature = "static"), not(target_os = "linux")), link(name = "hidapi"))] extern "C" { pub fn hid_init() -> c_int; pub fn hid_exit() -> c_int; pub fn hid_enumerate(vendor_id: c_ushort, product_id: c_ushort) -> *mut hid_device_info; pub fn hid_free_enumeration(devs: *mut hid_device_info); pub fn hid_open(vendor_id: c_ushort, product_id: c_ushort, serial_number: *const wchar_t) -> *mut hid_device; pub fn hid_open_path(path: *const c_char) -> *mut hid_device; pub fn hid_write(device: *mut hid_device, data: *const c_uchar, length: size_t) -> c_int; pub fn hid_read_timeout(device: *mut hid_device, data: *mut c_uchar, length: size_t, milleseconds: c_int) -> c_int; pub fn hid_read(device: *mut hid_device, data: *mut c_uchar, length: size_t) -> c_int; pub fn hid_set_nonblocking(device: *mut hid_device, nonblock: c_int) -> c_int; pub fn hid_send_feature_report(device: *mut hid_device, data: *const c_uchar, length: size_t) -> c_int; pub fn hid_get_feature_report(device: *mut hid_device, data: *mut c_uchar, length: size_t) -> c_int; pub fn hid_close(device: *mut hid_device); pub fn hid_get_manufacturer_string(device: *mut hid_device, string: *mut wchar_t, maxlen: size_t) -> c_int; pub fn hid_get_product_string(device: *mut hid_device, string: *mut wchar_t, maxlen: size_t) -> c_int; pub fn hid_get_serial_number_string(device: *mut hid_device, string: *mut wchar_t, maxlen: size_t) -> c_int; pub fn hid_get_indexed_string(device: *mut hid_device, string_index: c_int, string: *mut wchar_t, maxlen: size_t) -> c_int; pub fn hid_error(device: *mut hid_device) -> *const wchar_t; }