diff --git a/src/main.rs b/src/main.rs index 1677830..872c8f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,13 @@ mod bluetooth; mod patterns; -use std::convert::TryFrom; -use std::thread::sleep; -use std::time::Duration; +use crate::patterns::PixelColor; use bluer::gatt::remote::Characteristic; use patterns::Strip; +use std::convert::TryFrom; +use std::time::Duration; use tokio::sync::watch; -use crate::patterns::PixelColor; +use tokio::sync::watch::error::SendError; const SERVICE_UUID: bluer::Uuid = bluer::Uuid::from_u128(0xadaf0900c33242a893bd25e905756cb8); const PIXEL_DATA_UUID: bluer::Uuid = bluer::Uuid::from_u128(0xadaf0903c33242a893bd25e905756cb8); @@ -22,20 +22,20 @@ async fn main() -> bluer::Result<()> { let mut pixels = Vec::::new(); - for _ in 0..STRIP_SIZE{ - pixels.push(PixelColor{ - red: 255, green: 0, blue:0 + for _ in 0..STRIP_SIZE { + pixels.push(PixelColor { + red: 255, + green: 0, + blue: 0, }) } - - let strip = Strip:: { - strip : <[PixelColor; 25]>::try_from(pixels).unwrap() + let strip = Strip:: { + strip: <[PixelColor; 25]>::try_from(pixels).unwrap(), }; let (tx, rx) = watch::channel(Strip::::default()); - for device in devices { bluetooth::connect(&device, 3).await?; let char = bluetooth::get_char(&device, SERVICE_UUID, PIXEL_DATA_UUID).await?; @@ -52,13 +52,22 @@ async fn main() -> bluer::Result<()> { } } loop { - - tx.send(strip); + match tx.send(strip) { + Ok(_) => {} + Err(_) => { + break; + } + } tokio::time::sleep(Duration::from_secs(1)).await; - tx.send(Strip::::default()); + match tx.send(Strip::::default()) { + Ok(_) => {} + Err(_) => { + break; + } + } tokio::time::sleep(Duration::from_secs(1)).await; - } + Ok(()) } // fn create_pattern_list() -> Vec diff --git a/src/patterns.rs b/src/patterns.rs index 6d40766..51bf5bc 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -19,7 +19,6 @@ impl fmt::Display for PixelColor { } } - impl Default for PixelColor { fn default() -> Self { PixelColor { @@ -30,8 +29,6 @@ impl Default for PixelColor { } } - - #[derive(Copy, Clone)] pub struct Strip { pub strip: [PixelColor; N],