|
31 | 31 | //| print("touched!")""" |
32 | 32 | //| |
33 | 33 |
|
34 | | -//| def __init__(self, pin: microcontroller.Pin) -> None: |
| 34 | +//| def __init__(self, pin: microcontroller.Pin, pulldir: bool -> False) -> None: |
35 | 35 | //| """Use the TouchIn on the given pin. |
36 | 36 | //| |
37 | 37 | //| :param ~microcontroller.Pin pin: the pin to read from""" |
| 38 | +//| :param ~bool pulldir: kind of external pull resistor, false = pulldown, true = pullup |
38 | 39 | //| ... |
39 | 40 | //| |
40 | | -static mp_obj_t touchio_touchin_make_new(const mp_obj_type_t *type, |
41 | | - size_t n_args, size_t n_kw, const mp_obj_t *args) { |
| 41 | +//static mp_obj_t touchio_touchin_make_new(const mp_obj_type_t *type, |
| 42 | +// size_t n_args, size_t n_kw, const mp_obj_t *args) { |
42 | 43 | // check number of arguments |
43 | | - mp_arg_check_num(n_args, n_kw, 1, 1, false); |
44 | | - |
| 44 | + /// mp_arg_check_num(n_args, n_kw, 1, 1, false); |
| 45 | +static mp_obj_t touchio_touchin_make_new(const mp_obj_type_t *type, |
| 46 | + size_t n_args, size_t n_kw, const mp_obj_t *all_args) { |
| 47 | + enum { ARG_pin, ARG_pulldir }; |
| 48 | + static const mp_arg_t allowed_args[] = { |
| 49 | + { MP_QSTR_pin, MP_ARG_OBJ | MP_ARG_REQUIRED }, |
| 50 | + { MP_QSTR_pulldir, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, |
| 51 | + }; |
| 52 | + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; |
| 53 | + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); |
| 54 | + |
45 | 55 | // 1st argument is the pin |
46 | | - const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[0], MP_QSTR_pin); |
| 56 | + const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[ARG_pin].u_obj, MP_QSTR_pin); |
| 57 | + const bool pulldir = args[ARG_pulldir].u_bool; |
47 | 58 |
|
48 | 59 | touchio_touchin_obj_t *self = mp_obj_malloc(touchio_touchin_obj_t, &touchio_touchin_type); |
49 | | - common_hal_touchio_touchin_construct(self, pin); |
| 60 | + common_hal_touchio_touchin_construct(self, pin, pulldir); |
50 | 61 |
|
51 | 62 | return (mp_obj_t)self; |
52 | 63 | } |
|
0 commit comments