2019-12-30 18:59:00 -05:00
|
|
|
// std lib imports
|
|
|
|
use std::{thread, time};
|
2019-12-28 22:43:13 -05:00
|
|
|
|
|
|
|
// actual third party library being imported
|
2020-01-23 14:09:16 +00:00
|
|
|
use rppal::spi::{Bus, Mode, SlaveSelect, Spi};
|
2020-04-01 04:45:37 +01:00
|
|
|
use smart_leds::{RGB8, SmartLedsWrite, brightness};
|
2020-01-23 14:09:16 +00:00
|
|
|
use ws2812_spi::Ws2812;
|
2019-12-28 22:43:13 -05:00
|
|
|
|
|
|
|
// local files that need to be imported
|
|
|
|
mod app;
|
|
|
|
mod config;
|
|
|
|
mod generate;
|
2020-05-24 18:49:31 +01:00
|
|
|
mod request;
|
2020-11-22 22:59:43 -05:00
|
|
|
mod queue;
|
2019-12-28 22:43:13 -05:00
|
|
|
|
2020-01-23 14:09:16 +00:00
|
|
|
const NUM_LEDS: usize = 150;
|
|
|
|
|
2019-12-26 22:32:42 -05:00
|
|
|
fn main() {
|
2020-11-23 16:25:03 +00:00
|
|
|
let mut queue: queue::Queue<RGB8> = queue::Queue::new();
|
2020-11-22 23:45:50 -05:00
|
|
|
let spi = Spi::new(Bus::Spi0, SlaveSelect::Ss0, 3_000_000, Mode::Mode0).unwrap();
|
2020-01-23 14:09:16 +00:00
|
|
|
let mut ws = Ws2812::new(spi);
|
2020-01-24 22:08:10 +00:00
|
|
|
let mut configuration = config::init_config();
|
2020-04-03 23:39:59 +01:00
|
|
|
let mut is_headless: bool = false;
|
2019-12-29 20:58:49 -05:00
|
|
|
|
2020-01-24 22:08:10 +00:00
|
|
|
loop {
|
|
|
|
println!("{:?}", configuration);
|
2020-01-23 14:09:16 +00:00
|
|
|
|
2020-04-01 04:28:35 +01:00
|
|
|
let power_text = configuration.get_power_status();
|
|
|
|
configuration.change_power(&power_text);
|
|
|
|
let tvpower = app::match_to_power_status(power_text);
|
2020-01-23 14:09:16 +00:00
|
|
|
|
2020-04-01 04:28:35 +01:00
|
|
|
match tvpower {
|
|
|
|
app::TVPower::Off => {
|
2020-04-03 23:39:59 +01:00
|
|
|
if is_headless == false {
|
|
|
|
is_headless = true;
|
2020-01-24 22:08:10 +00:00
|
|
|
let color = RGB8::new(0, 0, 0);
|
|
|
|
let mut data = [RGB8::default(); NUM_LEDS];
|
|
|
|
|
|
|
|
for i in 0..NUM_LEDS {
|
|
|
|
data[i] = color;
|
2020-11-23 16:25:03 +00:00
|
|
|
|
|
|
|
if (queue.length() == NUM_LEDS) {
|
|
|
|
queue.dequeue();
|
|
|
|
}
|
|
|
|
|
|
|
|
queue.enqueue(data[i]);
|
|
|
|
ws.write(brightness(queue.queue.iter().cloned(), 32)).unwrap();
|
2020-01-24 22:08:10 +00:00
|
|
|
}
|
2020-04-01 04:28:35 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
app::TVPower::On => {
|
|
|
|
if false == configuration.is_change_app() {
|
2020-04-03 23:39:59 +01:00
|
|
|
is_headless = false;
|
2020-04-01 04:28:35 +01:00
|
|
|
|
|
|
|
let app_text = configuration.get_app_status();
|
|
|
|
configuration.change_active_app(&app_text);
|
|
|
|
let activeapp = app::match_to_app(app_text);
|
|
|
|
|
|
|
|
match activeapp {
|
|
|
|
app::ActiveApp::Roku => {
|
2020-11-23 16:25:03 +00:00
|
|
|
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();
|
|
|
|
}
|
2020-04-01 04:28:35 +01:00
|
|
|
},
|
|
|
|
app::ActiveApp::Hulu => {
|
2020-11-23 16:25:03 +00:00
|
|
|
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();
|
|
|
|
}
|
2020-04-01 04:28:35 +01:00
|
|
|
},
|
|
|
|
app::ActiveApp::Netflix => {
|
2020-11-23 16:25:03 +00:00
|
|
|
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();
|
|
|
|
}
|
2020-04-01 04:28:35 +01:00
|
|
|
},
|
2020-05-23 21:25:11 +01:00
|
|
|
app::ActiveApp::AmazonPrime => {
|
2020-11-23 16:25:03 +00:00
|
|
|
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();
|
|
|
|
}
|
2020-05-23 21:25:11 +01:00
|
|
|
},
|
|
|
|
app::ActiveApp::Pandora => {
|
2020-11-23 16:25:03 +00:00
|
|
|
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();
|
|
|
|
}
|
2020-05-23 21:25:11 +01:00
|
|
|
},
|
2020-04-01 04:28:35 +01:00
|
|
|
app::ActiveApp::Spotify => {
|
2020-11-23 16:25:03 +00:00
|
|
|
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();
|
|
|
|
}
|
2020-04-01 04:28:35 +01:00
|
|
|
},
|
|
|
|
app::ActiveApp::Plex => {
|
2020-11-23 16:25:03 +00:00
|
|
|
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();
|
|
|
|
}
|
2020-05-23 21:25:11 +01:00
|
|
|
},
|
|
|
|
app::ActiveApp::Crunchyroll => {
|
2020-11-23 16:25:03 +00:00
|
|
|
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();
|
|
|
|
}
|
2020-05-23 21:25:11 +01:00
|
|
|
},
|
|
|
|
app::ActiveApp::Funimation => {
|
2020-11-23 16:25:03 +00:00
|
|
|
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();
|
|
|
|
}
|
2020-05-23 21:25:11 +01:00
|
|
|
},
|
|
|
|
app::ActiveApp::VRV => {
|
2020-11-23 16:25:03 +00:00
|
|
|
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();
|
|
|
|
}
|
2020-04-01 04:28:35 +01:00
|
|
|
},
|
2020-04-04 03:34:52 +01:00
|
|
|
_ => println!("We don't know what app is running right now..."),
|
2020-04-01 04:28:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2020-01-03 23:15:13 -05:00
|
|
|
}
|
|
|
|
|
2020-04-01 04:28:35 +01:00
|
|
|
let sec = time::Duration::from_secs(1);
|
2019-12-30 18:59:00 -05:00
|
|
|
thread::sleep(sec);
|
2020-04-01 04:28:35 +01:00
|
|
|
}
|
2020-04-03 23:39:59 +01:00
|
|
|
}
|