Commit 845ab296 authored by René Rössler's avatar René Rössler 😍
Browse files

Merge branch 'led-strip' into 'master'

Led strip support

Closes #6

See merge request !1
parents c345cd18 6d63a377
Pipeline #138345957 passed with stage
in 10 minutes
......@@ -172,7 +172,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "chrono"
version = "0.4.10"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-integer 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -369,10 +369,9 @@ dependencies = [
[[package]]
name = "fern"
version = "0.5.9"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"colored 1.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -587,11 +586,11 @@ name = "gled"
version = "1.0.4"
dependencies = [
"cairo-rs 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-channel 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"elapsed 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"fern 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
"fern 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"floating-duration 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gdk 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gio 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -600,7 +599,7 @@ dependencies = [
"libgled 1.0.4",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"resvg 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -743,7 +742,7 @@ dependencies = [
[[package]]
name = "kurbo"
version = "0.5.6"
version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -774,13 +773,14 @@ dependencies = [
"delta_e 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"elapsed 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"floating-duration 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"kurbo 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
"resvg 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.51 (registry+https://github.com/rust-lang/crates.io-index)",
"strum 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"strum_macros 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"svgdom 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -890,10 +890,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "proc-macro-error"
version = "0.4.11"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro-error-attr 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro-error-attr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -902,7 +902,7 @@ dependencies = [
[[package]]
name = "proc-macro-error-attr"
version = "0.4.11"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -1092,12 +1092,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde"
version = "1.0.104"
version = "1.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde_derive"
version = "1.0.104"
version = "1.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -1107,12 +1107,12 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.48"
version = "1.0.51"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -1149,21 +1149,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "structopt"
version = "0.3.11"
version = "0.3.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt-derive 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt-derive 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "structopt-derive"
version = "0.4.4"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro-error 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro-error 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -1313,7 +1313,7 @@ dependencies = [
"data-url 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
"harfbuzz_rs 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"kurbo 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"kurbo 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"memmap2 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rctree 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -1400,7 +1400,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum cairo-sys-rs 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ff65ba02cac715be836f63429ab00a767d48336efc5497c5637afb53b4f14d63"
"checksum cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)" = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd"
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
"checksum chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "31850b4a4d6bae316f7a09e691c944c28299298837edc0a03f755618c23cbc01"
"checksum chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2"
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
"checksum cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "81fb25b677f8bf1eb325017cb6bb8452f87969db0fedb4f757b297bee78a7c62"
......@@ -1422,7 +1422,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum elapsed 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6f4e5af126dafd0741c2ad62d47f68b28602550102e5f0dd45c8a97fc8b49c29"
"checksum failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f8273f13c977665c5db7eb2b99ae520952fe5ac831ae4cd09d80c4c7042b5ed9"
"checksum failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0bc225b78e0391e4b8683440bf2e63c2deeeb2ce5189eab46e2b68c6d3725d08"
"checksum fern 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e69ab0d5aca163e388c3a49d284fed6c3d0810700e77c5ae2756a50ec1a4daaa"
"checksum fern 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8c9a4820f0ccc8a7afd67c39a0f1a0f4b07ca1725164271a64939d7aeb9af065"
"checksum flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6bd6d6f4752952feb71363cffc9ebac9411b75b87c6ab6058c40c8900cf43c0f"
"checksum float-cmp 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "75224bec9bfe1a65e2d34132933f2de7fe79900c96a0174307554244ece8150e"
"checksum floating-duration 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b2c60b71d9dbcd810a3be879dc9aafac6cec5c50dc2346e245f61f54a61fdf22"
......@@ -1456,7 +1456,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum inflate 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1cdb29978cc5797bd8dcc8e5bf7de604891df2a8dc576973d71a281e916db2ff"
"checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f"
"checksum jpeg-decoder 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "0256f0aec7352539102a9efbcb75543227b7ab1117e0f95450023af730128451"
"checksum kurbo 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c1f081c28eed05ad28554187729dabe9723f82e482ebf78a2fdd4666d5d99951"
"checksum kurbo 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)" = "bf50e17a1697110c694d47c5b1a6b64faf5eb3ffe5a286df23fb8cd516e33be6"
"checksum lab 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bcb6fe1d958d9c2a4298cb5024381522038952ebd0fd3af60d00d3844813c93c"
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558"
......@@ -1473,8 +1473,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
"checksum png 0.15.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ef859a23054bbfee7811284275ae522f0434a3c8e7f4b74bd4a35ae7e1c4a283"
"checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b"
"checksum proc-macro-error 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "e7959c6467d962050d639361f7703b2051c43036d03493c36f01d440fdd3138a"
"checksum proc-macro-error-attr 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "e4002d9f55991d5e019fb940a90e1a95eb80c24e77cb2462dd4dc869604d543a"
"checksum proc-macro-error 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "98e9e4b82e0ef281812565ea4751049f1bdcdfccda7d3f459f2e138a40c08678"
"checksum proc-macro-error-attr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4f5444ead4e9935abd7f27dc51f7e852a0569ac888096d5ec2499470794e2e53"
"checksum proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)" = "ecd45702f76d6d3c75a80564378ae228a85f0b59d2f3ed43c91b4a69eb2ebfc5"
"checksum proc-macro-nested 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "369a6ed065f249a159e06c45752c780bda2fb53c995718f9e484d08daa9eb42e"
"checksum proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3acb317c6ff86a4e579dfa00fc5e6cca91ecbb4e7eb2df0468805b674eb88548"
......@@ -1497,16 +1497,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ca4eaef519b494d1f2848fc602d18816fed808a981aedf4f1f00ceb7c9d32cf"
"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
"checksum ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8"
"checksum serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449"
"checksum serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64"
"checksum serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)" = "9371ade75d4c2d6cb154141b9752cf3781ec9c05e0e5cf35060e1e70ee7b9c25"
"checksum serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)" = "36df6ac6412072f67cf767ebbde4133a5b2e88e76dc6187fa7104cd16f783399"
"checksum serde_derive 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)" = "9e549e3abf4fb8621bd1609f11dfc9f5e50320802273b12f3811a67e6716ea6c"
"checksum serde_json 1.0.51 (registry+https://github.com/rust-lang/crates.io-index)" = "da07b57ee2623368351e9a0488bb0b261322a15a6e0ae53e243cbdc0f4208da9"
"checksum servo-freetype-sys 4.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2c4ccb6d0d32d277d3ef7dea86203d8210945eb7a45fba89dd445b3595dd0dfc"
"checksum simplecss 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "596554e63596d556a0dbd681416342ca61c75f1a45203201e7e77d3fa2fa9014"
"checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac"
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
"checksum structopt 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe43617218c0805c6eb37160119dc3c548110a67786da7218d1c6555212f073"
"checksum structopt-derive 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c6e79c80e0f4efd86ca960218d4e056249be189ff1c42824dcd9a7f51a56f0bd"
"checksum structopt 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "ff6da2e8d107dfd7b74df5ef4d205c6aebee0706c647f6bc6a2d5789905c00fb"
"checksum structopt-derive 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a489c87c08fbaf12e386665109dd13470dcc9c4583ea3e10dd2b4523e5ebd9ac"
"checksum strum 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)" = "57bd81eb48f4c437cadc685403cad539345bf703d78e63707418431cecd4522b"
"checksum strum_macros 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)" = "87c85aa3f8ea653bfd3ddf25f7ee357ee4d204731f6aa9ad04002306f6e2774c"
"checksum svgdom 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e4ae7d6df72b3a36c0f003f1f8919c96be43d20d7c015f8dcf2f82531a4fc33b"
......
......@@ -14,7 +14,7 @@ floating-duration = "0.1.2"
glib = "0.9.3"
chrono = "0.4.11"
crossbeam-channel = "0.4.2"
structopt = "0.3.12"
structopt = "0.3.13"
dirs = "2.0.2"
[dependencies.cairo-rs]
......
......@@ -10,7 +10,8 @@ All fields are optional.
{
"fixture": "rgb",
"render_groups": ["bla", "blub"],
"start": 42
"start": 42,
"count": 100
}
```
......@@ -32,6 +33,12 @@ Start addresses are summed up. If a group has the address `10` and a child node
**default**: *0*
### count
You can have multiple lights all at the same positions but with different addresses. If you are setting this values on a svg path, gled sets all light at uniformly distributed positions on the path.
**default**: *1*
## Example
![Lamp with parameter](lamp_with_parameter.jpeg)
......
......@@ -19,19 +19,20 @@ svgdom = "0.18.0"
artnet_protocol = "0.2.0"
lazy_static = "1.4.0"
delta_e = "0.2.1"
serde_json = "1.0.48"
serde_derive = "1.0.105"
serde_json = "1.0.51"
serde_derive = "1.0.106"
rand = "0.7.3"
floating-duration = "0.1.2"
strum = "0.18.0"
strum_macros = "0.18.0"
kurbo = "0.5.11"
[dependencies.resvg]
version = "0.9.0"
features = ["cairo-backend"]
[dependencies.serde]
version = "1.0.105"
version = "1.0.106"
features = ["rc"]
[profile.release]
......
......@@ -65,14 +65,13 @@ fn traverse_node(
parameter.start += start;
start = parameter.start;
parents.insert(node.id().clone());
if let Some(led) = parameter.led() {
parents.iter().for_each(|parent_id| {
parameters
.get_mut(parent_id)
.map(|parameter| parameter.leds.insert(led.clone()));
});
parameter.leds.insert(led);
}
let leds = parameter.leds();
parents.iter().for_each(|parent_id| {
if let Some(parameter) = parameters.get_mut(parent_id) {
parameter.leds.extend(leds.clone().into_iter())
}
});
parameter.leds.extend(leds.into_iter());
parameters.insert(node.id().clone(), parameter);
}
......
......@@ -3,7 +3,7 @@
use super::{Color, Led, Point};
use serde_derive::{Deserialize, Serialize};
use std::{
collections::{HashMap, HashSet},
collections::HashMap,
sync::{Arc, RwLock},
};
......@@ -11,7 +11,7 @@ pub type MeasurementPoints = Arc<RwLock<Option<HashMap<String, Vec<MeasurementPo
#[derive(Serialize, Deserialize, Clone)]
pub struct MeasurementPoint {
pub leds: HashSet<Led>,
pub leds: Vec<Led>,
pub point: Point,
pub color: Color,
}
......@@ -2,7 +2,6 @@
use log::error;
use serde_derive::{Deserialize, Serialize};
use std::collections::HashSet;
use super::{Fixture, Led};
......@@ -13,40 +12,47 @@ pub struct Parameter {
pub fixture: String,
pub start: u32,
pub render_groups: Vec<String>,
pub count: u32,
#[serde(skip)]
pub leds: HashSet<Led>,
pub leds: Vec<Led>,
}
// ANCHOR_END: parameter
impl Parameter {
pub fn led(&self) -> Option<Led> {
let full_address = self.start;
let universe: u16 = (full_address / 1000) as u16;
let start: u32 = full_address - u32::from(universe) * 1000;
let start = usize::from(start as u16);
pub fn leds(&self) -> Vec<Led> {
let fixture = match self.fixture.as_str() {
"rgb" => {
if start > 510 {
error!("Start index out of bounds: {}", start);
return None;
}
Fixture::RGB
}
"rgb" => Fixture::RGB,
"" => {
return None;
return vec![];
}
_ => {
error!("Fixture not (yet) implemented: {}", self.fixture);
return None;
return vec![];
}
};
Some(Led {
fixture,
universe,
start,
})
{ 0..self.count }
.filter_map(|led| {
let full_address = self.start + led * 3;
let mut universe: u16 = (full_address / 1000) as u16;
let mut start: usize = full_address as usize - universe as usize * 1000;
if fixture == Fixture::RGB && start > 510 {
universe += 1;
start -= 510;
}
if fixture == Fixture::RGB && start > 510 {
error!("Start index out of bounds: {}", start);
None
} else {
Some(Led {
fixture: fixture.clone(),
universe,
start,
})
}
})
.collect()
}
}
......@@ -56,7 +62,8 @@ impl Default for Parameter {
fixture: "rgb".to_owned(),
render_groups: vec![],
start: 0,
leds: HashSet::new(),
count: 1,
leds: vec![]
}
}
}
......@@ -8,10 +8,15 @@ use crate::{animation, svg, STATE};
use cairo::Context;
use elapsed::measure_time;
use log::{debug, info};
use resvg::{prelude::NodeExt, usvg, ScreenSize};
use resvg::{
prelude::NodeExt,
usvg::{self, NodeKind, PathData, PathSegment},
ScreenSize,
};
use serde_derive::{Deserialize, Serialize};
use std::{
collections::HashMap,
rc::Rc,
sync::{
atomic::{AtomicBool, Ordering},
Arc, Mutex, RwLock,
......@@ -166,6 +171,128 @@ fn create_surface(size: &Size, image: &Arc<Mutex<Option<Image>>>) {
info!("Done creating surfaces");
}
fn leds_on_path(
leds: usize,
path_data: Rc<PathData>,
parameter: &Parameter,
context: &Context,
measurement_points: &mut Vec<MeasurementPoint>,
) {
assert_eq!(leds, parameter.leds.len());
let path_length = path_data.length();
let led_distance = path_length / f64::from(leds as i32 - 1);
let mut leds_added: usize = 0;
let mut path_position = 0.0;
let mut prev_x = 0.0;
let mut prev_y = 0.0;
path_data.0.iter().for_each(|segment| match segment {
PathSegment::MoveTo { x, y } => {
let point = context.user_to_device(*x, *y);
measurement_points.push(MeasurementPoint {
leds: vec![parameter.leds.get(leds_added).unwrap().clone()],
point: Point::new(point.0, point.1),
color: Color {
red: 0,
green: 0,
blue: 0,
},
});
leds_added += 1;
prev_x = *x;
prev_y = *y;
}
PathSegment::LineTo { x, y } => {
let delta_x = *x - prev_x;
let delta_y = *y - prev_y;
let mut segment_position =
led_distance + f64::from(leds_added as i32) * led_distance - path_position;
let segment_length = (delta_x.powi(2) + delta_y.powi(2)).sqrt();
while segment_position <= segment_length {
let led_x = prev_x + delta_x * segment_position / segment_length;
let led_y = prev_y + delta_y * segment_position / segment_length;
let point = context.user_to_device(led_x, led_y);
measurement_points.push(MeasurementPoint {
leds: vec![parameter.leds.get(leds_added).unwrap().clone()],
point: Point::new(point.0, point.1),
color: Color {
red: 0,
green: 0,
blue: 0,
},
});
leds_added += 1;
segment_position += led_distance;
}
prev_x = *x;
prev_y = *y;
path_position += segment_length;
}
PathSegment::CurveTo {
x1,
y1,
x2,
y2,
x,
y,
} => {
use kurbo::{ParamCurve, ParamCurveArclen};
let curve = kurbo::CubicBez::new((prev_x, prev_y), (*x1, *y1), (*x2, *y2), (*x, *y));
let n = ((10.0 * curve.arclen(1.0)).ln() / 2_f64.ln()).ceil() as usize;
let mut curves = vec![curve];
{ 0..n }.for_each(|_| {
curves = curves
.iter()
.map(|curve| {
let curves = curve.subdivide();
std::iter::once(curves.0).chain(std::iter::once(curves.1))
})
.flatten()
.collect();
});
curves.drain(..).for_each(|curve| {
path_position += curve.arclen(1.0);
if path_position >= led_distance * f64::from(leds_added as i32) {
let end = curve.end();
let point = context.user_to_device(end.x, end.y);
measurement_points.push(MeasurementPoint {
leds: vec![parameter.leds.get(leds_added).unwrap().clone()],
point: Point::new(point.0, point.1),
color: Color {
red: 0,
green: 0,
blue: 0,
},
});
leds_added += 1;
}
});
prev_x = *x;
prev_y = *y;
}
PathSegment::ClosePath => {}
});
if leds_added == leds - 1 {
let point = context.user_to_device(prev_x, prev_y);
measurement_points.push(MeasurementPoint {
leds: vec![parameter.leds.get(leds_added).unwrap().clone()],
point: Point::new(point.0, point.1),
color: Color {
red: 0,
green: 0,
blue: 0,
},
});
leds_added += 1;
}
assert!((path_length - path_position).abs() < 0.1);
assert_eq!(leds_added, leds);
}
/// Render SVG file to surface and determine measurement points
fn render_svg(
parameters: &HashMap<String, Parameter>,
......@@ -193,26 +320,41 @@ fn render_svg(
*measurement_points = {
let mut measurement_points = HashMap::new();
tree.root().descendants().for_each(|node| {
if let (Some(rect), Some(parameter)) = (
&node.calculate_bbox(),
parameters.get(&node.id().to_owned()),
) {
if let Some(parameter) = parameters.get(&node.id().to_owned()) {
parameter.render_groups.iter().for_each(|render_group| {
let x = rect.x() + rect.width() / 2.0;
let y = rect.y() + rect.height() / 2.0;
let point = context.user_to_device(x, y);
measurement_points
let measurement_points = measurement_points
.entry(render_group.to_owned())
.or_insert_with(Vec::new)
.push(MeasurementPoint {
leds: parameter.leds.clone(),
point: Point::new(point.0, point.1),
color: Color {
red: 0,
green: 0,
blue: 0,
},
});
.or_insert_with(Vec::new);
match &*node.borrow() {
NodeKind::Path(path) if parameter.count > 1 => {
let mut path_data = Rc::clone(&path.data);
Rc::make_mut(&mut path_data)
.transform(node.abs_transform());
leds_on_path(
parameter.count as usize,
path_data,
parameter,
&context,
measurement_points,
);
}
_ => {
if let Some(rect) = &node.calculate_bbox() {
let x = rect.x() + rect.width() / 2.0;
let y = rect.y() + rect.height() / 2.0;
let point = context.user_to_device(x, y);
measurement_points.push(MeasurementPoint {
leds: parameter.leds.clone(),
point: Point::new(point.0, point.1),
color: Color {
red: 0,
green: 0,
blue: 0,
},
});
}
}
}
});
}
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment