Compare commits

..

1 commit

Author SHA1 Message Date
05b01d54b8 Add calibration util 2025-05-23 18:11:20 +02:00
15 changed files with 607 additions and 232 deletions

380
Cargo.lock generated
View file

@ -7,10 +7,11 @@ name = "ELApse"
version = "0.1.5"
dependencies = [
"clap",
"crossterm",
"crossterm_input",
"ftdi-embedded-hal",
"image",
"piston_window",
"rgb",
"unreal_asset",
"url",
]
@ -224,9 +225,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.6.0"
version = "2.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967"
[[package]]
name = "bitstream-io"
@ -351,6 +352,12 @@ dependencies = [
"target-lexicon",
]
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -424,6 +431,15 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
[[package]]
name = "convert_case"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb402b8d4c85569410425650ce3eddc7d698ed96d39a73f941b08fb63082f1e7"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "core-foundation"
version = "0.9.4"
@ -470,7 +486,7 @@ version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
]
[[package]]
@ -498,12 +514,107 @@ version = "0.8.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80"
[[package]]
name = "crossterm"
version = "0.29.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8b9f2e4c67f833b660cdb0a3523065869fb35570177239812ed4c905aeff87b"
dependencies = [
"bitflags 2.9.1",
"crossterm_winapi 0.9.1",
"derive_more",
"document-features",
"mio 1.0.3",
"parking_lot",
"rustix",
"signal-hook",
"signal-hook-mio",
"winapi 0.3.9",
]
[[package]]
name = "crossterm_input"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39fafa96a623903f0d9232a13ee43f69334caa770fb412f4319772a9db25952c"
dependencies = [
"crossterm_screen",
"crossterm_utils",
"crossterm_winapi 0.3.0",
"lazy_static",
"libc",
"mio 0.6.23",
"winapi 0.3.9",
]
[[package]]
name = "crossterm_screen"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a08dfba7fade62a6c2c48ad6451e288f15fd9ffa640078fc4b08948e81d19db7"
dependencies = [
"crossterm_utils",
"crossterm_winapi 0.3.0",
"winapi 0.3.9",
]
[[package]]
name = "crossterm_utils"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c13047e5f7265fe853d54211dbb9bce57220f62d952d48556299f7a65d564a3"
dependencies = [
"crossterm_winapi 0.3.0",
"lazy_static",
"libc",
"winapi 0.3.9",
]
[[package]]
name = "crossterm_winapi"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df25e92a352488d9b3e0215e4e99402945993026159f98b477047719f16a6530"
dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "crossterm_winapi"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b"
dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "crunchy"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
[[package]]
name = "derive_more"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "093242cf7570c207c83073cf82f79706fe7b8317e98620a47d5be7c3d8497678"
dependencies = [
"derive_more-impl",
]
[[package]]
name = "derive_more-impl"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bda628edc44c4bb645fbe0f758797143e4e07926f7ebf4e9bdfbd3d2ce621df3"
dependencies = [
"convert_case",
"proc-macro2",
"quote",
"syn 2.0.77",
]
[[package]]
name = "dispatch"
version = "0.2.0"
@ -519,6 +630,15 @@ dependencies = [
"libloading 0.8.5",
]
[[package]]
name = "document-features"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95249b50c6c185bee49034bcb378a49dc2b5dff0be90ff6616d31d64febab05d"
dependencies = [
"litrs",
]
[[package]]
name = "downcast-rs"
version = "1.2.1"
@ -584,6 +704,16 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "errno"
version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18"
dependencies = [
"libc",
"windows-sys 0.59.0",
]
[[package]]
name = "exr"
version = "1.72.0"
@ -681,6 +811,22 @@ dependencies = [
"static_assertions",
]
[[package]]
name = "fuchsia-zircon"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
dependencies = [
"bitflags 1.3.2",
"fuchsia-zircon-sys",
]
[[package]]
name = "fuchsia-zircon-sys"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]]
name = "funty"
version = "2.0.0"
@ -693,7 +839,7 @@ version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"libc",
"wasi",
]
@ -851,7 +997,7 @@ version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"crunchy",
]
@ -932,7 +1078,7 @@ version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"js-sys",
"wasm-bindgen",
"web-sys",
@ -955,6 +1101,15 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9c13ae9d91148fcb4aab6654c4c2a7d02a15395ea9e23f65170f175f8b269ce"
[[package]]
name = "iovec"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e"
dependencies = [
"libc",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
@ -1000,6 +1155,16 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "kernel32-sys"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
dependencies = [
"winapi 0.2.8",
"winapi-build",
]
[[package]]
name = "khronos_api"
version = "3.1.0"
@ -1020,9 +1185,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
[[package]]
name = "libc"
version = "0.2.158"
version = "0.2.172"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439"
checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
[[package]]
name = "libftd2xx"
@ -1043,7 +1208,7 @@ version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40bed7f53ea45282e0e4f1361d1a8094e62abe0ccfd9a6dbf7e3db932b2789ce"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
]
[[package]]
@ -1063,8 +1228,8 @@ version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
dependencies = [
"cfg-if",
"winapi",
"cfg-if 1.0.0",
"winapi 0.3.9",
]
[[package]]
@ -1073,7 +1238,7 @@ version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"windows-targets 0.52.6",
]
@ -1083,11 +1248,23 @@ version = "0.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3af92c55d7d839293953fcd0fda5ecfe93297cfde6ffbdec13b41d99c0ba6607"
dependencies = [
"bitflags 2.6.0",
"bitflags 2.9.1",
"libc",
"redox_syscall 0.4.1",
]
[[package]]
name = "linux-raw-sys"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12"
[[package]]
name = "litrs"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5"
[[package]]
name = "lock_api"
version = "0.4.12"
@ -1119,7 +1296,7 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea1f30cedd69f0a2954655f7188c6a834246d2bcf1e315e2ac40c4b24dc9519"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
]
[[package]]
@ -1171,6 +1348,25 @@ dependencies = [
"adler2",
]
[[package]]
name = "mio"
version = "0.6.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4"
dependencies = [
"cfg-if 0.1.10",
"fuchsia-zircon",
"fuchsia-zircon-sys",
"iovec",
"kernel32-sys",
"libc",
"log",
"miow",
"net2",
"slab",
"winapi 0.2.8",
]
[[package]]
name = "mio"
version = "0.8.11"
@ -1183,6 +1379,30 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "mio"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd"
dependencies = [
"libc",
"log",
"wasi",
"windows-sys 0.52.0",
]
[[package]]
name = "miow"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d"
dependencies = [
"kernel32-sys",
"net2",
"winapi 0.2.8",
"ws2_32-sys",
]
[[package]]
name = "naive-cityhash"
version = "0.2.0"
@ -1233,6 +1453,17 @@ dependencies = [
"jni-sys",
]
[[package]]
name = "net2"
version = "0.2.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b13b648036a2339d06de780866fbdfda0dde886de7b3af2ddeba8b14f4ee34ac"
dependencies = [
"cfg-if 0.1.10",
"libc",
"winapi 0.3.9",
]
[[package]]
name = "new_debug_unreachable"
version = "1.0.6"
@ -1246,7 +1477,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069"
dependencies = [
"bitflags 1.3.2",
"cfg-if",
"cfg-if 1.0.0",
"libc",
"memoffset",
]
@ -1259,7 +1490,7 @@ checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4"
dependencies = [
"autocfg",
"bitflags 1.3.2",
"cfg-if",
"cfg-if 1.0.0",
"libc",
"memoffset",
]
@ -1440,6 +1671,29 @@ dependencies = [
"ttf-parser 0.24.1",
]
[[package]]
name = "parking_lot"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
dependencies = [
"cfg-if 1.0.0",
"libc",
"redox_syscall 0.5.12",
"smallvec",
"windows-targets 0.52.6",
]
[[package]]
name = "paste"
version = "1.0.15"
@ -1740,7 +1994,7 @@ dependencies = [
"av1-grain",
"bitstream-io",
"built",
"cfg-if",
"cfg-if 1.0.0",
"interpolate_name",
"itertools",
"libc",
@ -1827,6 +2081,15 @@ dependencies = [
"bitflags 1.3.2",
]
[[package]]
name = "redox_syscall"
version = "0.5.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af"
dependencies = [
"bitflags 2.9.1",
]
[[package]]
name = "regex"
version = "1.10.6"
@ -1858,9 +2121,9 @@ checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
[[package]]
name = "rgb"
version = "0.8.52"
version = "0.8.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c6a884d2998352bb4daf0183589aec883f16a6da1f4dde84d8e2e9a5409a1ce"
checksum = "57397d16646700483b67d2dd6511d79318f9d057fdbd21a4066aeac8b41d310a"
dependencies = [
"bytemuck",
]
@ -1871,6 +2134,19 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustix"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266"
dependencies = [
"bitflags 2.9.1",
"errno",
"libc",
"linux-raw-sys",
"windows-sys 0.59.0",
]
[[package]]
name = "rusttype"
version = "0.9.3"
@ -1950,6 +2226,36 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "signal-hook"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d881a16cf4426aa584979d30bd82cb33429027e42122b169753d6ef1085ed6e2"
dependencies = [
"libc",
"signal-hook-registry",
]
[[package]]
name = "signal-hook-mio"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34db1a06d485c9142248b7a054f034b349b212551f3dfd19c94d45a754a217cd"
dependencies = [
"libc",
"mio 1.0.3",
"signal-hook",
]
[[package]]
name = "signal-hook-registry"
version = "1.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9203b8055f63a2a00e2f593bb0510367fe707d7ff1e5c872de2f537b339e5410"
dependencies = [
"libc",
]
[[package]]
name = "simd-adler32"
version = "0.3.7"
@ -2131,7 +2437,7 @@ dependencies = [
"arrayref",
"arrayvec",
"bytemuck",
"cfg-if",
"cfg-if 1.0.0",
"png",
"tiny-skia-path",
]
@ -2240,6 +2546,12 @@ dependencies = [
"tinyvec",
]
[[package]]
name = "unicode-segmentation"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493"
[[package]]
name = "unreal_asset"
version = "0.1.16"
@ -2360,7 +2672,7 @@ version = "0.2.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"once_cell",
"wasm-bindgen-macro",
]
@ -2510,6 +2822,12 @@ version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082"
[[package]]
name = "winapi"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
[[package]]
name = "winapi"
version = "0.3.9"
@ -2520,6 +2838,12 @@ dependencies = [
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
@ -2761,7 +3085,7 @@ dependencies = [
"instant",
"libc",
"log",
"mio",
"mio 0.8.11",
"ndk",
"objc2",
"once_cell",
@ -2799,6 +3123,16 @@ dependencies = [
"memchr",
]
[[package]]
name = "ws2_32-sys"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"
dependencies = [
"winapi 0.2.8",
"winapi-build",
]
[[package]]
name = "wyz"
version = "0.5.1"

View file

@ -9,10 +9,11 @@ readme = "README.md"
[dependencies]
clap = { version = "4.5.17", features = ["derive"] }
crossterm = "0.29.0"
crossterm_input = "0.5.0"
ftdi-embedded-hal = { version = "0.22.0", features = ["libftd2xx"] }
image = "0.25.2"
piston_window = "0.132.0"
rgb = "0.8.52"
unreal_asset = "0.1.16"
url = "2.5.2"

2
rust-toolchain.toml Normal file
View file

@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"

145
src/input.rs Normal file
View file

@ -0,0 +1,145 @@
#![allow(non_camel_case_types)]
use std::{io::{self, stdout, Read, Write}, net::UdpSocket, sync::mpsc::{self, Receiver, Sender}, thread, time::{Duration, Instant}};
use crate::{ parser, fileparser };
use crossterm_input::{input, RawScreen, Result, TerminalInput};
use piston_window::clear;
pub fn stdin(tx: Sender<Vec<[f32; 4]>>) {
let (stdintx, stdinrx): (Sender<Vec<u8>>, Receiver<Vec<u8>>) = mpsc::channel();
thread::spawn( move || {
let mut buf = [0; 1500];
let mut e = std::io::stdin().lock();
loop {
let amt = e.read(&mut buf).unwrap();
if buf[..amt].to_vec().len() > 0 {
let _ = stdintx.send(buf[..amt].to_vec());
}
}
});
thread::spawn( move || {
loop {
// let amt = e.read(&mut buf).unwrap();
match stdinrx.recv_timeout(Duration::from_millis(500)) {
Ok(d) => {
let r: Vec<[f32; 4]> = parser::parseleds(d, parser::ParserOptions::default().mirror(true).double(true).offset(15));
let _ = tx.send(r);
},
Err(_) => {
std::process::exit(0);
},
};
}
});
}
pub fn realtimeudp(tx: Sender<Vec<[f32; 4]>>,bindaddr: String) {
thread::spawn( move || {
let socket = UdpSocket::bind(bindaddr).unwrap();
let mut buf = [0; 1500];
loop {
let (amt, _src) = socket.recv_from(&mut buf).unwrap();
let r = parser::parseleds(buf[..amt].to_vec(), parser::ParserOptions::default().stripheader(2));
let _ = tx.send(r);
}
});
}
pub fn file(tx: Sender<Vec<[f32; 4]>>, path: String) {
thread::spawn( move || {
let Ok(rawbytes) = fileparser::parse(&path) else {
println!("File not found");
std::process::exit(1)
};
for frame in rawbytes.chunks(720) {
let st = Instant::now();
let r = parser::parseleds(frame.to_vec(), parser::ParserOptions::default().mirror(true).double(true).offset(15));
let _ = tx.send(r);
if Duration::from_secs_f32(1.0/60.0) > st.elapsed() {
thread::sleep(Duration::from_secs_f32(1.0/60.0)-st.elapsed());
};
}
std::process::exit(0);
});
}
pub fn calibration(tx: Sender<Vec<[f32; 4]>>) {
thread::spawn( move || {
let screen = RawScreen::into_raw_mode();
let mut stdout = stdout();
let mut async_stdin = input().read_async();
let mut colorse = [[1.0,0.0,0.0,1.0],[0.0,1.0,0.0,1.0],[0.0,0.0,1.0,1.0]];
let mut modifier = [[0.0,0.0,0.0,0.0];60];
let mut current: i64 = 0;
let mut currentcolor: usize = 0;
while true {
if let Some(key_event) = async_stdin.next() {
//input code starts here
match key_event {
crossterm_input::InputEvent::Keyboard(key_event) => {
match key_event {
crossterm_input::KeyEvent::Char('r') => { //R up
modifier[current as usize][0] += 0.01;
},
crossterm_input::KeyEvent::Char('t') => { //R down
modifier[current as usize][0] -= 0.01;
},
crossterm_input::KeyEvent::Char('g') => { //G up
modifier[current as usize][1] += 0.01
},
crossterm_input::KeyEvent::Char('h') => { //G down
modifier[current as usize][1] -= 0.01;
},
crossterm_input::KeyEvent::Char('b') => { //B up
modifier[current as usize][2] += 0.01;
},
crossterm_input::KeyEvent::Char('n') => { //B down
modifier[current as usize][2] -= 0.01;
},
crossterm_input::KeyEvent::Char('p') => { //B down
currentcolor += 1;
if currentcolor == 3 { currentcolor = 0 }
},
crossterm_input::KeyEvent::Left => { //B down
current -= 1;
if current == -1 {
current = 59;
}
print!("{:?}",current);
},
crossterm_input::KeyEvent::Right => { //B down
current += 1;
if current == 60 {
current = 0;
}
print!("{:?}",current);
},
crossterm_input::KeyEvent::Char('q') => {
break;
},
_ => {},
}
},
_ => {},
}
//input code ends here
}
let st = Instant::now();
let mut colors = vec![colorse[currentcolor];480];
for p in 0..60 {
for cur in (p*8)..(p*8+8) {
for l in 0..4 {
colors[cur as usize][l as usize] += modifier[p as usize][l as usize]
}
};
};
let _ = tx.send(colors);
if Duration::from_secs_f32(1.0/60.0) > st.elapsed() {
thread::sleep(Duration::from_secs_f32(1.0/60.0)-st.elapsed());
};
print!("\x1B[2J\x1B[1;1HCurrent modifiers: {:?}\x1B[2;1HCurrent line: {:?}",modifier[current as usize],current);
stdout.flush();
}
RawScreen::disable_raw_mode();
std::process::exit(0);
});
}

View file

@ -1,29 +0,0 @@
#![allow(non_camel_case_types)]
use std::{sync::mpsc::Sender, thread, time::{Duration, Instant}};
use crate::{fileparser, input::Input, parser};
impl Input {
pub fn file(tx: Sender<Vec<[f32; 4]>>, path: String) {
thread::spawn(move || {
let Ok(rawbytes) = fileparser::parse(&path) else {
println!("File not found");
std::process::exit(1)
};
for frame in rawbytes.chunks(720) {
let st = Instant::now();
let r = parser::parseleds(
frame.to_vec(),
parser::ParserOptions::default()
.mirror(true)
.double(true)
.offset(15),
);
let _ = tx.send(r);
if Duration::from_secs_f32(1.0 / 60.0) > st.elapsed() {
thread::sleep(Duration::from_secs_f32(1.0 / 60.0) - st.elapsed());
};
}
std::process::exit(0);
});
}
}

View file

@ -1,5 +0,0 @@
mod file;
mod realtimeudp;
mod stdin;
pub struct Input;

View file

@ -1,20 +0,0 @@
#![allow(non_camel_case_types)]
use std::{net::UdpSocket, sync::mpsc::Sender, thread};
use crate::{input::Input, parser};
impl Input {
pub fn realtimeudp(tx: Sender<Vec<[f32; 4]>>, bindaddr: String) {
thread::spawn(move || {
let socket = UdpSocket::bind(bindaddr).unwrap();
let mut buf = [0; 1500];
loop {
let (amt, _src) = socket.recv_from(&mut buf).unwrap();
let r = parser::parseleds(
buf[..amt].to_vec(),
parser::ParserOptions::default().stripheader(2),
);
let _ = tx.send(r);
}
});
}
}

View file

@ -1,39 +0,0 @@
#![allow(non_camel_case_types)]
use std::{io::Read, sync::mpsc::{self, Receiver, Sender}, thread, time::Duration};
use crate::{input::Input, parser};
impl Input {
pub fn stdin(tx: Sender<Vec<[f32; 4]>>) {
let (stdintx, stdinrx): (Sender<Vec<u8>>, Receiver<Vec<u8>>) = mpsc::channel();
thread::spawn(move || {
let mut buf = [0; 1500];
let mut e = std::io::stdin().lock();
loop {
let amt = e.read(&mut buf).unwrap();
if buf[..amt].to_vec().len() > 0 {
let _ = stdintx.send(buf[..amt].to_vec());
}
}
});
thread::spawn(move || {
loop {
// let amt = e.read(&mut buf).unwrap();
match stdinrx.recv_timeout(Duration::from_millis(500)) {
Ok(d) => {
let r: Vec<[f32; 4]> = parser::parseleds(
d,
parser::ParserOptions::default()
.mirror(true)
.double(true)
.offset(15),
);
let _ = tx.send(r);
}
Err(_) => {
std::process::exit(0);
}
};
}
});
}
}

View file

@ -1,3 +1,4 @@
#![feature(array_chunks)]
mod input;
mod output;
mod parser;
@ -7,8 +8,6 @@ mod fileparser;
use std::sync::mpsc::{self, Receiver, Sender};
use clap::Parser;
use url::Url;
use crate::output::Output;
use crate::input::Input;
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
@ -26,15 +25,16 @@ fn main() {
let args = Args::parse();
let (tx, rx): (Sender<Vec<[f32; 4]>>, Receiver<Vec<[f32; 4]>>) = mpsc::channel();
match args.input.as_str() {
"-" | "stdin" => Input::stdin(tx),
"-" | "stdin" => input::stdin(tx),
"calibration" => input::calibration(tx),
_ => {
match Url::parse(&args.input) {
Ok(o) => {
match o.scheme() {
"udp" => {
Input::realtimeudp(tx, utils::get_host(o));
input::realtimeudp(tx, utils::get_host(o));
},
"file" => Input::file(tx, o.path().to_owned()),
"file" => input::file(tx, o.path().to_owned()),
_ => {
println!("Unrecognized uri scheme");
std::process::exit(1);
@ -42,19 +42,19 @@ fn main() {
}
},
Err(_) => {
Input::file(tx, args.input);
input::file(tx, args.input);
},
};
}
}
match args.output.as_str() {
"piston" => Output::piston(rx),
"ftd2xx" => Output::ft2dxx(rx),
"piston" => output::piston(rx),
"ftd2xx" => output::ft2dxx(rx),
_ => {
match Url::parse(&args.output) {
Ok(o) => {
match o.scheme() {
"udp" => Output::realtimeudp(rx,utils::get_host(o)),
"udp" => output::realtimeudp(rx,utils::get_host(o)),
_ => {
println!("Unrecognized uri scheme");
std::process::exit(1);

91
src/output.rs Normal file
View file

@ -0,0 +1,91 @@
#![allow(non_camel_case_types)]
use piston_window::*;
use piston_window::graphics::math::Scalar;
use std::{net::UdpSocket, sync::mpsc::Receiver, time::Duration};
use ftdi_embedded_hal::eh0::prelude::_embedded_hal_blocking_spi_Write;
use ftdi_embedded_hal::{self as hal, libftd2xx};
use crate::utils::{compare, offset};
pub fn piston(rx: Receiver<Vec<[f32; 4]>>) {
let mut window: PistonWindow =
WindowSettings::new("ELApse", [800, 800])
.transparent(true)
.exit_on_esc(true).build().unwrap();
while let Some(e) = window.next() {
let r = match rx.recv_timeout(Duration::from_millis(66)) {
Ok(e) => e,
Err(_) => vec![[0.02, 0.02, 0.02, 1.0]; 480],
};
let size = window.size();
let wh = compare(size.height, size.width)*0.75;
window.draw_2d(&e, |c, g, _device| {
for e in 1..9 {
for i in 0..60 {
let rwh = wh*(1.0-(e as f64*0.06));
circle_arc(r[i*8+(e-1)], rwh/32.0, Scalar::deg_to_rad(offset((((360/60)*i)) as i16, 360, 90) as f64), Scalar::deg_to_rad(offset((((360/60)*i)+6) as i16, 360, 90) as f64), [(size.width/2.0)-(rwh/2.0), (size.height/2.0)-(rwh/2.0), rwh, rwh], c.transform, g);
}
}
});
}
}
pub fn realtimeudp(rx: Receiver<Vec<[f32; 4]>>, addr: String) {
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
loop {
let leds = rx.recv().unwrap();
let mut packet: Vec<u8> = vec![2, 2];
for led in leds {
packet.push((led[0]*255.0) as u8);
packet.push((led[1]*255.0) as u8);
packet.push((led[2]*255.0) as u8);
}
match socket.send_to(&packet, &addr) {
Ok(_) => (),
Err(err) => {
println!("Error while sending trying to send data: {}", err);
std::process::exit(1);
},
};
}
}
pub fn ft2dxx(rx: Receiver<Vec<[f32; 4]>>) {
let device = libftd2xx::Ft232h::with_description("Single RS232-HS").unwrap();
println!("Connected to FT232H");
let hal = hal::FtHal::init_freq(device, 3_000_000).unwrap();
let mut spi = hal.spi().unwrap();
// led stuff
loop {
let leds = rx.recv().unwrap();
let mut fdata: Vec<u8> = Vec::new();
for led in leds {
let sled = [led[1],led[0],led[2]]; //Shift colors (be gone when I make a color struct)
for i in 0..3 {
let mut data = (sled[i].clone()*255.0) as u8;
let patterns = [0b1000_1000, 0b1000_1110, 0b11101000, 0b11101110];
for _ in 0..4 {
let bits = (data & 0b1100_0000) >> 6;
fdata.push(patterns[bits as usize]);
data <<= 2;
}
}
}
let _ = spi.write(&fdata);
// for _ in 0..140 {
// spi.write(std::array::from_ref(&0)).unwrap();
// }
}
}
#[derive(clap::ValueEnum, Clone, Debug)]
pub enum Output {
piston,
realtimeudp,
ft2dxx,
}

View file

@ -1,40 +0,0 @@
#![allow(non_camel_case_types)]
use std::sync::mpsc::Receiver;
use ftdi_embedded_hal::eh0::prelude::_embedded_hal_blocking_spi_Write;
use ftdi_embedded_hal::{self as hal, libftd2xx};
use crate::output::Output;
impl Output {
pub fn ft2dxx(rx: Receiver<Vec<[f32; 4]>>) {
let device = libftd2xx::Ft232h::with_description("Single RS232-HS").unwrap();
println!("Connected to FT232H");
let hal = hal::FtHal::init_freq(device, 3_000_000).unwrap();
let mut spi = hal.spi().unwrap();
// led stuff
loop {
let leds = rx.recv().unwrap();
let mut fdata: Vec<u8> = Vec::new();
for led in leds {
let sled = [led[1], led[0], led[2]]; //Shift colors (be gone when I make a color struct)
for i in 0..3 {
let mut data = (sled[i].clone() * 255.0) as u8;
let patterns = [0b1000_1000, 0b1000_1110, 0b11101000, 0b11101110];
for _ in 0..4 {
let bits = (data & 0b1100_0000) >> 6;
fdata.push(patterns[bits as usize]);
data <<= 2;
}
}
}
let _ = spi.write(&fdata);
// for _ in 0..140 {
// spi.write(std::array::from_ref(&0)).unwrap();
// }
}
}
}

View file

@ -1,5 +0,0 @@
mod ft2dxx;
mod piston;
mod realtimeudp;
pub struct Output;

View file

@ -1,34 +0,0 @@
#![allow(non_camel_case_types)]
use piston_window::*;
use piston_window::graphics::math::Scalar;
use std::{sync::mpsc::Receiver, time::Duration};
use crate::output::Output;
use crate::utils::{compare, offset};
impl Output {
pub fn piston(rx: Receiver<Vec<[f32; 4]>>) {
let mut window: PistonWindow =
WindowSettings::new("ELApse", [800, 800])
.transparent(true)
.exit_on_esc(true).build().unwrap();
while let Some(e) = window.next() {
let r = match rx.recv_timeout(Duration::from_millis(66)) {
Ok(e) => e,
Err(_) => vec![[0.02, 0.02, 0.02, 1.0]; 480],
};
let size = window.size();
let wh = compare(size.height, size.width)*0.75;
window.draw_2d(&e, |c, g, _device| {
for e in 1..9 {
for i in 0..60 {
let rwh = wh*(1.0-(e as f64*0.06));
circle_arc(r[i*8+(e-1)], rwh/32.0, Scalar::deg_to_rad(offset((((360/60)*i)) as i16, 360, 90) as f64), Scalar::deg_to_rad(offset((((360/60)*i)+6) as i16, 360, 90) as f64), [(size.width/2.0)-(rwh/2.0), (size.height/2.0)-(rwh/2.0), rwh, rwh], c.transform, g);
}
}
});
}
}
}

View file

@ -1,26 +0,0 @@
#![allow(non_camel_case_types)]
use std::{net::UdpSocket, sync::mpsc::Receiver};
use crate::output::Output;
impl Output {
pub fn realtimeudp(rx: Receiver<Vec<[f32; 4]>>, addr: String) {
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
loop {
let leds = rx.recv().unwrap();
let mut packet: Vec<u8> = vec![2, 2];
for led in leds {
packet.push((led[0] * 255.0) as u8);
packet.push((led[1] * 255.0) as u8);
packet.push((led[2] * 255.0) as u8);
}
match socket.send_to(&packet, &addr) {
Ok(_) => (),
Err(err) => {
println!("Error while sending trying to send data: {}", err);
std::process::exit(1);
}
};
}
}
}

View file

@ -34,7 +34,7 @@ pub fn parseleds(mut data: Vec<u8>, options: ParserOptions) -> Vec<[f32; 4]> {
if data.len() < expectedlen {
data.append(&mut vec![5; expectedlen-out.len()]);
}
for x in data.as_chunks::<3>().0.iter() {
for x in data.array_chunks::<3>() {
out.push([utils::scaleu8tof32(x[0]), utils::scaleu8tof32(x[1]), utils::scaleu8tof32(x[2]), 1.0]);
if options.double && !options.mirror {
out.push(out.last().unwrap().clone());