mirror of
https://github.com/cccb/servicepoint.git
synced 2025-01-18 02:00:12 +01:00
add ruby example, update README.md
This commit is contained in:
parent
6137460457
commit
b693e9e1c9
15
README.md
15
README.md
|
@ -1,5 +1,10 @@
|
|||
# servicepoint
|
||||
|
||||
[![crates.io](https://img.shields.io/crates/v/servicepoint.svg)](https://crates.io/crates/servicepoint)
|
||||
[![Crates.io Total Downloads](https://img.shields.io/crates/d/servicepoint)](https://crates.io/crates/servicepoint)
|
||||
[![docs.rs](https://img.shields.io/docsrs/servicepoint)](https://docs.rs/servicepoint/latest/servicepoint/)
|
||||
[![GPLv3 licensed](https://img.shields.io/crates/l/servicepoint)](../../LICENSE)
|
||||
|
||||
In [CCCB](https://berlin.ccc.de/), there is a big pixel matrix hanging on the wall. It is called "Service Point
|
||||
Display" or "Airport Display".
|
||||
This repository contains a library for parsing, encoding and sending packets to this display via UDP in multiple
|
||||
|
@ -7,11 +12,11 @@ programming languages.
|
|||
|
||||
Take a look at the contained crates for language specific information:
|
||||
|
||||
| Language | Readme |
|
||||
|-----------|---------------------------------------------------------------------|
|
||||
| Rust | [servicepoint](crates/servicepoint/README.md) |
|
||||
| C / C++ | [servicepoint_binding_c](crates/servicepoint_binding_c/README.md) |
|
||||
| .NET (C#) | [servicepoint_binding_cs](crates/servicepoint_binding_cs/README.md) |
|
||||
| Crate | Languages | Readme |
|
||||
|-----------------------------|-----------------------------------|-------------------------------------------------------------------------|
|
||||
| servicepoint | Rust | [servicepoint](crates/servicepoint/README.md) |
|
||||
| servicepoint_binding_c | C / C++ | [servicepoint_binding_c](crates/servicepoint_binding_c/README.md) |
|
||||
| servicepoint_binding_uniffi | C# / Python / Go / Kotlin / Swift | [servicepoint_binding_cs](crates/servicepoint_binding_uniffi/README.md) |
|
||||
|
||||
## Projects using the library
|
||||
|
||||
|
|
90
crates/servicepoint_binding_uniffi/README.md
Normal file
90
crates/servicepoint_binding_uniffi/README.md
Normal file
|
@ -0,0 +1,90 @@
|
|||
# ServicePoint
|
||||
|
||||
In [CCCB](https://berlin.ccc.de/), there is a big pixel matrix hanging on the wall. It is called "Service Point
|
||||
Display" or "Airport Display".
|
||||
|
||||
This crate contains bindings for multiple programming languages, enabling non-rust-developers to use the library.
|
||||
|
||||
Also take a look at the main project [README](https://github.com/cccb/servicepoint/blob/main/README.md) for more
|
||||
information.
|
||||
|
||||
## Note on stability
|
||||
|
||||
This library is still in early development.
|
||||
You can absolutely use it, and it works, but expect minor breaking changes with every version bump.
|
||||
|
||||
## Notes on differences to rust library
|
||||
|
||||
- Performance will not be as good as the rust version:
|
||||
- most objects are reference counted.
|
||||
- objects with mutating methods will also have a MRSW lock
|
||||
- You will not get rust backtraces in release builds of the native code
|
||||
- Panic messages will work (PanicException)
|
||||
|
||||
## Supported languages
|
||||
|
||||
| Language | Support level | Notes |
|
||||
|-----------|---------------|-------------------------------------------------------------------------------------------------|
|
||||
| .NET (C#) | Full | see dedicated section |
|
||||
| Ruby | Working | LD_LIBRARY_PATH has to be set, see example project |
|
||||
| Python | Tested once | Required project file not included. The shared library will be loaded from the script location. |
|
||||
| Go | untested | |
|
||||
| Kotlin | untested | |
|
||||
| Swift | untested | |
|
||||
|
||||
## Installation
|
||||
|
||||
Including this repository as a submodule and building from source is the recommended way of using the library.
|
||||
|
||||
```bash
|
||||
git submodule add https://github.com/cccb/servicepoint.git
|
||||
git commit -m "add servicepoint submodule"
|
||||
```
|
||||
|
||||
Run `generate-bindings.sh` to regenerate all bindings. This will also build `libservicepoint.so` (or equivalent on your
|
||||
platform).
|
||||
|
||||
For languages not fully supported, there will be no project file for the library, just the naked source file(s).
|
||||
If you successfully use a language, please open an issue or PR to add the missing ones.
|
||||
|
||||
## .NET (C#)
|
||||
|
||||
This is the best supported language.
|
||||
|
||||
F# is not tested. If there are usability or functionality problems, please open an issue.
|
||||
|
||||
Currently, the project file is hard-coded for Linux and will need tweaks for other platforms (e.g. `.dylib` instead of `.so`).
|
||||
|
||||
You do not have to compile or copy the rust crate manually, as building `ServicePoint.csproj` also builds it.
|
||||
|
||||
### Example
|
||||
|
||||
```csharp
|
||||
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);
|
||||
}
|
||||
```
|
||||
|
||||
A full example including project files is available as part of this crate.
|
||||
|
||||
### Why is there no NuGet-Package?
|
||||
|
||||
NuGet packages are not a good way to distribute native
|
||||
binaries ([relevant issue](https://github.com/dotnet/sdk/issues/33845)).
|
||||
Because of that, there is no NuGet package you can use directly.
|
|
@ -19,6 +19,6 @@ COMMON_ARGS="--library $SERVICEPOINT_SO"
|
|||
${BINDGEN} generate $COMMON_ARGS --language python --out-dir "$LIBRARIES_PATH/python"
|
||||
${BINDGEN} generate $COMMON_ARGS --language kotlin --out-dir "$LIBRARIES_PATH/kotlin"
|
||||
${BINDGEN} generate $COMMON_ARGS --language swift --out-dir "$LIBRARIES_PATH/swift"
|
||||
${BINDGEN} generate $COMMON_ARGS --language ruby --out-dir "$LIBRARIES_PATH/ruby"
|
||||
${BINDGEN} generate $COMMON_ARGS --language ruby --out-dir "$LIBRARIES_PATH/ruby/lib"
|
||||
${BINDGEN_CS} $COMMON_ARGS --out-dir "$LIBRARIES_PATH/csharp/ServicePoint"
|
||||
${BINDGEN_GO} $COMMON_ARGS --out-dir "$LIBRARIES_PATH/go/"
|
||||
|
|
4
crates/servicepoint_binding_uniffi/libraries/.gitignore
vendored
Normal file
4
crates/servicepoint_binding_uniffi/libraries/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
go
|
||||
kotlin
|
||||
python
|
||||
swift
|
|
@ -0,0 +1,3 @@
|
|||
source 'https://rubygems.org'
|
||||
|
||||
gem 'servicepoint', path: '..'
|
|
@ -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
|
|
@ -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
|
||||
|
||||
|
3
crates/servicepoint_binding_uniffi/libraries/ruby/example/example.sh
Executable file
3
crates/servicepoint_binding_uniffi/libraries/ruby/example/example.sh
Executable 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
|
@ -0,0 +1,13 @@
|
|||
Gem::Specification.new do |s|
|
||||
s.name = "servicepoint"
|
||||
s.version = "0.0.0"
|
||||
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
|
11
flake.nix
11
flake.nix
|
@ -117,16 +117,19 @@
|
|||
clippy
|
||||
cargo-expand
|
||||
cargo-tarpaulin
|
||||
gcc
|
||||
gnumake
|
||||
dotnet-sdk_8
|
||||
];
|
||||
};
|
||||
in
|
||||
{
|
||||
default = pkgs.mkShell rec {
|
||||
inputsFrom = [ self.packages.${system}.servicepoint ];
|
||||
packages = [ rust-toolchain ];
|
||||
packages = with pkgs; [
|
||||
rust-toolchain
|
||||
ruby
|
||||
dotnet-sdk_8
|
||||
gcc
|
||||
gnumake
|
||||
];
|
||||
LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath (builtins.concatMap (d: d.buildInputs) inputsFrom)}";
|
||||
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue