Factor out code.py status messages

This commit is contained in:
microDev 2020-10-07 23:53:08 +05:30
parent d01b9ce933
commit 8487a51995
No known key found for this signature in database
GPG Key ID: 2C0867BE60967730

33
main.c
View File

@ -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");