Skip to content

Commit 19bb27a

Browse files
committed
extmod/machine_signal: Add signal_print() as repr() function.
Test code is: ``` from machine import Pin, Signal signal22= Signal(Pin(22, mode=Pin.OUT)) signal22 signal21= Signal(Pin(21, mode=Pin.IN), invert=True) signal21 ``` Ounput is: ``` Signal(Pin(22)) Signal(Pin(21), invert=True) ``` instead of ``` <Signal> <Signal> ```
1 parent 313068a commit 19bb27a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

extmod/machine_signal.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,21 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t
114114
return MP_OBJ_FROM_PTR(o);
115115
}
116116

117+
STATIC void signal_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
118+
machine_signal_t *self = MP_OBJ_TO_PTR(self_in);
119+
const mp_print_fun_t pin_print_function = (mp_print_fun_t)MP_OBJ_TYPE_GET_SLOT_OR_NULL(mp_obj_get_type(self->pin), print);
120+
mp_printf(print, "Signal(");
121+
if (pin_print_function) {
122+
pin_print_function(print, self->pin, kind);
123+
} else {
124+
mp_printf(print, "Pin()"); // correct the port
125+
}
126+
if (self->invert) {
127+
mp_printf(print, ", invert=True");
128+
}
129+
mp_printf(print, ")");
130+
}
131+
117132
STATIC mp_uint_t signal_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
118133
(void)errcode;
119134
machine_signal_t *self = MP_OBJ_TO_PTR(self_in);
@@ -177,6 +192,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
177192
MP_QSTR_Signal,
178193
MP_TYPE_FLAG_NONE,
179194
make_new, signal_make_new,
195+
print, signal_print,
180196
call, signal_call,
181197
protocol, &signal_pin_p,
182198
locals_dict, &signal_locals_dict

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy