Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
card10
firmware
Commits
4836abf4
Commit
4836abf4
authored
Aug 23, 2019
by
schneider
Browse files
feat(max30001): Pycardium support
parent
4f32a5ce
Changes
9
Hide whitespace changes
Inline
Side-by-side
Documentation/index.rst
View file @
4836abf4
...
...
@@ -24,6 +24,7 @@ Last but not least, if you want to start hacking the lower-level firmware, the
pycardium/stdlib
pycardium/bhi160
pycardium/bme680
pycardium/max30001
pycardium/buttons
pycardium/color
pycardium/display
...
...
Documentation/pycardium/max30001.rst
0 → 100644
View file @
4836abf4
``max30001`` - MAX30001
=====================
.. automodule:: max30001
:members:
pycardium/meson.build
View file @
4836abf4
...
...
@@ -9,6 +9,7 @@ modsrc = files(
'modules/interrupt.c'
,
'modules/sys_leds.c'
,
'modules/light_sensor.c'
,
'modules/max30001-sys.c'
,
'modules/os.c'
,
'modules/personal_state.c'
,
'modules/power.c'
,
...
...
pycardium/modules/interrupt.c
View file @
4836abf4
...
...
@@ -91,6 +91,9 @@ static const mp_rom_map_elem_t interrupt_module_globals_table[] = {
MP_OBJ_NEW_SMALL_INT
(
EPIC_INT_BHI160_ORIENTATION
)
},
{
MP_ROM_QSTR
(
MP_QSTR_BHI160_GYROSCOPE
),
MP_OBJ_NEW_SMALL_INT
(
EPIC_INT_BHI160_GYROSCOPE
)
},
{
MP_ROM_QSTR
(
MP_QSTR_MAX30001_ECG
),
MP_OBJ_NEW_SMALL_INT
(
EPIC_INT_MAX30001_ECG
)
},
};
static
MP_DEFINE_CONST_DICT
(
interrupt_module_globals
,
interrupt_module_globals_table
...
...
pycardium/modules/max30001-sys.c
0 → 100644
View file @
4836abf4
#include
"py/obj.h"
#include
"py/runtime.h"
#include
"py/builtin.h"
#include
"epicardium.h"
#include
"api/common.h"
#include
"mphalport.h"
STATIC
mp_obj_t
mp_max30001_enable_sensor
(
size_t
n_args
,
const
mp_obj_t
*
args
)
{
struct
max30001_sensor_config
cfg
=
{
0
};
cfg
.
usb
=
mp_obj_is_true
(
args
[
0
]);
cfg
.
bias
=
mp_obj_is_true
(
args
[
1
]);
cfg
.
sample_rate
=
mp_obj_get_int
(
args
[
2
]);
cfg
.
sample_buffer_len
=
mp_obj_get_int
(
args
[
3
]);
int
stream_id
=
epic_max30001_enable_sensor
(
&
cfg
);
return
MP_OBJ_NEW_SMALL_INT
(
stream_id
);
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
mp_max30001_enable_sensor_obj
,
4
,
4
,
mp_max30001_enable_sensor
);
STATIC
mp_obj_t
mp_max30001_read_sensor
(
mp_obj_t
stream_id_in
)
{
int16_t
buf
[
256
];
int
stream_id
=
mp_obj_get_int
(
stream_id_in
);
int
n
=
epic_stream_read
(
stream_id
,
buf
,
sizeof
(
buf
));
mp_obj_list_t
*
list
=
mp_obj_new_list
(
0
,
NULL
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
mp_obj_list_append
(
list
,
mp_obj_new_int
(
buf
[
i
]));
}
return
MP_OBJ_FROM_PTR
(
list
);
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
mp_max30001_read_sensor_obj
,
mp_max30001_read_sensor
);
STATIC
mp_obj_t
mp_max30001_disable_sensor
(
void
)
{
int
ret
=
epic_max30001_disable_sensor
();
return
MP_OBJ_NEW_SMALL_INT
(
ret
);
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_0
(
mp_max30001_disable_sensor_obj
,
mp_max30001_disable_sensor
);
STATIC
const
mp_rom_map_elem_t
max30001_module_globals_table
[]
=
{
{
MP_ROM_QSTR
(
MP_QSTR___name__
),
MP_ROM_QSTR
(
MP_QSTR_sys_max30001
)
},
{
MP_ROM_QSTR
(
MP_QSTR_enable_sensor
),
MP_ROM_PTR
(
&
mp_max30001_enable_sensor_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_read_sensor
),
MP_ROM_PTR
(
&
mp_max30001_read_sensor_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_disable_sensor
),
MP_ROM_PTR
(
&
mp_max30001_disable_sensor_obj
)
},
};
STATIC
MP_DEFINE_CONST_DICT
(
max30001_module_globals
,
max30001_module_globals_table
);
// Define module object.
const
mp_obj_module_t
max30001_module
=
{
.
base
=
{
&
mp_type_module
},
.
globals
=
(
mp_obj_dict_t
*
)
&
max30001_module_globals
,
};
/* clang-format off */
// Register the module to make it available in Python
MP_REGISTER_MODULE
(
MP_QSTR_sys_max30001
,
max30001_module
,
MODULE_MAX30001_ENABLED
);
pycardium/modules/py/max30001.py
0 → 100644
View file @
4836abf4
import
sys_max30001
import
interrupt
import
ucollections
class
MAX30001
:
"""
The MAX30001 class provides a stram interface to the MAX30001
ECG and BIO-Z sensor.
.. code-block:: python
import max30001
m = max30001.MAX30001()
m.read()
m.close()
"""
def
__init__
(
self
,
usb
=
False
,
bias
=
True
,
sample_rate
=
128
,
callback
=
None
,
sample_buffer_len
=
256
,
):
"""
Initializes the MAX30001 (if it is not already running).
:param usb: True if all ECG leads should use the USB-C connector
:param bias: True if the internal bias of the ECG should be used. Mandatory if the card10 is not attached to the body and the USB-C connector is used.
:param sample_rate: Selected sample rate in Hz. Supported values: 128 and 256.
:param callback: If not None: A callback which is called with the data when ever new data is available
:param sample_buffer: Length of the internal buffer (in samples)
"""
self
.
sample_rate
=
sample_rate
self
.
callback
=
callback
self
.
sample_buffer_len
=
sample_buffer_len
self
.
interrupt_id
=
interrupt
.
MAX30001_ECG
self
.
usb
=
usb
self
.
bias
=
bias
self
.
_callback
=
callback
self
.
enable_sensor
()
def
enable_sensor
(
self
):
"""
Enables the sensor. Automatically called by __init__.
"""
interrupt
.
disable_callback
(
self
.
interrupt_id
)
interrupt
.
set_callback
(
self
.
interrupt_id
,
self
.
_interrupt
)
self
.
stream_id
=
sys_max30001
.
enable_sensor
(
self
.
usb
,
self
.
bias
,
self
.
sample_rate
,
self
.
sample_buffer_len
)
if
self
.
stream_id
<
0
:
raise
ValueError
(
"Enable sensor returned %i"
,
self
.
stream_id
)
self
.
active
=
True
if
self
.
_callback
:
interrupt
.
enable_callback
(
self
.
interrupt_id
)
def
__enter__
(
self
):
return
self
def
__exit__
(
self
,
_et
,
_ev
,
_t
):
self
.
close
()
def
close
(
self
):
"""
Close the currently open connection to the sensor.
"""
if
self
.
active
:
self
.
active
=
False
ret
=
sys_max30001
.
disable_sensor
(
self
.
sensor_id
)
if
ret
<
0
:
raise
ValueError
(
"Disable sensor returned %i"
,
ret
)
interrupt
.
disable_callback
(
self
.
interrupt_id
)
interrupt
.
set_callback
(
self
.
interrupt_id
,
None
)
def
read
(
self
):
"""
Read as many samples (signed integer) as currently available.
"""
if
self
.
active
:
return
sys_max30001
.
read_sensor
(
self
.
stream_id
)
return
[]
def
_interrupt
(
self
,
_
):
if
self
.
active
:
data
=
self
.
read
()
if
self
.
_callback
:
self
.
_callback
(
data
)
pycardium/modules/py/meson.build
View file @
4836abf4
...
...
@@ -4,6 +4,7 @@ python_modules = files(
'htmlcolor.py'
,
'display.py'
,
'leds.py'
,
'max30001.py'
,
'pride.py'
,
'ledfx.py'
,
'simple_menu.py'
,
...
...
pycardium/modules/qstrdefs.h
View file @
4836abf4
...
...
@@ -163,3 +163,5 @@ Q(NO_CONTACT)
Q
(
CHAOS
)
Q
(
COMMUNICATION
)
Q
(
CAMP
)
Q
(
MAX30001_ECG
)
pycardium/mpconfigport.h
View file @
4836abf4
...
...
@@ -53,6 +53,7 @@ int mp_hal_trng_read_int(void);
#define MODULE_INTERRUPT_ENABLED (1)
#define MODULE_LEDS_ENABLED (1)
#define MODULE_LIGHT_SENSOR_ENABLED (1)
#define MODULE_MAX30001_ENABLED (1)
#define MODULE_OS_ENABLED (1)
#define MODULE_PERSONAL_STATE_ENABLED (1)
#define MODULE_POWER_ENABLED (1)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment