add small routine to send data
This commit is contained in:
parent
534b300931
commit
33da38381a
9
Cargo.lock
generated
9
Cargo.lock
generated
|
@ -39,7 +39,7 @@ dependencies = [
|
|||
"strum",
|
||||
"tokio",
|
||||
"tokio-stream",
|
||||
"uuid 0.8.2",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -417,7 +417,6 @@ dependencies = [
|
|||
"bluer",
|
||||
"futures",
|
||||
"tokio",
|
||||
"uuid 1.0.0-alpha.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -565,12 +564,6 @@ dependencies = [
|
|||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.0.0-alpha.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb3ab47baa004111b323696c6eaa2752e7356f7f77cf6b6dc7a2087368ce1ca4"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
|
|
|
@ -8,5 +8,4 @@ edition = "2018"
|
|||
[dependencies]
|
||||
bluer = "0.13.1"
|
||||
tokio = "1.15.0"
|
||||
futures = "0.3.19"
|
||||
uuid = "1.0.0-alpha.1"
|
||||
futures = "0.3.19"
|
30
src/main.rs
30
src/main.rs
|
@ -1,7 +1,8 @@
|
|||
use bluer::{AdapterEvent, Device};
|
||||
use bluer::gatt::remote::Characteristic;
|
||||
use futures::{pin_mut, StreamExt};
|
||||
use std::error::Error;
|
||||
use std::time::Duration;
|
||||
use tokio::time::sleep;
|
||||
|
||||
const SERVICE_UUID: bluer::Uuid = bluer::Uuid::from_u128(0xadaf0900c33242a893bd25e905756cb8);
|
||||
const PIXEL_DATA_UUID: bluer::Uuid = bluer::Uuid::from_u128(0xadaf0903c33242a893bd25e905756cb8);
|
||||
|
@ -25,8 +26,12 @@ async fn main() -> bluer::Result<()> {
|
|||
let device = adapter.device(addr)?;
|
||||
match find_neopixel_service(&device).await {
|
||||
Ok(Some(char)) => {
|
||||
send_seq(char)
|
||||
println!("found characteristic");
|
||||
match send_seq(&char).await {
|
||||
// this loop should never stop
|
||||
_ => ()
|
||||
}
|
||||
|
||||
}
|
||||
Ok(None) => {
|
||||
println!("characteristic not found")
|
||||
|
@ -49,13 +54,24 @@ async fn main() -> bluer::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn send_seq(char: &Characteristic) -> {
|
||||
async fn send_seq(char: &Characteristic) -> bluer::Result<()> {
|
||||
println!(" Characteristic flags : {:?}, ", char.flags().await?);
|
||||
|
||||
let base_data = vec![0x00, 0x00, 0x01];
|
||||
for i in 0..10 {
|
||||
# base_data.
|
||||
let mut base_data: Vec<u8> = vec![0x00, 0x00, 0x01];
|
||||
let mut off_data: Vec<u8> = vec![0x00, 0x00, 0x01];
|
||||
for _ in 0..10 {
|
||||
base_data.append(&mut vec![0xff, 0x00, 0x00]);
|
||||
off_data.append(&mut vec![0x00, 0x00, 0x00]);
|
||||
}
|
||||
|
||||
loop {
|
||||
char.write(&*base_data).await?;
|
||||
sleep(Duration::from_secs(1)).await;
|
||||
char.write(&*off_data).await?;
|
||||
sleep(Duration::from_secs(1)).await;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async fn connect(device: &Device, retries: u8) -> bluer::Result<()> {
|
||||
|
@ -65,7 +81,7 @@ async fn connect(device: &Device, retries: u8) -> bluer::Result<()> {
|
|||
for i in 0..retries {
|
||||
match device.connect().await {
|
||||
Ok(()) => return Ok(()),
|
||||
Err(err) => {
|
||||
Err(_) => {
|
||||
println!("connection error ({}), retry…", i);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user