Skip to content

Commit 22feda1

Browse files
authored
Merge pull request #4708 from hierophect/supervisor-run-reason
Remove overwrite of run_reason in main
2 parents 3e1c354 + f38f5db commit 22feda1

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

main.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,17 +334,19 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
334334
bool fake_sleeping = false;
335335
while (true) {
336336
RUN_BACKGROUND_TASKS;
337+
338+
// If a reload was requested by the supervisor or autoreload, return
337339
if (reload_requested) {
338340
#if CIRCUITPY_ALARM
339341
if (fake_sleeping) {
340342
board_init();
341343
}
342344
#endif
343-
supervisor_set_run_reason(RUN_REASON_AUTO_RELOAD);
344345
reload_requested = false;
345346
return true;
346347
}
347348

349+
// If interrupted by keyboard, return
348350
if (serial_connected() && serial_bytes_available()) {
349351
#if CIRCUITPY_ALARM
350352
if (fake_sleeping) {
@@ -371,6 +373,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
371373
}
372374
#endif
373375

376+
// If messages haven't been printed yet, print them
374377
if (!printed_press_any_key && serial_connected()) {
375378
if (!serial_connected_at_start) {
376379
print_code_py_status_message(safe_mode);
@@ -597,6 +600,7 @@ int __attribute__((used)) main(void) {
597600
for (;;) {
598601
if (!skip_repl) {
599602
exit_code = run_repl();
603+
supervisor_set_run_reason(RUN_REASON_REPL_RELOAD);
600604
}
601605
if (exit_code == PYEXEC_FORCED_EXIT) {
602606
if (!first_run) {

supervisor/shared/autoreload.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "py/reload.h"
3131
#include "supervisor/shared/tick.h"
3232

33+
#include "shared-bindings/supervisor/Runtime.h"
34+
3335
static volatile uint32_t autoreload_delay_ms = 0;
3436
static bool autoreload_enabled = false;
3537
static bool autoreload_suspended = false;
@@ -44,6 +46,7 @@ inline void autoreload_tick() {
4446
!autoreload_suspended && !reload_requested) {
4547
mp_raise_reload_exception();
4648
reload_requested = true;
49+
supervisor_set_run_reason(RUN_REASON_AUTO_RELOAD);
4750
supervisor_disable_tick();
4851
}
4952
autoreload_delay_ms--;
@@ -91,4 +94,5 @@ void autoreload_now() {
9194
}
9295
mp_raise_reload_exception();
9396
reload_requested = true;
97+
supervisor_set_run_reason(RUN_REASON_AUTO_RELOAD);
9498
}

0 commit comments

Comments
 (0)