From 8487a51995d708b6ade7f714600b37ee6e7d4a5a Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Wed, 7 Oct 2020 23:53:08 +0530 Subject: [PATCH] Factor out code.py status messages --- main.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/main.c b/main.c index 1f7352b0e9..b43b3b8c80 100755 --- a/main.c +++ b/main.c @@ -242,16 +242,24 @@ void cleanup_after_vm(supervisor_allocation* heap) { reset_status_led(); } +void print_code_py_status_message(safe_mode_t safe_mode) { + if (autoreload_is_enabled()) { + serial_write_compressed(translate("Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.\n")); + } else { + serial_write_compressed(translate("Auto-reload is off.\n")); + } + if (safe_mode != NO_SAFE_MODE) { + serial_write_compressed(translate("Running in safe mode! ")); + serial_write_compressed(translate("Not running saved code.\n")); + } +} + bool run_code_py(safe_mode_t safe_mode) { bool serial_connected_at_start = serial_connected(); #if CIRCUITPY_AUTORELOAD_DELAY_MS > 0 if (serial_connected_at_start) { serial_write("\n"); - if (autoreload_is_enabled()) { - serial_write_compressed(translate("Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.\n")); - } else { - serial_write_compressed(translate("Auto-reload is off.\n")); - } + print_code_py_status_message(safe_mode); } #endif @@ -263,10 +271,7 @@ bool run_code_py(safe_mode_t safe_mode) { bool found_main = false; - if (safe_mode != NO_SAFE_MODE) { - serial_write_compressed(translate("Running in safe mode! ")); - serial_write_compressed(translate("Not running saved code.\n")); - } else { + if (safe_mode == NO_SAFE_MODE) { new_status_color(MAIN_RUNNING); static const char * const supported_filenames[] = STRING_LIST("code.txt", "code.py", "main.py", "main.txt"); @@ -320,15 +325,7 @@ bool run_code_py(safe_mode_t safe_mode) { if (!serial_connected_before_animation && serial_connected()) { if (!serial_connected_at_start) { - if (autoreload_is_enabled()) { - serial_write_compressed(translate("Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.\n")); - } else { - serial_write_compressed(translate("Auto-reload is off.\n")); - } - if (safe_mode != NO_SAFE_MODE) { - serial_write_compressed(translate("Running in safe mode! ")); - serial_write_compressed(translate("Not running saved code.\n")); - } + print_code_py_status_message(safe_mode); } print_safe_mode_message(safe_mode); serial_write("\n");