41
41
* Adafruit's BLE library: https://github.com/adafruit/Adafruit_CircuitPython_BLE
42
42
"""
43
43
import struct
44
- import _bleio
44
+ from collections import namedtuple
45
45
46
+ import _bleio
46
47
from adafruit_ble .services import Service
47
48
from adafruit_ble .uuid import StandardUUID
48
49
from adafruit_ble .characteristics import Characteristic , ComplexCharacteristic
51
52
__version__ = "0.0.0-auto.0"
52
53
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BLE_Heart_Rate.git"
53
54
55
+ HeartRateMeasurementValues = namedtuple (
56
+ "HeartRateMeasurementValues" ,
57
+ ("heart_rate" , "contact" , "energy_expended" , "rr_intervals" ))
58
+ """Namedtuple for measurement values.
59
+
60
+ .. py:attribute:: HeartRateMeasurementValues.heart_rate
61
+
62
+ Heart rate (int), in beats per minute.
63
+
64
+ .. py:attribute:: HeartRateMeasurementValues.contact
65
+
66
+ ``True`` if device is contacting the body, ``False`` if not,
67
+ ``None`` if device does not support contact detection.
68
+
69
+ .. py:attribute:: HeartRateMeasurementValues.energy_expended
70
+
71
+ Energy expended (int), in kilo joules, or ``None`` if no value.
72
+
73
+ .. py:attribute:: HeartRateMeasurementValues.rr_intervals
74
+
75
+ Sequence of RR intervals, measuring the time between
76
+ beats. Oldest first, in ints that are units of 1024ths of a second.
77
+ This sequence will be empty if the device does not report the intervals.
78
+ *Caution:* inexpensive heart rate monitors may not measure this
79
+ accurately. Do not use for diagnosis.
80
+
81
+ For example::
82
+
83
+ bpm = svc.measurement_values.heart_rate
84
+ """
85
+
54
86
class _HeartRateMeasurement (ComplexCharacteristic ):
55
87
"""Notify-only characteristic of streaming heart rate data."""
56
88
uuid = StandardUUID (0x2A37 )
@@ -109,15 +141,10 @@ def __init__(self, service=None):
109
141
110
142
@property
111
143
def measurement_values (self ):
112
- """All the measurement values, as a tuple:
113
- (heart_rate, contact, energy_expended, rr_intervals)
114
- * heart_rate: int (beats per minute)
115
- * contact: True if contacting, False if not, None if unknown
116
- * energy_expended: int (Kilo joules), or None if no value
117
- * rr_intervals: list of RR-intervals, if any,
118
- oldest first, in ints that are1024ths of a second,
119
-
120
- Return None if no packet has been read yet.
144
+ """All the measurement values, returned as a HeartRateMeasurementValues
145
+ namedtuple.
146
+
147
+ Return ``None`` if no packet has been read yet.
121
148
"""
122
149
buf = self ._measurement_buf
123
150
packet_length = self .heart_rate_measurement .readinto (buf )
@@ -152,7 +179,7 @@ def measurement_values(self):
152
179
rr_val = struct .unpack_from ("<H" , buf , offset )[0 ]
153
180
rr_values .append (rr_val )
154
181
155
- return (bpm , contact , energy_expended , rr_values )
182
+ return HeartRateMeasurementValues (bpm , contact , energy_expended , rr_values )
156
183
157
184
@property
158
185
def location (self ):
@@ -163,6 +190,10 @@ def location(self):
163
190
For instance, some armbands are meant to be worn just below the inner elbow,
164
191
but that is not a prescribed location. So the sensor will report something
165
192
else, such as "Wrist".
193
+
194
+ Possible values are:
195
+ "Other", "Chest", "Wrist", "Finger", "Hand", "Ear Lobe", "Foot", and
196
+ "InvalidLocation" (if value returned does not match the specification).
166
197
"""
167
198
168
199
try :
0 commit comments