fixed bug - turning on/off functionality

This commit is contained in:
Wyatt J. Miller 2020-04-01 04:28:35 +01:00
parent 023434cfcc
commit 96509ff1cc
2 changed files with 77 additions and 83 deletions

View File

@ -68,6 +68,9 @@ impl Configuration {
next.text().to_string() next.text().to_string()
} }
pub fn change_color(num_leds: usize, num_one: &u8, num_two: &u8, num_three: &u8) {
// code goes here
}
} }
// grab the config // grab the config

View File

@ -30,103 +30,94 @@ fn main() {
let mut ws = Ws2812::new(spi); let mut ws = Ws2812::new(spi);
let delay = Delay::new(); let delay = Delay::new();
let mut configuration = config::init_config(); let mut configuration = config::init_config();
let mut headless_count: u32 = 0;
loop { loop {
println!("{:?}", configuration); println!("{:?}", configuration);
if false == configuration.is_change_app() {
let app_text = configuration.get_app_status(); let power_text = configuration.get_power_status();
configuration.change_active_app(&app_text); configuration.change_power(&power_text);
let activeapp = app::match_to_app(app_text); let tvpower = app::match_to_power_status(power_text);
match activeapp { match tvpower {
app::ActiveApp::Roku => { app::TVPower::Off => {
let color = RGB8::new(255, 0, 255); headless_count += headless_count + 1;
let mut data = [RGB8::default(); NUM_LEDS];
for i in 0..NUM_LEDS { if headless_count <= 2 {
data[i] = color;
}
ws.write(brightness(data.iter().cloned(), 32)).unwrap();
},
app::ActiveApp::Hulu => {
let green = RGB8::new(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();
},
app::ActiveApp::Netflix => {
let red = RGB8::new(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();
},
app::ActiveApp::AmazonPrime => println!("The light are light blue!"),
app::ActiveApp::Spotify => {
let green = RGB8::new(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();
},
app::ActiveApp::Plex => {
let orange = RGB8::new(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();
},
_ => println!("Oops!"),
}
}
if false == configuration.is_change_power() {
let power_text = configuration.get_power_status();
configuration.change_power(&power_text);
let tvpower = app::match_to_power_status(power_text);
match tvpower {
app::TVPower::On => {
continue
},
app::TVPower::Off => {
let color = RGB8::new(0, 0, 0); let color = RGB8::new(0, 0, 0);
let mut data = [RGB8::default(); NUM_LEDS]; let mut data = [RGB8::default(); NUM_LEDS];
for i in 0..NUM_LEDS { for i in 0..NUM_LEDS {
data[i] = color; data[i] = color;
} }
ws.write(brightness(data.iter().cloned(), 32)).unwrap(); ws.write(brightness(data.iter().cloned(), 32)).unwrap();
}, }
_ => println!("We don't know what the power status of the TV is..."), },
} app::TVPower::On => {
if false == configuration.is_change_app() {
headless_count = 0;
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 => {
let color = RGB8::new(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();
},
app::ActiveApp::Hulu => {
let green = RGB8::new(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();
},
app::ActiveApp::Netflix => {
let red = RGB8::new(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();
},
app::ActiveApp::AmazonPrime => println!("The light are light blue!"),
app::ActiveApp::Spotify => {
let green = RGB8::new(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();
},
app::ActiveApp::Plex => {
let orange = RGB8::new(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();
},
_ => println!("Oops!"),
}
}
},
_ => println!("We don't know what the power status of the TV is..."),
} }
let sec = time::Duration::from_secs(3); let sec = time::Duration::from_secs(1);
thread::sleep(sec); 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()
} }