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§
- Acc
- Struct to store acceleration from the PMD data stream
- Control
Point - Struct that has access to the PMD control point point and PMD data
- Control
Response - Store data returned from the device after a write to the control point
- Ecg
- Struct to store ECG from the PMD data stream
- Heart
Rate - Structure to contain HR data and RR interval
- PmdRead
- Struct for reveiving measurement type data on PMD data
- Polar
Sensor - The core Polar device structure. Keeps track of connection and event dispatching.
- Stream
Settings - Struct to store the settings for a specific stream on your device
- Supported
Features - Struct that reads what features are available on your device
Enums§
- Control
Point Command - Command options to write to the control point
- Control
Point Response Code - Response code returned after a write to PMD control point
- Error
- Error type for general errors and Ble errors from btleplug
- H10Measurement
Type - List of measurement types you can request
- Notify
Stream - A list of stream types that can be subscribed to
- PmdData
- Enum to store which kind of data was received
Traits§
- Event
Handler - Trait for handling events coming from a device
Type Aliases§
- Polar
Result - Result simplification type