You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

hidapi

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hidapi - cargo Package Compare versions

Comparing version
0.5.0
to
0.5.1
+5
.cargo_vcs_info.json
{
"git": {
"sha1": "bbdce3d50704c0abf2ce04bc60f8aee6af254f6b"
}
}
/****************************************************************************
Copyright (c) 2018 Roland Ruckerbauer All Rights Reserved.
This file is part of hidapi-rs, based on hidapi-rs by Osspial
****************************************************************************/
//! Opens the first hid device it can find, and reads data in a blocking fashion
//! from it in an endless loop.
extern crate failure;
extern crate hidapi;
use failure::Error;
use hidapi::HidApi;
fn main() {
fn run() -> Result<(), Error> {
let hidapi = HidApi::new()?;
let device_info = hidapi
.devices()
.iter()
.next()
.expect("No devices are available!")
.clone();
println!("Opening device:\n {:#?}\n", device_info);
let device = device_info.open_device(&hidapi)?;
let mut buf = vec![0; 64];
println!("Reading data from device ...\n");
loop {
let len = device.read(&mut buf)?;
println!("{:?}", &buf[..len]);
}
Ok(())
}
if let Err(e) = run() {
eprintln!("Error: {}", e);
}
}
+2
-2

@@ -15,4 +15,4 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO

name = "hidapi"
version = "0.5.0"
authors = ["Roland Ruckerbauer <roland.rucky@gmail.com>", "Osspial <osspial@gmail.com>", "Artyom Pavlov <newpavlov@gmail.com>", "mberndt123"]
version = "0.5.1"
authors = ["Roland Ruckerbauer <roland.rucky@gmail.com>", "Osspial <osspial@gmail.com>", "Artyom Pavlov <newpavlov@gmail.com>", "mberndt123", "niklasad1"]
build = "build.rs"

@@ -19,0 +19,0 @@ links = "hidapi"

@@ -19,3 +19,3 @@ # hidapi [![Build Status](https://travis-ci.org/ruabmbua/hidapi-rs.svg?branch=master)](https://travis-ci.org/ruabmbua/hidapi-rs) [![Version](https://img.shields.io/crates/v/hidapi.svg)](https://crates.io/crates/hidapi) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/Osspial/hidapi-rs/blob/master/LICENSE.txt) [![Documentation](https://docs.rs/hidapi/badge.svg)](https://docs.rs/hidapi)

// Print out information about all connected devices
for device in &api.devices() {
for device in api.devices() {
println!("{:#?}", device);

@@ -22,0 +22,0 @@ }

@@ -52,2 +52,3 @@ // **************************************************************************

use std::rc::Rc;
use std::sync::atomic::{AtomicBool, Ordering};

@@ -64,9 +65,9 @@ pub use error::HidError;

fn acquire() -> HidResult<HidApiLock> {
if unsafe { !HID_API_LOCK } {
if HID_API_LOCK.compare_and_swap(false, true, Ordering::SeqCst) {
// Initialize the HID and prevent other HIDs from being created
unsafe {
if ffi::hid_init() == -1 {
HID_API_LOCK.store(false, Ordering::SeqCst);
return Err(HidError::InitializationError);
}
HID_API_LOCK = true;
Ok(HidApiLock)

@@ -82,6 +83,4 @@ }

fn drop(&mut self) {
unsafe {
ffi::hid_exit();
HID_API_LOCK = false;
}
unsafe { ffi::hid_exit(); }
HID_API_LOCK.store(false, Ordering::SeqCst);
}

@@ -97,3 +96,3 @@ }

static mut HID_API_LOCK: bool = false;
static HID_API_LOCK: AtomicBool = AtomicBool::new(false);

@@ -100,0 +99,0 @@ impl HidApi {

Sorry, the diff of this file is not supported yet