Skip to content

Commit adf9b21

Browse files
authored
Merge pull request #1317 from ATMakersBill/serial_bytes_avail_backport
Adding the serial_bytes_available() method to the 3.x branch
2 parents fa1edb2 + bd4188a commit adf9b21

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_HID
1717
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_LIS3DH
1818
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel
1919
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Thermistor
20+
21+
#Adding per @danh to reduce memory usage and get the latest changes in
22+
CFLAGS_INLINE_LIMIT = 55

ports/atmel-samd/common-hal/supervisor/Runtime.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ bool common_hal_get_serial_connected(void) {
3232
return (bool) usb_connected();
3333
}
3434

35+
bool common_hal_get_serial_bytes_available(void) {
36+
return (bool) usb_bytes_available();
37+
}
38+

ports/nrf/common-hal/supervisor/Runtime.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ bool common_hal_get_serial_connected(void) {
3232
return (bool) serial_connected();
3333
}
3434

35+
bool common_hal_get_serial_bytes_available(void) {
36+
return (bool) serial_bytes_available();
37+
}
38+

shared-bindings/supervisor/Runtime.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@
5353
//|
5454
//| Returns the USB serial communication status (read-only).
5555
//|
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+
//|
5662
//| .. note::
5763
//|
5864
//| SAMD: Will return ``True`` if the USB serial connection
@@ -80,8 +86,28 @@ const mp_obj_property_t supervisor_serial_connected_obj = {
8086
(mp_obj_t)&mp_const_none_obj},
8187
};
8288

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+
83108
STATIC const mp_rom_map_elem_t supervisor_runtime_locals_dict_table[] = {
84109
{ 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) },
85111
};
86112

87113
STATIC MP_DEFINE_CONST_DICT(supervisor_runtime_locals_dict, supervisor_runtime_locals_dict_table);

shared-bindings/supervisor/Runtime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const mp_obj_type_t supervisor_runtime_type;
3535

3636
bool common_hal_get_serial_connected(void);
3737

38+
bool common_hal_get_serial_bytes_available(void);
39+
3840
//TODO: placeholders for future functions
3941
//bool common_hal_get_repl_active(void);
4042
//bool common_hal_get_usb_enumerated(void);

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