split servicepoint_binding_uniffi into own crate
Some checks failed
Rust / build (push) Has been cancelled

This commit is contained in:
Vinzenz Schroeter 2025-02-16 13:13:54 +01:00
parent 2f7a2dfd62
commit 21931f847f
94 changed files with 158 additions and 9856 deletions

4
libraries/.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
go
kotlin
python
swift

2
libraries/csharp/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
bin
obj

View file

@ -0,0 +1,2 @@
bin
obj

View file

@ -0,0 +1,19 @@
using System.Threading;
using ServicePoint;
var connection = new Connection("127.0.0.1:2342");
connection.Send(Command.Clear());
connection.Send(Command.Brightness(5));
var pixels = Bitmap.NewMaxSized();
for (ulong offset = 0; offset < ulong.MaxValue; offset++)
{
pixels.Fill(false);
for (ulong y = 0; y < pixels.Height(); y++)
pixels.Set((y + offset) % pixels.Width(), y, true);
connection.Send(Command.BitmapLinearWin(0, 0, pixels));
Thread.Sleep(14);
}

View file

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>ServicePoint.Example</RootNamespace>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../ServicePoint/ServicePoint.csproj"/>
</ItemGroup>
</Project>

View file

@ -0,0 +1,16 @@
namespace ServicePoint.Tests;
public class BitmapTests
{
[Fact]
public void BasicFunctions()
{
var bitmap = new Bitmap(8, 2);
Assert.False(bitmap.Get(0, 0));
Assert.False(bitmap.Get(bitmap.Width() - 1, bitmap.Height() - 1));
bitmap.Fill(true);
Assert.True(bitmap.Get(1, 1));
bitmap.Set(1, 1, false);
Assert.False(bitmap.Get(1, 1));
}
}

View file

@ -0,0 +1,31 @@
namespace ServicePoint.Tests;
public class CharGridTests
{
[Fact]
public void BasicFunctions()
{
var grid = new CharGrid(8, 2);
Assert.Equal("\0", grid.Get(0, 0));
Assert.Equal("\0", grid.Get(grid.Width() - 1, grid.Height() - 1));
grid.Fill(" ");
Assert.Equal(" ", grid.Get(1, 1));
grid.Set(1, 1, "-");
Assert.Equal("-", grid.Get(1, 1));
Assert.Throws<PanicException>(() => grid.Get(8, 2));
}
[Fact]
public void RowAndCol()
{
var grid = new CharGrid(3, 2);
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"));
grid.SetRow(1, "Foo");
Assert.Equal("Foo", grid.GetRow(1));
Assert.Equal(" o", grid.GetCol(2));
}
}

View file

@ -0,0 +1,42 @@
namespace ServicePoint.Tests;
public class CommandTests
{
private Connection _connection = Connection.NewFake();
[Fact]
public void ClearSendable()
{
_connection.Send(Command.Clear());
}
[Fact]
public void BrightnessSendable()
{
_connection.Send(Command.Brightness(5));
}
[Fact]
public void InvalidBrightnessThrows()
{
Assert.Throws<ServicePointException.InvalidBrightness>(() => Command.Brightness(42));
}
[Fact]
public void FadeOutSendable()
{
_connection.Send(Command.FadeOut());
}
[Fact]
public void HardResetSendable()
{
_connection.Send(Command.HardReset());
}
[Fact]
public void BitmapLinearWinSendable()
{
_connection.Send(Command.BitmapLinearWin(0, 0, Bitmap.NewMaxSized(), CompressionCode.Uncompressed));
}
}

View file

@ -0,0 +1,11 @@
namespace ServicePoint.Tests;
public class ConnectionTests
{
[Fact]
public void InvalidHostnameThrows()
{
Assert.Throws<ServicePointException.IoException>(() => new Connection(""));
Assert.Throws<ServicePointException.IoException>(() => new Connection("-%6$§"));
}
}

View file

@ -0,0 +1,2 @@
global using Xunit;
global using ServicePoint;

View file

@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../ServicePoint/ServicePoint.csproj"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
</ItemGroup>
<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,14 @@
using ServicePoint;
public static class ServicePointConstants
{
private static readonly Constants _instance = ServicepointBindingUniffiMethods.GetConstants();
public static readonly ulong PixelWidth = _instance.pixelWidth;
public static readonly ulong PixelHeight = _instance.pixelHeight;
public static readonly ulong PixelCount = _instance.pixelCount;
public static readonly ulong TileWidth = _instance.tileWidth;
public static readonly ulong TileHeight = _instance.tileHeight;
public static readonly ulong TileSize = _instance.tileSize;
}

View file

