Skip to content

Expose display’s root_group, add function to resize REPL terminal #5954

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 5 commits into from
Feb 2, 2022
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
18 changes: 18 additions & 0 deletions shared-bindings/displayio/Display.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,23 @@ const mp_obj_property_t displayio_display_bus_obj = {
MP_ROM_NONE},
};

//| root_group: Group
//| """The root group on the display."""
//|
//|
STATIC mp_obj_t displayio_display_obj_get_root_group(mp_obj_t self_in) {
displayio_display_obj_t *self = native_display(self_in);
return common_hal_displayio_display_get_root_group(self);
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_root_group_obj, displayio_display_obj_get_root_group);

const mp_obj_property_t displayio_display_root_group_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&displayio_display_get_root_group_obj,
MP_ROM_NONE,
MP_ROM_NONE},
};


//| def fill_row(self, y: int, buffer: WriteableBuffer) -> WriteableBuffer:
//| """Extract the pixels from a single row
Expand Down Expand Up @@ -517,6 +534,7 @@ STATIC const mp_rom_map_elem_t displayio_display_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_display_height_obj) },
{ MP_ROM_QSTR(MP_QSTR_rotation), MP_ROM_PTR(&displayio_display_rotation_obj) },
{ MP_ROM_QSTR(MP_QSTR_bus), MP_ROM_PTR(&displayio_display_bus_obj) },
{ MP_ROM_QSTR(MP_QSTR_root_group), MP_ROM_PTR(&displayio_display_root_group_obj) },
};
STATIC MP_DEFINE_CONST_DICT(displayio_display_locals_dict, displayio_display_locals_dict_table);

Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/displayio/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ mp_float_t common_hal_displayio_display_get_brightness(displayio_display_obj_t *
bool common_hal_displayio_display_set_brightness(displayio_display_obj_t *self, mp_float_t brightness);

mp_obj_t common_hal_displayio_display_get_bus(displayio_display_obj_t *self);

mp_obj_t common_hal_displayio_display_get_root_group(displayio_display_obj_t *self);

#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_DISPLAY_H
17 changes: 17 additions & 0 deletions shared-bindings/supervisor/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "shared/runtime/interrupt_char.h"
#include "supervisor/shared/autoreload.h"
#include "supervisor/shared/bluetooth/bluetooth.h"
#include "supervisor/shared/display.h"
#include "supervisor/shared/status_leds.h"
#include "supervisor/shared/stack.h"
#include "supervisor/shared/traceback.h"
Expand Down Expand Up @@ -299,6 +300,21 @@ STATIC mp_obj_t supervisor_disable_ble_workflow(void) {
}
MP_DEFINE_CONST_FUN_OBJ_0(supervisor_disable_ble_workflow_obj, supervisor_disable_ble_workflow);

//| def reset_terminal(x_pixels: int, y_pixels: int) -> None:
//| """Reset the CircuitPython serial terminal with new dimensions."""
//| ...
//|
STATIC mp_obj_t supervisor_reset_terminal(mp_obj_t x_pixels, mp_obj_t y_pixels) {
#if CIRCUITPY_DISPLAYIO
supervisor_stop_terminal();
supervisor_start_terminal(mp_obj_get_int(x_pixels), mp_obj_get_int(y_pixels));
#else
mp_raise_NotImplementedError(NULL);
#endif
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(supervisor_reset_terminal_obj, supervisor_reset_terminal);

STATIC const mp_rom_map_elem_t supervisor_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_supervisor) },
{ MP_ROM_QSTR(MP_QSTR_enable_autoreload), MP_ROM_PTR(&supervisor_enable_autoreload_obj) },
Expand All @@ -312,6 +328,7 @@ STATIC const mp_rom_map_elem_t supervisor_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&supervisor_ticks_ms_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_previous_traceback), MP_ROM_PTR(&supervisor_get_previous_traceback_obj) },
{ MP_ROM_QSTR(MP_QSTR_disable_ble_workflow), MP_ROM_PTR(&supervisor_disable_ble_workflow_obj) },
{ MP_ROM_QSTR(MP_QSTR_reset_terminal), MP_ROM_PTR(&supervisor_reset_terminal_obj) },
};

STATIC MP_DEFINE_CONST_DICT(supervisor_module_globals, supervisor_module_globals_table);
Expand Down
4 changes: 4 additions & 0 deletions shared-module/displayio/Display.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ mp_obj_t common_hal_displayio_display_get_bus(displayio_display_obj_t *self) {
return self->core.bus;
}

mp_obj_t common_hal_displayio_display_get_root_group(displayio_display_obj_t *self) {
return self->core.current_group;
}

STATIC const displayio_area_t *_get_refresh_areas(displayio_display_obj_t *self) {
if (self->core.full_refresh) {
self->core.area.next = NULL;
Expand Down
15 changes: 9 additions & 6 deletions shared-module/displayio/display_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,15 @@ void displayio_display_core_set_rotation(displayio_display_core_t *self,
}

bool displayio_display_core_show(displayio_display_core_t *self, displayio_group_t *root_group) {
if (root_group == NULL) {
if (!circuitpython_splash.in_group) {
root_group = &circuitpython_splash;
} else if (self->current_group == &circuitpython_splash) {
return true;
}

if (root_group == NULL) { // set the display to the REPL, reset REPL position and size
circuitpython_splash.in_group = false;
// force the circuit_python_splash out of any group (Note: could cause problems with the parent group)
circuitpython_splash.x = 0; // reset position in case someone moved it.
circuitpython_splash.y = 0;
supervisor_stop_terminal();
supervisor_start_terminal(self->width, self->height);
root_group = &circuitpython_splash;
}
if (root_group == self->current_group) {
return true;
Expand Down