ruabmbua / hidapi-rs

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

Missing devices and incorrect usage pages with ZSA Moonlander #83

Closed netthier closed 2 years ago

netthier commented 2 years ago

Note: The linux-static-hidraw backend is not affected by this issue.

let api = HidApi::new().unwrap();

dbg!(
    api
        .device_list()
        .filter(|e| is_my_device(e))
        .map(|e| (e.clone(), e.usage_page(), e.usage()))
        .collect::<Vec<_>>());

where is_my_device compares the PID and VID to that of my Moonlander keyboard. The output is 4 times exactly the following:

    (
        HidDeviceInfo {
            vendor_id: 12951,
            product_id: 6505,
        },
        0,
        0,
    ),

Notably, both the usage page and usage are 0.

Running comparable code in with Python's hid results in the following output:

Python 3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import hid
>>> print("\n\n".join(str(i) for i in hid.enumerate()))
{'path': b'/dev/hidraw6', 'vendor_id': 12951, 'product_id': 6505, 'serial_number': '', 'release_number': 1, 'manufacturer_string': 'ZSA', 'product_string': 'Moonlander Mark I', 'usage_page': 65376, 'usage': 97, 'interface_number': 1}

{'path': b'/dev/hidraw5', 'vendor_id': 12951, 'product_id': 6505, 'serial_number': '', 'release_number': 1, 'manufacturer_string': 'ZSA', 'product_string': 'Moonlander Mark I', 'usage_page': 1, 'usage': 2, 'interface_number': 2}

{'path': b'/dev/hidraw5', 'vendor_id': 12951, 'product_id': 6505, 'serial_number': '', 'release_number': 1, 'manufacturer_string': 'ZSA', 'product_string': 'Moonlander Mark I', 'usage_page': 1, 'usage': 1, 'interface_number': 2}

{'path': b'/dev/hidraw4', 'vendor_id': 12951, 'product_id': 6505, 'serial_number': '', 'release_number': 1, 'manufacturer_string': 'ZSA', 'product_string': 'Moonlander Mark I', 'usage_page': 1, 'usage': 128, 'interface_number': 3}

{'path': b'/dev/hidraw4', 'vendor_id': 12951, 'product_id': 6505, 'serial_number': '', 'release_number': 1, 'manufacturer_string': 'ZSA', 'product_string': 'Moonlander Mark I', 'usage_page': 12, 'usage': 1, 'interface_number': 3}

{'path': b'/dev/hidraw4', 'vendor_id': 12951, 'product_id': 6505, 'serial_number': '', 'release_number': 1, 'manufacturer_string': 'ZSA', 'product_string': 'Moonlander Mark I', 'usage_page': 1, 'usage': 6, 'interface_number': 3}

With 7 instead of 4 devices found, and all with non-zero usage pages and usages.

Am I using the Rust API incorrectly here? My goal is to read from and write to the first device in the Python enumeration, which corresponds to QMK's raw HID feature.

ruabmbua commented 2 years ago

Problem was solved by switching to the linux-static-hidraw backend.