Commit eace0b5d authored by Arist's avatar Arist
Browse files

feat(max86150): MAX86150 Pycardium API: use namedtuple

parent 7e91ee57
Pipeline #4502 failed with stages
in 2 minutes and 19 seconds
......@@ -38,7 +38,7 @@ class SPO2:
def update_history(self, datasets):
for val in datasets:
# get red value (first in tuple)
self.avg[self.avg_pos] = val[0]
self.avg[self.avg_pos] = val.red
if self.avg_pos < 9:
self.avg_pos += 1
else:
......@@ -53,7 +53,7 @@ class SPO2:
self.history.append(self.filtered_value)
# trim old elements
self.history = self.history[-self.HISTORY_MAX :]
self.history = self.history[-self.HISTORY_MAX:]
def draw_histogram(self):
self.disp.clear(self.COLOR_BACKGROUND)
......
import sys_max86150
import uerrno
import interrupt
import ucollections
Max86150Data = ucollections.namedtuple(
"Max86150Data", ["red", "infrared", "ecg"]
)
class MAX86150:
......@@ -68,7 +73,18 @@ class MAX86150:
Read as many samples (signed integer) as currently available.
"""
assert self.active, "Sensor is inactive"
return sys_max86150.read_sensor(self.stream_id)
result = []
for sample in sys_max86150.read_sensor(self.stream_id):
result.append(self._convert(sample))
return result
def _convert(self, sample):
return Max86150Data(
sample[0],
sample[1],
sample[2],
)
def _interrupt(self, _):
if self.active:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment