-
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 3 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 |
---|---|---|
|
@@ -107,11 +107,22 @@ void EspClass::wdtFeed(void) | |
|
||
extern "C" void esp_yield(); | ||
|
||
void EspClass::deepSleep(uint64_t time_us, WakeMode mode) | ||
bool EspClass::deepSleep(uint64_t time_us, WakeMode mode) | ||
{ | ||
system_deep_sleep_set_option(static_cast<int>(mode)); | ||
system_deep_sleep(time_us); | ||
esp_yield(); | ||
if (time_us > deepSleepMax()) | ||
{ | ||
#ifdef DEBUG_SERIAL | ||
DEBUG_SERIAL.println("Error: max sleeptime exceeded"); | ||
#endif | ||
return 0; // error: max sleeptime exceeded | ||
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. return type is bool, but returned value is int => return false here 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. You're right. |
||
} | ||
else | ||
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. Please remove else and braces. |
||
{ | ||
system_deep_sleep_set_option(static_cast<int>(mode)); | ||
system_deep_sleep(time_us); | ||
esp_yield(); | ||
return 1; // never gets called | ||
} | ||
} | ||
|
||
//this calculation was taken verbatim from the SDK api reference for SDK 2.1.0. | ||
|
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 not be more useful (and help fix peoples code which is broken already) if, instead of possibly printing an error and
return false;
, you just printed a warning and adjusted the time down todeepSleepMax()
?Existing code will not expect to ever get a return value and potentially go off into lala-land, since this was a
void
."Be conservative in what you do, be liberal in what you accept from others."
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.
@earlephilhower Point taken. I'll make some changes to the code.