diff options
author | Daniel Campora <daniel@wipy.io> | 2015-08-11 11:18:02 +0200 |
---|---|---|
committer | Daniel Campora <daniel@wipy.io> | 2015-08-16 20:17:52 +0200 |
commit | ea5061e409449118ed45ce2956800780631bcf9e (patch) | |
tree | 107417699e361857372ec07670ae68770cf75832 /cc3200/misc/mpcallback.c | |
parent | 4c5bfe2d10cd8397e970c4c23f6c15b97133fcc0 (diff) | |
download | micropython-ea5061e409449118ed45ce2956800780631bcf9e.tar.gz micropython-ea5061e409449118ed45ce2956800780631bcf9e.zip |
cc3200: Improve callback API.
Rename "wakes" param to "wake_from" and make "value" an object
instead of an integer.
Diffstat (limited to 'cc3200/misc/mpcallback.c')
-rw-r--r-- | cc3200/misc/mpcallback.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/cc3200/misc/mpcallback.c b/cc3200/misc/mpcallback.c index 35342a0ccf..ff04e713f8 100644 --- a/cc3200/misc/mpcallback.c +++ b/cc3200/misc/mpcallback.c @@ -46,8 +46,8 @@ const mp_arg_t mpcallback_init_args[] = { { MP_QSTR_mode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_handler, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_priority, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} }, - { MP_QSTR_value, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, - { MP_QSTR_wakes, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = PYB_PWR_MODE_ACTIVE} }, + { MP_QSTR_value, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, + { MP_QSTR_wake_from, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = PYB_PWR_MODE_ACTIVE} }, }; /****************************************************************************** @@ -58,14 +58,14 @@ void mpcallback_init0 (void) { mp_obj_list_init(&MP_STATE_PORT(mpcallback_obj_list), 0); } -mp_obj_t mpcallback_new (mp_obj_t parent, mp_obj_t handler, const mp_cb_methods_t *methods) { +mp_obj_t mpcallback_new (mp_obj_t parent, mp_obj_t handler, const mp_cb_methods_t *methods, bool enable) { mpcallback_obj_t *self = m_new_obj(mpcallback_obj_t); self->base.type = &pyb_callback_type; self->handler = handler; self->parent = parent; self->methods = (mp_cb_methods_t *)methods; - self->isenabled = true; - // remove any old callback if present + self->isenabled = enable; + // remove it in case it was already registered mpcallback_remove(self->parent); mp_obj_list_append(&MP_STATE_PORT(mpcallback_obj_list), self); return self; @@ -138,11 +138,11 @@ void mpcallback_handler (mp_obj_t self_in) { // uncaught exception; disable the callback so that it doesn't run again self->methods->disable (self->parent); self->handler = mp_const_none; - // signal the error using the heart beat led and print an - // exception message as well - mperror_signal_error(); + // signal the error using the heart beat led and + // by printing a message printf("Uncaught exception in callback handler\n"); mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val); + mperror_signal_error(); } gc_unlock(); } |