@ -0,0 +1,53 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<PackageId>ServicePoint</PackageId>
<Version>0.13.1</Version>
<Authors>Repository Authors</Authors>
<Company>None</Company>
<Product>ServicePoint</Product>
<PackageTags>CCCB</PackageTags>
<Description>
C# bindings for the rust crate servicepoint. You will need a suitable native shared library to use this.
For documentation, see the rust documentation: https://docs.rs/servicepoint/latest/servicepoint/.
Note that this library is still in early development. Breaking changes are expected before 1.0 is released.
</Description>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
</PropertyGroup>
<!-- generate C# bindings -->
<Target Name="BuildBindings" Condition="'$(Configuration)'=='Release'" BeforeTargets="PrepareForBuild">
<Exec Command="cargo build -p servicepoint_binding_uniffi --release"/>
</Target>
<Target Name="BuildBindings" Condition="'$(Configuration)'=='Debug'" BeforeTargets="PrepareForBuild">
<Exec Command="cargo build -p servicepoint_binding_uniffi"/>
</Target>
<!-- include native binary in output -->
<ItemGroup Condition="'$(Configuration)'=='Debug'">
<Content Include="../../../../../target/debug/libservicepoint_binding_uniffi.so" CopyToOutputDirectory="Always">
<Link>libservicepoint_binding_uniffi.so</Link>
</Content>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Release'">
<Content Include="../../../../../target/release/libservicepoint_binding_uniffi.so" CopyToOutputDirectory="Always">
<Link>libservicepoint_binding_uniffi.so</Link>
</Content>
</ItemGroup>
<ItemGroup>
<!-- add README.md to package -->
<None Include="../README.md" Pack="true" PackagePath="\"/>
<!-- include link to source code at revision -->
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
</ItemGroup>
</Project>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,34 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServicePoint", "ServicePoint\ServicePoint.csproj", "{53576D3C-E32E-49BF-BF10-2DB504E50CE1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServicePoint.Example", "ServicePoint.Example\ServicePoint.Example.csproj", "{FEF24227-090E-46C2-B8F6-ACB5AA1A4309}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServicePoint.Tests", "ServicePoint.Tests\ServicePoint.Tests.csproj", "{9DC15508-A980-4135-9FC6-659FF54B4E5C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{53576D3C-E32E-49BF-BF10-2DB504E50CE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{53576D3C-E32E-49BF-BF10-2DB504E50CE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{53576D3C-E32E-49BF-BF10-2DB504E50CE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{53576D3C-E32E-49BF-BF10-2DB504E50CE1}.Release|Any CPU.Build.0 = Release|Any CPU
{FEF24227-090E-46C2-B8F6-ACB5AA1A4309}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FEF24227-090E-46C2-B8F6-ACB5AA1A4309}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FEF24227-090E-46C2-B8F6-ACB5AA1A4309}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FEF24227-090E-46C2-B8F6-ACB5AA1A4309}.Release|Any CPU.Build.0 = Release|Any CPU
{9DC15508-A980-4135-9FC6-659FF54B4E5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9DC15508-A980-4135-9FC6-659FF54B4E5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9DC15508-A980-4135-9FC6-659FF54B4E5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9DC15508-A980-4135-9FC6-659FF54B4E5C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View file

@ -0,0 +1,3 @@
source 'https://rubygems.org'
gem 'servicepoint', path: '..'

View file

@ -0,0 +1,19 @@
PATH
remote: ..
specs:
servicepoint (0.0.0)
ffi
GEM
remote: https://rubygems.org/
specs:
ffi (1.17.0-x86_64-linux-gnu)
PLATFORMS
x86_64-linux
DEPENDENCIES
servicepoint!
BUNDLED WITH
2.3.27

View file

@ -0,0 +1,25 @@
require_relative "../lib/servicepoint_binding_uniffi"
include ServicepointBindingUniffi
connection = Connection.new("172.23.42.29:2342")
pixels = Bitmap.new_max_sized
x_offset = 0
loop do
pixels.fill(false)
(0..((pixels.height) -1)).each do |y|
pixels.set((y + x_offset) % pixels.width, y, true);
end
command = Command.bitmap_linear_win(0, 0, pixels, CompressionCode::UNCOMPRESSED)
connection.send(command)
sleep 0.0005
x_offset += 1
end

View file

@ -0,0 +1,3 @@
#!/usr/bin/env bash
LD_LIBRARY_PATH="../../../../../target/release:$LD_LIBRARY_PATH" ruby example.rb

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,13 @@
Gem::Specification.new do |s|
s.name = "servicepoint"
s.version = "0.13.1"
s.summary = ""
s.description = ""
s.authors = ["kaesaecracker"]
s.email = ""
s.files = ["lib/servicepoint_binding_uniffi.rb"]
s.homepage =
"https://rubygems.org/gems/hola"
s.license = "MIT"
s.add_dependency 'ffi'
end