removed some pre-Rust 2018 'features', made code more readable

This commit is contained in:
Wyatt J. Miller 2020-05-23 21:08:20 +01:00
parent 946f238ee2
commit b652eedede
2 changed files with 28 additions and 24 deletions

View File

@ -1,7 +1,3 @@
extern crate serde;
extern crate serde_derive;
extern crate serde_json;
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::Read;
use std::path::Path; use std::path::Path;
@ -47,9 +43,13 @@ impl Configuration {
let response = get_request(&request); let response = get_request(&request);
match response { match response {
Ok(res) => { Ok(res) => {
let document = Document::from_read(res).unwrap(); let document = Document::from_read(res)
let next = document.find(Name("app")).next().unwrap(); .unwrap();
next.text().to_string() let next = document.find(Name("app"))
.next()
.unwrap();
next.text()
.to_string()
} }
Err(_) => "_".to_string() Err(_) => "_".to_string()
} }
@ -65,9 +65,13 @@ impl Configuration {
let response = get_request(&request); let response = get_request(&request);
match response { match response {
Ok(res) => { Ok(res) => {
let document = Document::from_read(res).unwrap(); let document = Document::from_read(res)
let next = document.find(Name("power-mode")).next().unwrap(); .unwrap();
next.text().to_string() let next = document.find(Name("power-mode"))
.next()
.unwrap();
next.text()
.to_string()
} }
Err(_) => "_".to_string() Err(_) => "_".to_string()
} }

View File

@ -1,10 +1,3 @@
// external crates getting imported
extern crate reqwest;
extern crate select;
extern crate serde;
extern crate serde_derive;
extern crate serde_json;
// std lib imports // std lib imports
use std::{thread, time}; use std::{thread, time};
@ -21,7 +14,8 @@ mod generate;
const NUM_LEDS: usize = 150; const NUM_LEDS: usize = 150;
fn main() { fn main() {
let spi = Spi::new(Bus::Spi0, SlaveSelect::Ss0, 3_000_000, Mode::Mode0).unwrap(); let spi = Spi::new(Bus::Spi0, SlaveSelect::Ss0, 3_000_000, Mode::Mode0)
.unwrap();
let mut ws = Ws2812::new(spi); let mut ws = Ws2812::new(spi);
let mut configuration = config::init_config(); let mut configuration = config::init_config();
let mut is_headless: bool = false; let mut is_headless: bool = false;
@ -45,7 +39,8 @@ fn main() {
data[i] = color; data[i] = color;
} }
ws.write(brightness(data.iter().cloned(), 32)).unwrap(); ws.write(brightness(data.iter().cloned(), 32))
.unwrap();
} }
}, },
app::TVPower::On => { app::TVPower::On => {
@ -59,24 +54,29 @@ fn main() {
match activeapp { match activeapp {
app::ActiveApp::Roku => { app::ActiveApp::Roku => {
let data = change_color(&255, &0, &255); let data = change_color(&255, &0, &255);
ws.write(brightness(data.iter().cloned(), 10)).unwrap(); ws.write(brightness(data.iter().cloned(), 10))
.unwrap();
}, },
app::ActiveApp::Hulu => { app::ActiveApp::Hulu => {
let data = change_color(&51, &255, &85); let data = change_color(&51, &255, &85);
ws.write(brightness(data.iter().cloned(), 32)).unwrap(); ws.write(brightness(data.iter().cloned(), 32))
.unwrap();
}, },
app::ActiveApp::Netflix => { app::ActiveApp::Netflix => {
let data = change_color(&255, &77, &77); let data = change_color(&255, &77, &77);
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 data = change_color(&51, &255, &85); let data = change_color(&51, &255, &85);
ws.write(brightness(data.iter().cloned(), 32)).unwrap(); ws.write(brightness(data.iter().cloned(), 32))
.unwrap();
}, },
app::ActiveApp::Plex => { app::ActiveApp::Plex => {
let data = change_color(&255, &187, &51); let data = change_color(&255, &187, &51);
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..."),
} }