Closed markmandel closed 4 years ago
Huh, interesting. Is there a reason you need to Open HidAPI
yourself? We do this internally, and, I would not be surprised if this is the cause of the issue.
Passing the appropriate (constant) VID/PID for a streamdeck XL to the connect
call should achieve the same function as your example, they are unique for a given type of product, and what we use internally to determine product type.
And if you do need the HidAPI instance externally we could add a connect_with_hidapi
constructor that passes an existing instance in (and refactor the connect
constructor to use this internally).
Thanks for the quick reply! I think I was just starting to come to the same conclusion - that creating the HidAPI
first was causing the issues.
I guess, as new person to trying to make this connection (and working with StreamDeck), I had no idea what the device values should be, or how to even look them up -- or even if they were even constant. So I went looking for a searching tool -- I don't explicitly need to library for any reason other than that.
Looking at my code, I see I could also create my own StreamDeck
instance (basically mimic what you do in connect()
, or maaaaybe drop my initial hid
once I've worked out the details of what I want to connect to.
Worked out a nice workaround! :+1: Shifted my discovery code into it's own function, and now everything works, since the discover instance of HidAPI
gets dropped as soon as we move out of the scope of the find_deck
function.
Works for me!
let (vid, pid, serial) = find_deck();
let mut deck = StreamDeck::connect(vid, pid, serial).expect("could not connect to StreamDeck");
println!("Connected!");
fn find_deck() -> (u16, u16, Option<String>) {
let hid = HidApi::new().expect("could not connect to hidapi");
let device = hid
.device_list()
.filter(|item| item.product_id() == XL)
.next()
.expect("Could not find Streamdeck");
println!(
"Attempting to connect to {:?}. vid: {:?}, pid: {:?}, serial: {:?}",
device.product_string(),
device.vendor_id(),
device.product_id(),
device.serial_number(),
);
(
device.vendor_id(),
device.product_id(),
device.serial_number().map(|str| String::from(str)),
)
}
Not sure what I'm doing wrong. Hopefully if we can resolve this, it could be turned into a nice example.
I'm using HidApi to search for my Streamdeck, and then connecting to it from there.
My code looks like the following:
But whenever I run it I get back:
I've tried this with passing the Serial number through, and without. I'm at a bit of a loss :disappointed:
As an aside - I am able to connect via streamdeck-ui, with their udev rules, as well as your udev rules, so I don't think that is the issue.