diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2018-11-04 11:40:15 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-04 11:40:15 -0800 |
| commit | adf9b2108f14911dea7ba28b7a908887199b6462 (patch) | |
| tree | 93183afe283b039e8807811fa9fdcd57126d45d0 | |
| parent | fa1edb2a01f7238ac6fc108142aae35faf7f9b15 (diff) | |
| parent | bd4188a0924700d30d53a860c56e4bd4c081608b (diff) | |
Merge pull request #1317 from ATMakersBill/serial_bytes_avail_backport
Adding the serial_bytes_available() method to the 3.x branch
| -rw-r--r-- | ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk | 3 | ||||
| -rwxr-xr-x | ports/atmel-samd/common-hal/supervisor/Runtime.c | 4 | ||||
| -rwxr-xr-x | ports/nrf/common-hal/supervisor/Runtime.c | 4 | ||||
| -rwxr-xr-x | shared-bindings/supervisor/Runtime.c | 26 | ||||
| -rwxr-xr-x | shared-bindings/supervisor/Runtime.h | 2 |
5 files changed, 39 insertions, 0 deletions
diff --git a/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk b/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk index 831106adc..aff875e29 100644 --- a/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk @@ -17,3 +17,6 @@ FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_HID FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_LIS3DH FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Thermistor + +#Adding per @danh to reduce memory usage and get the latest changes in +CFLAGS_INLINE_LIMIT = 55 diff --git a/ports/atmel-samd/common-hal/supervisor/Runtime.c b/ports/atmel-samd/common-hal/supervisor/Runtime.c index 8efe7cb78..2636fe646 100755 --- a/ports/atmel-samd/common-hal/supervisor/Runtime.c +++ b/ports/atmel-samd/common-hal/supervisor/Runtime.c @@ -32,3 +32,7 @@ bool common_hal_get_serial_connected(void) { return (bool) usb_connected(); } +bool common_hal_get_serial_bytes_available(void) { + return (bool) usb_bytes_available(); +} + diff --git a/ports/nrf/common-hal/supervisor/Runtime.c b/ports/nrf/common-hal/supervisor/Runtime.c index b73a94a1b..feab6987d 100755 --- a/ports/nrf/common-hal/supervisor/Runtime.c +++ b/ports/nrf/common-hal/supervisor/Runtime.c @@ -32,3 +32,7 @@ bool common_hal_get_serial_connected(void) { return (bool) serial_connected(); } +bool common_hal_get_serial_bytes_available(void) { + return (bool) serial_bytes_available(); +} + diff --git a/shared-bindings/supervisor/Runtime.c b/shared-bindings/supervisor/Runtime.c index b061595cf..27b62abd4 100755 --- a/shared-bindings/supervisor/Runtime.c +++ b/shared-bindings/supervisor/Runtime.c @@ -53,6 +53,12 @@ //| //| Returns the USB serial communication status (read-only). //| +//| .. attribute:: runtime.serial_bytes_available +//| +//| Returns the whether any bytes are available to read +//| on the USB serial input. Allows for polling to see whether +//| to call the built-in input() or wait. (read-only) +//| //| .. note:: //| //| SAMD: Will return ``True`` if the USB serial connection @@ -80,8 +86,28 @@ const mp_obj_property_t supervisor_serial_connected_obj = { (mp_obj_t)&mp_const_none_obj}, }; +/*Added to allow for polling of USB Console*/ +STATIC mp_obj_t supervisor_get_serial_bytes_available(mp_obj_t self){ + if (!common_hal_get_serial_bytes_available()) { + return mp_const_false; + } + else { + return mp_const_true; + } +} +MP_DEFINE_CONST_FUN_OBJ_1(supervisor_get_serial_bytes_available_obj, supervisor_get_serial_bytes_available); + +const mp_obj_property_t supervisor_serial_bytes_available_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&supervisor_get_serial_bytes_available_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + + STATIC const mp_rom_map_elem_t supervisor_runtime_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_serial_connected), MP_ROM_PTR(&supervisor_serial_connected_obj) }, + { MP_ROM_QSTR(MP_QSTR_serial_bytes_available), MP_ROM_PTR(&supervisor_serial_bytes_available_obj) }, }; STATIC MP_DEFINE_CONST_DICT(supervisor_runtime_locals_dict, supervisor_runtime_locals_dict_table); diff --git a/shared-bindings/supervisor/Runtime.h b/shared-bindings/supervisor/Runtime.h index 4a67925ec..864b070cd 100755 --- a/shared-bindings/supervisor/Runtime.h +++ b/shared-bindings/supervisor/Runtime.h @@ -35,6 +35,8 @@ const mp_obj_type_t supervisor_runtime_type; bool common_hal_get_serial_connected(void); +bool common_hal_get_serial_bytes_available(void); + //TODO: placeholders for future functions //bool common_hal_get_repl_active(void); //bool common_hal_get_usb_enumerated(void); |
