added abstraction that changes color for lights

This commit is contained in:
Wyatt J. Miller 2020-04-05 05:43:21 +01:00
parent c32454792f
commit aee9c527ab

View File

@ -58,49 +58,24 @@ fn main() {
match activeapp { match activeapp {
app::ActiveApp::Roku => { app::ActiveApp::Roku => {
let color = RGB8::new(255, 0, 255); let data = change_color(&255, &0, &255);
let mut data = [RGB8::default(); NUM_LEDS];
for i in 0..NUM_LEDS {
data[i] = color;
}
ws.write(brightness(data.iter().cloned(), 10)).unwrap(); ws.write(brightness(data.iter().cloned(), 10)).unwrap();
}, },
app::ActiveApp::Hulu => { app::ActiveApp::Hulu => {
let green = RGB8::new(51, 255, 85); let data = change_color(&51, &255, &85);
let mut data = [RGB8::default(); NUM_LEDS];
for i in 0..NUM_LEDS {
data[i] = green;
}
ws.write(brightness(data.iter().cloned(), 32)).unwrap(); ws.write(brightness(data.iter().cloned(), 32)).unwrap();
}, },
app::ActiveApp::Netflix => { app::ActiveApp::Netflix => {
let red = RGB8::new(255, 77, 77); let data = change_color(&255, &77, &77);
let mut data = [RGB8::default(); NUM_LEDS];
for i in 0..NUM_LEDS {
data[i] = red;
}
ws.write(brightness(data.iter().cloned(), 32)).unwrap(); ws.write(brightness(data.iter().cloned(), 32)).unwrap();
}, },
app::ActiveApp::AmazonPrime => println!("The light are light blue!"), app::ActiveApp::AmazonPrime => println!("The light are light blue!"),
app::ActiveApp::Spotify => { app::ActiveApp::Spotify => {
let green = RGB8::new(51, 255, 85); let data = change_color(&51, &255, &85);
let mut data = [RGB8::default(); NUM_LEDS];
for i in 0..NUM_LEDS {
data[i] = green;
}
ws.write(brightness(data.iter().cloned(), 32)).unwrap(); ws.write(brightness(data.iter().cloned(), 32)).unwrap();
}, },
app::ActiveApp::Plex => { app::ActiveApp::Plex => {
let orange = RGB8::new(255, 187, 51); let data = change_color(&255, &187, &51);
let mut data = [RGB8::default(); NUM_LEDS];
for i in 0..NUM_LEDS {
data[i] = orange;
}
ws.write(brightness(data.iter().cloned(), 32)).unwrap(); ws.write(brightness(data.iter().cloned(), 32)).unwrap();
}, },
_ => println!("We don't know what app is running right now..."), _ => println!("We don't know what app is running right now..."),
@ -115,7 +90,13 @@ fn main() {
} }
} }
#[warn(unreachable_patterns)] fn change_color(num_one: &u8, num_two: &u8, num_three: &u8) -> [RGB8; 150] {
pub fn change_color(_num_leds: usize, _num_one: &u8, _num_two: &u8, _num_three: &u8) { let color = RGB8::new(*num_one, *num_two, *num_three);
// code goes here let mut data = [RGB8::default(); NUM_LEDS];
for i in 0..NUM_LEDS {
data[i] = color;
}
data
} }