From 2d17ff0de3931a1ab20d5c7dd75db9c6bf999fc8 Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Fri, 19 Apr 2024 13:40:26 +0200 Subject: [PATCH] fix display binary format --- DisplayCommands/Internals/DisplayConnection.cs | 5 ++++- DisplayCommands/Internals/HeaderWindow.cs | 14 +++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/DisplayCommands/Internals/DisplayConnection.cs b/DisplayCommands/Internals/DisplayConnection.cs index 466aa1c..4505d95 100644 --- a/DisplayCommands/Internals/DisplayConnection.cs +++ b/DisplayCommands/Internals/DisplayConnection.cs @@ -15,6 +15,7 @@ internal sealed class DisplayConnection(IOptions options) public ValueTask SendClearAsync() { var header = new HeaderWindow { Command = DisplayCommand.Clear }; + return SendAsync(header, Memory.Empty); } @@ -28,6 +29,7 @@ internal sealed class DisplayConnection(IOptions options) PosX = x, PosY = y }; + return SendAsync(header, grid.Data); } @@ -81,7 +83,7 @@ internal sealed class DisplayConnection(IOptions options) { Command = DisplayCommand.BitmapLinearWin, PosX = x, PosY = y, - Width = pixels.Width, + Width = (ushort)(pixels.Width / 8), Height = pixels.Height }; @@ -111,6 +113,7 @@ internal sealed class DisplayConnection(IOptions options) var buffer = _arrayPool.Rent(messageSize); var message = buffer.AsMemory(0, messageSize); + header.ChangeToNetworkOrder(); MemoryMarshal.Write(message.Span, header); payload.CopyTo(message[headerSize..]); diff --git a/DisplayCommands/Internals/HeaderWindow.cs b/DisplayCommands/Internals/HeaderWindow.cs index 05d5541..fcb9176 100644 --- a/DisplayCommands/Internals/HeaderWindow.cs +++ b/DisplayCommands/Internals/HeaderWindow.cs @@ -1,3 +1,4 @@ +using System.Buffers.Binary; using System.Runtime.InteropServices; namespace DisplayCommands.Internals; @@ -14,4 +15,15 @@ internal struct HeaderWindow public ushort Width; public ushort Height; -} \ No newline at end of file + + public void ChangeToNetworkOrder() + { + if (!BitConverter.IsLittleEndian) + return; + Command = (DisplayCommand)BinaryPrimitives.ReverseEndianness((ushort)Command); + PosX = BinaryPrimitives.ReverseEndianness(PosX); + PosY = BinaryPrimitives.ReverseEndianness(PosY); + Width = BinaryPrimitives.ReverseEndianness(Width); + Height = BinaryPrimitives.ReverseEndianness(Height); + } +}