Skip to content

Commit 2fa671c

Browse files
committed
avoid status bar updates immediately after hard restart
1 parent 52080e2 commit 2fa671c

File tree

8 files changed

+28
-12
lines changed

8 files changed

+28
-12
lines changed

main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,10 @@ int __attribute__((used)) main(void) {
937937

938938
stack_init();
939939

940+
#if CIRCUITPY_STATUS_BAR
941+
supervisor_status_bar_init();
942+
#endif
943+
940944
#if CIRCUITPY_BLEIO
941945
// Early init so that a reset press can cause BLE public advertising.
942946
supervisor_bluetooth_init();

shared-bindings/supervisor/StatusBar.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
//| """Whether status bar information is sent over the console (REPL) serial connection,
5353
//| using OSC terminal escape codes that change the terminal's title. Default is ``True``.
5454
//| If set to ``False``, status bar will be cleared and then disabled.
55-
//| May be set in ``boot.py`` or later.
55+
//| May be set in ``boot.py`` or later. Persists across soft restarts.
5656
//| """
5757
//|
5858
STATIC mp_obj_t supervisor_status_bar_get_console(mp_obj_t self_in) {
@@ -83,7 +83,8 @@ MP_PROPERTY_GETSET(supervisor_status_bar_console_obj,
8383
//| display: bool
8484
//| """Whether status bar information is displayed on the top line of the display.
8585
//| Default is ``True``. If set to ``False``, status bar will be cleared and then disabled.
86-
//| May be set in ``boot.py`` or later. Not available if `terminalio` is not available.
86+
//| May be set in ``boot.py`` or later. Persists across soft restarts.
87+
//| Not available if `terminalio` is not available.
8788
//| """
8889
//|
8990
STATIC mp_obj_t supervisor_status_bar_get_display(mp_obj_t self_in) {

shared-module/supervisor/StatusBar.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ bool shared_module_supervisor_status_bar_get_console(supervisor_status_bar_obj_t
4040
}
4141

4242
void shared_module_supervisor_status_bar_set_console(supervisor_status_bar_obj_t *self, bool enabled) {
43-
// Clear before changing state. If disabling, will remain cleared.
44-
supervisor_status_bar_clear();
43+
if (self->written) {
44+
// Clear before changing state. If disabling, will remain cleared.
45+
supervisor_status_bar_clear();
46+
}
4547

4648
self->console = enabled;
4749

@@ -55,8 +57,10 @@ bool shared_module_supervisor_status_bar_get_display(supervisor_status_bar_obj_t
5557

5658
#if CIRCUITPY_TERMINALIO
5759
void shared_module_supervisor_status_bar_set_display(supervisor_status_bar_obj_t *self, bool enabled) {
58-
terminalio_terminal_clear_status_bar(&supervisor_terminal);
59-
// Clear before changing state. If disabling, will remain cleared.
60+
if (self->written) {
61+
// Clear before changing state. If disabling, will remain cleared.
62+
terminalio_terminal_clear_status_bar(&supervisor_terminal);
63+
}
6064

6165
self->display = enabled;
6266

@@ -70,5 +74,6 @@ bool supervisor_status_bar_get_update_in_progress(supervisor_status_bar_obj_t *s
7074
}
7175

7276
void supervisor_status_bar_set_update_in_progress(supervisor_status_bar_obj_t *self, bool update_in_progress) {
77+
self->written = true;
7378
self->update_in_progress = update_in_progress;
7479
}

shared-module/supervisor/StatusBar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ typedef struct {
3434
bool console;
3535
bool display;
3636
bool update_in_progress;
37+
bool written;
3738
} supervisor_status_bar_obj_t;
3839

3940
extern bool supervisor_status_bar_get_update_in_progress(supervisor_status_bar_obj_t *self);

shared-module/supervisor/__init__.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,4 @@ supervisor_status_bar_obj_t shared_module_supervisor_status_bar_obj = {
3434
.base = {
3535
.type = &supervisor_status_bar_type,
3636
},
37-
.console = true,
38-
.display = true,
3937
};

supervisor/shared/display.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,8 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) {
144144
scroll_area->full_change = true;
145145

146146
common_hal_terminalio_terminal_construct(&supervisor_terminal, scroll_area, &supervisor_terminal_font, status_bar);
147-
#if CIRCUITPY_STATUS_BAR
148-
// Update the status bar since we just cleared the terminal.
149-
supervisor_status_bar_update();
150-
#endif
147+
148+
// Do not update status bar until after boot.py has run, in case it is disabled.
151149
}
152150
#endif
153151

supervisor/shared/status_bar.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ static background_callback_t status_bar_background_cb;
5050
static bool _forced_dirty = false;
5151
static bool _suspended = false;
5252

53+
void supervisor_status_bar_init(void) {
54+
shared_module_supervisor_status_bar_obj.console = true;
55+
shared_module_supervisor_status_bar_obj.display = true;
56+
shared_module_supervisor_status_bar_obj.update_in_progress = false;
57+
shared_module_supervisor_status_bar_obj.written = false;
58+
}
59+
5360
// Clear if possible, but give up if we can't do it now.
5461
void supervisor_status_bar_clear(void) {
5562
if (!_suspended) {

supervisor/shared/status_bar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
#include <stdbool.h>
3030

31+
void supervisor_status_bar_init(void);
32+
3133
void supervisor_status_bar_start(void);
3234
void supervisor_status_bar_suspend(void);
3335
void supervisor_status_bar_resume(void);

0 commit comments

Comments
 (0)