Sleep 2.0 Question: SystemSleepResult or SleepResult

I am struggling a bit with the documentation around Sleep 2.0 sleep results.

I see in the new Sleep API, there is a new result type called SystemSleepResult and there is an example in the new 1.5.0 section on sleep:

SystemSleepConfiguration config;
      .gpio(D2, RISING);
SystemSleepResult result = System.sleep(config);

But, there does not seem to be any documentation on the SystemSleepResult type in the documentation. There is documentation on SleepResult but this type has different options for the result codes.
Screen Shot 2020-04-14 at 9.27.18 AM

Screen Shot 2020-04-14 at 9.27.36 AM

So, which one should we be using going forward? And, if the answer is SystemSleepResult, where are some definitions of the responses and how to use them in the documentation? Am I missing something?



1 Like

I’m guessing @rickkas7 would know best :slight_smile:

I would hazard a guess

SystemSleepResult result = System.sleep(config); then
if (result.wakeupReason() == WAKEUP_REASON_RTC) { setLowPowerMode(“0”);}

Workbench should allow you to drill into the definitions? Surely more accurate than documentation!

1 Like

You should use SystemSleepResult as it’s a superset of the older SleepResult class. It’s also now documented:

1 Like

Is there a reason for the enumerator to be in this class SystemSleepWakeupReason::BY_GPIO rather than as before WAKEUP_REASON_PIN?

Newer definitions are in an enum class like:

enum class SystemSleepWakeupReason: uint16_t {

The reason is that otherwise BY_GPIO would be reserved across all enumerations, not just this one. By using an enum class we reduce the number of globally scoped names.

It’s more verbose, but has the advantage of also making it easy to see all of the possible values for SystemSleepWakeupReason by auto-completion.

SystemSleepConfiguration config;
      .gpio(D2, FALLING)
SystemSleepResult result = System.sleep(config);
if (result.wakeupReason() == SystemSleepWakeupReason::BY_GPIO) {
  // Waken by pin 
  pin_t whichPin = result.wakeupPin();
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.