34
34
//| class Listener:
35
35
//| """Listens for CAN message
36
36
//|
37
- //| canio.Listener is not constructed directly, but instead by calling
38
- //| `~canio.CAN.listen`."""
37
+ //| `canio.Listener` is not constructed directly, but instead by calling
38
+ //| `canio.CAN.listen`.
39
+ //|
40
+ //| In addition to using the `receive` method to retrieve a message or
41
+ //| the `in_waiting` method to check for an available message, a
42
+ //| listener can be used as an iterable, yielding messages until no
43
+ //| message arrives within ``self.timeout`` seconds."""
39
44
//|
40
45
41
46
//| def receive(self) -> Optional[Union[RemoteTransmissionRequest,Message]]:
42
- //| """Reads a message, after waiting up to self.timeout seconds
47
+ //| """Reads a message, after waiting up to `` self.timeout`` seconds
43
48
//|
44
- //| If no message is received in time, None is returned. Otherwise,
45
- //| a Message is returned."""
49
+ //| If no message is received in time, ` None` is returned. Otherwise,
50
+ //| a ` Message` or `RemoteTransmissionRequest` is returned."""
46
51
//| ...
47
52
//|
48
53
STATIC mp_obj_t canio_listener_receive (mp_obj_t self_in ) {
@@ -60,7 +65,8 @@ STATIC mp_obj_t canio_listener_receive(mp_obj_t self_in) {
60
65
STATIC MP_DEFINE_CONST_FUN_OBJ_1 (canio_listener_receive_obj , canio_listener_receive );
61
66
62
67
//| def in_waiting(self) -> int:
63
- //| """Returns the number of messages waiting"""
68
+ //| """Returns the number of messages (including remote
69
+ //| transmission requests) waiting"""
64
70
//| ...
65
71
//|
66
72
STATIC mp_obj_t canio_listener_in_waiting (mp_obj_t self_in ) {
@@ -70,15 +76,21 @@ STATIC mp_obj_t canio_listener_in_waiting(mp_obj_t self_in) {
70
76
}
71
77
STATIC MP_DEFINE_CONST_FUN_OBJ_1 (canio_listener_in_waiting_obj , canio_listener_in_waiting );
72
78
73
- //| def __iter__(self):
74
- //| """Returns self, unless the object is deinitialized"""
79
+ //| def __iter__(self) -> Listener:
80
+ //| """Returns self, unless the object is deinitialized.
81
+ //|
82
+ //| This method exists so that `Listener` can be used as an
83
+ //| iterable"""
75
84
//| ...
76
85
//|
77
- //| def __next__(self):
86
+ //| def __next__(self) -> Union[RemoteTransmissionRequest,Message] :
78
87
//| """Reads a message, after waiting up to self.timeout seconds
79
88
//|
80
89
//| If no message is received in time, raises StopIteration. Otherwise,
81
- //| a Message is returned."""
90
+ //| a Message or is returned.
91
+ //|
92
+ //| This method enables the `Listener` to be used as an
93
+ //| iterable, for instance in a for-loop."""
82
94
//| ...
83
95
//|
84
96
STATIC mp_obj_t canio_iternext (mp_obj_t self_in ) {
0 commit comments