From d7106554cf6a3521507e0d1eb702f1c0f74e3ed8 Mon Sep 17 00:00:00 2001 From: chriskoz Date: Sun, 27 Dec 2020 14:33:32 -0800 Subject: [PATCH] Adding logic to sleep indefinitly when sleep_time == 0. This allows users to set the second "resume_wifi_ble" argument while still allowing an indefinite sleep time by setting the first argument to 0. This assumes no one is actually using 0 as a real sleep time for some reason. --- esp32/mods/modmachine.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/esp32/mods/modmachine.c b/esp32/mods/modmachine.c index 28f4f4b9e0..33cfbc0739 100644 --- a/esp32/mods/modmachine.c +++ b/esp32/mods/modmachine.c @@ -427,10 +427,16 @@ STATIC mp_obj_t machine_sleep (uint n_args, const mp_obj_t *arg) { else { int64_t sleep_time = (int64_t)mp_obj_get_int_truncated(arg[0]) * 1000; - struct timeval tv; - gettimeofday(&tv, NULL); - mach_expected_wakeup_time = (int64_t)((tv.tv_sec * 1000000ull) + tv.tv_usec) + sleep_time; - esp_sleep_enable_timer_wakeup(sleep_time); + if (sleep_time == 0) { + mach_expected_wakeup_time = 0; + esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER); + } + else { + struct timeval tv; + gettimeofday(&tv, NULL); + mach_expected_wakeup_time = (int64_t)((tv.tv_sec * 1000000ull) + tv.tv_usec) + sleep_time; + esp_sleep_enable_timer_wakeup(sleep_time); + } if(n_args == 2) { reconnect = (bool)mp_obj_is_true(arg[1]);