Commit 16549137 authored by schneider's avatar schneider
Browse files

chore(spo2): Code style

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