Skip to content

Commit

Permalink
docs: enhance README
Browse files Browse the repository at this point in the history
  • Loading branch information
zHElEARN committed Jul 20, 2024
1 parent 2c52a46 commit 89aadb3
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,29 @@ Since `polar-python` is not yet available on PyPI, you can install it locally by

Below is an example of how to use `polar-python` to connect to a Polar device, query its features, set measurement settings, and start data streaming.

### Step 1: Import Libraries and Initialize Console

```python
import asyncio
from typing import Union
from bleak import BleakScanner
from rich.console import Console
from rich import inspect
from polar_python import PolarDevice, MeasurementSettings, SettingType, ECGData, ACCData
```

### Step 2: Define Data Callback Function

```python
def data_callback(data: Union[ECGData, ACCData]):
"""
Callback function to handle incoming data from the Polar device.
# Initialize Rich Console
console = Console()
Args:
data (Union[ECGData, ACCData]): The data received from the Polar device.
"""
```

### Step 3: Define Main Function to Connect to Polar Device

```python
async def main():
"""
Main function to connect to a Polar device, query its features,
Expand All @@ -58,32 +68,25 @@ async def main():
lambda bd, ad: bd.name and "Polar H10" in bd.name, timeout=5
)
if device is None:
console.print("[bold red]Device not found[/bold red]")
return
```
# Inspect the device details
inspect(device)
def data_callback(data: Union[ECGData, ACCData]):
"""
Callback function to handle incoming data from the Polar device.
Args:
data (Union[ECGData, ACCData]): The data received from the Polar device.
"""
console.print(f"[bold green]Received Data:[/bold green] {data}")
### Step 4: Connect to Polar Device and Query Features
```python
# Establish connection to the Polar device
async with PolarDevice(device, data_callback) as polar_device:
# Query available features
available_features = await polar_device.available_features()
inspect(available_features)
# Query and print stream settings for each feature
for feature in available_features:
settings = await polar_device.request_stream_settings(feature)
console.print(f"[bold blue]Settings for {feature}:[/bold blue] {settings}")
```
### Step 5: Define and Start Data Streams
```python
# Define ECG measurement settings
ecg_settings = MeasurementSettings(
measurement_type="ECG",
Expand All @@ -109,8 +112,11 @@ async def main():
# Keep the stream running for 120 seconds
await asyncio.sleep(120)
```
### Step 6: Run the Main Function
```python
if __name__ == "__main__":
asyncio.run(main())
```
Expand All @@ -124,3 +130,4 @@ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file
- [Bleak](https://github.com/hbldh/bleak) - BLE library for Python.
- [Rich](https://github.com/Textualize/rich) - Python library for rich text and beautiful formatting in the terminal.
- [bleakheart](https://github.com/fsmeraldi/bleakheart) - For providing inspiration and valuable insights.
- [Polar BLE SDK](https://github.com/polarofficial/polar-ble-sdk) - For providing official BLE SDK and documentation for Polar devices.

0 comments on commit 89aadb3

Please sign in to comment.