Commit 16549137 authored by schneider's avatar schneider
Browse files

chore(spo2): Code style

parent 61f05b17
......@@ -42,20 +42,21 @@ class SPO2:
self.disp.clear(self.COLOR_BACKGROUND)
self.draw_histogram(self.ir_history, color.RED)
self.draw_histogram(self.red_history, color.GREEN)
spo2, spo2_valid, hr, hr_valid = spo2_algo.maxim_rd117(self.ir_history, self.red_history)
spo2, spo2_valid, hr, hr_valid = spo2_algo.maxim_rd117(
self.ir_history, self.red_history
)
print(utime.time_ms() - self.t0, spo2, spo2_valid, hr, hr_valid)
self.t0 = utime.time_ms()
if hr_valid:
self.disp.print('HR: {0:3} bpm'.format(hr), posy=20)
self.disp.print("HR: {0:3} bpm".format(hr), posy=20)
else:
self.disp.print('HR: --- bpm'.format(hr), posy=20)
self.disp.print("HR: --- bpm".format(hr), posy=20)
if spo2_valid:
self.disp.print('SpO2: {0:3}%'.format(spo2), posy=0)
self.disp.print("SpO2: {0:3}%".format(spo2), posy=0)
else:
self.disp.print('SpO2: ---%'.format(spo2), posy=0)
self.disp.print("SpO2: ---%".format(spo2), posy=0)
self.disp.update()
"""
......@@ -76,14 +77,15 @@ class SPO2:
# 4x over sampling is active ATM
self.sensor = max86150.MAX86150(callback=callback, sample_rate=self.RATE * 4)
while True:
utime.sleep(.1)
utime.sleep(0.1)
if buttons.read(buttons.BOTTOM_RIGHT):
pass
while buttons.read(buttons.BOTTOM_RIGHT): pass
while buttons.read(buttons.BOTTOM_RIGHT):
pass
def update_history(self, datasets):
for val in datasets:
#print("%d,%d" % (val.red, val.infrared))
# print("%d,%d" % (val.red, val.infrared))
self.ir_history.append(val.infrared)
self.red_history.append(val.red)
......@@ -141,7 +143,6 @@ class SPO2:
self.disp.line(x, prev, x + 1, value, col=col)
prev = value
def close(self):
if self.self is not None:
self.sensor.close()
......
......@@ -5,8 +5,7 @@
#include "py/obj.h"
#include "py/runtime.h"
static mp_obj_t
mp_maxim_rd177(mp_obj_t ir, mp_obj_t red)
static mp_obj_t mp_maxim_rd177(mp_obj_t ir, mp_obj_t red)
{
uint32_t pun_ir_buffer[500];
uint32_t pun_red_buffer[500];
......@@ -41,24 +40,27 @@ mp_maxim_rd177(mp_obj_t ir, mp_obj_t red)
}
n_ir_buffer_length = ir_len;
for(size_t i=0; i<ir_len; i++) {
for (size_t i = 0; i < ir_len; i++) {
pun_ir_buffer[i] = mp_obj_get_int(ir_elem[i]);
pun_red_buffer[i] = mp_obj_get_int(red_elem[i]);
}
maxim_heart_rate_and_oxygen_saturation(pun_ir_buffer, n_ir_buffer_length, pun_red_buffer, &pn_spo2, &pch_spo2_valid, &pn_heart_rate, &pch_hr_valid);
maxim_heart_rate_and_oxygen_saturation(
pun_ir_buffer,
n_ir_buffer_length,
pun_red_buffer,
&pn_spo2,
&pch_spo2_valid,
&pn_heart_rate,
&pch_hr_valid
);
mp_obj_t spo2 = mp_obj_new_int(pn_spo2);
mp_obj_t hr = mp_obj_new_int(pn_heart_rate);
mp_obj_t spo2_valid = mp_obj_new_int(pch_spo2_valid);
mp_obj_t hr_valid = mp_obj_new_int(pch_hr_valid);
mp_obj_t tup[] = {
spo2,
spo2_valid,
hr,
hr_valid
};
mp_obj_t tup[] = { spo2, spo2_valid, hr, hr_valid };
return mp_obj_new_tuple(4, tup);
}
......
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