34 lines
808 B
Rust
34 lines
808 B
Rust
|
use bluer::gatt::remote::Characteristic;
|
||
|
|
||
|
const BASE_STRIP_DATA : [u8; 5] = [0x0, 0x0, 0x0, 0x0, 0x1];
|
||
|
|
||
|
#[derive(Clone, Copy)]
|
||
|
pub(crate) struct PixelColor {
|
||
|
pub(crate) red: u8,
|
||
|
pub(crate) green: u8,
|
||
|
pub(crate) blue: u8,
|
||
|
}
|
||
|
|
||
|
|
||
|
pub(crate) struct Strip<const N: usize> {
|
||
|
pub strip: [PixelColor; N],
|
||
|
}
|
||
|
|
||
|
impl<const N: usize> Strip<N> {
|
||
|
pub fn to_array(&self) -> Vec<u8> {
|
||
|
let mut data : Vec<u8> = vec![];
|
||
|
|
||
|
for i in 0..N {
|
||
|
data.append(&mut vec![self.strip[i].red, self.strip[i].green, self.strip[i].blue]);
|
||
|
}
|
||
|
data
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async fn write_strip<const N: usize>(data: Strip<N>, char: Characteristic) -> bluer::Result<()> {
|
||
|
let mut frame= BASE_STRIP_DATA.to_vec();
|
||
|
frame.append(&mut data.to_array());
|
||
|
char.write(&*frame).await?;
|
||
|
Ok(())
|
||
|
}
|