Implement sleep on code.py exit

This commit is contained in:
microDev 2020-09-30 11:15:02 +05:30 committed by Scott Shawcroft
parent 930cf14dce
commit 0e444f0de8
No known key found for this signature in database
GPG Key ID: 0DFD512649C052DA
1 changed files with 16 additions and 0 deletions

16
main.c
View File

@ -57,6 +57,9 @@
#include "supervisor/shared/status_leds.h" #include "supervisor/shared/status_leds.h"
#include "supervisor/shared/stack.h" #include "supervisor/shared/stack.h"
#include "supervisor/serial.h" #include "supervisor/serial.h"
#include "supervisor/usb.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "boards/board.h" #include "boards/board.h"
@ -300,6 +303,19 @@ bool run_code_py(safe_mode_t safe_mode) {
} }
} }
for (uint8_t i = 0; i<=100; i++) {
if (!usb_msc_ejected()) {
//Go into light sleep
break;
}
mp_hal_delay_ms(10);
}
if (usb_msc_ejected()) {
//Go into deep sleep
common_hal_mcu_deep_sleep();
}
// Display a different completion message if the user has no USB attached (cannot save files) // Display a different completion message if the user has no USB attached (cannot save files)
if (!serial_connected_at_start) { if (!serial_connected_at_start) {
serial_write_compressed(translate("\nCode done running. Waiting for reload.\n")); serial_write_compressed(translate("\nCode done running. Waiting for reload.\n"));