This commit is contained in:
parent
13a34e83d7
commit
178ab1eb74
|
@ -1,12 +1,13 @@
|
|||
using System.Threading;
|
||||
using ServicePoint;
|
||||
|
||||
var connection = new Connection("127.0.0.1:2342");
|
||||
connection.Send(Command.Clear());
|
||||
//var connection = new Connection("127.0.0.1:2342");
|
||||
var connection = new FakeConnection();
|
||||
connection.Send(new ClearCommand());
|
||||
|
||||
connection.Send(Command.Brightness(5));
|
||||
connection.Send(new GlobalBrightnessCommand(5));
|
||||
|
||||
connection.Send(Command.Utf8Data(0,0, CharGrid.Load("This is a test")));
|
||||
connection.Send(new CharGridCommand(0, 0, CharGrid.Load("This is a test")));
|
||||
|
||||
var pixels = Bitmap.NewMaxSized();
|
||||
for (ulong offset = 0; offset < pixels.Width(); offset++)
|
||||
|
@ -16,6 +17,6 @@ for (ulong offset = 0; offset < pixels.Width(); offset++)
|
|||
for (ulong y = 0; y < pixels.Height(); y++)
|
||||
pixels.Set((y + offset) % pixels.Width(), y, true);
|
||||
|
||||
connection.Send(Command.BitmapLinearWin(0, 0, pixels, CompressionCode.Lzma));
|
||||
connection.Send(new BitmapCommand(0, 0, pixels, CompressionCode.Lzma));
|
||||
Thread.Sleep(14);
|
||||
}
|
||||
|
|
|
@ -12,4 +12,8 @@
|
|||
<ProjectReference Include="../ServicePoint/ServicePoint.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<PublishAot>true</PublishAot>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
|
@ -12,7 +12,7 @@ public class CharGridTests
|
|||
Assert.Equal(" ", grid.Get(1, 1));
|
||||
grid.Set(1, 1, "-");
|
||||
Assert.Equal("-", grid.Get(1, 1));
|
||||
Assert.Throws<PanicException>(() => grid.Get(8, 2));
|
||||
Assert.Throws<ServicePointException.OutOfBounds>(() => grid.Get(8, 2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -22,8 +22,8 @@ public class CharGridTests
|
|||
Assert.Equal("\0\0\0", grid.GetRow(0));
|
||||
grid.Fill(" ");
|
||||
Assert.Equal(" ", grid.GetCol(1));
|
||||
Assert.Throws<CharGridException.OutOfBounds>(() => grid.GetCol(3));
|
||||
Assert.Throws<CharGridException.InvalidSeriesLength>(() => grid.SetRow(1, "Text"));
|
||||
Assert.Throws<ServicePointException.OutOfBounds>(() => grid.GetCol(3));
|
||||
Assert.Throws<ServicePointException.InvalidSeriesLength>(() => grid.SetRow(1, "Text"));
|
||||
grid.SetRow(1, "Foo");
|
||||
Assert.Equal("Foo", grid.GetRow(1));
|
||||
Assert.Equal(" o", grid.GetCol(2));
|
||||
|
|
|
@ -2,41 +2,48 @@ namespace ServicePoint.Tests;
|
|||
|
||||
public class CommandTests
|
||||
{
|
||||
private Connection _connection = Connection.NewFake();
|
||||
private IConnection _connection = new FakeConnection();
|
||||
|
||||
[Fact]
|
||||
public void ClearSendable()
|
||||
{
|
||||
_connection.Send(Command.Clear());
|
||||
_connection.Send(new ClearCommand());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenericAsPacket()
|
||||
{
|
||||
var command = new ClearCommand();
|
||||
Assert.Equal(command.AsPacket(), command.AsGeneric().AsPacket());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BrightnessSendable()
|
||||
{
|
||||
_connection.Send(Command.Brightness(5));
|
||||
_connection.Send(new GlobalBrightnessCommand(5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InvalidBrightnessThrows()
|
||||
{
|
||||
Assert.Throws<ServicePointException.InvalidBrightness>(() => Command.Brightness(42));
|
||||
Assert.Throws<ServicePointException.InvalidBrightness>(() => new GlobalBrightnessCommand(42));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FadeOutSendable()
|
||||
{
|
||||
_connection.Send(Command.FadeOut());
|
||||
_connection.Send(new FadeOutCommand());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HardResetSendable()
|
||||
{
|
||||
_connection.Send(Command.HardReset());
|
||||
_connection.Send(new HardResetCommand());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BitmapLinearWinSendable()
|
||||
{
|
||||
_connection.Send(Command.BitmapLinearWin(0, 0, Bitmap.NewMaxSized(), CompressionCode.Uncompressed));
|
||||
_connection.Send(new BitmapCommand(0, 0, Bitmap.NewMaxSized(), CompressionCode.Uncompressed));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
global using Xunit;
|
||||
global using ServicePoint;
|
||||
global using System;
|
||||
|
|
15
ServicePoint/ConnectionExtensions.cs
Normal file
15
ServicePoint/ConnectionExtensions.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
namespace ServicePoint;
|
||||
|
||||
public static class ConnectionExtensions
|
||||
{
|
||||
public static void Send(this IConnection connection, Packet packet) => connection.SendPacket(packet);
|
||||
public static void Send(this IConnection connection, Command command) => connection.SendCommand(command);
|
||||
public static void Send(this IConnection connection, IClearCommand command) => connection.SendPacket(command.AsPacket());
|
||||
public static void Send(this IConnection connection, IFadeOutCommand command) => connection.SendPacket(command.AsPacket());
|
||||
public static void Send(this IConnection connection, IBitmapCommand command) => connection.SendPacket(command.AsPacket());
|
||||
public static void Send(this IConnection connection, IBitVecCommand command) => connection.SendPacket(command.AsPacket());
|
||||
public static void Send(this IConnection connection, IBrightnessGridCommand command) => connection.SendPacket(command.AsPacket());
|
||||
public static void Send(this IConnection connection, IHardResetCommand command) => connection.SendPacket(command.AsPacket());
|
||||
public static void Send(this IConnection connection, ICharGridCommand command) => connection.SendPacket(command.AsPacket());
|
||||
public static void Send(this IConnection connection, IGlobalBrightnessCommand command) => connection.SendPacket(command.AsPacket());
|
||||
}
|
14
ServicePoint/FakeConnection.cs
Normal file
14
ServicePoint/FakeConnection.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
namespace ServicePoint;
|
||||
|
||||
public sealed class FakeConnection() : IConnection
|
||||
{
|
||||
public void SendCommand(Command command)
|
||||
{
|
||||
SendPacket(command.AsPacket());
|
||||
}
|
||||
|
||||
public void SendPacket(Packet packet)
|
||||
{
|
||||
_ = packet.AsBytes();
|
||||
}
|
||||
}
|
|
@ -23,7 +23,17 @@
|
|||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- generate C# bindings -->
|
||||
<PropertyGroup>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<IsAotCompatible>true</IsAotCompatible>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<DirectPInvoke Include="servicepoint_binding_uniffi" />
|
||||
<NativeLibrary Include="libservicepoint_binding_uniffi.so" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- generate library to link against -->
|
||||
<Target Name="BuildBindings" Condition="'$(Configuration)'=='Release'" BeforeTargets="PrepareForBuild">
|
||||
<Exec Command="cargo build--manifest-path ../servicepoint-binding-uniffi/Cargo.toml --release"/>
|
||||
</Target>
|
||||
|
@ -33,14 +43,18 @@
|
|||
|
||||
<!-- include native binary in output -->
|
||||
<ItemGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<Content Include="../target/debug/libservicepoint_binding_uniffi.so" CopyToOutputDirectory="Always">
|
||||
<Content Include="../servicepoint-binding-uniffi/target/debug/libservicepoint_binding_uniffi.so" CopyToOutputDirectory="Always">
|
||||
<Link>libservicepoint_binding_uniffi.so</Link>
|
||||
</Content>
|
||||
<!-- Specify the path to search for libraries for AOT -->
|
||||
<LinkerArg Include="-L../servicepoint-binding-uniffi/target/debug/libservicepoint_binding_uniffi.so" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(Configuration)'=='Release'">
|
||||
<Content Include="../target/release/libservicepoint_binding_uniffi.so" CopyToOutputDirectory="Always">
|
||||
<Content Include="../servicepoint-binding-uniffi/target/release/libservicepoint_binding_uniffi.so" CopyToOutputDirectory="Always">
|
||||
<Link>libservicepoint_binding_uniffi.so</Link>
|
||||
</Content>
|
||||
<!-- Specify the path to search for libraries for AOT -->
|
||||
<LinkerArg Include="-L../servicepoint-binding-uniffi/target/release/libservicepoint_binding_uniffi.so" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,11 +2,11 @@
|
|||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1749494155,
|
||||
"narHash": "sha256-FG4DEYBpROupu758beabUk9lhrblSf5hnv84v1TLqMc=",
|
||||
"lastModified": 1749857119,
|
||||
"narHash": "sha256-tG5xUn3hFaPpAHYIvr2F88b+ovcIO5k1HqajFy7ZFPM=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "88331c17ba434359491e8d5889cce872464052c2",
|
||||
"rev": "5f4f306bea96741f1588ea4f450b2a2e29f42b98",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
14
flake.nix
14
flake.nix
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
description = "Flake for the servicepoint library.";
|
||||
description = "C# bindings for the servicepoint library.";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
|
||||
};
|
||||
|
||||
outputs =
|
||||
inputs@{
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
}:
|
||||
|
@ -32,12 +32,11 @@
|
|||
devShells = forAllSystems (
|
||||
{ pkgs, system }:
|
||||
{
|
||||
default = pkgs.mkShell rec {
|
||||
default = pkgs.mkShell {
|
||||
packages = with pkgs; [
|
||||
(pkgs.symlinkJoin
|
||||
{
|
||||
(pkgs.symlinkJoin {
|
||||
name = "rust-toolchain";
|
||||
paths = with pkgs; [
|
||||
paths = [
|
||||
rustc
|
||||
cargo
|
||||
rustPlatform.rustcSrc
|
||||
|
@ -53,8 +52,11 @@
|
|||
xe
|
||||
xz
|
||||
pkg-config
|
||||
gdb
|
||||
zlib
|
||||
];
|
||||
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
||||
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1;
|
||||
};
|
||||
}
|
||||
);
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 635fef024437d29b922999fe1d8bd7e6e30524a9
|
||||
Subproject commit ecb4f51997d4f2c3f5bd66033ef13992d88c139c
|
Loading…
Reference in a new issue