rainbows!
This commit is contained in:
parent
5dbd46ea8e
commit
57fcccb8a6
50
src/main.rs
50
src/main.rs
@ -7,10 +7,15 @@ extern crate serde_json;
|
||||
|
||||
// std lib imports
|
||||
use std::{thread, time};
|
||||
use std::error::Error;
|
||||
|
||||
// actual third party library being imported
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Result;
|
||||
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;
|
||||
|
||||
// local files that need to be imported
|
||||
mod app;
|
||||
@ -18,10 +23,21 @@ mod config;
|
||||
mod generate;
|
||||
mod led;
|
||||
|
||||
const GPIO_PIN: u8 = 19;
|
||||
const NUM_LEDS: usize = 150;
|
||||
|
||||
fn main() {
|
||||
let spi = Spi::new(Bus::Spi0, SlaveSelect::Ss0, 3_000_000, Mode::Mode0).unwrap();
|
||||
let mut ws = Ws2812::new(spi);
|
||||
let delay = Delay::new();
|
||||
let configuration = config::init_config();
|
||||
println!("{:?}", configuration);
|
||||
|
||||
|
||||
// let gil = Python::acquire_gil();
|
||||
// let py = gil.python();
|
||||
// let m = PyModule::import(py, "led.py").unwrap();
|
||||
|
||||
loop {
|
||||
let app_text = configuration.get_tv_status();
|
||||
let power_text = configuration.get_power_status();
|
||||
@ -32,16 +48,15 @@ fn main() {
|
||||
match activeapp {
|
||||
app::ActiveApp::Roku => println!("The lights are light purple!"),
|
||||
app::ActiveApp::Netflix => {
|
||||
let mut panel = led::Led::new(256);
|
||||
let green = RGB8::new(255, 0, 0);
|
||||
let mut data = [RGB8::default(); NUM_LEDS];
|
||||
|
||||
let color: Vec<led::ColorRGB> = [0; 265].iter().map(|val| {
|
||||
match val {
|
||||
0 => led::ColorRGB(0x03, 0x00, 0x00),
|
||||
_ => panic!("Invalid color!"),
|
||||
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);
|
||||
}
|
||||
ws.write(brightness(data.iter().cloned(), 32)).unwrap();
|
||||
}
|
||||
}).collect();
|
||||
|
||||
panel.set_leds(&color);
|
||||
},
|
||||
app::ActiveApp::Hulu => println!("The lights are green!"),
|
||||
app::ActiveApp::AmazonPrime => println!("The light are light blue!"),
|
||||
@ -51,7 +66,7 @@ fn main() {
|
||||
|
||||
match tvpower {
|
||||
app::TVPower::On => println!("TV is on!"),
|
||||
app::TVPower::Off => println!("TV is off!"),
|
||||
app::TVPower::Off => println!("TV is off"),
|
||||
_ => println!("We don't know what the power status of the TV is..."),
|
||||
}
|
||||
|
||||
@ -59,3 +74,16 @@ fn main() {
|
||||
thread::sleep(sec);
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
Loading…
Reference in New Issue
Block a user