Coder Social home page Coder Social logo

streamdecksharp's People

Contributors

jdahlblom avatar patrick-dmxc avatar wischi-chr avatar wswhitehouse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

streamdecksharp's Issues

Exceptions when disposing of a deck in WPF

Not sure if this is WPF-specific, but I wouldn't have thought so...

To reproduce:

  • Create new WPF application (I'm using .NET 6)
  • Add StreamDeckSharp dependency (3.2.0)
  • Create a button in the main window, with a Click action of OpenAndDispose
  • Add code as shown below:
private void OpenAndDispose(object sender, RoutedEventArgs e)
{
    var devices = StreamDeck.EnumerateDevices().ToList();
    var device = devices[0];
    var deck = StreamDeck.OpenDevice(device.DevicePath);
    deck.Dispose();
}
  • Run the code and click the button

Each time the button is clicked, there are three exceptions:

  • At StreamDeckSharp.Internals.ConcurrentBufferedQueue`2.Take() - System.InvalidOperationException: 'Adding is completed and buffer is empty.'
  • At HidSharp.Platform.Windows.NativeMethods.OverlappedOperation(IntPtr ioHandle, IntPtr eventHandle, Int32 eventTimeout, IntPtr closeEventHandle, Boolean overlapResult, NativeOverlapped* overlapped, UInt32& bytesTransferred) - System.ObjectDisposedException: 'Closed.'
  • At HidSharp.AsyncResult`1.EndOperation() - System.ObjectDisposedException: 'Closed.'

Is there a safe way of disposing of the deck objects?

Reference Issues, nuget ver 2.2

I opened a .net 4.8 project, then added the nuget package and the code

     using (var deck = StreamDeck.OpenDevice())
     {
        deck.SetBrightness(100);
     }

resulted in the following errors. I did notice that the dependent nuget packages did not load, and tried again after I loaded them as well. Same result. I hope I can use this package, it is exactly what I was looking for.

error CS0012: The type 'IMacroBoard' is defined in an assembly that is not referenced. You must add a reference to assembly 'OpenMacroBoard.SDK, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null'.
error CS0012: The type 'IMacroBoard' is defined in an assembly that is not referenced. You must add a reference to assembly 'OpenMacroBoard.SDK, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null'.
error CS1061: 'IStreamDeckBoard' does not contain a definition for 'SetBrightness' and no accessible extension method 'SetBrightness' accepting a first argument of type 'IStreamDeckBoard' could be found (are you missing a using directive or an assembly reference?)

Images not working

I've been trying to adapt some of this code to c++, which normally is easy enough. I think I have it correct, but I cannot get images to display on the streamdeck. I'm trying this with a v2 15 button unit. Other things (brightness/etc) I have working with it so I know I'm on the right track. As a simple test, I created a green raw buffer like this:

rgbData = gcnew array(72723);
for (lp = 0; lp < rgbData->Length; ) { rgbData[lp++] = 0; rgbData[lp++] = 255; rgbData[lp++] = 0; }

and converted it to jpg with EncodeImageToJpg(). The output of that conversion sent with header via hid_write is shown in the image below. I've tried changing the page # from 0 to 1, as in some other code I've found it started counting with 1. Didn't help.

I've also tried loading (File::ReadAllBytes(File)) a JPG saved from a paint program and sending that with the header. No luck. And I understand that GIF (animated?) and maybe PNG are also supported but haven't tried those yet since JPG seems to be the main thing supported... and maybe BMP. I also saw a video on youtube showing that you could replace the default power on image... anyone know how that is done?

I didn't have much success getting this project's source to compile, is someone able to reproduce this green test and compare the generated message to mine below to see if it reveals anything? Or can I get a compiled version that works for someone else somehow to test with my unit?

** Image Removed : See below follow-up post **

StreamDeck disconnected?

Hi.

I am writing a Windows Service and I have found that it would be useful if there was a way to test whether the StreamDeck was still connected before issuing commands to it, is this possible?

Thanks

Phil

Loads into PowerShell, but fails to find OpenMacroBoard.SDK assembly

For some reason, I can load this library, but I can't successfully call OpenDevice() method from PowerShell.

I'm trying to load this library into PowerShell 7.0.1, but I'm getting an error. I downloaded both NuGet packages and unzipped them, to get the .NET Standard 2.0 DLLs. I loaded them both, but then the OpenDevice() method won't work correctly.

The OpenMacroBoard SDK I downloaded from NuGet is v1.0.0, not v1.1.0.0, like StreamDeckSharp is looking for.

PS > [System.Reflection.Assembly]::LoadFile("OpenMacroBoard.SDK.dll")
PS > [System.Reflection.Assembly]::LoadFile("StreamDeckSharp.dll")
PS > [StreamDeckSharp.StreamDeck]::OpenDevice()
ExtendedTypeSystemException: The following exception occurred while retrieving member "OpenDevice": "Could not load file or assembly 'OpenMacroBoard.SDK, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot 
find the file specified."

Any ideas where to get the v1.1.0 of the OpenMacroBoard DLL?

Cannot Open Device

I programmed an App for a Database Filling tool. On the PC if bild the Solution everything runs cool.
if i now try to run it on an other Mashine it wont open then Streamdeck.

Maybe u can help me...

It would be soo great

Stremdeck XL

there seems to be an issue with the StreamDeck XL .. once connected (without a standard Streamdeck) I get the error "StreamDeck" namespace not found

any ideas on how to fix this?

device id

Hi! First of all thanks for this library, I am a long time user and I love it !!!
I have a question concerning the device id that is returned StreamDeck.EnumerateDevices method. The Device ID I get looks like

\?\hid#vid_0fd9&pid_006c#6&ec79805&1&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}

From what I understand there is a vendor id, a product id and at the end a guid. In the middle the "ec79805" seems like a device id?
I wonder where I can find a unique ID for the device so that I can identify a device independently on which usb slot it is connected to.
That would help me to "sort" the devices if there are multiple StramDecks connected. I can of course just use the DeviceName to sort, but I'd like to understand the encoding of the above string. Any insight would be appreciated, thanks!

Change title and icon

Hi everyone!

Is it possible to change the title of a button? and its icon?

Thanks.

Streamdeck shows button for split second, then returns to show the Elgato logo

Hi!

Started playing around with this library, and I tried to get a simple button working.
I already have the Counter Example plugin as an example on my Streamdeck on button 0, and then I try to add a White Button on button1.

When the app starts, it displays the White Button for a split second, then clears ALL the buttons to display the Elgato Logo. After that if I click on the buttons it returns to the Streamdeck config, so if I clickthe Counter it will return to normal. Any idea?

Upgrade path from StreamDeckSharp 3.0.0 to 4.2.0-preview - replacement for KeyBitmap.Create.FromGraphics() ?

Hi,

I have a new StreamDeck Mini and looking at other reports, the PID has changed from 0x0063 to 0x0090. 4.2.0 appears to fix this.

However, I updated to 4.2.0 and that updates OpenMacroBoard to 4.0.0-preview as well (from 3.0.0). And this seems to have a LOT of changes or missing features.

The one I was using a lot, and can't seem to find a simple alternative for, is KeyBitmap.Create.FromGraphics().

I have now created a a System.Drawing.Bitmap which I want to display on a button on the StreamDeck. I can save this to disk then use KeyBitmap.Create.FromFile(), and have proved I can display it on the new StreamDeck - so I am happy the newer libraries fix the initial issues of not seeing the StreamDeck. But clearly that's not an acceptable method to display the Bitmap ;-)

Does anyone know of a way to do this? Is there any documentation for the alternative methods in the 4.0.x version? Is there a direct replacement for KeyBitmap.Create.FromGraphics() ?

Thanks in advance,

Chris

Want to mention on the README that it can work on macOS?

Hi there :)

