Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit aca898e

Browse files
committed
esp8266/machine_uart: Add uart.any() method.
Returns 0 or 1, corresponding to no or at least 1 char waiting.
1 parent 218a876 commit aca898e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

esp8266/machine_uart.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,16 @@ STATIC mp_obj_t pyb_uart_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_
193193
}
194194
MP_DEFINE_CONST_FUN_OBJ_KW(pyb_uart_init_obj, 1, pyb_uart_init);
195195

196+
STATIC mp_obj_t pyb_uart_any(mp_obj_t self_in) {
197+
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
198+
return MP_OBJ_NEW_SMALL_INT(uart_rx_any(self->uart_id));
199+
}
200+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_any_obj, pyb_uart_any);
201+
196202
STATIC const mp_rom_map_elem_t pyb_uart_locals_dict_table[] = {
197203
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_uart_init_obj) },
198204

205+
{ MP_ROM_QSTR(MP_QSTR_any), MP_ROM_PTR(&pyb_uart_any_obj) },
199206
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
200207
{ MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) },
201208
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },

0 commit comments

Comments
 (0)