Skip to content

Commit 5307ed9

Browse files
committed
CAN.listen: block until a message comes in or timeout is reached
1 parent 9e85099 commit 5307ed9

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

shared-bindings/_canio/Listener.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,17 @@ STATIC mp_obj_t canio_listener_iter(mp_obj_t self_in) {
100100
STATIC MP_DEFINE_CONST_FUN_OBJ_1(canio_listener_iter_obj, canio_listener_iter);
101101

102102
//| def __next__(self):
103-
//| """Returns the next waiting message, if one is available
104-
//|
105-
//| If the object is deinitialized, raises ValueError.
103+
//| """Reads a message, after waiting up to self.timeout seconds
106104
//|
107-
//| If no message is waiting raises StopIteration"""
105+
//| If no message is received in time, raises StopIteration. Otherwise,
106+
//| a Message is returned."""
108107
//| ...
109108
//|
110109
STATIC mp_obj_t canio_listener_next(mp_obj_t self_in) {
111-
canio_listener_obj_t *self = MP_OBJ_TO_PTR(self_in);
112-
common_hal_canio_listener_check_for_deinit(self);
113-
if (common_hal_canio_listener_in_waiting(self)) {
114-
return canio_listener_read(self_in);
110+
mp_obj_t result = canio_listener_read(self_in);
111+
if (result == mp_const_none) {
112+
return MP_OBJ_STOP_ITERATION;
115113
}
116-
return MP_OBJ_STOP_ITERATION;
117114
}
118115
STATIC MP_DEFINE_CONST_FUN_OBJ_1(canio_listener_next_obj, canio_listener_next);
119116

0 commit comments

Comments
 (0)