From 6aa625e16134d346647ecff9a8e503d0adc329ed Mon Sep 17 00:00:00 2001 From: hexawyz <8518235+hexawyz@users.noreply.github.com> Date: Sun, 9 Feb 2025 22:03:33 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20StreamDeck:=20Add=20a=20shortcut=20?= =?UTF-8?q?for=20image=20duplication.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StreamDeckDeviceDriver.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Exo/Devices/Exo.Devices.Elgato.StreamDeck/StreamDeckDeviceDriver.cs b/src/Exo/Devices/Exo.Devices.Elgato.StreamDeck/StreamDeckDeviceDriver.cs index cc36bb5..652b61a 100644 --- a/src/Exo/Devices/Exo.Devices.Elgato.StreamDeck/StreamDeckDeviceDriver.cs +++ b/src/Exo/Devices/Exo.Devices.Elgato.StreamDeck/StreamDeckDeviceDriver.cs @@ -176,6 +176,7 @@ CancellationToken cancellationToken private readonly Guid[] _buttonIds; private readonly StreamDeckDeviceInfo _deviceInfo; private uint _idleSleepDelay; + private UInt128 _lastImageId; private readonly ushort _productId; private readonly ushort _versionNumber; private readonly Button[] _buttons; @@ -189,7 +190,6 @@ CancellationToken cancellationToken IDeviceFeatureSet IDeviceDriver.Features => _embeddedMonitorFeatures; IDeviceFeatureSet IDeviceDriver.Features => _powerManagementFeatures; - private StreamDeckDeviceDriver ( StreamDeckDevice device, @@ -270,13 +270,16 @@ public Button(StreamDeckDeviceDriver driver, byte buttonId) // Bitmap seems to not work at all. Until I find a way to understand how colors are mapped, it is better to disable it. (e.g. black would give dark purple, white would give maroon) EmbeddedMonitorInformation IEmbeddedMonitor.MonitorInformation => new(MonitorShape.Square, _driver.ButtonImageSize, PixelFormat.B8G8R8, /*ImageFormats.Bitmap | */ImageFormats.Jpeg, false); - ValueTask IEmbeddedMonitor.SetImageAsync(UInt128 imageId, ImageFormat imageFormat, ReadOnlyMemory data, CancellationToken cancellationToken) + async ValueTask IEmbeddedMonitor.SetImageAsync(UInt128 imageId, ImageFormat imageFormat, ReadOnlyMemory data, CancellationToken cancellationToken) { if (imageFormat is not (ImageFormat.Bitmap or ImageFormat.Jpeg)) { - return ValueTask.FromException(ExceptionDispatchInfo.SetCurrentStackTrace(new ArgumentOutOfRangeException(nameof(imageFormat)))); + throw new ArgumentOutOfRangeException(nameof(imageFormat)); } - return new ValueTask(_driver._device.SetKeyImageDataAsync(_keyIndex, data, cancellationToken)); + // We basically can avoid sending a lengthy transfer over to the device if two consecutive images are the same. + // The write buffer will still contain the data from the last upload. + await _driver._device.SetKeyImageDataAsync(_keyIndex, imageId == _driver._lastImageId ? Array.Empty() : data, cancellationToken); + _driver._lastImageId = imageId; } } }