2019-12-28 21:43:13 -06:00
|
|
|
// external crates getting imported
|
2019-12-29 19:58:49 -06:00
|
|
|
extern crate reqwest;
|
|
|
|
extern crate select;
|
2019-12-28 21:43:13 -06:00
|
|
|
extern crate serde;
|
|
|
|
extern crate serde_derive;
|
|
|
|
extern crate serde_json;
|
2019-12-30 17:59:00 -06:00
|
|
|
|
|
|
|
// std lib imports
|
|
|
|
use std::{thread, time};
|
2020-01-23 08:09:16 -06:00
|
|
|
use std::error::Error;
|
2019-12-28 21:43:13 -06:00
|
|
|
|
|
|
|
// actual third party library being imported
|
2020-01-23 08:09:16 -06:00
|
|
|
use rppal::spi::{Bus, Mode, SlaveSelect, Spi};
|
|
|
|
use rppal::gpio::Gpio;
|
|
|
|
use rppal::hal::{Delay, Timer};
|
|
|
|
use smart_leds::{RGB8, SmartLedsWrite, brightness};
|
|
|
|
use ws2812_spi::Ws2812;
|
|
|
|
use embedded_hal;
|
2019-12-28 21:43:13 -06:00
|
|
|
|
|
|
|
// local files that need to be imported
|
|
|
|
mod app;
|
|
|
|
mod config;
|
|
|
|
mod generate;
|
2020-01-04 14:16:54 -06:00
|
|
|
mod led;
|
2019-12-28 21:43:13 -06:00
|
|
|
|
2020-01-23 08:09:16 -06:00
|
|
|
const GPIO_PIN: u8 = 19;
|
|
|
|
const NUM_LEDS: usize = 150;
|
|
|
|
|
2019-12-26 21:32:42 -06:00
|
|
|
fn main() {
|
2020-01-23 08:09:16 -06:00
|
|
|
let spi = Spi::new(Bus::Spi0, SlaveSelect::Ss0, 3_000_000, Mode::Mode0).unwrap();
|
|
|
|
let mut ws = Ws2812::new(spi);
|
|
|
|
let delay = Delay::new();
|
2019-12-28 21:43:13 -06:00
|
|
|
let configuration = config::init_config();
|
2019-12-29 19:58:49 -06:00
|
|
|
println!("{:?}", configuration);
|
|
|
|
|
2020-01-23 08:09:16 -06:00
|
|
|
|
|
|
|
// let gil = Python::acquire_gil();
|
|
|
|
// let py = gil.python();
|
|
|
|
// let m = PyModule::import(py, "led.py").unwrap();
|
|
|
|
|
2019-12-29 19:58:49 -06:00
|
|
|
loop {
|
2020-01-03 22:15:13 -06:00
|
|
|
let app_text = configuration.get_tv_status();
|
|
|
|
let power_text = configuration.get_power_status();
|
2019-12-29 19:58:49 -06:00
|
|
|
|
2020-01-03 22:15:13 -06:00
|
|
|
let activeapp = app::match_to_app(app_text);
|
|
|
|
let tvpower = app::match_to_power_status(power_text);
|
2019-12-29 19:58:49 -06:00
|
|
|
|
|
|
|
match activeapp {
|
|
|
|
app::ActiveApp::Roku => println!("The lights are light purple!"),
|
2020-01-21 16:25:29 -06:00
|
|
|
app::ActiveApp::Netflix => {
|
2020-01-23 08:09:16 -06:00
|
|
|
let green = RGB8::new(255, 0, 0);
|
|
|
|
let mut data = [RGB8::default(); NUM_LEDS];
|
2020-01-21 16:25:29 -06:00
|
|
|
|
2020-01-23 08:09:16 -06:00
|
|
|
for j in 0..(256 * 5) {
|
|
|
|
for i in 0..NUM_LEDS {
|
|
|
|
data[i] = wheel((((i * 256) as u16 / NUM_LEDS as u16 + j as u16) & 255) as u8);
|
2020-01-21 16:25:29 -06:00
|
|
|
}
|
2020-01-23 08:09:16 -06:00
|
|
|
ws.write(brightness(data.iter().cloned(), 32)).unwrap();
|
|
|
|
}
|
2020-01-21 16:25:29 -06:00
|
|
|
},
|
2019-12-29 19:58:49 -06:00
|
|
|
app::ActiveApp::Hulu => println!("The lights are green!"),
|
|
|
|
app::ActiveApp::AmazonPrime => println!("The light are light blue!"),
|
|
|
|
app::ActiveApp::Spotify => println!("The lights are light green!"),
|
|
|
|
_ => println!("Oops!"),
|
|
|
|
}
|
|
|
|
|
2020-01-03 22:15:13 -06:00
|
|
|
match tvpower {
|
|
|
|
app::TVPower::On => println!("TV is on!"),
|
2020-01-23 08:09:16 -06:00
|
|
|
app::TVPower::Off => println!("TV is off"),
|
2020-01-03 22:15:13 -06:00
|
|
|
_ => println!("We don't know what the power status of the TV is..."),
|
|
|
|
}
|
|
|
|
|
|
|
|
let sec = time::Duration::from_secs(3);
|
2019-12-30 17:59:00 -06:00
|
|
|
thread::sleep(sec);
|
2019-12-29 19:58:49 -06:00
|
|
|
}
|
2019-12-26 21:32:42 -06:00
|
|
|
}
|
2020-01-23 08:09:16 -06:00
|
|
|
|
|
|
|
fn wheel(mut wheel_pos: u8) -> RGB8 {
|
|
|
|
wheel_pos = 255 - wheel_pos;
|
|
|
|
if wheel_pos < 85 {
|
|
|
|
return (255 - wheel_pos * 3, 0, wheel_pos * 3).into();
|
|
|
|
}
|
|
|
|
if wheel_pos < 170 {
|
|
|
|
wheel_pos -= 85;
|
|
|
|
return (0, wheel_pos * 3, 255 - wheel_pos * 3).into();
|
|
|
|
}
|
|
|
|
wheel_pos -= 170;
|
|
|
|
(wheel_pos * 3, 255 - wheel_pos * 3, 0).into()
|
|
|
|
}
|