ruabmbua / hidapi-rs

Rust bindings for the hidapi C library
MIT License
167 stars 80 forks source link

Can not open BlueTooth Hid device on Mac #84

Closed dongjian closed 2 years ago

dongjian commented 2 years ago

test code :

hidapi.device_list().for_each(|v| {
            if v.product_id() == 0x4013 {
                println!(
                    "---vid  {:x?}  pid  {:x?}  usage  {:x?}   usagepage{:x?}",
                    v.product_id(),
                    v.vendor_id(),
                    v.usage(),
                    v.usage_page()
                );
                let res = v.open_device(&hidapi);
                match res {
                    Ok(_) => {
                        println!("OOOPPPPEEEENNN!!!!!!")
                    }
                    Err(_) => (),
                };
            }
        });
log:
---vid  4013  pid  3151  usage  6   usagepage1
---vid  4013  pid  3151  usage  1   usagepagec
---vid  4013  pid  3151  usage  80   usagepage1
---vid  4013  pid  3151  usage  2   usagepage1
---vid  4013  pid  3151  usage  1   usagepage1
---vid  4013  pid  3151  usage  202   usagepageff55

It's works fine on Windows with the same code . But can't open device on Mac(Can find but can not open)

dongjian commented 2 years ago

It's strange . after some test . I found that I can open the device use "sudo cargo run"

timfish commented 2 years ago

Some platforms don't let you access keyboard/mouse HID devices as a security precaution. I think this is the expected behaviour on macOS.

ruabmbua commented 2 years ago

Yes, as far as I know certain hid devices on macos can`t be opened directly with raw HID access, only the kernel driver is allowed to access it. You can only get around that with special permissions (sudo will do).

dongjian commented 2 years ago

Thanks! Links may be helpful to others who have similar problems: https://github.com/libusb/hidapi/issues/344 https://github.com/libusb/hidapi/pull/397