Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open specific interface of device #101

Closed
LuggaFiech opened this issue Feb 10, 2023 · 1 comment
Closed

Open specific interface of device #101

LuggaFiech opened this issue Feb 10, 2023 · 1 comment

Comments

@LuggaFiech
Copy link

Is there any way of opening a specific interface of a composite device?

@ruabmbua
Copy link
Owner

ruabmbua commented Feb 14, 2023

Yes, the trick is that each device is enumerated multiple times for each interface / usage page etc...

Here is a modified example of logitech_gprox which opens a specific interface:

/****************************************************************************
    Copyright (c) 2022 ruabmbua All Rights Reserved.
****************************************************************************/

//! Sets the sidechannel volume of the logitech gpro x headset

extern crate hidapi;

use hidapi::HidApi;
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    let vol = std::env::args()
        .nth(1)
        .map(|arg| arg.parse::<u8>())
        .ok_or("missing sidechannel volume arg")??
        .min(100);

    let api = HidApi::new()?;

    // let dev = api.open(0x046d, 0x0aaa)?;

    let Some(devinfo) = api
        .device_list()
        .filter(|d| d.vendor_id() == 0x046d && d.product_id() == 0x0aaa && d.interface_number() == 3)
        .next()
    else {
        return Err("device not found".into());
    };

    let dev = devinfo.open_device(&api)?;

    println!("Setting sidechannel volume to {}", vol);

    dev.write(&[0x11, 0xff, 0x05, 0x1c, vol])?;

    Ok(())
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants