Compare commits

..
Author SHA1 Message Date
wymiller 2777da423e mod: loop optimization 2026-11-20 20:21:24 -05:00
wymiller 77d8f0375c update readme 2023-01-04 18:21:08 -06:00
wymiller 6202522acd updated readme and cleaned typos
Signed-off-by: Wyatt J. Miller <wyatt@wyattjmiller.com>
2022-06-14 09:21:22 -05:00
Wyatt J. Miller 66a7ec5127 Update rust.yml 2020-12-08 17:39:39 -05:00
Wyatt J. Miller 8a898b5cf8 Update rust.yml 2020-12-08 17:27:49 -05:00
10 changed files with 236 additions and 197 deletions

No files matched your search

+1
View File
@@ -0,0 +1 @@
use flake
+9
View File
@@ -15,6 +15,15 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name : Install ARM compiler
run: sudo apt-get install gcc-arm-linux-gnueabihf -y
- name: Set ARM compiler as environment variable
run: export CC=arm-linux-gnueabihf-gcc
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: armv7-unknown-linux-gnueabihf
override: true
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Build - name: Build
run: cargo build --verbose run: cargo build --verbose
+2 -5
View File
@@ -2,7 +2,7 @@
authors = ["Wyatt J. Miller <wjmiller2016@gmail.com>"] authors = ["Wyatt J. Miller <wjmiller2016@gmail.com>"]
edition = "2018" edition = "2018"
name = "bleak" name = "bleak"
version = "0.3.1" version = "0.3.0"
[dependencies] [dependencies]
chrono = "0.4.11" chrono = "0.4.11"
@@ -15,15 +15,12 @@ serde_json = "1.0.53"
smart-leds = "0.3.0" smart-leds = "0.3.0"
ws2812-spi = "0.3.0" ws2812-spi = "0.3.0"
[dependencies.async-std]
version = "1.8.0"
[dependencies.rppal] [dependencies.rppal]
features = ["hal"] features = ["hal"]
version = "0.11.3" version = "0.11.3"
[dependencies.reqwest] [dependencies.reqwest]
version = "0.10.9" version = "0.9.24"
[dependencies.openssl] [dependencies.openssl]
features = ["vendored"] features = ["vendored"]
+10 -11
View File
@@ -1,7 +1,5 @@
![Bleak logo](docs/img/bleak_logo.png) ![Bleak logo](docs/img/bleak_logo.png)
[![Build Status](https://cicd.wyattjmiller.com/api/badges/wyatt/bleak/status.svg)](https://cicd.wyattjmiller.com/wyatt/bleak)
Change the aura of the room with your smart TV! Change the aura of the room with your smart TV!
This project is licensed by the [Mozilla Public License v2](https://www.mozilla.org/en-US/MPL/2.0/). A copy of this license is in the project's root directory for your convenience. This project is licensed by the [Mozilla Public License v2](https://www.mozilla.org/en-US/MPL/2.0/). A copy of this license is in the project's root directory for your convenience.
@@ -10,21 +8,18 @@ The logo is licensed by the [CC BY-NC-ND 4.0](https://creativecommons.org/licens
## What is this?? ## What is this??
This came from an idea in high school where one could change a channel and some LEDs could change color. This project is just that, only with Smart TV's (Roku TV's and Roku devices supported). One changes the application to Netflix, the LEDs turn red. Another changes the application to Hulu, the LEDs turn green. This came from an idea in high school where one could change a channel and some LEDs could change color based on the channel selected. This project is just that, only with smart TV's (see the [supported devices](#smart-tv-support) for a list of supported devices). One changes the application to Netflix, the LEDs turn red. Another changes the application to Hulu, the LEDs turn green.
## How does it work? ## How does it work?
`bleak` sends out a API request to your Roku TV/Roku device you specify in a JSON file, which is read by `bleak`, and based on that response, the LEDs will change color. These requests happen at one second intervals. `bleak` sends out a network request to your smart TV's IP address that you specify in a JSON file, which is read by `bleak`, and based on that response, the LEDs will change color. These requests happen at one second intervals.
TL;DR
Read the source code.
## Pre-requisites ## Pre-requisites
* A Raspberry Pi (tested with a Raspberry Pi 4) * A Raspberry Pi (tested with a Raspberry Pi 4)
* A WS2818 LED light strip (you can order this from [Amazon](https://www.amazon.com/s?k=ws2818+led+strip)) * A WS2818 LED light strip (you can order this from [Amazon](https://www.amazon.com/s?k=ws2818+led+strip))
* Rust 1.40+ (this is the version of Rust `bleak` was written in) However, any version of Rust 2018 will most likely be fine * Rust 1.40+ (this is the version of Rust `bleak` was written in) However, any version of Rust 2018 will most likely be fine
* [Supported](#smart-tv-support) smart TV
## Installation ## Installation
@@ -106,7 +101,7 @@ or you can:
to run this program as one is hacking away. to run this program as one is hacking away.
I wrote a systmed service file so starting and stopping would be like I'm starting and stopping any service on a Linux machine. I also didn't like `bleak` taking control of my terminal session :) I wrote a systemd service file so starting and stopping would be like I'm starting and stopping any service on a Linux machine. I also didn't like `bleak` taking control of my terminal session :)
## Troubleshooting ## Troubleshooting
@@ -119,13 +114,17 @@ If you find any other issues with `bleak`, please send them my way in the form o
## Smart TV support ## Smart TV support
In development: Supported:
* Roku devices and Roku TV's * Roku devices and Roku TV's
In development:
* Apple TV 4K/HD
Future possibilities: Future possibilities:
* Samsung SmartThings TV * Samsung TV (probably utilizing SmartThings API)
* Android TV * Android TV
* Amazon's Fire TV * Amazon's Fire TV
Generated
+61
View File
@@ -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
}
+71
View File
@@ -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";
};
};
});
};
}
+62 -22
View File
@@ -1,17 +1,36 @@
// enum used when a certain TV app is being used // enum used when a certain TV app is being used
#[warn(dead_code)] #[warn(dead_code)]
pub enum ActiveApp { pub enum ActiveApp {
Roku, Roku(ActiveAppData),
Netflix, Netflix(ActiveAppData),
Hulu, Hulu(ActiveAppData),
AmazonPrime, AmazonPrime(ActiveAppData),
Plex, Plex(ActiveAppData),
Pandora, Pandora(ActiveAppData),
Spotify, Spotify(ActiveAppData),
Crunchyroll, Crunchyroll(ActiveAppData),
Funimation, Nothing,
VRV, }
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 // 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(); let mut result = text.split_whitespace();
match result.next() { match result.next() {
Some("Roku") => ActiveApp::Roku, Some("Roku") => ActiveApp::Roku(ActiveAppData {
Some("Netflix") => ActiveApp::Netflix, app_name: String::from("Roku"),
Some("Hulu") => ActiveApp::Hulu, rgb: [255, 0, 255],
Some("Prime") => ActiveApp::AmazonPrime, }),
Some("Plex") => ActiveApp::Plex, Some("Netflix") => ActiveApp::Netflix(ActiveAppData {
Some("Pandora") => ActiveApp::Pandora, app_name: String::from("Netflix"),
Some("Spotify") => ActiveApp::Spotify, rgb: [255, 77, 77],
Some("Plex") => ActiveApp::Plex, }),
Some("Crunchyroll") => ActiveApp::Crunchyroll, Some("Hulu") => ActiveApp::Hulu(ActiveAppData {
Some("Funimation") => ActiveApp::Funimation, app_name: String::from("Hulu"),
Some("VRV") => ActiveApp::VRV, 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, _ => ActiveApp::Nothing,
} }
} }
+2 -3
View File
@@ -1,4 +1,3 @@
use async_std::{prelude::*, task};
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::Read;
use std::path::Path; use std::path::Path;
@@ -39,7 +38,7 @@ impl Configuration {
port = self.port port = self.port
); );
let response = task::block_on(request::get_request(&request)); let response = request::get_request(&request);
match response { match response {
Ok(res) => { Ok(res) => {
@@ -62,7 +61,7 @@ impl Configuration {
port = self.port port = self.port
); );
let response = task::block_on(request::get_request(&request)); let response = request::get_request(&request);
match response { match response {
Ok(res) => { Ok(res) => {
let document = Document::from_read(res) let document = Document::from_read(res)
+16 -152
View File
@@ -3,15 +3,15 @@ use std::{thread, time};
// actual third party library being imported // actual third party library being imported
use rppal::spi::{Bus, Mode, SlaveSelect, Spi}; use rppal::spi::{Bus, Mode, SlaveSelect, Spi};
use smart_leds::{RGB8, SmartLedsWrite, brightness}; use smart_leds::{brightness, SmartLedsWrite, RGB8};
use ws2812_spi::Ws2812; use ws2812_spi::Ws2812;
// local files that need to be imported // local files that need to be imported
mod app; mod app;
mod config; mod config;
mod generate; mod generate;
mod request;
mod queue; mod queue;
mod request;
const NUM_LEDS: usize = 150; const NUM_LEDS: usize = 150;
@@ -44,10 +44,11 @@ fn main() {
} }
queue.enqueue(data[i]); 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 => { app::TVPower::On => {
if false == configuration.is_change_app() { if false == configuration.is_change_app() {
is_headless = false; is_headless = false;
@@ -56,161 +57,24 @@ fn main() {
configuration.change_active_app(&app_text); configuration.change_active_app(&app_text);
let activeapp = app::match_to_app(app_text); let activeapp = app::match_to_app(app_text);
match activeapp { if let Some(data) = activeapp.data() {
app::ActiveApp::Roku => { let [red, green, blue] = data.rgb;
let color = RGB8::new(255, 0, 255); let color = RGB8::new(red, green, blue);
let mut data = [RGB8::default(); NUM_LEDS];
for i in 0..NUM_LEDS { for _ in 0..NUM_LEDS {
data[i] = color; if queue.length() == NUM_LEDS {
if (queue.length() == NUM_LEDS) {
queue.dequeue(); queue.dequeue();
} }
queue.enqueue(data[i]); queue.enqueue(color);
ws.write(brightness(queue.queue.iter().cloned(), 32)).unwrap(); ws.write(brightness(queue.queue.iter().cloned(), 32))
.unwrap();
}
} else {
println!("We don't know what app is running right now...");
} }
},
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();
}
},
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..."),
} }
} }
},
} }
let sec = time::Duration::from_secs(1); let sec = time::Duration::from_secs(1);
+2 -4
View File
@@ -1,6 +1,4 @@
use async_std::{prelude::*, io}; pub fn get_request(request: &String) -> Result<reqwest::Response, reqwest::Error> {
let response = reqwest::get(request);
pub async fn get_request(request: &String) -> io::Result<reqwest::Response, reqwest::Error> {
let response = reqwest::get(request).await?;
response response
} }