2 releases (1 stable)
1.0.0 | Jul 2, 2022 |
---|---|
0.0.1 | Dec 18, 2021 |
#1366 in Hardware support
26 downloads per month
Used in polar-arctic
650KB
1K
SLoC
Arctic
Rust library for handling Polar bluetooth heart rate monitors.
Currently only targetting support for H10 due to lack of other devices.
Note for MacOS
Using Btleplug on MacOS will require you to give your terminal (or whatever app you're using) permissions to use Bluetooth. View here to see how to resolve this issue.
Examples
There are several examples in the examples folder
lib.rs
:
Arctic
arctic is a library for interacting with bluetooth Polar heart rate devices. It uses btleplug as the bluetooth backend which supports Windows, Mac, and Linux
Usage
Example of how to use the library to keep track of heart rate from a Polar H10
use arctic::{async_trait, Error as ArcticError, EventHandler, NotifyStream, PolarSensor, HeartRate};
struct Handler;
#[async_trait]
impl EventHandler for Handler {
// Handler for heart rate events
async fn heart_rate_update(&self, _ctx: &PolarSensor, heartrate: HeartRate) {
println!("Heart rate: {:?}", heartrate);
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a new PolarSensor with a specific ID.
// The ID is found on the device itself.
let mut polar = PolarSensor::new("7B45F72B".to_string()).await.unwrap();
// Simple loop to continue looking for the device until it's found
while !polar.is_connected().await {
match polar.connect().await {
Err(ArcticError::NoBleAdaptor) => {
// If there's no bluetooth adapter this library cannot work, so return.
println!("No bluetooth adapter found");
return Ok(());
}
Err(why) => println!("Could not connect: {:?}", why),
_ => {}
}
}
// Subscribe to heart rate events
if let Err(why) = polar.subscribe(NotifyStream::HeartRate).await {
println!("Could not subscribe to heart rate notifications: {:?}", why)
}
// Set the event handler to our struct defined above
polar.event_handler(Handler);
// Run the event loop until it ends
let result = polar.event_loop().await;
println!("No more data: {:?}", result);
Ok(())
}
Dependencies
~6–38MB
~524K SLoC