From c73246c09dbd35f958c536620a52811e003de016 Mon Sep 17 00:00:00 2001 From: Roland Ruckerbauer Date: Fri, 21 Jul 2017 16:12:55 +0200 Subject: [PATCH] Fixed issue #5 & some minor changes --- Cargo.toml | 4 ++-- src/lib.rs | 25 +++++++++++-------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0e18271..638d4db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hidapi" -version = "0.4.0" +version = "0.4.1" authors = [ "Roland Ruckerbauer ", "Osspial ", @@ -12,7 +12,7 @@ license = "MIT" keywords = ["hid", "api", "usb","binding", "wrapper"] build = "build.rs" links = "hidapi" -documentation = "https://beta.docs.rs/hidapi" +documentation = "https://docs.rs/hidapi" [dependencies] libc = "0.2.15" diff --git a/src/lib.rs b/src/lib.rs index 7ceabc9..4594279 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,7 @@ //! //! ```toml //! [dependencies] -//! hidapi = "0.3" +//! hidapi = "0.4" //! ``` //! # Example //! @@ -59,19 +59,19 @@ pub struct HidApi { devices: Vec, } -static mut hid_api_lock: bool = false; +static mut HID_API_LOCK: bool = false; impl HidApi { /// Initializes the HID pub fn new() -> HidResult { - if unsafe { !hid_api_lock } { + if unsafe { !HID_API_LOCK } { // Initialize the HID and prevent other HIDs from being created unsafe { if ffi::hid_init() == -1 { return Err("Failed to init hid"); } - hid_api_lock = true; + HID_API_LOCK = true; } @@ -95,19 +95,16 @@ impl HidApi { { let mut current_device = enumeration; - 'do_while: loop { - + while !current_device.is_null() { device_vector.push(conv_hid_device_info(current_device)); - - if (*current_device).next.is_null() { - break 'do_while; - } else { - current_device = (*current_device).next; - } + current_device = (*current_device).next; } + } - ffi::hid_free_enumeration(enumeration); + if !enumeration.is_null() { + ffi::hid_free_enumeration(enumeration); + } device_vector } @@ -165,7 +162,7 @@ impl Drop for HidApi { fn drop(&mut self) { unsafe { ffi::hid_exit(); - hid_api_lock = false; + HID_API_LOCK = false; } } }