|
52 | 52 | #include "supervisor/memory.h"
|
53 | 53 | #include "supervisor/port.h"
|
54 | 54 | #include "supervisor/serial.h"
|
55 |
| -#include "supervisor/shared/autoreload.h" |
| 55 | +#include "supervisor/shared/reload.h" |
56 | 56 | #include "supervisor/shared/safe_mode.h"
|
57 | 57 | #include "supervisor/shared/stack.h"
|
58 | 58 | #include "supervisor/shared/status_leds.h"
|
@@ -389,12 +389,28 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool first_run, bool *simulate_re
|
389 | 389 |
|
390 | 390 | // Print done before resetting everything so that we get the message over
|
391 | 391 | // BLE before it is reset and we have a delay before reconnect.
|
392 |
| - if (result.return_code == PYEXEC_RELOAD) { |
| 392 | + if ((result.return_code & PYEXEC_RELOAD) && supervisor_get_run_reason() == RUN_REASON_AUTO_RELOAD) { |
393 | 393 | serial_write_compressed(translate("\nCode stopped by auto-reload.\n"));
|
| 394 | + |
| 395 | + // Wait for autoreload interval before reloading |
| 396 | + uint64_t start_ticks = 0; |
| 397 | + do { |
| 398 | + // Start waiting, or restart interval if another reload request was initiated |
| 399 | + // while we were waiting. |
| 400 | + if (reload_requested) { |
| 401 | + reload_requested = false; |
| 402 | + start_ticks = supervisor_ticks_ms64(); |
| 403 | + } |
| 404 | + RUN_BACKGROUND_TASKS; |
| 405 | + } while (supervisor_ticks_ms64() - start_ticks < CIRCUITPY_AUTORELOAD_DELAY_MS); |
| 406 | + |
| 407 | + // Restore request for use below. |
| 408 | + reload_requested = true; |
394 | 409 | } else {
|
395 | 410 | serial_write_compressed(translate("\nCode done running.\n"));
|
396 | 411 | }
|
397 | 412 |
|
| 413 | + |
398 | 414 | // Finished executing python code. Cleanup includes filesystem flush and a board reset.
|
399 | 415 | cleanup_after_vm(heap, result.exception);
|
400 | 416 |
|
@@ -474,8 +490,8 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool first_run, bool *simulate_re
|
474 | 490 | while (!skip_wait) {
|
475 | 491 | RUN_BACKGROUND_TASKS;
|
476 | 492 |
|
477 |
| - // If a reload was requested by the supervisor or autoreload, return |
478 |
| - if (result.return_code & PYEXEC_RELOAD) { |
| 493 | + // If a reload was requested by the supervisor or autoreload, return. |
| 494 | + if (reload_requested) { |
479 | 495 | next_code_stickiness_situation |= SUPERVISOR_NEXT_CODE_OPT_STICKY_ON_RELOAD;
|
480 | 496 | // Should the STICKY_ON_SUCCESS and STICKY_ON_ERROR bits be cleared in
|
481 | 497 | // next_code_stickiness_situation? I can see arguments either way, but I'm deciding
|
|
0 commit comments