Commit 902ade82 authored by schneider's avatar schneider
Browse files

fix(spo2): Use averaging from TomoStrap

parent d7b8753d
......@@ -24,6 +24,7 @@ class SPO2:
self.filtered_value = 0.0
self.source = "Red"
self.average = 0
self.prev_w = 0
def open(self):
def callback(datasets):
......@@ -46,13 +47,19 @@ class SPO2:
while buttons.read(buttons.BOTTOM_RIGHT): pass
def update_history(self, datasets):
alpha = 0.995
alpha = 0.9975
for val in datasets:
"""
print("%d,%d" % (val.red, val.infrared))
if self.source == "Red":
self.avg[self.avg_pos] = val.red
d = val.red
else:
self.avg[self.avg_pos] = val.infrared
d = val.infrared
w = d + self.prev_w * 0.95
self.history.append(w - self.prev_w)
self.prev_w = w
"""
self.avg[self.avg_pos] = d
if self.avg_pos < 9:
self.avg_pos += 1
......@@ -68,15 +75,11 @@ class SPO2:
self.history.append(self.filtered_value)
"""
#print("%d,%d" % (val.red, val.infrared))
if self.source == "Red":
d = val.red
else:
d = val.infrared
"""
self.average = alpha * self.average + (1 - alpha) * d
d -= self.average
self.history.append(d)
"""
# trim old elements
self.history = self.history[-self.HISTORY_MAX :]
......
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