remove warning and use rustfmt
This commit is contained in:
parent
142fdb44d7
commit
517e98dea2
37
src/main.rs
37
src/main.rs
|
@ -1,13 +1,13 @@
|
||||||
mod bluetooth;
|
mod bluetooth;
|
||||||
mod patterns;
|
mod patterns;
|
||||||
|
|
||||||
use std::convert::TryFrom;
|
use crate::patterns::PixelColor;
|
||||||
use std::thread::sleep;
|
|
||||||
use std::time::Duration;
|
|
||||||
use bluer::gatt::remote::Characteristic;
|
use bluer::gatt::remote::Characteristic;
|
||||||
use patterns::Strip;
|
use patterns::Strip;
|
||||||
|
use std::convert::TryFrom;
|
||||||
|
use std::time::Duration;
|
||||||
use tokio::sync::watch;
|
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 SERVICE_UUID: bluer::Uuid = bluer::Uuid::from_u128(0xadaf0900c33242a893bd25e905756cb8);
|
||||||
const PIXEL_DATA_UUID: bluer::Uuid = bluer::Uuid::from_u128(0xadaf0903c33242a893bd25e905756cb8);
|
const PIXEL_DATA_UUID: bluer::Uuid = bluer::Uuid::from_u128(0xadaf0903c33242a893bd25e905756cb8);
|
||||||
|
@ -24,18 +24,18 @@ async fn main() -> bluer::Result<()> {
|
||||||
|
|
||||||
for _ in 0..STRIP_SIZE {
|
for _ in 0..STRIP_SIZE {
|
||||||
pixels.push(PixelColor {
|
pixels.push(PixelColor {
|
||||||
red: 255, green: 0, blue:0
|
red: 255,
|
||||||
|
green: 0,
|
||||||
|
blue: 0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let strip = Strip::<STRIP_SIZE> {
|
let strip = Strip::<STRIP_SIZE> {
|
||||||
strip : <[PixelColor; 25]>::try_from(pixels).unwrap()
|
strip: <[PixelColor; 25]>::try_from(pixels).unwrap(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let (tx, rx) = watch::channel(Strip::<STRIP_SIZE>::default());
|
let (tx, rx) = watch::channel(Strip::<STRIP_SIZE>::default());
|
||||||
|
|
||||||
|
|
||||||
for device in devices {
|
for device in devices {
|
||||||
bluetooth::connect(&device, 3).await?;
|
bluetooth::connect(&device, 3).await?;
|
||||||
let char = bluetooth::get_char(&device, SERVICE_UUID, PIXEL_DATA_UUID).await?;
|
let char = bluetooth::get_char(&device, SERVICE_UUID, PIXEL_DATA_UUID).await?;
|
||||||
|
@ -52,14 +52,23 @@ async fn main() -> bluer::Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loop {
|
loop {
|
||||||
|
match tx.send(strip) {
|
||||||
tx.send(strip);
|
Ok(_) => {}
|
||||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
Err(_) => {
|
||||||
tx.send(Strip::<STRIP_SIZE>::default());
|
break;
|
||||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||||
|
match tx.send(Strip::<STRIP_SIZE>::default()) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(_) => {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
// fn create_pattern_list() -> Vec<patterns>
|
// fn create_pattern_list() -> Vec<patterns>
|
||||||
// async fn send_seq(char: &Characteristic) -> bluer::Result<()> {
|
// async fn send_seq(char: &Characteristic) -> bluer::Result<()> {
|
||||||
|
|
|
@ -19,7 +19,6 @@ impl fmt::Display for PixelColor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Default for PixelColor {
|
impl Default for PixelColor {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
PixelColor {
|
PixelColor {
|
||||||
|
@ -30,8 +29,6 @@ impl Default for PixelColor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct Strip<const N: usize> {
|
pub struct Strip<const N: usize> {
|
||||||
pub strip: [PixelColor; N],
|
pub strip: [PixelColor; N],
|
||||||
|
|
Loading…
Reference in New Issue
Block a user