diff --git a/pycardium/modules/bhi160-sys.c b/pycardium/modules/bhi160-sys.c
index 35d81b257f3f43d1a16c97e6788ce808d5cd022d..0477286f8c018af4ef17a90caa5f1260077b0986 100644
--- a/pycardium/modules/bhi160-sys.c
+++ b/pycardium/modules/bhi160-sys.c
@@ -5,6 +5,15 @@
#include "api/common.h"
#include "mphalport.h"
+extern const mp_obj_type_t mp_type_bhi160_sample;
+
+typedef struct _bhi160_sample_obj_t {
+ mp_obj_base_t base;
+ int x;
+ int y;
+ int z;
+} bhi160_sample_obj_t;
+
STATIC mp_obj_t mp_bhi160_enable_sensor(size_t n_args, const mp_obj_t *args)
{
int sensor_type = mp_obj_get_int(args[0]);
@@ -30,8 +39,55 @@ STATIC mp_obj_t mp_bhi160_read_sensor(mp_obj_t stream_id_in)
int n = epic_stream_read(sd, buf, sizeof(buf));
- return MP_OBJ_NEW_SMALL_INT(n);
+// mp_obj_list_t *list = mp_obj_new_list(0, NULL);
+ //for(int i = 0; i < n; i++) {
+ bhi160_sample_obj_t *o = m_new_obj(bhi160_sample_obj_t);
+ o->base.type = &mp_type_bhi160_sample;
+ o->x = buf[0].x;
+ o->y = buf[0].y;
+ o->z = buf[0].z;
+
+ //mp_obj_list_append(list, o);
+ //}
+
+ //return MP_OBJ_FROM_PTR(list);
+ return MP_OBJ_FROM_PTR(o);
+}
+
+STATIC mp_obj_t mp_bhi160_x(mp_obj_t type)
+{
+ bhi160_sample_obj_t *self = MP_OBJ_TO_PTR(type);
+ return MP_OBJ_NEW_SMALL_INT(self->x);
+}
+static MP_DEFINE_CONST_FUN_OBJ_1(mp_bhi160_x_obj, mp_bhi160_x);
+
+STATIC mp_obj_t mp_bhi160_y(mp_obj_t type)
+{
+ bhi160_sample_obj_t *self = MP_OBJ_TO_PTR(type);
+ return MP_OBJ_NEW_SMALL_INT(self->y);
}
+static MP_DEFINE_CONST_FUN_OBJ_1(mp_bhi160_y_obj, mp_bhi160_y);
+
+STATIC mp_obj_t mp_bhi160_z(mp_obj_t type)
+{
+ bhi160_sample_obj_t *self = MP_OBJ_TO_PTR(type);
+ return MP_OBJ_NEW_SMALL_INT(self->z);
+}
+static MP_DEFINE_CONST_FUN_OBJ_1(mp_bhi160_z_obj, mp_bhi160_z);
+
+STATIC const mp_rom_map_elem_t bhi160_sample_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_get_x), MP_ROM_PTR(&mp_bhi160_x_obj) },
+ { MP_ROM_QSTR(MP_QSTR_get_y), MP_ROM_PTR(&mp_bhi160_y_obj) },
+ { MP_ROM_QSTR(MP_QSTR_get_z), MP_ROM_PTR(&mp_bhi160_z_obj) },
+};
+
+STATIC MP_DEFINE_CONST_DICT(bhi160_sample_locals_dict, bhi160_sample_locals_dict_table);
+
+const mp_obj_type_t mp_type_bhi160_sample = {
+ { &mp_type_type },
+ .name = MP_QSTR_BHI160Sample,
+ .locals_dict = (mp_obj_dict_t *)&bhi160_sample_locals_dict,
+};
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
mp_bhi160_enable_sensor_obj, 4, 4, mp_bhi160_enable_sensor
diff --git a/pycardium/modules/qstrdefs.h b/pycardium/modules/qstrdefs.h
index 800b97775d3c2b02e096d83c906744f095d25698..c40d0ed6de7a770620c6c52e29646da493a0f5f6 100644
--- a/pycardium/modules/qstrdefs.h
+++ b/pycardium/modules/qstrdefs.h
@@ -64,6 +64,10 @@ Q(RTC_ALARM)
Q(sys_bhi160)
Q(enable_sensor)
Q(read_sensor)
+Q(BHI160Sample)
+Q(get_x)
+Q(get_y)
+Q(get_z)
/* display */
Q(sys_display)