@@ -71,6 +71,12 @@ byte console_uart_rx_buf[64];
71
71
bool tud_vendor_connected (void );
72
72
#endif
73
73
74
+ // Set to true to temporarily discard writes to the console only.
75
+ static bool _console_write_disabled ;
76
+
77
+ // Set to true to temporarily discard writes to the display terminal only.
78
+ static bool _display_write_disabled ;
79
+
74
80
#if CIRCUITPY_CONSOLE_UART
75
81
STATIC void console_uart_print_strn (void * env , const char * str , size_t len ) {
76
82
(void )env ;
@@ -277,22 +283,36 @@ bool serial_bytes_available(void) {
277
283
return false;
278
284
}
279
285
286
+ #if CIRCUITPY_STATUS_BAR
287
+ // Detect when USB is down when the status bar write starts. If USB comes up in the middle of writing
288
+ // the status bar, we want to the skip the rest so so junk doesn't get written out.
289
+ static bool ignore_rest_of_status_bar_update = false;
290
+ #endif
291
+
280
292
void serial_write_substring (const char * text , uint32_t length ) {
281
293
if (length == 0 ) {
282
294
return ;
283
295
}
284
296
285
297
#if CIRCUITPY_TERMINALIO
286
298
int errcode ;
287
- // We might be writing
288
299
// If the status bar is disabled for the display, common_hal_terminalio_terminal_write() will not write it.
289
300
common_hal_terminalio_terminal_write (& supervisor_terminal , (const uint8_t * )text , length , & errcode );
290
301
#endif
291
302
292
303
#if CIRCUITPY_STATUS_BAR
293
304
// If the status bar is disabled for the console, skip writing out the OSC sequence.
294
- if (supervisor_status_bar_get_update_in_progress (& shared_module_supervisor_status_bar_obj ) &&
295
- !shared_module_supervisor_status_bar_get_console (& shared_module_supervisor_status_bar_obj )) {
305
+ if (supervisor_status_bar_get_update_in_progress (& shared_module_supervisor_status_bar_obj )) {
306
+ if (!shared_module_supervisor_status_bar_get_console (& shared_module_supervisor_status_bar_obj )) {
307
+ // Console status bar disabled, so just return.
308
+ return ;
309
+ }
310
+ } else {
311
+ // Status bar update is not in progress, so clear this history flag (will get cleared repeatedly).
312
+ ignore_rest_of_status_bar_update = false;
313
+ }
314
+
315
+ if (ignore_rest_of_status_bar_update ) {
296
316
return ;
297
317
}
298
318
#endif
@@ -325,14 +345,23 @@ void serial_write_substring(const char *text, uint32_t length) {
325
345
326
346
#if CIRCUITPY_USB
327
347
uint32_t count = 0 ;
328
- while (count < length && tud_cdc_connected ()) {
329
- count += tud_cdc_write (text + count , length - count );
330
- // If we're in an interrupt, then don't wait for more room. Queue up what we can.
331
- if (cpu_interrupt_active ()) {
332
- break ;
348
+ if (tud_cdc_connected ()) {
349
+ while (count < length ) {
350
+ count += tud_cdc_write (text + count , length - count );
351
+ // If we're in an interrupt, then don't wait for more room. Queue up what we can.
352
+ if (cpu_interrupt_active ()) {
353
+ break ;
354
+ }
355
+ usb_background ();
333
356
}
334
- usb_background ();
335
357
}
358
+ #if CIRCUITPY_STATUS_BAR
359
+ else {
360
+ // USB was not connected for the first part of the status bar update. Ignore the rest
361
+ // so we don't send the remaining part of the OSC sequence if USB comes up later.
362
+ ignore_rest_of_status_bar_update = true;
363
+ }
364
+ #endif
336
365
#endif
337
366
338
367
port_serial_write_substring (text , length );
@@ -341,3 +370,11 @@ void serial_write_substring(const char *text, uint32_t length) {
341
370
void serial_write (const char * text ) {
342
371
serial_write_substring (text , strlen (text ));
343
372
}
373
+
374
+ void serial_console_write_disable (bool disabled ) {
375
+ _serial_console_write_disabled = disabled ;
376
+ }
377
+
378
+ void serial_display_write_disable (bool disabled ) {
379
+ _serial_display_write_disabled = disabled ;
380
+ }
0 commit comments