Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Disentangle machine.sleep() args #511

Open
wants to merge 1 commit into
base: Dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions esp32/mods/modmachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down