Merge pull request #1 from kaesaecracker/restructure
Restructure, build.rs, move c_api
This commit is contained in:
commit
333cf954f8
73 changed files with 1643 additions and 1762 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -3,3 +3,4 @@ target
|
||||||
out
|
out
|
||||||
bin
|
bin
|
||||||
obj
|
obj
|
||||||
|
.direnv
|
||||||
|
|
|
||||||
379
Cargo.lock
generated
379
Cargo.lock
generated
|
|
@ -17,15 +17,6 @@ dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "announce"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"clap",
|
|
||||||
"env_logger",
|
|
||||||
"servicepoint2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstream"
|
name = "anstream"
|
||||||
version = "0.6.14"
|
version = "0.6.14"
|
||||||
|
|
@ -75,6 +66,35 @@ dependencies = [
|
||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "atty"
|
||||||
|
version = "0.2.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||||
|
dependencies = [
|
||||||
|
"hermit-abi",
|
||||||
|
"libc",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "1.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "2.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bzip2"
|
name = "bzip2"
|
||||||
version = "0.4.4"
|
version = "0.4.4"
|
||||||
|
|
@ -97,10 +117,29 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cbindgen"
|
||||||
version = "1.0.97"
|
version = "0.26.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4"
|
checksum = "da6bc11b07529f16944307272d5bd9b22530bc7d05751717c9d416586cedab49"
|
||||||
|
dependencies = [
|
||||||
|
"clap 3.2.25",
|
||||||
|
"heck 0.4.1",
|
||||||
|
"indexmap",
|
||||||
|
"log",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"syn 1.0.109",
|
||||||
|
"tempfile",
|
||||||
|
"toml",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cc"
|
||||||
|
version = "1.0.98"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"jobserver",
|
"jobserver",
|
||||||
"libc",
|
"libc",
|
||||||
|
|
@ -113,6 +152,21 @@ version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap"
|
||||||
|
version = "3.2.25"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123"
|
||||||
|
dependencies = [
|
||||||
|
"atty",
|
||||||
|
"bitflags 1.3.2",
|
||||||
|
"clap_lex 0.2.4",
|
||||||
|
"indexmap",
|
||||||
|
"strsim 0.10.0",
|
||||||
|
"termcolor",
|
||||||
|
"textwrap",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "4.5.4"
|
version = "4.5.4"
|
||||||
|
|
@ -131,8 +185,8 @@ checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstream",
|
"anstream",
|
||||||
"anstyle",
|
"anstyle",
|
||||||
"clap_lex",
|
"clap_lex 0.7.0",
|
||||||
"strsim",
|
"strsim 0.11.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -141,10 +195,19 @@ version = "4.5.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64"
|
checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck",
|
"heck 0.5.0",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.63",
|
"syn 2.0.66",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_lex"
|
||||||
|
version = "0.2.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"
|
||||||
|
dependencies = [
|
||||||
|
"os_str_bytes",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -161,9 +224,9 @@ checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crc32fast"
|
name = "crc32fast"
|
||||||
version = "1.4.0"
|
version = "1.4.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa"
|
checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
@ -179,27 +242,20 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "env_filter"
|
name = "errno"
|
||||||
version = "0.1.0"
|
version = "0.3.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea"
|
checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"log",
|
"libc",
|
||||||
"regex",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "env_logger"
|
name = "fastrand"
|
||||||
version = "0.11.3"
|
version = "2.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9"
|
checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a"
|
||||||
dependencies = [
|
|
||||||
"anstream",
|
|
||||||
"anstyle",
|
|
||||||
"env_filter",
|
|
||||||
"humantime",
|
|
||||||
"log",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "flate2"
|
name = "flate2"
|
||||||
|
|
@ -211,16 +267,6 @@ dependencies = [
|
||||||
"miniz_oxide",
|
"miniz_oxide",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "game_of_life"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"clap",
|
|
||||||
"env_logger",
|
|
||||||
"rand",
|
|
||||||
"servicepoint2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.2.15"
|
version = "0.2.15"
|
||||||
|
|
@ -232,6 +278,18 @@ dependencies = [
|
||||||
"wasi",
|
"wasi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hashbrown"
|
||||||
|
version = "0.12.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "heck"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
|
|
@ -239,10 +297,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "humantime"
|
name = "hermit-abi"
|
||||||
version = "2.1.0"
|
version = "0.1.19"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "indexmap"
|
||||||
|
version = "1.9.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"hashbrown",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "is_terminal_polyfill"
|
name = "is_terminal_polyfill"
|
||||||
|
|
@ -250,6 +321,12 @@ version = "1.70.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800"
|
checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itoa"
|
||||||
|
version = "1.0.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jobserver"
|
name = "jobserver"
|
||||||
version = "0.1.31"
|
version = "0.1.31"
|
||||||
|
|
@ -259,11 +336,25 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lang_c"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"servicepoint_binding_c",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.154"
|
version = "0.2.155"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346"
|
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "linux-raw-sys"
|
||||||
|
version = "0.4.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
|
|
@ -279,28 +370,25 @@ checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "miniz_oxide"
|
name = "miniz_oxide"
|
||||||
version = "0.7.2"
|
version = "0.7.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7"
|
checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"adler",
|
"adler",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "moving_line"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"clap",
|
|
||||||
"env_logger",
|
|
||||||
"servicepoint2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.19.0"
|
version = "1.19.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "os_str_bytes"
|
||||||
|
version = "6.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pkg-config"
|
name = "pkg-config"
|
||||||
version = "0.3.30"
|
version = "0.3.30"
|
||||||
|
|
@ -315,9 +403,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.82"
|
version = "1.0.84"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b"
|
checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
@ -361,16 +449,6 @@ dependencies = [
|
||||||
"getrandom",
|
"getrandom",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "random_brightness"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"clap",
|
|
||||||
"env_logger",
|
|
||||||
"rand",
|
|
||||||
"servicepoint2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.10.4"
|
version = "1.10.4"
|
||||||
|
|
@ -411,24 +489,91 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "servicepoint-binding-cs"
|
name = "rustix"
|
||||||
version = "0.4.2"
|
version = "0.38.34"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"csbindgen",
|
"bitflags 2.5.0",
|
||||||
"servicepoint2",
|
"errno",
|
||||||
|
"libc",
|
||||||
|
"linux-raw-sys",
|
||||||
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "servicepoint2"
|
name = "ryu"
|
||||||
version = "0.4.2"
|
version = "1.0.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde"
|
||||||
|
version = "1.0.203"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094"
|
||||||
|
dependencies = [
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_derive"
|
||||||
|
version = "1.0.203"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.66",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_json"
|
||||||
|
version = "1.0.117"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3"
|
||||||
|
dependencies = [
|
||||||
|
"itoa",
|
||||||
|
"ryu",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "servicepoint"
|
||||||
|
version = "0.5.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bzip2",
|
"bzip2",
|
||||||
|
"clap 4.5.4",
|
||||||
"flate2",
|
"flate2",
|
||||||
"log",
|
"log",
|
||||||
|
"rand",
|
||||||
"rust-lzma",
|
"rust-lzma",
|
||||||
"zstd",
|
"zstd",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "servicepoint_binding_c"
|
||||||
|
version = "0.5.0"
|
||||||
|
dependencies = [
|
||||||
|
"cbindgen",
|
||||||
|
"servicepoint",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "servicepoint_binding_cs"
|
||||||
|
version = "0.5.0"
|
||||||
|
dependencies = [
|
||||||
|
"csbindgen",
|
||||||
|
"servicepoint",
|
||||||
|
"servicepoint_binding_c",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strsim"
|
||||||
|
version = "0.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "strsim"
|
name = "strsim"
|
||||||
version = "0.11.1"
|
version = "0.11.1"
|
||||||
|
|
@ -448,15 +593,51 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.63"
|
version = "2.0.66"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704"
|
checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tempfile"
|
||||||
|
version = "3.10.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"fastrand",
|
||||||
|
"rustix",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "termcolor"
|
||||||
|
version = "1.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-util",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "textwrap"
|
||||||
|
version = "0.16.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml"
|
||||||
|
version = "0.5.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.12"
|
version = "1.0.12"
|
||||||
|
|
@ -481,6 +662,37 @@ version = "0.11.0+wasi-snapshot-preview1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi"
|
||||||
|
version = "0.3.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-i686-pc-windows-gnu",
|
||||||
|
"winapi-x86_64-pc-windows-gnu",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-i686-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-util"
|
||||||
|
version = "0.1.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-x86_64-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.52.0"
|
version = "0.52.0"
|
||||||
|
|
@ -554,15 +766,6 @@ version = "0.52.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
|
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wiping_clear"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"clap",
|
|
||||||
"env_logger",
|
|
||||||
"servicepoint2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zstd"
|
name = "zstd"
|
||||||
version = "0.13.1"
|
version = "0.13.1"
|
||||||
|
|
|
||||||
14
Cargo.toml
14
Cargo.toml
|
|
@ -1,11 +1,11 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
members = [
|
members = [
|
||||||
"servicepoint2",
|
"crates/servicepoint",
|
||||||
"servicepoint2-binding-cs",
|
"crates/servicepoint_binding_c",
|
||||||
"examples/announce",
|
"crates/servicepoint_binding_cs",
|
||||||
"examples/game_of_life",
|
"crates/servicepoint_binding_c/examples/lang_c"
|
||||||
"examples/moving_line",
|
|
||||||
"examples/wiping_clear",
|
|
||||||
"examples/random_brightness"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[workspace.package]
|
||||||
|
version = "0.5.0"
|
||||||
|
|
|
||||||
203
README.md
203
README.md
|
|
@ -1,160 +1,73 @@
|
||||||
# servicepoint2
|
# servicepoint
|
||||||
|
|
||||||
[](https://crates.io/crates/servicepoint2)
|
|
||||||
[](https://crates.io/crates/servicepoint2)
|
|
||||||
[](https://docs.rs/servicepoint2/latest/servicepoint2/)
|
|
||||||
[](./LICENSE)
|
|
||||||
|
|
||||||
In [CCCB](https://berlin.ccc.de/), there is a big pixel matrix hanging on the wall. It is called "Service Point
|
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".
|
Display" or "Airport Display".
|
||||||
This repository contains a library for parsing, encoding and sending packets to this display via UDP.
|
This repository contains a library for parsing, encoding and sending packets to this display via UDP in multiple
|
||||||
|
programming languages.
|
||||||
|
|
||||||
## Note on stability
|
Take a look at the contained crates for language specific information:
|
||||||
|
|
||||||
This library is still in early development.
|
| Language | Readme |
|
||||||
You can absolutely use it, and it works, but expect minor breaking changes with every version bump.
|
|----------|---------------------------------------------------------------------|
|
||||||
Please specify the full version including patch in your Cargo.toml until 1.0 is released.
|
| Rust | [servicepoint](crates/servicepoint/README.md) |
|
||||||
|
| C / C++ | [servicepoint_binding_c](crates/servicepoint_binding_c/README.md) |
|
||||||
Expect bugs and/or missing features in the language bindings for now. If you need something specific, open an issue or a pull request.
|
| C# / F# | [servicepoint_binding_cs](crates/servicepoint_binding_cs/README.md) |
|
||||||
|
|
||||||
## Rust
|
|
||||||
|
|
||||||
This is where the library works the best.
|
|
||||||
Any API usage accepted by the compiler in a safe context is either safe or buggy (issues welcome)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cargo add servicepoint2
|
|
||||||
```
|
|
||||||
|
|
||||||
```rust
|
|
||||||
fn main() {
|
|
||||||
// establish connection
|
|
||||||
let connection = servicepoint2::Connection::open("172.23.42.29:2342")
|
|
||||||
.expect("connection failed");
|
|
||||||
|
|
||||||
// clear screen content
|
|
||||||
connection.send(servicepoint2::Command::Clear.into())
|
|
||||||
.expect("send failed");
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
More examples are available in the repository folder and in the [Projects using the library]() section
|
|
||||||
|
|
||||||
## C / C++
|
|
||||||
|
|
||||||
The lowest common denominator. Things to keep in mind:
|
|
||||||
|
|
||||||
- This is a chainsaw. You will cut your leg.
|
|
||||||
- function names are: `sp2_` \<struct_name\> \<rust name\>.
|
|
||||||
- Use the rust documentation.
|
|
||||||
- Instances get consumed in the same way they do when writing rust / C# code. Do not use an instance after an (implicit!) free.
|
|
||||||
- Option<T> or Result<T, E> turn into nullable return values - check for NULL!
|
|
||||||
- There are no specifics for C++ here yet. You might get a nicer header when generating directly for C++, but it should be usable.
|
|
||||||
- Reading and writing to instances concurrently is not safe. Only reading concurrently is safe.
|
|
||||||
|
|
||||||
```c++
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "servicepoint2.h"
|
|
||||||
|
|
||||||
int main(void) {
|
|
||||||
sp2_Connection *connection = sp2_connection_open("localhost:2342");
|
|
||||||
if (connection == NULL)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
sp2_PixelGrid *pixels = sp2_pixel_grid_new(sp2_PIXEL_WIDTH, sp2_PIXEL_HEIGHT);
|
|
||||||
sp2_pixel_grid_fill(pixels, true);
|
|
||||||
|
|
||||||
sp2_Command *command = sp2_command_bitmap_linear_win(0, 0, pixels, Uncompressed);
|
|
||||||
sp2_Packet *packet = sp2_packet_from_command(command);
|
|
||||||
if (!sp2_connection_send(connection, packet))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
sp2_connection_dealloc(connection);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## C# / F#
|
|
||||||
|
|
||||||
Uses C bindings internally to provide a similar API to rust. Things to keep in mind:
|
|
||||||
|
|
||||||
- You will get a `NullPointerException` when trying to call a method where the native instance has been consumed already (e.g. when `Send`ing a command instance twice). Send a clone instead of the original if you want to keep using it.
|
|
||||||
- Some lower-level APIs _will_ panic in native code when used improperly.
|
|
||||||
Example: manipulating the `Span<byte>` of an object after freeing the instance.
|
|
||||||
- C# specifics are documented in the library. Use the rust documentation for everything else. Naming and semantics are the same apart from CamelCase instead of kebab_case.
|
|
||||||
- You will only get rust backtraces in debug builds of the native code.
|
|
||||||
- F# is not explicitly tested. If there are usability or functionality problems, please open an issue.
|
|
||||||
- Reading and writing to instances concurrently is not safe. Only reading concurrently is safe.
|
|
||||||
|
|
||||||
```csharp
|
|
||||||
using ServicePoint2;
|
|
||||||
|
|
||||||
// using statement calls Dispose() on scope exit, which frees unmanaged instances
|
|
||||||
using var connection = Connection.Open("127.0.0.1:2342");
|
|
||||||
using var pixels = PixelGrid.New(Constants.PixelWidth, Constants.PixelHeight);
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
pixels.Fill(true);
|
|
||||||
connection.Send(Command.BitmapLinearWin(0, 0, pixels.Clone()));
|
|
||||||
Thread.Sleep(5000);
|
|
||||||
|
|
||||||
pixels.Fill(false);
|
|
||||||
connection.Send(Command.BitmapLinearWin(0, 0, pixels.Clone()));
|
|
||||||
Thread.Sleep(5000);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Installation
|
|
||||||
|
|
||||||
NuGet packages are not a good way to distribute native projects ([relevant issue](https://github.com/dotnet/sdk/issues/33845)).
|
|
||||||
Because of that, there is no NuGet package you can use directly.
|
|
||||||
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/kaesaecracker/servicepoint.git
|
|
||||||
git commit -m "add servicepoint submodule"
|
|
||||||
```
|
|
||||||
|
|
||||||
You can now reference `servicepoint2-bindings-cs/src/ServicePoint2.csproj` in your project.
|
|
||||||
The rust library will automatically be built.
|
|
||||||
|
|
||||||
Please provide more information in the form of an issue if you need the build to copy a different library file for your platform.
|
|
||||||
|
|
||||||
### Installation
|
|
||||||
|
|
||||||
Copy the header to your project and compile against.
|
|
||||||
|
|
||||||
You have the choice of linking statically (recommended) or dynamically.
|
|
||||||
- The C example shows how to link statically against the `staticlib` variant.
|
|
||||||
- When linked dynamically, you have to provide the `cdylib` at runtime in the _same_ version, as there are no API/ABI guarantees yet.
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
This library has multiple compression libraries as optional dependencies.
|
|
||||||
If you do not need compression/decompression support you can disable those features.
|
|
||||||
In the likely case you only need one of them, you can include that one specifically.
|
|
||||||
|
|
||||||
```toml
|
|
||||||
[dependencies.servicepoint2]
|
|
||||||
git = "https://github.com/kaesaecracker/servicepoint.git"
|
|
||||||
default-features = false
|
|
||||||
features = ["compression-bz"]
|
|
||||||
```
|
|
||||||
|
|
||||||
Language bindings will not know which features are available and may fail at runtime.
|
|
||||||
It is recommended to include all features for builds used outside of rust.
|
|
||||||
|
|
||||||
## Projects using the library
|
## Projects using the library
|
||||||
|
|
||||||
- screen simulator (rust): https://github.com/kaesaecracker/pixel-receiver-rs
|
- screen simulator (rust): [servicepoint-simulator](https://github.com/kaesaecracker/servicepoint-simulator)
|
||||||
- tanks game (C#): https://github.com/kaesaecracker/cccb-tanks-cs
|
- tanks game (C#): [servicepoint-tanks](https://github.com/kaesaecracker/cccb-tanks-cs)
|
||||||
|
- cellular automata slideshow (rust): [servicepoint-life](https://github.com/kaesaecracker/servicepoint-life)
|
||||||
|
|
||||||
To add yourself to the list, open a pull request.
|
To add yourself to the list, open a pull request.
|
||||||
|
|
||||||
## Where is servicepoint1?
|
## About the display
|
||||||
|
|
||||||
This library is a spiritual mix of a not-yet-working rust library called `servicepoint` and a bunch of working but also unfinished C# code. Because most of the API concept and a bunch of code is taken from the rust library, the result is called `servicepoint2`.
|
- Resolution: 352x160=56,320 pixels
|
||||||
|
- Pixels are grouped into 44x20=880 tiles (8x8=64 pixels each)
|
||||||
|
- Smallest addressable unit: row of pixels inside of a tile (8 pixels = 1 byte)
|
||||||
|
- The brightness can only be set per tile
|
||||||
|
- Screen content can be changed using a simple UDP protocol
|
||||||
|
- Between each row of tiles, there is a gap of around 4 pixels size. This gap changes the aspect ratio of the display.
|
||||||
|
|
||||||
|
### Binary format
|
||||||
|
|
||||||
|
A UDP package sent to the display has a header size of 10 bytes.
|
||||||
|
Each header value has a size of two bytes (unsigned 16 bit integer).
|
||||||
|
Depending on the command, there can be a payload following the header.
|
||||||
|
|
||||||
|
The commands are implemented in DisplayCommands.
|
||||||
|
|
||||||
|
To change screen contents, these commands are the most relevant:
|
||||||
|
|
||||||
|
1. Clear screen
|
||||||
|
- command: `0x0002`
|
||||||
|
- (rest does not matter)
|
||||||
|
2. Send CP437 data: render specified text into rectangular region
|
||||||
|
- command: `0x0003`
|
||||||
|
- top left tile x
|
||||||
|
- top left tile y
|
||||||
|
- width in tiles
|
||||||
|
- height in tiles
|
||||||
|
- payload: (width in tiles * height in tiles) bytes
|
||||||
|
- 1 byte = 1 character
|
||||||
|
- each character is rendered into one tile (mono-spaced)
|
||||||
|
- characters are encoded using code page 437
|
||||||
|
3. Send bitmap window: set pixel states for a rectangular region
|
||||||
|
- command: `0x0013`
|
||||||
|
- top left tile x
|
||||||
|
- top left _pixel_ y
|
||||||
|
- width in tiles
|
||||||
|
- height in _pixels_
|
||||||
|
- payload: (width in tiles * height in pixels) bytes
|
||||||
|
- network byte order
|
||||||
|
- 1 bit = 1 pixel
|
||||||
|
|
||||||
|
There are other commands implemented as well, e.g. for changing the brightness.
|
||||||
|
|
||||||
|
## What happened to servicepoint2?
|
||||||
|
|
||||||
|
After `servicepoint2` has been merged into `servicepoint`, `servicepoint2` will not continue to get any updates.
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
[package]
|
[package]
|
||||||
name = "servicepoint2"
|
name = "servicepoint"
|
||||||
version = "0.4.2"
|
version.workspace = true
|
||||||
publish = true
|
publish = true
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
description = "A rust library for the CCCB Service Point Display."
|
description = "A rust library for the CCCB Service Point Display."
|
||||||
homepage = "https://docs.rs/crate/servicepoint2"
|
homepage = "https://docs.rs/crate/servicepoint"
|
||||||
repository = "https://github.com/kaesaecracker/servicepoint"
|
repository = "https://github.com/cccb/servicepoint"
|
||||||
readme = "../README.md"
|
readme = "README.md"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["staticlib", "rlib", "cdylib"]
|
crate-type = ["rlib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
@ -26,4 +26,8 @@ compression_bzip2 = ["dep:bzip2"]
|
||||||
compression_lzma = ["dep:rust-lzma"]
|
compression_lzma = ["dep:rust-lzma"]
|
||||||
compression_zstd = ["dep:zstd"]
|
compression_zstd = ["dep:zstd"]
|
||||||
all_compressions = ["compression_zlib", "compression_bzip2", "compression_lzma", "compression_zstd"]
|
all_compressions = ["compression_zlib", "compression_bzip2", "compression_lzma", "compression_zstd"]
|
||||||
c_api = []
|
|
||||||
|
[dev-dependencies]
|
||||||
|
# for examples
|
||||||
|
clap = { version = "4.5", features = ["derive"] }
|
||||||
|
rand = "0.8"
|
||||||
54
crates/servicepoint/README.md
Normal file
54
crates/servicepoint/README.md
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
# servicepoint
|
||||||
|
|
||||||
|
[](https://crates.io/crates/servicepoint)
|
||||||
|
[](https://crates.io/crates/servicepoint)
|
||||||
|
[](https://docs.rs/servicepoint/latest/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 crate contains a library for parsing, encoding and sending packets to this display via UDP.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
```rust
|
||||||
|
fn main() {
|
||||||
|
// establish connection
|
||||||
|
let connection = servicepoint::Connection::open("172.23.42.29:2342")
|
||||||
|
.expect("connection failed");
|
||||||
|
|
||||||
|
// clear screen content
|
||||||
|
connection.send(servicepoint::Command::Clear.into())
|
||||||
|
.expect("send failed");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
More examples are available in the crate.
|
||||||
|
Execute `cargo run --example` for a list of available examples and `cargo run --example <name>` to run one.
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
Please specify the full version including patch in your Cargo.toml until 1.0 is released.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo add servicepoint
|
||||||
|
```
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
This library has multiple compression libraries as optional dependencies.
|
||||||
|
If you do not need compression/decompression support you can disable those features.
|
||||||
|
In the likely case you only need one of them, you can include that one specifically.
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[dependencies]
|
||||||
|
servicepoint = { version = "0.5.0", default-features = false, features = ["compression-bz"] }
|
||||||
|
```
|
||||||
|
|
||||||
|
## Everything else
|
||||||
|
|
||||||
|
Look at the main project [README](https://github.com/cccb/servicepoint/blob/main/README.md) for further information.
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
use servicepoint2::{ByteGrid, Command, Connection, Grid, Origin};
|
use servicepoint::{ByteGrid, Command, Connection, Grid, Origin};
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
|
|
@ -14,10 +14,11 @@ struct Cli {
|
||||||
|
|
||||||
/// example: `cargo run -- --text "Hallo,
|
/// example: `cargo run -- --text "Hallo,
|
||||||
/// CCCB"`
|
/// CCCB"`
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
env_logger::init();
|
let mut cli = Cli::parse();
|
||||||
let cli = Cli::parse();
|
if cli.text.is_empty() {
|
||||||
|
cli.text.push("Hello, CCCB!".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
let connection = Connection::open(&cli.destination).unwrap();
|
let connection = Connection::open(&cli.destination).unwrap();
|
||||||
if cli.clear {
|
if cli.clear {
|
||||||
|
|
@ -3,7 +3,7 @@ use std::thread;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use rand::{distributions, Rng};
|
use rand::{distributions, Rng};
|
||||||
|
|
||||||
use servicepoint2::*;
|
use servicepoint::*;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
|
|
@ -14,7 +14,6 @@ struct Cli {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
env_logger::init();
|
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
let connection = Connection::open(&cli.destination).unwrap();
|
let connection = Connection::open(&cli.destination).unwrap();
|
||||||
|
|
@ -22,13 +21,11 @@ fn main() {
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
connection
|
connection
|
||||||
.send(
|
.send(Command::BitmapLinearWin(
|
||||||
Command::BitmapLinearWin(
|
|
||||||
Origin(0, 0),
|
Origin(0, 0),
|
||||||
field.clone(),
|
field.clone(),
|
||||||
CompressionCode::Lzma,
|
CompressionCode::Lzma,
|
||||||
)
|
))
|
||||||
)
|
|
||||||
.expect("could not send");
|
.expect("could not send");
|
||||||
thread::sleep(FRAME_PACING);
|
thread::sleep(FRAME_PACING);
|
||||||
field = iteration(field);
|
field = iteration(field);
|
||||||
|
|
@ -2,7 +2,7 @@ use std::thread;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
use servicepoint2::*;
|
use servicepoint::*;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
|
|
@ -11,8 +11,6 @@ struct Cli {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
env_logger::init();
|
|
||||||
|
|
||||||
let connection = Connection::open(Cli::parse().destination).unwrap();
|
let connection = Connection::open(Cli::parse().destination).unwrap();
|
||||||
|
|
||||||
let mut pixels = PixelGrid::max_sized();
|
let mut pixels = PixelGrid::max_sized();
|
||||||
|
|
@ -23,13 +21,11 @@ fn main() {
|
||||||
pixels.set((y + x_offset) % PIXEL_WIDTH, y, true);
|
pixels.set((y + x_offset) % PIXEL_WIDTH, y, true);
|
||||||
}
|
}
|
||||||
connection
|
connection
|
||||||
.send(
|
.send(Command::BitmapLinearWin(
|
||||||
Command::BitmapLinearWin(
|
|
||||||
Origin(0, 0),
|
Origin(0, 0),
|
||||||
pixels.clone(),
|
pixels.clone(),
|
||||||
CompressionCode::Lzma,
|
CompressionCode::Lzma,
|
||||||
)
|
))
|
||||||
)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
thread::sleep(FRAME_PACING);
|
thread::sleep(FRAME_PACING);
|
||||||
}
|
}
|
||||||
|
|
@ -3,8 +3,8 @@ use std::time::Duration;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
use servicepoint2::Command::{BitmapLinearWin, Brightness, CharBrightness};
|
use servicepoint::Command::{BitmapLinearWin, Brightness, CharBrightness};
|
||||||
use servicepoint2::*;
|
use servicepoint::*;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
|
|
@ -17,7 +17,6 @@ struct Cli {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
env_logger::init();
|
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
let connection = Connection::open(cli.destination).unwrap();
|
let connection = Connection::open(cli.destination).unwrap();
|
||||||
|
|
@ -55,9 +54,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
connection
|
connection.send(CharBrightness(origin, luma)).unwrap();
|
||||||
.send(CharBrightness(origin, luma))
|
|
||||||
.unwrap();
|
|
||||||
std::thread::sleep(wait_duration);
|
std::thread::sleep(wait_duration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,7 +3,7 @@ use std::time::Duration;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
use servicepoint2::*;
|
use servicepoint::*;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
|
|
@ -14,7 +14,6 @@ struct Cli {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
env_logger::init();
|
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
let sleep_duration = Duration::max(
|
let sleep_duration = Duration::max(
|
||||||
|
|
@ -37,9 +36,7 @@ fn main() {
|
||||||
let bit_vec = BitVec::from(&*pixel_data);
|
let bit_vec = BitVec::from(&*pixel_data);
|
||||||
|
|
||||||
connection
|
connection
|
||||||
.send(
|
.send(Command::BitmapLinearAnd(0, bit_vec, CompressionCode::Lzma))
|
||||||
Command::BitmapLinearAnd(0, bit_vec, CompressionCode::Lzma)
|
|
||||||
)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
thread::sleep(sleep_duration);
|
thread::sleep(sleep_duration);
|
||||||
}
|
}
|
||||||
|
|
@ -72,7 +72,7 @@ impl BitVec {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
/// use servicepoint2::BitVec;
|
/// use servicepoint::BitVec;
|
||||||
/// let mut vec = BitVec::new(8);
|
/// let mut vec = BitVec::new(8);
|
||||||
/// vec.fill(true);
|
/// vec.fill(true);
|
||||||
/// ```
|
/// ```
|
||||||
|
|
@ -135,103 +135,6 @@ impl From<&[u8]> for BitVec {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "c_api")]
|
|
||||||
pub mod c_api {
|
|
||||||
use crate::{BitVec, CByteSlice, DataRef};
|
|
||||||
|
|
||||||
/// Creates a new `BitVec` instance.
|
|
||||||
/// The returned instance has to be freed with `bit_vec_dealloc`.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_bit_vec_new(size: usize) -> *mut BitVec {
|
|
||||||
Box::into_raw(Box::new(BitVec::new(size)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Loads a `BitVec` from the provided data.
|
|
||||||
/// The returned instance has to be freed with `bit_vec_dealloc`.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_bit_vec_load(
|
|
||||||
data: *const u8,
|
|
||||||
data_length: usize,
|
|
||||||
) -> *mut BitVec {
|
|
||||||
let data = std::slice::from_raw_parts(data, data_length);
|
|
||||||
Box::into_raw(Box::new(BitVec::from(data)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clones a `BitVec`.
|
|
||||||
/// The returned instance has to be freed with `bit_vec_dealloc`.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_bit_vec_clone(
|
|
||||||
this: *const BitVec,
|
|
||||||
) -> *mut BitVec {
|
|
||||||
Box::into_raw(Box::new((*this).clone()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Deallocates a `BitVec`.
|
|
||||||
///
|
|
||||||
/// Note: do not call this if the grid has been consumed in another way, e.g. to create a command.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_bit_vec_dealloc(this: *mut BitVec) {
|
|
||||||
_ = Box::from_raw(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets the value of a bit from the `BitVec`.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_bit_vec_get(
|
|
||||||
this: *const BitVec,
|
|
||||||
index: usize,
|
|
||||||
) -> bool {
|
|
||||||
(*this).get(index)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the value of a bit in the `BitVec`.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_bit_vec_set(
|
|
||||||
this: *mut BitVec,
|
|
||||||
index: usize,
|
|
||||||
value: bool,
|
|
||||||
) -> bool {
|
|
||||||
(*this).set(index, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the value of all bits in the `BitVec`.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_bit_vec_fill(this: *mut BitVec, value: bool) {
|
|
||||||
(*this).fill(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets the length of the `BitVec` in bits.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_bit_vec_len(this: *const BitVec) -> usize {
|
|
||||||
(*this).len()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if length is 0.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_bit_vec_is_empty(this: *const BitVec) -> bool {
|
|
||||||
(*this).is_empty()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets an unsafe reference to the data of the `BitVec` instance.
|
|
||||||
///
|
|
||||||
/// ## Safety
|
|
||||||
///
|
|
||||||
/// The caller has to make sure to never access the returned memory after the `BitVec`
|
|
||||||
/// instance has been consumed or manually deallocated.
|
|
||||||
///
|
|
||||||
/// Reading and writing concurrently to either the original instance or the returned data will
|
|
||||||
/// result in undefined behavior.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_bit_vec_unsafe_data_ref(
|
|
||||||
this: *mut BitVec,
|
|
||||||
) -> CByteSlice {
|
|
||||||
let data = (*this).data_ref_mut();
|
|
||||||
CByteSlice {
|
|
||||||
start: data.as_mut_ptr_range().start,
|
|
||||||
length: data.len(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{BitVec, DataRef};
|
use crate::{BitVec, DataRef};
|
||||||
|
|
@ -108,119 +108,6 @@ impl From<ByteGrid> for Vec<u8> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "c_api")]
|
|
||||||
pub mod c_api {
|
|
||||||
use crate::data_ref::DataRef;
|
|
||||||
use crate::grid::Grid;
|
|
||||||
use crate::{ByteGrid, CByteSlice};
|
|
||||||
|
|
||||||
/// Creates a new `ByteGrid` instance.
|
|
||||||
/// The returned instance has to be freed with `byte_grid_dealloc`.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_byte_grid_new(
|
|
||||||
width: usize,
|
|
||||||
height: usize,
|
|
||||||
) -> *mut ByteGrid {
|
|
||||||
Box::into_raw(Box::new(ByteGrid::new(width, height)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Loads a `ByteGrid` with the specified dimensions from the provided data.
|
|
||||||
/// The returned instance has to be freed with `byte_grid_dealloc`.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_byte_grid_load(
|
|
||||||
width: usize,
|
|
||||||
height: usize,
|
|
||||||
data: *const u8,
|
|
||||||
data_length: usize,
|
|
||||||
) -> *mut ByteGrid {
|
|
||||||
let data = std::slice::from_raw_parts(data, data_length);
|
|
||||||
Box::into_raw(Box::new(ByteGrid::load(width, height, data)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clones a `ByteGrid`.
|
|
||||||
/// The returned instance has to be freed with `byte_grid_dealloc`.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_byte_grid_clone(
|
|
||||||
this: *const ByteGrid,
|
|
||||||
) -> *mut ByteGrid {
|
|
||||||
Box::into_raw(Box::new((*this).clone()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Deallocates a `ByteGrid`.
|
|
||||||
///
|
|
||||||
/// Note: do not call this if the grid has been consumed in another way, e.g. to create a command.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_byte_grid_dealloc(this: *mut ByteGrid) {
|
|
||||||
_ = Box::from_raw(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the current value at the specified position
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_byte_grid_get(
|
|
||||||
this: *const ByteGrid,
|
|
||||||
x: usize,
|
|
||||||
y: usize,
|
|
||||||
) -> u8 {
|
|
||||||
(*this).get(x, y)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the current value at the specified position
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_byte_grid_set(
|
|
||||||
this: *mut ByteGrid,
|
|
||||||
x: usize,
|
|
||||||
y: usize,
|
|
||||||
value: u8,
|
|
||||||
) {
|
|
||||||
(*this).set(x, y, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fills the whole `ByteGrid` with the specified value
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_byte_grid_fill(
|
|
||||||
this: *mut ByteGrid,
|
|
||||||
value: u8,
|
|
||||||
) {
|
|
||||||
(*this).fill(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets the width in pixels of the `ByteGrid` instance.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_byte_grid_width(
|
|
||||||
this: *const ByteGrid,
|
|
||||||
) -> usize {
|
|
||||||
(*this).width
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets the height in pixels of the `ByteGrid` instance.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_byte_grid_height(
|
|
||||||
this: *const ByteGrid,
|
|
||||||
) -> usize {
|
|
||||||
(*this).height
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets an unsafe reference to the data of the `ByteGrid` instance.
|
|
||||||
///
|
|
||||||
/// ## Safety
|
|
||||||
///
|
|
||||||
/// The caller has to make sure to never access the returned memory after the `ByteGrid`
|
|
||||||
/// instance has been consumed or manually deallocated.
|
|
||||||
///
|
|
||||||
/// Reading and writing concurrently to either the original instance or the returned data will
|
|
||||||
/// result in undefined behavior.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_byte_grid_unsafe_data_ref(
|
|
||||||
this: *mut ByteGrid,
|
|
||||||
) -> CByteSlice {
|
|
||||||
let data = (*this).data_ref_mut();
|
|
||||||
CByteSlice {
|
|
||||||
start: data.as_mut_ptr_range().start,
|
|
||||||
length: data.len(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{ByteGrid, DataRef, Grid};
|
use crate::{ByteGrid, DataRef, Grid};
|
||||||
|
|
@ -391,179 +391,6 @@ impl Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "c_api")]
|
|
||||||
pub mod c_api {
|
|
||||||
use std::ptr::null_mut;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
BitVec, Brightness, ByteGrid, Command, CompressionCode, Offset, Origin,
|
|
||||||
Packet, PixelGrid,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Tries to turn a `Packet` into a `Command`. The packet is gets deallocated in the process.
|
|
||||||
///
|
|
||||||
/// Returns: pointer to command or NULL
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_command_try_from_packet(
|
|
||||||
packet: *mut Packet,
|
|
||||||
) -> *mut Command {
|
|
||||||
let packet = *Box::from_raw(packet);
|
|
||||||
match Command::try_from(packet) {
|
|
||||||
Err(_) => null_mut(),
|
|
||||||
Ok(command) => Box::into_raw(Box::new(command)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clones a `Command` instance
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_command_clone(
|
|
||||||
original: *const Command,
|
|
||||||
) -> *mut Command {
|
|
||||||
Box::into_raw(Box::new((*original).clone()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Allocates a new `Command::Clear` instance
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_command_clear() -> *mut Command {
|
|
||||||
Box::into_raw(Box::new(Command::Clear))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Allocates a new `Command::HardReset` instance
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_command_hard_reset() -> *mut Command {
|
|
||||||
Box::into_raw(Box::new(Command::HardReset))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Allocates a new `Command::FadeOut` instance
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_command_fade_out() -> *mut Command {
|
|
||||||
Box::into_raw(Box::new(Command::FadeOut))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Allocates a new `Command::Brightness` instance
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_command_brightness(
|
|
||||||
brightness: Brightness,
|
|
||||||
) -> *mut Command {
|
|
||||||
Box::into_raw(Box::new(Command::Brightness(brightness)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Allocates a new `Command::CharBrightness` instance.
|
|
||||||
/// The passed `ByteGrid` gets deallocated in the process.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_command_char_brightness(
|
|
||||||
x: usize,
|
|
||||||
y: usize,
|
|
||||||
byte_grid: *mut ByteGrid,
|
|
||||||
) -> *mut Command {
|
|
||||||
let byte_grid = *Box::from_raw(byte_grid);
|
|
||||||
Box::into_raw(Box::new(Command::CharBrightness(
|
|
||||||
Origin(x, y),
|
|
||||||
byte_grid,
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Allocates a new `Command::BitmapLinear` instance.
|
|
||||||
/// The passed `BitVec` gets deallocated in the process.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_command_bitmap_linear(
|
|
||||||
offset: Offset,
|
|
||||||
bit_vec: *mut BitVec,
|
|
||||||
compression: CompressionCode,
|
|
||||||
) -> *mut Command {
|
|
||||||
let bit_vec = *Box::from_raw(bit_vec);
|
|
||||||
Box::into_raw(Box::new(Command::BitmapLinear(
|
|
||||||
offset,
|
|
||||||
bit_vec,
|
|
||||||
compression,
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Allocates a new `Command::BitmapLinearAnd` instance.
|
|
||||||
/// The passed `BitVec` gets deallocated in the process.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_command_bitmap_linear_and(
|
|
||||||
offset: Offset,
|
|
||||||
bit_vec: *mut BitVec,
|
|
||||||
compression: CompressionCode,
|
|
||||||
) -> *mut Command {
|
|
||||||
let bit_vec = *Box::from_raw(bit_vec);
|
|
||||||
Box::into_raw(Box::new(Command::BitmapLinearAnd(
|
|
||||||
offset,
|
|
||||||
bit_vec,
|
|
||||||
compression,
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Allocates a new `Command::BitmapLinearOr` instance.
|
|
||||||
/// The passed `BitVec` gets deallocated in the process.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_command_bitmap_linear_or(
|
|
||||||
offset: Offset,
|
|
||||||
bit_vec: *mut BitVec,
|
|
||||||
compression: CompressionCode,
|
|
||||||
) -> *mut Command {
|
|
||||||
let bit_vec = *Box::from_raw(bit_vec);
|
|
||||||
Box::into_raw(Box::new(Command::BitmapLinearOr(
|
|
||||||
offset,
|
|
||||||
bit_vec,
|
|
||||||
compression,
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Allocates a new `Command::BitmapLinearXor` instance.
|
|
||||||
/// The passed `BitVec` gets deallocated in the process.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_command_bitmap_linear_xor(
|
|
||||||
offset: Offset,
|
|
||||||
bit_vec: *mut BitVec,
|
|
||||||
compression: CompressionCode,
|
|
||||||
) -> *mut Command {
|
|
||||||
let bit_vec = *Box::from_raw(bit_vec);
|
|
||||||
Box::into_raw(Box::new(Command::BitmapLinearXor(
|
|
||||||
offset,
|
|
||||||
bit_vec,
|
|
||||||
compression,
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Allocates a new `Command::Cp437Data` instance.
|
|
||||||
/// The passed `ByteGrid` gets deallocated in the process.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_command_cp437_data(
|
|
||||||
x: usize,
|
|
||||||
y: usize,
|
|
||||||
byte_grid: *mut ByteGrid,
|
|
||||||
) -> *mut Command {
|
|
||||||
let byte_grid = *Box::from_raw(byte_grid);
|
|
||||||
Box::into_raw(Box::new(Command::Cp437Data(Origin(x, y), byte_grid)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Allocates a new `Command::BitmapLinearWin` instance.
|
|
||||||
/// The passed `PixelGrid` gets deallocated in the process.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_command_bitmap_linear_win(
|
|
||||||
x: usize,
|
|
||||||
y: usize,
|
|
||||||
byte_grid: *mut PixelGrid,
|
|
||||||
compression_code: CompressionCode,
|
|
||||||
) -> *mut Command {
|
|
||||||
let byte_grid = *Box::from_raw(byte_grid);
|
|
||||||
Box::into_raw(Box::new(Command::BitmapLinearWin(
|
|
||||||
Origin(x, y),
|
|
||||||
byte_grid,
|
|
||||||
compression_code,
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Deallocates a `Command`. Note that connection_send does this implicitly, so you only need
|
|
||||||
/// to do this if you use the library for parsing commands.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_command_dealloc(ptr: *mut Command) {
|
|
||||||
_ = Box::from_raw(ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::command::TryFromPacketError;
|
use crate::command::TryFromPacketError;
|
||||||
|
|
@ -10,8 +10,6 @@ pub struct Connection {
|
||||||
socket: UdpSocket,
|
socket: UdpSocket,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl Connection {
|
impl Connection {
|
||||||
/// Open a new UDP socket and connect to the provided host.
|
/// Open a new UDP socket and connect to the provided host.
|
||||||
///
|
///
|
||||||
|
|
@ -23,7 +21,7 @@ impl Connection {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// let connection = servicepoint2::Connection::open("172.23.42.29:2342")
|
/// let connection = servicepoint::Connection::open("172.23.42.29:2342")
|
||||||
/// .expect("connection failed");
|
/// .expect("connection failed");
|
||||||
/// ```
|
/// ```
|
||||||
pub fn open(addr: impl ToSocketAddrs + Debug) -> std::io::Result<Self> {
|
pub fn open(addr: impl ToSocketAddrs + Debug) -> std::io::Result<Self> {
|
||||||
|
|
@ -48,8 +46,8 @@ impl Connection {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use servicepoint2::{Command, CompressionCode, Grid, PixelGrid};
|
/// use servicepoint::{Command, CompressionCode, Grid, PixelGrid};
|
||||||
/// let connection = servicepoint2::Connection::open("172.23.42.29:2342")
|
/// let connection = servicepoint::Connection::open("172.23.42.29:2342")
|
||||||
/// .expect("connection failed");
|
/// .expect("connection failed");
|
||||||
///
|
///
|
||||||
/// // turn off all pixels
|
/// // turn off all pixels
|
||||||
|
|
@ -61,10 +59,13 @@ impl Connection {
|
||||||
/// pixels.fill(true);
|
/// pixels.fill(true);
|
||||||
///
|
///
|
||||||
/// // send pixels to display
|
/// // send pixels to display
|
||||||
/// connection.send(Command::BitmapLinearWin(servicepoint2::Origin(0, 0), pixels, CompressionCode::Uncompressed))
|
/// connection.send(Command::BitmapLinearWin(servicepoint::Origin(0, 0), pixels, CompressionCode::Uncompressed))
|
||||||
/// .expect("send failed");
|
/// .expect("send failed");
|
||||||
/// ```
|
/// ```
|
||||||
pub fn send(&self, packet: impl Into<Packet>) -> Result<(), std::io::Error> {
|
pub fn send(
|
||||||
|
&self,
|
||||||
|
packet: impl Into<Packet>,
|
||||||
|
) -> Result<(), std::io::Error> {
|
||||||
let packet = packet.into();
|
let packet = packet.into();
|
||||||
debug!("sending {packet:?}");
|
debug!("sending {packet:?}");
|
||||||
let data: Vec<u8> = packet.into();
|
let data: Vec<u8> = packet.into();
|
||||||
|
|
@ -72,46 +73,3 @@ impl Connection {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "c_api")]
|
|
||||||
pub mod c_api {
|
|
||||||
use std::ffi::{c_char, CStr};
|
|
||||||
use std::ptr::null_mut;
|
|
||||||
|
|
||||||
use crate::{Connection, Packet};
|
|
||||||
|
|
||||||
/// Creates a new instance of Connection.
|
|
||||||
/// The returned instance has to be deallocated with `connection_dealloc`.
|
|
||||||
///
|
|
||||||
/// returns: NULL if connection fails or connected instance
|
|
||||||
///
|
|
||||||
/// Panics: bad string encoding
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_connection_open(
|
|
||||||
host: *const c_char,
|
|
||||||
) -> *mut Connection {
|
|
||||||
let host = CStr::from_ptr(host).to_str().expect("Bad encoding");
|
|
||||||
let connection = match Connection::open(host) {
|
|
||||||
Err(_) => return null_mut(),
|
|
||||||
Ok(value) => value,
|
|
||||||
};
|
|
||||||
|
|
||||||
Box::into_raw(Box::new(connection))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sends the command instance. The instance is consumed / destroyed and cannot be used after this call.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_connection_send(
|
|
||||||
connection: *const Connection,
|
|
||||||
command_ptr: *mut Packet,
|
|
||||||
) -> bool {
|
|
||||||
let packet = Box::from_raw(command_ptr);
|
|
||||||
(*connection).send(*packet).is_ok()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Closes and deallocates a connection instance
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp2_connection_dealloc(ptr: *mut Connection) {
|
|
||||||
_ = Box::from_raw(ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -35,7 +35,7 @@ pub trait Grid<T> {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// To avoid boxing, this example is using the concrete type `ByteGrid`.
|
/// To avoid boxing, this example is using the concrete type `ByteGrid`.
|
||||||
/// ```
|
/// ```
|
||||||
/// use servicepoint2::{ByteGrid, Grid};
|
/// use servicepoint::{ByteGrid, Grid};
|
||||||
/// fn split(grid: ByteGrid) -> (ByteGrid, ByteGrid) {
|
/// fn split(grid: ByteGrid) -> (ByteGrid, ByteGrid) {
|
||||||
/// assert!(grid.width() >= 2);
|
/// assert!(grid.width() >= 2);
|
||||||
/// let split_x = grid.width() / 2;
|
/// let split_x = grid.width() / 2;
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue