|
53 | 53 | //| |
54 | 54 | //| Returns the USB serial communication status (read-only). |
55 | 55 | //| |
| 56 | +//| .. attribute:: runtime.serial_bytes_available |
| 57 | +//| |
| 58 | +//| Returns the whether any bytes are available to read |
| 59 | +//| on the USB serial input. Allows for polling to see whether |
| 60 | +//| to call the built-in input() or wait. (read-only) |
| 61 | +//| |
56 | 62 | //| .. note:: |
57 | 63 | //| |
58 | 64 | //| SAMD: Will return ``True`` if the USB serial connection |
@@ -80,8 +86,28 @@ const mp_obj_property_t supervisor_serial_connected_obj = { |
80 | 86 | (mp_obj_t)&mp_const_none_obj}, |
81 | 87 | }; |
82 | 88 |
|
| 89 | +/*Added to allow for polling of USB Console*/ |
| 90 | +STATIC mp_obj_t supervisor_get_serial_bytes_available(mp_obj_t self){ |
| 91 | + if (!common_hal_get_serial_bytes_available()) { |
| 92 | + return mp_const_false; |
| 93 | + } |
| 94 | + else { |
| 95 | + return mp_const_true; |
| 96 | + } |
| 97 | +} |
| 98 | +MP_DEFINE_CONST_FUN_OBJ_1(supervisor_get_serial_bytes_available_obj, supervisor_get_serial_bytes_available); |
| 99 | + |
| 100 | +const mp_obj_property_t supervisor_serial_bytes_available_obj = { |
| 101 | + .base.type = &mp_type_property, |
| 102 | + .proxy = {(mp_obj_t)&supervisor_get_serial_bytes_available_obj, |
| 103 | + (mp_obj_t)&mp_const_none_obj, |
| 104 | + (mp_obj_t)&mp_const_none_obj}, |
| 105 | +}; |
| 106 | + |
| 107 | + |
83 | 108 | STATIC const mp_rom_map_elem_t supervisor_runtime_locals_dict_table[] = { |
84 | 109 | { MP_ROM_QSTR(MP_QSTR_serial_connected), MP_ROM_PTR(&supervisor_serial_connected_obj) }, |
| 110 | + { MP_ROM_QSTR(MP_QSTR_serial_bytes_available), MP_ROM_PTR(&supervisor_serial_bytes_available_obj) }, |
85 | 111 | }; |
86 | 112 |
|
87 | 113 | STATIC MP_DEFINE_CONST_DICT(supervisor_runtime_locals_dict, supervisor_runtime_locals_dict_table); |
|
0 commit comments