Commit 5a7cc7c9 authored by schneider's avatar schneider
Browse files

change(spo2): Allocate buffers on heap

parent beab46e5
......@@ -5,10 +5,13 @@
#include "py/obj.h"
#include "py/runtime.h"
static mp_obj_t mp_maxim_rd177(mp_obj_t ir, mp_obj_t red)
{
struct spo2_memory {
uint32_t pun_ir_buffer[500];
uint32_t pun_red_buffer[500];
};
static mp_obj_t mp_maxim_rd177(mp_obj_t ir, mp_obj_t red)
{
int32_t n_ir_buffer_length;
int32_t pn_spo2 = 0;
......@@ -39,16 +42,24 @@ static mp_obj_t mp_maxim_rd177(mp_obj_t ir, mp_obj_t red)
);
}
struct spo2_memory *m =
(struct spo2_memory *)MP_STATE_PORT(spo2_memory);
if (!m) {
/* Will raise an exception if out of memory: */
m = m_malloc(sizeof(struct spo2_memory));
MP_STATE_PORT(spo2_memory) = m;
}
n_ir_buffer_length = ir_len;
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]);
m->pun_ir_buffer[i] = mp_obj_get_int(ir_elem[i]);
m->pun_red_buffer[i] = mp_obj_get_int(red_elem[i]);
}
maxim_heart_rate_and_oxygen_saturation(
pun_ir_buffer,
m->pun_ir_buffer,
n_ir_buffer_length,
pun_red_buffer,
m->pun_red_buffer,
&pn_spo2,
&pch_spo2_valid,
&pn_heart_rate,
......
......@@ -114,4 +114,5 @@ typedef long mp_off_t;
#define MICROPY_PORT_ROOT_POINTERS \
const char *readline_hist[16]; \
mp_obj_t interrupt_callbacks[EPIC_INT_NUM]; \
void *spo2_memory; \
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