diff options
| author | Damien George <damien.p.george@gmail.com> | 2017-06-15 17:34:51 +1000 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2017-06-15 17:34:51 +1000 |
| commit | fd860dc552b2ec53df8c6ce7e1245206719d469b (patch) | |
| tree | f0e1fa830f923ebc76d8815c4a30772853696219 /stmhal | |
| parent | 4abe3731e3fbce88c2efa265950c5e13b30426d6 (diff) | |
stmhal: Add .value() method to Switch object, to mirror Pin and Signal.
Diffstat (limited to 'stmhal')
| -rw-r--r-- | stmhal/usrsw.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/stmhal/usrsw.c b/stmhal/usrsw.c index d4f0c6939..63cd440d4 100644 --- a/stmhal/usrsw.c +++ b/stmhal/usrsw.c @@ -97,6 +97,12 @@ mp_obj_t pyb_switch_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_ return switch_get() ? mp_const_true : mp_const_false; } +mp_obj_t pyb_switch_value(mp_obj_t self_in) { + (void)self_in; + return mp_obj_new_bool(switch_get()); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_switch_value_obj, pyb_switch_value); + STATIC mp_obj_t switch_callback(mp_obj_t line) { if (MP_STATE_PORT(pyb_switch_callback) != mp_const_none) { mp_call_function_0(MP_STATE_PORT(pyb_switch_callback)); @@ -123,6 +129,7 @@ mp_obj_t pyb_switch_callback(mp_obj_t self_in, mp_obj_t callback) { STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_switch_callback_obj, pyb_switch_callback); STATIC const mp_rom_map_elem_t pyb_switch_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&pyb_switch_value_obj) }, { MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&pyb_switch_callback_obj) }, }; |
