added get to some properties
Signed-off-by: thatscringebro <thatscringebro@tutanota.com>
This commit is contained in:
parent
f908c728df
commit
025e39f000
@ -4,3 +4,6 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
btleplug = "0.11.8"
|
||||
tokio = { version = "1.44.2", features = ["full"] }
|
||||
uuid = "1.16.0"
|
||||
|
||||
45
src/lib.rs
45
src/lib.rs
@ -1,14 +1,39 @@
|
||||
pub fn add(left: u64, right: u64) -> u64 {
|
||||
left + right
|
||||
}
|
||||
use btleplug::Result;
|
||||
use btleplug::api::{Central, Manager as _, Peripheral as _, ScanFilter};
|
||||
use btleplug::platform::{Adapter, Manager, Peripheral};
|
||||
use std::error::Error;
|
||||
use uuid::{Uuid, uuid};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
const FIRMWARE_VERSION_UUID: Uuid = uuid!("00002a26-0000-1000-8000-00805f9b34fb");
|
||||
const BATTERY_LEVEL_UUID: Uuid = uuid!("00002a19-0000-1000-8000-00805f9b34fb");
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = add(2, 2);
|
||||
assert_eq!(result, 4);
|
||||
pub async fn find_infinitime(adapter: &Adapter) -> Option<Peripheral> {
|
||||
for p in adapter.peripherals().await.unwrap() {
|
||||
if p.properties()
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.local_name
|
||||
.iter()
|
||||
.any(|name| name.to_lowercase().contains("infinitime"))
|
||||
{
|
||||
return Some(p);
|
||||
}
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
async fn get_property_value(infinitime: &Peripheral, property: Uuid) -> String {
|
||||
let chars = infinitime.characteristics();
|
||||
let cmd_char = chars.iter().find(|c| c.uuid == property).unwrap();
|
||||
let result = infinitime.read(cmd_char).await.unwrap();
|
||||
|
||||
return String::from_utf8(result).expect("Invalid UTF-8");
|
||||
}
|
||||
|
||||
pub async fn get_firmware_version(infinitime: &Peripheral) -> String {
|
||||
return get_property_value(infinitime, FIRMWARE_VERSION_UUID).await;
|
||||
}
|
||||
pub async fn get_battery_level(infinitime: &Peripheral) -> String {
|
||||
return get_property_value(infinitime, BATTERY_LEVEL_UUID).await;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user