Skip to content

Commit 0e444f0

Browse files
microdev1tannewt
authored andcommitted
Implement sleep on code.py exit
1 parent 930cf14 commit 0e444f0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

main.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
#include "supervisor/shared/status_leds.h"
5858
#include "supervisor/shared/stack.h"
5959
#include "supervisor/serial.h"
60+
#include "supervisor/usb.h"
61+
62+
#include "shared-bindings/microcontroller/__init__.h"
6063

6164
#include "boards/board.h"
6265

@@ -300,6 +303,19 @@ bool run_code_py(safe_mode_t safe_mode) {
300303
}
301304
}
302305

306+
for (uint8_t i = 0; i<=100; i++) {
307+
if (!usb_msc_ejected()) {
308+
//Go into light sleep
309+
break;
310+
}
311+
mp_hal_delay_ms(10);
312+
}
313+
314+
if (usb_msc_ejected()) {
315+
//Go into deep sleep
316+
common_hal_mcu_deep_sleep();
317+
}
318+
303319
// Display a different completion message if the user has no USB attached (cannot save files)
304320
if (!serial_connected_at_start) {
305321
serial_write_compressed(translate("\nCode done running. Waiting for reload.\n"));

0 commit comments

Comments
 (0)