added notification test
This commit is contained in:
parent
bcfb0eec12
commit
abe0e23cae
19
src/lib.rs
19
src/lib.rs
@ -1,12 +1,13 @@
|
||||
use btleplug::Result;
|
||||
use btleplug::api::{Central, Manager as _, Peripheral as _, ScanFilter};
|
||||
use btleplug::api::{Central, Manager as _, Peripheral as _, ScanFilter, WriteType};
|
||||
use btleplug::platform::{Adapter, Manager, Peripheral};
|
||||
use std::error::Error;
|
||||
use uuid::{Uuid, uuid};
|
||||
|
||||
const FIRMWARE_VERSION_UUID: Uuid = uuid!("00002a26-0000-1000-8000-00805f9b34fb");
|
||||
const BATTERY_LEVEL_UUID: Uuid = uuid!("00002a19-0000-1000-8000-00805f9b34fb");
|
||||
const HEART_RATE_UUDI: Uuid = uuid!("00002a37-0000-1000-8000-00805f9b34fb");
|
||||
const HEART_RATE_UUID: Uuid = uuid!("00002a37-0000-1000-8000-00805f9b34fb");
|
||||
const NOTIFICATION_UUID: Uuid = uuid!("00002a37-0000-1000-8000-00805f9b34fb");
|
||||
|
||||
pub async fn find_infinitime(adapter: &Adapter) -> Option<Peripheral> {
|
||||
for p in adapter.peripherals().await.unwrap() {
|
||||
@ -42,7 +43,19 @@ pub async fn get_battery_level(infinitime: &Peripheral) -> String {
|
||||
return percent.to_string();
|
||||
}
|
||||
pub async fn get_heart_rate(infinitime: &Peripheral) -> String {
|
||||
let data = get_property_value(infinitime, HEART_RATE_UUDI).await;
|
||||
let data = get_property_value(infinitime, HEART_RATE_UUID).await;
|
||||
let rate = data[1];
|
||||
return rate.to_string();
|
||||
}
|
||||
pub async fn send_notification(infinitime: &Peripheral) {
|
||||
let chars = infinitime.characteristics();
|
||||
let cmd_char = chars.iter().find(|c| c.uuid == NOTIFICATION_UUID).unwrap();
|
||||
infinitime
|
||||
.write(
|
||||
cmd_char,
|
||||
"\\x00\\x01\\x00Test Title\\x00Test Body".as_bytes(),
|
||||
WriteType::WithoutResponse,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user