parent
1c12e9aaba
commit
b4fc464a4d
42
main.c
42
main.c
|
@ -98,16 +98,21 @@ void reset_mp(void) {
|
||||||
|
|
||||||
mp_obj_list_init(mp_sys_argv, 0);
|
mp_obj_list_init(mp_sys_argv, 0);
|
||||||
}
|
}
|
||||||
|
#define STRING_LIST(...) {__VA_ARGS__, ""}
|
||||||
|
|
||||||
bool maybe_run(const char* filename, pyexec_result_t* exec_result) {
|
bool maybe_run_list(const char ** filenames, pyexec_result_t* exec_result) {
|
||||||
mp_import_stat_t stat = mp_import_stat(filename);
|
|
||||||
if (stat != MP_IMPORT_STAT_FILE) {
|
for (int i = 0; filenames[i] != (char*)""; i++) {
|
||||||
return false;
|
mp_import_stat_t stat = mp_import_stat(filenames[i]);
|
||||||
|
if (stat != MP_IMPORT_STAT_FILE) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
serial_write(filenames[i]);
|
||||||
|
serial_write(MSG_OUTPUT_SUFFIX);
|
||||||
|
pyexec_file(filenames[i], exec_result);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
serial_write(filename);
|
return false;
|
||||||
serial_write(MSG_OUTPUT_SUFFIX);
|
|
||||||
pyexec_file(filename, exec_result);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool start_mp(safe_mode_t safe_mode) {
|
bool start_mp(safe_mode_t safe_mode) {
|
||||||
|
@ -132,10 +137,17 @@ bool start_mp(safe_mode_t safe_mode) {
|
||||||
serial_write(MSG_SAFE_MODE_NO_MAIN);
|
serial_write(MSG_SAFE_MODE_NO_MAIN);
|
||||||
} else {
|
} else {
|
||||||
new_status_color(MAIN_RUNNING);
|
new_status_color(MAIN_RUNNING);
|
||||||
found_main = maybe_run("code.txt", &result) ||
|
|
||||||
maybe_run("code.py", &result) ||
|
const char *supported_filenames[] = STRING_LIST("code.txt", "code.py", "main.py", "main.txt");
|
||||||
maybe_run("main.py", &result) ||
|
const char *double_extension_filenames[] = STRING_LIST("code.txt.py", "code.py.txt", "code.txt.txt","code.py.py",
|
||||||
maybe_run("main.txt", &result);
|
"main.txt.py", "main.py.txt", "main.txt.txt","main.py.py");
|
||||||
|
found_main = maybe_run_list(supported_filenames, &result);
|
||||||
|
if (!found_main){
|
||||||
|
found_main = maybe_run_list(double_extension_filenames, &result);
|
||||||
|
if (found_main) {
|
||||||
|
serial_write(MSG_DOUBLE_FILE_EXTENSION);
|
||||||
|
}
|
||||||
|
}
|
||||||
reset_status_led();
|
reset_status_led();
|
||||||
|
|
||||||
if (result.return_code & PYEXEC_FORCED_EXIT) {
|
if (result.return_code & PYEXEC_FORCED_EXIT) {
|
||||||
|
@ -253,10 +265,8 @@ int __attribute__((used)) main(void) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO(tannewt): Re-add support for flashing boot error output.
|
// TODO(tannewt): Re-add support for flashing boot error output.
|
||||||
bool found_boot = maybe_run("settings.txt", NULL) ||
|
static const char *filenames[] = STRING_LIST("settings.txt", "settings.py", "boot.py", "boot.txt");
|
||||||
maybe_run("settings.py", NULL) ||
|
bool found_boot = maybe_run_list(filenames, NULL);
|
||||||
maybe_run("boot.py", NULL) ||
|
|
||||||
maybe_run("boot.txt", NULL);
|
|
||||||
(void) found_boot;
|
(void) found_boot;
|
||||||
|
|
||||||
#ifdef CIRCUITPY_BOOT_OUTPUT_FILE
|
#ifdef CIRCUITPY_BOOT_OUTPUT_FILE
|
||||||
|
|
|
@ -92,4 +92,8 @@
|
||||||
#define MSG_SOFT_REBOOT "soft reboot"
|
#define MSG_SOFT_REBOOT "soft reboot"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef MSG_DOUBLE_FILE_EXTENSION
|
||||||
|
#define MSG_DOUBLE_FILE_EXTENSION "WARNING: Your code filename has two extensions\r\n"
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // MICROPY_SUPERVISOR_MESSAGES_DEFAULT_H
|
#endif // MICROPY_SUPERVISOR_MESSAGES_DEFAULT_H
|
||||||
|
|
Loading…
Reference in New Issue