diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..981815e --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-schemas": { + "locked": { + "lastModified": 1780327564, + "narHash": "sha256-HiRPtA0spK+Dkgbhz/1zW9glXxNVB+L4Rj2VYmdawb8=", + "rev": "6cc9bd98891b1fc6bb2b8cb3277df8bc72799ca6", + "revCount": 149, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/DeterminateSystems/flake-schemas/0.5.0/019e83cf-9af3-78b1-ac5b-70e68ad1efe1/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/DeterminateSystems/flake-schemas/%2A.tar.gz" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1794872590, + "narHash": "sha256-E+XLAfnC7+bdr4qlEgRv6cdGmiqTU5oeFNKCha7epqQ=", + "rev": "f68407657ad294471eb4b2e65d193df26edf729f", + "revCount": 1018921, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2605.1018921%2Brev-f68407657ad294471eb4b2e65d193df26edf729f/01a1ea95-6db4-7d02-8a1d-753f3849fe0e/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/NixOS/nixpkgs/%2A.tar.gz" + } + }, + "root": { + "inputs": { + "flake-schemas": "flake-schemas", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1795082704, + "narHash": "sha256-YK+6Nl8oR2Fhh3YO3DhBNCN7TmIGWw3tLhk25kfiWw4=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "85d4adbbd952fcaf89fed3cb4ba540a4770d6e64", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..9bfaca3 --- /dev/null +++ b/flake.nix @@ -0,0 +1,71 @@ +{ + description = "bleak"; + + # Flake inputs + inputs = { + flake-schemas.url = "https://flakehub.com/f/DeterminateSystems/flake-schemas/*.tar.gz"; + nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/*.tar.gz"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + # Flake outputs that other flakes can use + outputs = { + self, + flake-schemas, + nixpkgs, + rust-overlay, + }: let + # Nixpkgs overlays + overlays = [ + rust-overlay.overlays.default + (final: prev: { + rustToolchain = final.rust-bin.stable.latest.default.override {extensions = ["rust-src"];}; + }) + ]; + + # Helpers for producing system-specific outputs + supportedSystems = ["x86_64-linux" "aarch64-darwin" "x86_64-darwin" "aarch64-linux"]; + forEachSupportedSystem = f: + nixpkgs.lib.genAttrs supportedSystems (system: + f { + pkgs = import nixpkgs {inherit overlays system;}; + }); + in { + # Schemas tell Nix about the structure of your flake's outputs + schemas = flake-schemas.schemas; + + # Development environments + devShells = forEachSupportedSystem ({pkgs}: { + default = pkgs.mkShell { + # Pinned packages available in the environment + packages = with pkgs; [ + rustToolchain + rust-analyzer + curl + git + jq + wget + nixpkgs-fmt + openssl + openssl.dev + patchelf + cargo-watch + cargo-chef + pkg-config-unwrapped + ]; + + # Environment variables + env = { + RUST_BACKTRACE = "1"; + RUST_SRC_PATH = "${pkgs.rustToolchain}/lib/rustlib/src/rust/library"; + PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; + # ZELLIJ_CONFIG_FILE = "config.kdl"; + # PATH = "$PATH:$HOME/.local/share/nvim/mason/bin/deno"; + }; + }; + }); + }; +} diff --git a/src/app.rs b/src/app.rs index 8c70cdd..0fa4c1b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,17 +1,36 @@ // enum used when a certain TV app is being used #[warn(dead_code)] pub enum ActiveApp { - Roku, - Netflix, - Hulu, - AmazonPrime, - Plex, - Pandora, - Spotify, - Crunchyroll, - Funimation, - VRV, - Nothing + Roku(ActiveAppData), + Netflix(ActiveAppData), + Hulu(ActiveAppData), + AmazonPrime(ActiveAppData), + Plex(ActiveAppData), + Pandora(ActiveAppData), + Spotify(ActiveAppData), + Crunchyroll(ActiveAppData), + Nothing, +} + +pub struct ActiveAppData { + pub app_name: String, + pub rgb: [u8; 3], +} + +impl ActiveApp { + pub fn data(&self) -> Option<&ActiveAppData> { + match self { + ActiveApp::Roku(data) + | ActiveApp::Netflix(data) + | ActiveApp::Hulu(data) + | ActiveApp::AmazonPrime(data) + | ActiveApp::Plex(data) + | ActiveApp::Pandora(data) + | ActiveApp::Spotify(data) + | ActiveApp::Crunchyroll(data) => Some(data), + ActiveApp::Nothing => None, + } + } } // enum used to select what kind of TV you are using @@ -33,17 +52,38 @@ pub fn match_to_app(text: String) -> ActiveApp { let mut result = text.split_whitespace(); match result.next() { - Some("Roku") => ActiveApp::Roku, - Some("Netflix") => ActiveApp::Netflix, - Some("Hulu") => ActiveApp::Hulu, - Some("Prime") => ActiveApp::AmazonPrime, - Some("Plex") => ActiveApp::Plex, - Some("Pandora") => ActiveApp::Pandora, - Some("Spotify") => ActiveApp::Spotify, - Some("Plex") => ActiveApp::Plex, - Some("Crunchyroll") => ActiveApp::Crunchyroll, - Some("Funimation") => ActiveApp::Funimation, - Some("VRV") => ActiveApp::VRV, + Some("Roku") => ActiveApp::Roku(ActiveAppData { + app_name: String::from("Roku"), + rgb: [255, 0, 255], + }), + Some("Netflix") => ActiveApp::Netflix(ActiveAppData { + app_name: String::from("Netflix"), + rgb: [255, 77, 77], + }), + Some("Hulu") => ActiveApp::Hulu(ActiveAppData { + app_name: String::from("Hulu"), + rgb: [51, 255, 85], + }), + Some("Prime") => ActiveApp::AmazonPrime(ActiveAppData { + app_name: String::from("Prime"), + rgb: [99, 193, 255], + }), + Some("Plex") => ActiveApp::Plex(ActiveAppData { + app_name: String::from("Plex"), + rgb: [255, 187, 51], + }), + Some("Pandora") => ActiveApp::Pandora(ActiveAppData { + app_name: String::from("Pandora"), + rgb: [99, 193, 255], + }), + Some("Spotify") => ActiveApp::Spotify(ActiveAppData { + app_name: String::from("Spotify"), + rgb: [51, 255, 85], + }), + Some("Crunchyroll") => ActiveApp::Crunchyroll(ActiveAppData { + app_name: String::from("Crunchyroll"), + rgb: [255, 187, 51], + }), _ => ActiveApp::Nothing, } } @@ -53,4 +93,4 @@ pub fn match_to_power_status(text: String) -> TVPower { "PowerOn" => TVPower::On, _ => TVPower::Off, } -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index 60b1cb0..d98dea4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,15 +3,15 @@ use std::{thread, time}; // actual third party library being imported use rppal::spi::{Bus, Mode, SlaveSelect, Spi}; -use smart_leds::{RGB8, SmartLedsWrite, brightness}; +use smart_leds::{brightness, SmartLedsWrite, RGB8}; use ws2812_spi::Ws2812; // local files that need to be imported mod app; mod config; mod generate; -mod request; mod queue; +mod request; const NUM_LEDS: usize = 150; @@ -44,10 +44,11 @@ fn main() { } queue.enqueue(data[i]); - ws.write(brightness(queue.queue.iter().cloned(), 32)).unwrap(); + ws.write(brightness(queue.queue.iter().cloned(), 32)) + .unwrap(); } } - }, + } app::TVPower::On => { if false == configuration.is_change_app() { is_headless = false; @@ -56,164 +57,27 @@ fn main() { configuration.change_active_app(&app_text); let activeapp = app::match_to_app(app_text); - match activeapp { - app::ActiveApp::Roku => { - let color = RGB8::new(255, 0, 255); - let mut data = [RGB8::default(); NUM_LEDS]; + if let Some(data) = activeapp.data() { + let [red, green, blue] = data.rgb; + let color = RGB8::new(red, green, blue); - for i in 0..NUM_LEDS { - data[i] = color; - - if (queue.length() == NUM_LEDS) { - queue.dequeue(); - } - - queue.enqueue(data[i]); - ws.write(brightness(queue.queue.iter().cloned(), 32)).unwrap(); - } - }, - app::ActiveApp::Hulu => { - let color = RGB8::new(51, 255, 85); - let mut data = [RGB8::default(); NUM_LEDS]; - - for i in 0..NUM_LEDS { - data[i] = color; - - if (queue.length() == NUM_LEDS) { - queue.dequeue(); - } - - queue.enqueue(data[i]); - ws.write(brightness(queue.queue.iter().cloned(), 32)).unwrap(); + for _ in 0..NUM_LEDS { + if queue.length() == NUM_LEDS { + queue.dequeue(); } - }, - app::ActiveApp::Netflix => { - let color = RGB8::new(255, 77, 77); - let mut data = [RGB8::default(); NUM_LEDS]; - for i in 0..NUM_LEDS { - data[i] = color; - - if (queue.length() == NUM_LEDS) { - queue.dequeue(); - } - - queue.enqueue(data[i]); - ws.write(brightness(queue.queue.iter().cloned(), 32)).unwrap(); - } - }, - app::ActiveApp::AmazonPrime => { - let color = RGB8::new(99, 193, 255); - let mut data = [RGB8::default(); NUM_LEDS]; - - for i in 0..NUM_LEDS { - data[i] = color; - - if (queue.length() == NUM_LEDS) { - queue.dequeue(); - } - - queue.enqueue(data[i]); - ws.write(brightness(queue.queue.iter().cloned(), 32)).unwrap(); - } - }, - app::ActiveApp::Pandora => { - let color = RGB8::new(99, 123, 255); - let mut data = [RGB8::default(); NUM_LEDS]; - - for i in 0..NUM_LEDS { - data[i] = color; - - if (queue.length() == NUM_LEDS) { - queue.dequeue(); - } - - queue.enqueue(data[i]); - ws.write(brightness(queue.queue.iter().cloned(), 32)).unwrap(); - } - }, - app::ActiveApp::Spotify => { - let color = RGB8::new(51, 255, 85); - let mut data = [RGB8::default(); NUM_LEDS]; - - for i in 0..NUM_LEDS { - data[i] = color; - - if (queue.length() == NUM_LEDS) { - queue.dequeue(); - } - - queue.enqueue(data[i]); - ws.write(brightness(queue.queue.iter().cloned(), 32)).unwrap(); - } - }, - app::ActiveApp::Plex => { - let color = RGB8::new(255, 187, 51); - let mut data = [RGB8::default(); NUM_LEDS]; - - for i in 0..NUM_LEDS { - data[i] = color; - - if (queue.length() == NUM_LEDS) { - queue.dequeue(); - } - - queue.enqueue(data[i]); - ws.write(brightness(queue.queue.iter().cloned(), 32)).unwrap(); - } - }, - app::ActiveApp::Crunchyroll => { - let color = RGB8::new(255, 187, 51); - let mut data = [RGB8::default(); NUM_LEDS]; - - for i in 0..NUM_LEDS { - data[i] = color; - - if (queue.length() == NUM_LEDS) { - queue.dequeue(); - } - - queue.enqueue(data[i]); - ws.write(brightness(queue.queue.iter().cloned(), 32)).unwrap(); - } - }, - app::ActiveApp::Funimation => { - let color = RGB8::new(255, 0, 255); - let mut data = [RGB8::default(); NUM_LEDS]; - - for i in 0..NUM_LEDS { - data[i] = color; - - if (queue.length() == NUM_LEDS) { - queue.dequeue(); - } - - queue.enqueue(data[i]); - ws.write(brightness(queue.queue.iter().cloned(), 32)).unwrap(); - } - }, - app::ActiveApp::VRV => { - let color = RGB8::new(255, 187, 51); - let mut data = [RGB8::default(); NUM_LEDS]; - - for i in 0..NUM_LEDS { - data[i] = color; - - if (queue.length() == NUM_LEDS) { - queue.dequeue(); - } - - queue.enqueue(data[i]); - ws.write(brightness(queue.queue.iter().cloned(), 32)).unwrap(); - } - }, - _ => println!("We don't know what app is running right now..."), + queue.enqueue(color); + ws.write(brightness(queue.queue.iter().cloned(), 32)) + .unwrap(); + } + } else { + println!("We don't know what app is running right now..."); } } - }, + } } let sec = time::Duration::from_secs(1); thread::sleep(sec); - } + } }