Expand description
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(())
}
Structs
Struct to store acceleration from the PMD data stream
Struct that has access to the PMD control point point and PMD data
Store data returned from the device after a write to the control point
Struct to store ECG from the PMD data stream
Structure to contain HR data and RR interval
Struct for reveiving measurement type data on PMD data
The core Polar device structure. Keeps track of connection and event dispatching.
Struct to store the settings for a specific stream on your device
Struct that reads what features are available on your device
Enums
Command options to write to the control point
Response code returned after a write to PMD control point
Error type for general errors and Ble errors from btleplug
List of measurement types you can request
A list of stream types that can be subscribed to
Enum to store which kind of data was received
Traits
Trait for handling events coming from a device
Type Definitions
Result simplification type