Skip to content

Adding the serial_bytes_available() method to the 3.x branch #1317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions ports/atmel-samd/common-hal/supervisor/Runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

4 changes: 4 additions & 0 deletions ports/nrf/common-hal/supervisor/Runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

26 changes: 26 additions & 0 deletions shared-bindings/supervisor/Runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions shared-bindings/supervisor/Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down