-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Return error in class deepSleep() when max sleeptime is exceeded #4936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 16 commits
37b8fa1
c67c733
ed9967d
270da15
0d0dd7b
a86f817
89854fc
fda08a6
d58f66a
609869f
8e270ac
0c3b3e6
d0c16b5
b5b218a
5e5f13e
033d5ef
ac538c2
fada2f6
cebeafc
39a2121
24bb46d
26021c1
a8359f5
364f341
eab0b4d
dfdb0dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,13 @@ extern "C" void esp_yield(); | |
|
||
void EspClass::deepSleep(uint64_t time_us, WakeMode mode) | ||
{ | ||
if (time_us > deepSleepMax()) // we need to prevent the esp8266 from not waking up from deepsleep | ||
{ | ||
time_us = (deepSleepMax() - (round(deepSleepMax() * 5 / 100))); // 5% correction because of inaccurate timekeeping by the esp8266 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for round() here. You're doing integer division already, so this takes the integer division result, promotes it to a double, then promotes deepSleepMax() to a double, subtracts them as doubles, then truncates it all back to an integer. A shorter way which won't cause a program to include the whole floating point libs (if not being included already): I bring this up because there was much howling of pain when we included floating point support in printf with the latest release, as some folks binaries ended up being just a hair too big for OTA... |
||
#ifdef DEBUG_SERIAL | ||
DEBUG_SERIAL.println("Warning: max sleeptime exceeded; sleeptime has been adjusted to max possible sleeptime!"); | ||
#endif | ||
} | ||
system_deep_sleep_set_option(static_cast<int>(mode)); | ||
system_deep_sleep(time_us); | ||
esp_yield(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hate to dogpile here, but if you do find out that
deepSleepMax()
doesn't really work and need to derate by 5% or whatever, please use that # to compare and notdeepSleepMax()
in thisif
condition. Otherwise someone will pass in, say,deepSleepMax() - 1
which won't work but which won't be caught by this check.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it also be wise to increasingly loop the whole function until users's
time_us
is reached ?