ryankurte / rust-streamdeck

libusb based driver for Elgato StreamDeck devices
Mozilla Public License 2.0
57 stars 24 forks source link

Add support for V2 devices. #4

Closed dalegaard closed 4 years ago

dalegaard commented 4 years ago

This commit adds support for V2 devices which use a different protocol to the original streamdeck.

The write paths for all four device models are now unified.

All devices are now adressed zero-indexed starting top-left, for consistency.

The written images are now flipped correctly for all models, and for this I updated the image dependency as well. The various public button setting functions will internally convert to the correct format. set_button_image now takes a DynamicImage instead of a raw buffer and applies the relevant transformations to get the image into the correct device format.

Tested on Original and XL streamdecks, but not the Original V2 or Mini as I don't have those available for testing.

Sorry that this turned out as a single commit, I tried to split it up but kinda gave up. Hope it's OK anyway! Rustfmt changed a few lines here and there as well, but it didn't seem too bad so I decided to leave that in.

dalegaard commented 4 years ago

So I figured I should probably get read_buttons to give sensible results on the XL as well, so I went back and added that as well.

ryankurte commented 4 years ago

hey thanks for the PR! i'll have a go at testing it on my mini then get it merged.

dalegaard commented 4 years ago

Found a small bug(fixed in 74e4d98) that affects the Mini, as it uses BMP and thus has an image_base. The is_last field would be incorrectly set on the first packet.

Also fixed a bunch of cosmetic stuff as it was bugging me :smile:

ryankurte commented 4 years ago

looks great, and tested working on my mini, thanks! doing anything fun with the collection of streamdecks?

ryankurte commented 4 years ago

aand published in 0.4.3

dalegaard commented 4 years ago

:+1:

I'm working on a Companion alternative inspired by of all things, bspwm and sxhkd. What better language to use than Rust? I have three XLs and figured I might as well add XL support to your lib, rather than implement a new lib from scratch!

ryankurte commented 4 years ago

ohh awesome! agreed, i'm finding it harder and harder to go back to other languages eh.

feel free to raise other issues / PRs if there are other features you need! i put it together for ryankurte/autodeck which is probably not an exhaustive use case.

AleksanderZdunek commented 4 years ago

Hi I've tested 0.4.3 with Original and Original V2. get-buttons, reset, set-brightness, set-colour, set-image looks to be working correctly on both.

version panicks on Original V2 thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Utf8Error { valid_up_to: 0, error_len: Some(1) }', src/lib.rs:148:12

I also noticed that if I spam key presses on the V2, read_buttons() may occasionally return Err(Error::NoData). This may be correct and expected behaviour, but I thought it worth noting that I haven't been able to reproduce on Original.

ryankurte commented 4 years ago

thread 'main' panicked at 'called Result::unwrap() on an Err value: Utf8Error { valid_up_to: 0, error_len: Some(1) }', src/lib.rs:148:12

hmmm, we must be pulling the version string incorrectly for this?

I also noticed that if I spam key presses on the V2, read_buttons() may occasionally return Err(Error::NoData).

i'm honestly not super sure, given we have a static polling rate this shouldn't really have any impact unless there's some bug with the way they handle button presses in their firmware.

if that's the case, it's pretty out of our control, but perhaps useful to update the API with that expectation in the case of the original v2? probably just documenting this behaviour on the method would do.

dalegaard commented 4 years ago

We slice from 5.. on the returned version string, has to be 6.. for the V2 devices and 5.. for the original. I'll make a PR.