Starting a new module on the Xnucleo

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
aoxpn
Posts: 1
Joined: Thu Aug 25, 2016 8:10 am

Starting a new module on the Xnucleo

Post by aoxpn » Tue Apr 25, 2017 8:26 am

Hey everyone,
I'm starting to handle Micropython and would like to create my own module.
I have already read different topics on the forum and find a few example code.
But I have issue :[ maybe it's easy to fix I think. Here my code :

typedef struct _pyb_sensorTemp_obj_t {
mp_obj_base_t base;
mp_int_t temperature;
} pyb_sensorTemp_obj_t;

STATIC mp_obj_t pyb_temp_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
// check arguments
mp_arg_check_num(n_args, n_kw, 0, 0, false);

// init accel object
pyb_sensorTemp_obj_t *o = m_new_obj(pyb_sensorTemp_obj_t);
o->base.type = &pyb_sensorTemp_type;
sensorTemp_start();

return o;
}
STATIC const mp_map_elem_t pyb_temp_locals_dict_table[]{
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_SENSOR_TEMP) }
{ MP_OBJ_NEW_QSTR(MP_QSTR_temp), (mp_obj_t)&pyb_sensorTemp_obj } }
}

STATIC MP_DEFINE_CONST_DICT(pyb_sensorTemp_locals_dict, pyb_temp_locals_dict_table);

const mp_obj_type_t pyb_sensorTemp_type = {
{ &mp_type_type },
.name = MP_QSTR_SENSOR_TEMP,
.make_new = pyb_sensorTemp_make_new,
.locals_dict = (mp_obj_t)&pyb_sensorTemp_locals_
};

I have an issue on my mp_obj_t pyb_temp_make_new function. When I tried to compile it I have this message :
error : assignement from incompatible pointer type [-Werror]
o->base.type = pyb_sensorTemp_type;

Maybe I don't really understand the API C of micropython

Thank you in advance

Post Reply