I was playing with the library... and I was able to make it run on macOS by installing runtime.osx.10.10-x64.CoreCompat.System.Drawing from NuGet.

Would it make sense to add this bit to the README? it could be with a disclaimer that you can't support it, but could be useful for people that still want to try it out.

It's not exactly what I was after but wow, this is a nice library! kudos!

ClearKey only clears part of the key when different sized Stream Decks are connected

I've got a Stream Deck and a Stream Deck XL. When both are used in the same application, calling deckXL.ClearKeys() only clears part of each Stream Deck XL key.

I believe this is because the XL keys are 96x96, whereas the Stream Deck keys are 72x72.

StreamDeckJpgHardwareBase.cachedNullImage is a static field, so it assumes the same null image can be used for all hardware - but its size depends on the instance that GetNullImage was first called on.

I suspect that just making cachedNullImage an instance field would be fine here - if I've read the code correctly, there are only normally 4 instances of StreamDeckJpgHardwareBase anyway, so it's not like it's hugely wasteful.

Could not load HidSharp...

I have two project, one use the nuget package "StreamDeckSharp", another one use the nuget package "HidSharp".
If the following hidsharp overwrites the previous HidSharp.dll, will see the error "could not load hidsharp...." for the StreamDeckSharp.

so i think there two hidsharp.dll have some conflicts.

so why not reference HidSharp nuget directly on this project(StreamDeckSharp)?

or i miss something?

I put down the source code, modify the reference, and then compile it, it works and i didn't see any mistakes either.

New Device Connected Event

I can find events on the device for connected and disconnected and I am able to enumerate all connected devices. However this relies on the stream deck being connected at the point when you first start the software or would require the use of a poll.

Would you consider implementing the HidSharp DeviceList Changed event and filtering this by the Stream Deck vendor ID so there is an easy way to know when a previously unseen Stream Deck is connected.

Glitches

Hi,

not sure if this is still relevant and probably you did this already. But have you tried updating the firmware on your StreamDeck via the original elgato software? This seemed to have solved all glitching problems for me...

Hope this helps and thanks for your cool API!

FromHID() needs to be changed to OpenDevice() in PowerShell example

Just found this out when updating to a more recent version.
In the PowerShell example it should now be
$deckInterface = [StreamDeckSharp.StreamDeck]::OpenDevice()

Can also use some of the other new graphics methods
$imgRed = [StreamDeckSharp.KeyBitmap]::FromRGBColor([byte]255,[byte]0,[byte]0)
$deckInterface.SetKeyBitmap(0, $imgRed)

I have a sample for controlling Blackmagic ATEM with program/preview live image updates here
https://github.com/imorrish/VISE_Scripts/tree/master/Stream%20Deck

Problem with fast draws.

Hi Christian,

i have a problem related to your project, but surely not caused by your project.

I try to compose pre loaded Images with different transformations (i.e. rotations, scales, translations) into one Bitmap using a Graphics Class inside a Timer-thread.

Problem is, that i can't access the images in a thread, but have to invoke the UI-Thread via a delegate to do so. But the UI-Thread is only checked every 500 ms, which is way too slow for me.

        public void mydraw()
        {
            if (Thread.CurrentThread != myUIthred) //Tell the UI thread to invoke mydraw if its not himself.
            {
                BeginInvoke(myaction);
                 return;
            }
            tempg.Clear(Color.Black);        //         tempg is created elsewhere:    tempg = Graphics.FromImage(result);
            tempg.TranslateTransform(1024, 1024);
            tempg.RotateTransform((float)angle);
            tempg.TranslateTransform(-1024, -1024);
            tempg.DrawImage(back, 0, 0);    // back, middle, ring and over are preloaded images
            tempg.DrawImage(middle, 0, 0);
            tempg.DrawImage(ring, 0, 0);
            //tempg.Flush();
            tempg.TranslateTransform(1024, 1024);
            tempg.RotateTransform((float)-angle);
            tempg.TranslateTransform(-1024, -1024);
            tempg.DrawImage(over, 0, 0);
            //tempg.Flush();
            tempg.Save();

            deck.SetKeyBitmap(9, KeyBitmap.Create.FromBitmap((Bitmap)result));

            angle = angle +2;  // for testing - angles are read from simulator in a another thread
       }

I guess, while showing the videoframes on the streamdeck, you encountered the same problem.

Do you have a reciepe or tip for me, how i can achive drawing in a higher frame rate while using Bitmaps? Maybe you could push me into the right direction.

I hope it is ok for you that i ask this question via a git issue.

Gern auch auf deutsch :-)

Viele Grüße aus Bremen

Andreas

AppDomain reload problem in Unity3D

Hi,
I tried to integrate the lib into a Unity 3D application. The connection to the device works, but unfortunately there are problems in the Unity editor because it reloads the AppDomain when switching between edit/play mode. this causes the editor to hang. This behavior occurs as soon as you call a streamdeck method. For example: StreamDeck.EnumerateDevices() is sufficient to block the editor after the play mode has ended. Is there any way to circumvent this problem?

Suggestions for how to diagnose a disconnection issue

I'm using StreamDeckSharp for some church A/V presentation software - you select a hymn, reading, PowerPoint presentation or whatever, and the Stream Deck displays the individual pages/slides to present.

Until yesterday, everything was going fine... but with one style of presentation, I'm seeing the Stream Deck disconnect after I've set all the button bitmaps. No exceptions are thrown.
Interestingly, all the code setting the bitmaps completes and then it disconnects, but only a subset of the buttons are displayed - and it's not always the last one that's failing to be shown.

I can always reproduce it by showing the "problematic" presentations multiple times, but any given time it has about a 50% chance of being absolutely fine.

This is a WPF app, and I'm calling SetKeyBitmap from the WPF thread, if that's relevant. If I sleep (in the WPF thread) for 100ms after each SetKeyBitmap call, that seems to sort things out, which suggests there may be a race condition (or buffer overflow) somewhere, but I don't know enough about the internals to diagnose things any further... and if I try to stress test it by setting bitmaps on all keys 100x over in a loop, that doesn't provoke the disconnection. It's infuriating!

Hardware: Stream Deck (but I can test on a Stream Deck XL as well)
Versions: currently 3.0.0, but I first encountered this on 2.2.0 (with OpenMacroBoard.SDK 2.1.0)

StreamDeck Mini

Hi, have you ever tested the StreamDeck Mini? It seems it's not recognized when using StreamDeck.EnumerateDevices(null).

Add non threaded SetKeyBitmap

Hi !
First thanks a lot for your lib, the stream deck would have been out interest without it :D

I've been using your library but I had some troubles
When settings the keys pictures from a dispatcher timer lot of transmission errors occurred on the Stream deck (pictures with errors, pictures on the wrong key). Adding a delay between each call seems to stabilize it, however it was slow :D

I solved it by using a custom synchronous method :

It has two advantages, I can control the actual send rate, so instead of enqueing without knowing what I really send to the deck, I can control the "flow"outside of the Steamdeck controller,

        public void SetKeyBitmapSync(int keyId, StreamDeckKeyBitmap bitmap)
        {
            VerifyNotDisposed();

            var page1 = StreamDeckCom.GeneratePage1(keyId, bitmap.rawBitmapData);
            var page2 = StreamDeckCom.GeneratePage2(keyId, bitmap.rawBitmapData);

            device.Write(page1);
            device.Write(page2);
        }

Also it would be nice to implement some kind of comparers on the StreamDeckKeyBitmap, maybe by using a dumb md5 hash of the rawBitmapData, in this way it allows the user to easily keep track of previous key states and avoid sending them again if it doesn't changes,
I solved it like this, then I use the Hash to compare two StreamDeckKeyBitmap :

public partial class StreamDeckKeyBitmap
    {
        /// <summary>
        /// Solid black bitmap
        /// </summary>
        /// <remarks>
        /// If you need a black bitmap (for example to clear keys) use this property for better performance (in theory ^^)
        /// </remarks>
        public static StreamDeckKeyBitmap Black { get { return black; } }

        public string Hash { get; }

        private static readonly StreamDeckKeyBitmap black = new StreamDeckKeyBitmap(null);

        /// <remarks>
        /// The raw pixel format is a byte array of length 15552. This number is based on the image
        /// dimensions used by StreamDeck 72x72 pixels and 3 channels (RGB) for each pixel. 72 x 72 x 3 = 15552.
        ///
        /// The channels are in the order BGR and the pixel rows (stride) are in reverse order.
        /// If you need some help try <see cref="StreamDeckKeyBitmap"/>
        /// </remarks>
        internal readonly byte[] rawBitmapData;

        internal StreamDeckKeyBitmap(byte[] bitmapData)
        {
            if (bitmapData != null)
            {
                if (bitmapData.Length != StreamDeckHID.rawBitmapDataLength) throw new NotSupportedException("Unsupported bitmap array length");
                this.rawBitmapData = bitmapData;

                this.Hash = GetMd5Hash(this.rawBitmapData);
            }
        }

        private static string GetMd5Hash(byte[] input)
        {
            using (MD5 md5Hash = MD5.Create())
            {
                byte[] data = md5Hash.ComputeHash(input);
                StringBuilder sBuilder = new StringBuilder();
                for (int i = 0; i < data.Length; i++)
                {
                    sBuilder.Append(data[i].ToString("x2"));
                }
                return sBuilder.ToString();
            }
        }
    }
}

Feature request: Button down creates smaller image

First of all, my compliments about your library. It is really easy to use and well documented, keep up the good work!

If you have some time left it would be great is you can add a Property that enables "Make image smaller on button down". What do i mean? Well lets say the image is 100,100 when i push the button i would like to see that the image would be downsized to let's say 80,80 and when i release the button it returns to it's original size 100,100

This way the push action of a button is more like a software button. I noticed this behaviour if you use the stock StreamDeck software.

Streamdeck Plus

Recently got my Streamdeck Plus (ProductID 0x0084)
It features 8 normal buttons , 4 ecoders with images (imagesize unknown yet, but rectangle not square)

I'll play with it the next days and capture some reports.

UsbDeview report
report.zip

API to get all HID devices/Property to get HID device name

Hey, thanks for the great work on this library! Would love to suggest to features:

  1. An API like StreamDeck.GetAllDevices() that would return make a list of all Stream Deck devices with their device path.

  2. A property on IStreamDeck to get the device path for it.

This would help to give a lot of flexibility to discovering, connecting, and reconnecting stream deck devices. Thanks!

Readme.md needs updating

The code used in the main Readme.md seems to be from a previous release, both the example class and the table reference non-existent methods, and the "Examples" section doesn't seem to know that you separated the examples into their own repository some time ago. The problem being that newcomers like myself might just give up on a library that appears broken before they understand what is necessary.

I plan to submit a PR with an updated Readme as time allows. In case you get to it before I do, I'd also recommend making it more clear that the example code and the rainbow picture below it are not connected, although that is less critical.

Overall, problematic documentation, but great library! :)

Switch profiles on Streamdeck

Perhaps I am missing a method or perhaps it is not possible with the Streamdeck API, but is there a function to switch to an existing PROFILE after the device has been opened, i.e. something like this?

var device = StreamDeck.OpenDevice(someDevice.DevicePath); device.SwitchProfile("MyProfile");

?

nuget version 0.3.5 dependent on non-existing version of OpenMacroBoard.sdk

When trying to install latest release of StreamDeckSharp (v0.3.5 from nuget) there is an error message:

Unable to find a version of 'OpenMacroBoard.SDK' that is compatible with 'StreamDeckSharp 0.3.5 constraint: OpenMacroBoard.SDK (>= 0.4.0 && < 1.0.0)'.

It seems OpenMacroBoard.SDK was not updated in nuget to the newer version and as such, cannot install StreamDeckSharp through nuget

Support for Stream Deck XL

2019-05-28 - Ordered a Stream Deck XL
2019-06-17 - Stream Deck XL arrived (start development)
2019-06-19 - Release v0.3.2

Finished (v0.3.2)

  • SetKeyBitmap
  • KeyStateChanged event
  • ConnectionStateChanged event

Finished (v0.3.4)

  • GetFirmwareVersion
  • GetSerialNumber
  • ShowLogo
  • SetBrightness

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.