From 66c4aeffa618aa3cab9c7e3f71df11bdfe3d08cb Mon Sep 17 00:00:00 2001 From: Tropicananass Date: Sat, 28 Jun 2025 14:28:32 +0000 Subject: [PATCH] Adding alsa lib and cpal --- .devcontainer/Dockerfile | 21 +- .devcontainer/devcontainer.json | 27 +- Cargo.lock | 495 +++++++++++++++++- README.md | 5 + lightsabre_backend/Cargo.toml | 2 +- lightsabre_backend/src/cputasks/modes.rs | 52 +- .../src/cputasks/modes/artnet.rs | 3 - .../src/cputasks/modes/diagnostics.rs | 2 +- .../src/cputasks/modes/standalone.rs | 18 + lightsabre_backend/src/devices/selector.rs | 7 +- lightsabre_backend/src/iotasks/selector.rs | 2 +- 11 files changed, 570 insertions(+), 64 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 4311bfc..ccbacd9 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -4,11 +4,22 @@ FROM mcr.microsoft.com/devcontainers/rust:1-1-bookworm # Install ARM cross-compilation toolchain packages RUN apt-get update && \ apt-get install -y --no-install-recommends \ - gdb-multiarch \ - gcc-arm-linux-gnueabihf \ - g++-arm-linux-gnueabihf \ - binutils-arm-linux-gnueabihf && \ + gdb-multiarch \ + gcc-arm-linux-gnueabihf \ + g++-arm-linux-gnueabihf \ + binutils-arm-linux-gnueabihf && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* -RUN rustup target add armv7-unknown-linux-gnueabihf \ No newline at end of file +# install arm32 cross-compiler +RUN dpkg --add-architecture armhf && \ + apt update && \ + apt install -y \ + libasound2-dev:armhf && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +RUN rustup target add armv7-unknown-linux-gnueabihf + +ENV PKG_CONFIG_LIBDIR=/usr/lib/arm-linux-gnueabihf/pkgconfig +ENV PKG_CONFIG_ALLOW_CROSS=true \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 499f06c..4adb78c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -4,7 +4,6 @@ "name": "lightsabre-devcontainer", // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile "dockerFile": "Dockerfile", - // Use 'mounts' to make the cargo cache persistent in a Docker Volume. "mounts": [ { @@ -12,30 +11,26 @@ "target": "/usr/local/cargo", "type": "volume" }, - "type=bind,source=/home/${localEnv:USER}/.ssh,target=/home/vscode/.ssh,readonly", - "type=bind,source=/home/${localEnv:USER}/.bashrc,target=/home/vscode/.bashrc,readonly", - "type=bind,source=/home/${localEnv:USER}/.bashrc.d,target=/home/vscode/.bashrc.d,readonly" + "type=bind,source=/home/${localEnv:USER}/.ssh,target=/home/vscode/.ssh,readonly", + "type=bind,source=/home/${localEnv:USER}/.bashrc,target=/home/vscode/.bashrc,readonly", + "type=bind,source=/home/${localEnv:USER}/.bashrc.d,target=/home/vscode/.bashrc.d,readonly" ], - // Features to add to the dev container. More info: https://containers.dev/features. // "features": {}, - // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], - // Use 'postCreateCommand' to run commands after the container is created. "postCreateCommand": "rustc --version", - // Configure tool-specific properties. - "customizations": { - "vscode": { - "extensions": [ + "customizations": { + "vscode": { + "extensions": [ "streetsidesoftware.code-spell-checker", "rust-lang.rust-analyzer", - "vadimcn.vscode-lldb"] - } - } - + "vadimcn.vscode-lldb" + ] + } + } // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. // "remoteUser": "root" -} +} \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 9d52884..09e46e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,6 +26,28 @@ dependencies = [ "memchr", ] +[[package]] +name = "alsa" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed7572b7ba83a31e20d1b48970ee402d2e3e0537dcfe0a3ff4d6eb7508617d43" +dependencies = [ + "alsa-sys", + "bitflags 2.9.1", + "cfg-if", + "libc", +] + +[[package]] +name = "alsa-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db8fee663d06c4e303404ef5f40488a53e062f89ba8bfed81f42325aafad1527" +dependencies = [ + "libc", + "pkg-config", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -119,7 +141,7 @@ dependencies = [ "miniz_oxide", "object", "rustc-demangle", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -161,6 +183,12 @@ dependencies = [ "shlex", ] +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + [[package]] name = "cfg-if" version = "1.0.0" @@ -193,12 +221,62 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" +[[package]] +name = "combine" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" +dependencies = [ + "bytes", + "memchr", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "coreaudio-rs" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aae284fbaf7d27aa0e292f7677dfbe26503b0d555026f702940805a630eac17" +dependencies = [ + "bitflags 1.3.2", + "libc", + "objc2-audio-toolbox", + "objc2-core-audio", + "objc2-core-audio-types", + "objc2-core-foundation", +] + +[[package]] +name = "cpal" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbd307f43cc2a697e2d1f8bc7a1d824b5269e052209e28883e5bc04d095aaa3f" +dependencies = [ + "alsa", + "coreaudio-rs", + "dasp_sample", + "jni", + "js-sys", + "libc", + "mach2", + "ndk", + "ndk-context", + "num-derive", + "num-traits", + "objc2-audio-toolbox", + "objc2-core-audio", + "objc2-core-audio-types", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows", +] + [[package]] name = "crossbeam" version = "0.8.4" @@ -265,6 +343,22 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "dasp_sample" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c87e182de0887fd5361989c677c4e8f5000cd9491d6d563161a8f3a5519fc7f" + +[[package]] +name = "dispatch2" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec" +dependencies = [ + "bitflags 2.9.1", + "objc2", +] + [[package]] name = "env_filter" version = "0.1.3" @@ -288,12 +382,24 @@ dependencies = [ "log", ] +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + [[package]] name = "gimli" version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" +[[package]] +name = "hashbrown" +version = "0.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" + [[package]] name = "iana-time-zone" version = "0.1.63" @@ -306,7 +412,7 @@ dependencies = [ "js-sys", "log", "wasm-bindgen", - "windows-core", + "windows-core 0.61.2", ] [[package]] @@ -318,6 +424,16 @@ dependencies = [ "cc", ] +[[package]] +name = "indexmap" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" +dependencies = [ + "equivalent", + "hashbrown", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.1" @@ -348,6 +464,28 @@ dependencies = [ "syn", ] +[[package]] +name = "jni" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" +dependencies = [ + "cesu8", + "cfg-if", + "combine", + "jni-sys", + "log", + "thiserror", + "walkdir", + "windows-sys 0.45.0", +] + +[[package]] +name = "jni-sys" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" + [[package]] name = "js-sys" version = "0.3.77" @@ -369,6 +507,7 @@ name = "lightsabre_backend" version = "0.1.0" dependencies = [ "artnet_protocol", + "cpal", "crossbeam", "ctrlc", "env_logger", @@ -394,6 +533,15 @@ version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" +[[package]] +name = "mach2" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d640282b302c0bb0a2a8e0233ead9035e3bed871f0b7e81fe4a1ec829765db44" +dependencies = [ + "libc", +] + [[package]] name = "memchr" version = "2.7.4" @@ -429,6 +577,35 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "ndk" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3f42e7bbe13d351b6bead8286a43aac9534b82bd3cc43e47037f012ebfd62d4" +dependencies = [ + "bitflags 2.9.1", + "jni-sys", + "log", + "ndk-sys", + "num_enum", + "thiserror", +] + +[[package]] +name = "ndk-context" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b" + +[[package]] +name = "ndk-sys" +version = "0.6.0+11769913" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee6cda3051665f1fb8d9e08fc35c96d5a244fb1be711a03b71118828afc9a873" +dependencies = [ + "jni-sys", +] + [[package]] name = "nix" version = "0.26.4" @@ -454,6 +631,17 @@ dependencies = [ "libc", ] +[[package]] +name = "num-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -463,6 +651,100 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "objc2" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88c6597e14493ab2e44ce58f2fdecf095a51f12ca57bec060a11c57332520551" +dependencies = [ + "objc2-encode", +] + +[[package]] +name = "objc2-audio-toolbox" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10cbe18d879e20a4aea544f8befe38bcf52255eb63d3f23eca2842f3319e4c07" +dependencies = [ + "bitflags 2.9.1", + "libc", + "objc2", + "objc2-core-audio", + "objc2-core-audio-types", + "objc2-core-foundation", + "objc2-foundation", +] + +[[package]] +name = "objc2-core-audio" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca44961e888e19313b808f23497073e3f6b3c22bb485056674c8b49f3b025c82" +dependencies = [ + "dispatch2", + "objc2", + "objc2-core-audio-types", + "objc2-core-foundation", +] + +[[package]] +name = "objc2-core-audio-types" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0f1cc99bb07ad2ddb6527ddf83db6a15271bb036b3eb94b801cd44fdc666ee1" +dependencies = [ + "bitflags 2.9.1", + "objc2", +] + +[[package]] +name = "objc2-core-foundation" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c10c2894a6fed806ade6027bcd50662746363a9589d3ec9d9bef30a4e4bc166" +dependencies = [ + "bitflags 2.9.1", + "dispatch2", + "objc2", +] + +[[package]] +name = "objc2-encode" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef25abbcd74fb2609453eb695bd2f860d389e457f67dc17cafc8b8cbc89d0c33" + +[[package]] +name = "objc2-foundation" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900831247d2fe1a09a683278e5384cfb8c80c79fe6b166f9d14bfdde0ea1b03c" +dependencies = [ + "objc2", +] + [[package]] name = "object" version = "0.36.7" @@ -504,7 +786,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -519,6 +801,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + [[package]] name = "portable-atomic" version = "1.11.0" @@ -534,6 +822,15 @@ dependencies = [ "portable-atomic", ] +[[package]] +name = "proc-macro-crate" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edce586971a4dfaa28950c6f18ed55e0406c1ab88bbce2c6f6293a7aaba73d35" +dependencies = [ + "toml_edit", +] + [[package]] name = "proc-macro2" version = "1.0.95" @@ -631,6 +928,15 @@ version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -748,6 +1054,23 @@ dependencies = [ "syn", ] +[[package]] +name = "toml_datetime" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" + +[[package]] +name = "toml_edit" +version = "0.22.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + [[package]] name = "unicode-ident" version = "1.0.18" @@ -760,6 +1083,16 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -792,6 +1125,19 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" +dependencies = [ + "cfg-if", + "js-sys", + "once_cell", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.100" @@ -824,6 +1170,45 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "web-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "windows" +version = "0.54.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9252e5725dbed82865af151df558e754e4a3c2c30818359eb17465f1346a1b49" +dependencies = [ + "windows-core 0.54.0", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-core" +version = "0.54.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12661b9c89351d684a50a8a643ce5f608e20243b9fb84687800163429f161d65" +dependencies = [ + "windows-result 0.1.2", + "windows-targets 0.52.6", +] + [[package]] name = "windows-core" version = "0.61.2" @@ -833,7 +1218,7 @@ dependencies = [ "windows-implement", "windows-interface", "windows-link", - "windows-result", + "windows-result 0.3.4", "windows-strings", ] @@ -865,6 +1250,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-result" version = "0.3.4" @@ -883,13 +1277,22 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -898,7 +1301,22 @@ version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", ] [[package]] @@ -907,28 +1325,46 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -941,26 +1377,59 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74c7b26e3480b707944fc872477815d29a8e429d2f93a1ce000f5fa84a15cbcd" +dependencies = [ + "memchr", +] diff --git a/README.md b/README.md index 2fcb420..0ae0679 100755 --- a/README.md +++ b/README.md @@ -59,6 +59,11 @@ For more details : https://rustup.rs/ #### I2S Microphone [I2S microphone](https://learn.adafruit.com/adafruit-i2s-mems-microphone-breakout/raspberry-pi-wiring-test) +As we are using [cpal](https://crates.io/crates/cpal) crate to access microphone from alsa, libasound2-dev is necessary: + +``` +sudo apt install libasound2-dev +``` ## Documentation diff --git a/lightsabre_backend/Cargo.toml b/lightsabre_backend/Cargo.toml index 7fdbced..21f87f9 100644 --- a/lightsabre_backend/Cargo.toml +++ b/lightsabre_backend/Cargo.toml @@ -5,6 +5,7 @@ edition = "2024" [dependencies] artnet_protocol = "0.4.3" +cpal = "0.16.0" crossbeam = "0.8.4" ctrlc = { version = "3.4.7", features = ["termination"] } env_logger = "0.11.8" @@ -12,7 +13,6 @@ log = "0.4.27" nix = "0.30.1" rpi-mailbox = "0.3.0" rppal = "0.22.1" -# tokio = { version = "1.45.1", features = ["full"] } [features] default = ["rpizero2", "16channel"] diff --git a/lightsabre_backend/src/cputasks/modes.rs b/lightsabre_backend/src/cputasks/modes.rs index 26362d5..fc60f19 100644 --- a/lightsabre_backend/src/cputasks/modes.rs +++ b/lightsabre_backend/src/cputasks/modes.rs @@ -27,6 +27,12 @@ pub enum AppMode { Manual, } +impl Default for AppMode { + fn default() -> Self { + Self::Standalone + } +} + impl AppMode { pub fn for_each(mut f: F) { f(AppMode::Diagnostics); @@ -36,13 +42,25 @@ impl AppMode { } } -impl From for AppMode { - fn from(value: usize) -> Self { +impl From> for AppMode { + fn from(value: Option) -> Self { match value { - 1 => AppMode::ArtNet, - 2 => AppMode::Standalone, - 3 => AppMode::Manual, - _ => AppMode::Diagnostics, + Some(0) => AppMode::Diagnostics, + Some(1) => AppMode::ArtNet, + Some(2) => AppMode::Standalone, + Some(3) => AppMode::Manual, + _ => AppMode::default(), + } + } +} + +impl Into> for AppMode { + fn into(self) -> Box { + match self { + AppMode::Diagnostics => Box::new(diagnostics::DiagnosticsMode::new()), + AppMode::ArtNet => Box::new(artnet::ArtNetMode::new()), + AppMode::Standalone => Box::new(standalone::StandaloneMode::new()), + AppMode::Manual => Box::new(manual::ManualMode::new()), } } } @@ -56,23 +74,19 @@ pub struct ModeManager { impl ModeManager { pub fn new(mode_rx: Receiver) -> Self { let mut handlers: HashMap> = HashMap::new(); - handlers.insert(AppMode::Manual, Box::new(manual::ManualMode::new())); - handlers.insert( - AppMode::Standalone, - Box::new(standalone::StandaloneMode::new()), - ); - handlers.insert( - AppMode::Diagnostics, - Box::new(diagnostics::DiagnosticsMode::new()), - ); - handlers.insert(AppMode::ArtNet, Box::new(artnet::ArtNetMode::new())); + AppMode::for_each(|mode| { + handlers.insert(mode, mode.into()); + }); - let mode_manager = ModeManager { + let mut mode_manager = ModeManager { mode_handler_map: handlers, - mode: Arc::new(Mutex::new(AppMode::Diagnostics)), + mode: Arc::new(Mutex::new(AppMode::default())), mode_rx: mode_rx.clone(), }; + log::info!("Starting app with mode {:?}", AppMode::default()); + mode_manager.get_handler(None).enter(); + mode_manager } @@ -80,7 +94,7 @@ impl ModeManager { if let Ok(Message::ModeChanged { mode: next }) = self.mode_rx.try_recv() { let current = self.get_current_mode(); if current != next { - log::info!(" Changing mode from {:?} to {:?}", current, next); + log::info!("Switching mode from {:?} to {:?}", current, next); self.get_handler(Some(current)).exit(); self.get_handler(Some(next)).enter(); self.set_current_mode(next); diff --git a/lightsabre_backend/src/cputasks/modes/artnet.rs b/lightsabre_backend/src/cputasks/modes/artnet.rs index 7f83f79..dd72d6a 100644 --- a/lightsabre_backend/src/cputasks/modes/artnet.rs +++ b/lightsabre_backend/src/cputasks/modes/artnet.rs @@ -14,9 +14,6 @@ pub struct ArtNetMode { } impl ArtNetMode { - const _SHORT: &str = "LightSabre\0"; - const _SHORT_PAD: [u8; 18 - Self::_SHORT.len()] = [0; 7]; - pub fn new() -> Self { ArtNetMode::default() } diff --git a/lightsabre_backend/src/cputasks/modes/diagnostics.rs b/lightsabre_backend/src/cputasks/modes/diagnostics.rs index 490b5c3..ee61dd4 100644 --- a/lightsabre_backend/src/cputasks/modes/diagnostics.rs +++ b/lightsabre_backend/src/cputasks/modes/diagnostics.rs @@ -41,8 +41,8 @@ impl AppModeHandler for DiagnosticsMode { } fn run(&mut self, led_driver: &mut LedDriver) { - log::trace!("[Diagnostics] Running..."); if self.cycle_count % 50 == 0 { + log::trace!("[Diagnostics] Running..."); let (led, color) = match self.led_iterator.next() { Some(led) => { led_driver.set_color(**self.color_iterator.peek().unwrap(), led); diff --git a/lightsabre_backend/src/cputasks/modes/standalone.rs b/lightsabre_backend/src/cputasks/modes/standalone.rs index 26ece22..2fe3548 100644 --- a/lightsabre_backend/src/cputasks/modes/standalone.rs +++ b/lightsabre_backend/src/cputasks/modes/standalone.rs @@ -1,3 +1,4 @@ +use cpal::traits::{DeviceTrait, HostTrait}; use rppal::gpio::Gpio; use crate::cputasks::modes::AppModeHandler; @@ -29,6 +30,23 @@ impl StandaloneMode { impl AppModeHandler for StandaloneMode { fn enter(&mut self) { log::debug!("[Standalone] Entering Standalone Mode"); + let host = cpal::default_host(); + + // default_input_device() + host.devices() + .unwrap() + .for_each(|device| log::info!("{:?}", device.name())); + + if let Some(device) = host + .input_devices() + .unwrap() + .find(|device| device.name() == Ok(String::from("snd_rpi_googlevoicehat_soundcar"))) + { + log::info!("Found record device {:?}", device.name()); + log::info!("Default config : {:?}", device.default_input_config()) + } else { + log::error!("Record device not found"); + } } fn run(&mut self, _: &mut LedDriver) { diff --git a/lightsabre_backend/src/devices/selector.rs b/lightsabre_backend/src/devices/selector.rs index 37586dd..7a43a1e 100644 --- a/lightsabre_backend/src/devices/selector.rs +++ b/lightsabre_backend/src/devices/selector.rs @@ -39,10 +39,7 @@ impl Selector { .expect("Failed to set interrupt"); } - pub fn get_current_index(&self) -> usize { - self.selector_pins - .iter() - .position(|pin| pin.is_low()) - .unwrap_or(0) // Default to 0 if no pin is low + pub fn get_current_index(&self) -> Option { + self.selector_pins.iter().position(|pin| pin.is_low()) } } diff --git a/lightsabre_backend/src/iotasks/selector.rs b/lightsabre_backend/src/iotasks/selector.rs index 0830e77..6d0ce93 100644 --- a/lightsabre_backend/src/iotasks/selector.rs +++ b/lightsabre_backend/src/iotasks/selector.rs @@ -19,7 +19,7 @@ impl SelectorTask { AppMode::for_each(|mode| { log::debug!( "Setting up selector callback for mode: ({}){:?}", - mode as usize, + mode as isize, mode ); let tx = tx.clone();