fix display binary format

This commit is contained in:
Vinzenz Schroeter 2024-04-19 13:40:26 +02:00
parent 043022186f
commit 2d17ff0de3
2 changed files with 17 additions and 2 deletions

View file

@ -15,6 +15,7 @@ internal sealed class DisplayConnection(IOptions<DisplayConfiguration> options)
public ValueTask SendClearAsync() public ValueTask SendClearAsync()
{ {
var header = new HeaderWindow { Command = DisplayCommand.Clear }; var header = new HeaderWindow { Command = DisplayCommand.Clear };
return SendAsync(header, Memory<byte>.Empty); return SendAsync(header, Memory<byte>.Empty);
} }
@ -28,6 +29,7 @@ internal sealed class DisplayConnection(IOptions<DisplayConfiguration> options)
PosX = x, PosX = x,
PosY = y PosY = y
}; };
return SendAsync(header, grid.Data); return SendAsync(header, grid.Data);
} }
@ -81,7 +83,7 @@ internal sealed class DisplayConnection(IOptions<DisplayConfiguration> options)
{ {
Command = DisplayCommand.BitmapLinearWin, Command = DisplayCommand.BitmapLinearWin,
PosX = x, PosY = y, PosX = x, PosY = y,
Width = pixels.Width, Width = (ushort)(pixels.Width / 8),
Height = pixels.Height Height = pixels.Height
}; };
@ -111,6 +113,7 @@ internal sealed class DisplayConnection(IOptions<DisplayConfiguration> options)
var buffer = _arrayPool.Rent(messageSize); var buffer = _arrayPool.Rent(messageSize);
var message = buffer.AsMemory(0, messageSize); var message = buffer.AsMemory(0, messageSize);
header.ChangeToNetworkOrder();
MemoryMarshal.Write(message.Span, header); MemoryMarshal.Write(message.Span, header);
payload.CopyTo(message[headerSize..]); payload.CopyTo(message[headerSize..]);

View file

@ -1,3 +1,4 @@
using System.Buffers.Binary;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace DisplayCommands.Internals; namespace DisplayCommands.Internals;
@ -14,4 +15,15 @@ internal struct HeaderWindow
public ushort Width; public ushort Width;
public ushort Height; public ushort Height;
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);
}
} }