fix display binary format
This commit is contained in:
		
							parent
							
								
									043022186f
								
							
						
					
					
						commit
						2d17ff0de3
					
				
					 2 changed files with 17 additions and 2 deletions
				
			
		|  | @ -15,6 +15,7 @@ internal sealed class DisplayConnection(IOptions<DisplayConfiguration> options) | |||
|     public ValueTask SendClearAsync() | ||||
|     { | ||||
|         var header = new HeaderWindow { Command = DisplayCommand.Clear }; | ||||
| 
 | ||||
|         return SendAsync(header, Memory<byte>.Empty); | ||||
|     } | ||||
| 
 | ||||
|  | @ -28,6 +29,7 @@ internal sealed class DisplayConnection(IOptions<DisplayConfiguration> options) | |||
|             PosX = x, | ||||
|             PosY = y | ||||
|         }; | ||||
| 
 | ||||
|         return SendAsync(header, grid.Data); | ||||
|     } | ||||
| 
 | ||||
|  | @ -81,7 +83,7 @@ internal sealed class DisplayConnection(IOptions<DisplayConfiguration> 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<DisplayConfiguration> options) | |||
|         var buffer = _arrayPool.Rent(messageSize); | ||||
|         var message = buffer.AsMemory(0, messageSize); | ||||
| 
 | ||||
|         header.ChangeToNetworkOrder(); | ||||
|         MemoryMarshal.Write(message.Span, header); | ||||
|         payload.CopyTo(message[headerSize..]); | ||||
| 
 | ||||
|  |  | |||
|  | @ -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; | ||||
| } | ||||
| 
 | ||||
|     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); | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vinzenz Schroeter
						Vinzenz Schroeter