# Sleep 2.0 Question: SystemSleepResult or SleepResult

**URL:** https://community.particle.io/t/sleep-2-0-question-systemsleepresult-or-sleepresult/55676
**Category:** Firmware
**Created:** [April 14, 2020, 1:29pm UTC](https://community.particle.io/t/sleep-2-0-question-systemsleepresult-or-sleepresult/55676 "2020-04-14T13:29:53Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![chipmc](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/chipmc/32/15905_2.png) [@chipmc](https://community.particle.io/u/chipmc)
#### Post date: [April 14, 2020, 1:29pm UTC](https://community.particle.io/t/sleep-2-0-question-systemsleepresult-or-sleepresult/55676/1 "2020-04-14T13:29:53Z")

</div>

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](https://docs.particle.io/reference/device-os/firmware/boron/#systemsleepconfiguration-mode-) in the new 1.5.0 section on sleep:

```auto
SystemSleepConfiguration config;
config.mode(SystemSleepMode::STOP)
      .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](https://docs.particle.io/reference/device-os/firmware/boron/#sleepresult-) but this type has different options for the result codes.  
 ![Screen Shot 2020-04-14 at 9.27.18 AM](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/a/3/a3cc3c527dd18257a332787da9a5df1d82134535.png)

![Screen Shot 2020-04-14 at 9.27.36 AM](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/d/7/d7950815b46885f0cd02348c94dfed8e503c794a.png)

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?

Thanks,

Chip

---

<div class="post-metadata">

### Author: ![no1089](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/no1089/32/24051_2.png) [@no1089](https://community.particle.io/u/no1089)
#### Post date: [April 14, 2020, 1:59pm UTC](https://community.particle.io/t/sleep-2-0-question-systemsleepresult-or-sleepresult/55676/2 "2020-04-14T13:59:34Z")

</div>

I’m guessing @rickkas7 would know best 🙂

---

<div class="post-metadata">

### Author: ![armor](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/armor/32/18398_2.png) [@armor](https://community.particle.io/u/armor)
#### Post date: [April 14, 2020, 3:10pm UTC](https://community.particle.io/t/sleep-2-0-question-systemsleepresult-or-sleepresult/55676/3 "2020-04-14T15:10:33Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)
#### Post date: [April 14, 2020, 3:17pm UTC](https://community.particle.io/t/sleep-2-0-question-systemsleepresult-or-sleepresult/55676/4 "2020-04-14T15:17:26Z")

</div>

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

[https://docs.particle.io/reference/device-os/firmware/#systemsleepresult-class](https://docs.particle.io/reference/device-os/firmware/#systemsleepresult-class)

---

<div class="post-metadata">

### Author: ![armor](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/armor/32/18398_2.png) [@armor](https://community.particle.io/u/armor)
#### Post date: [April 14, 2020, 3:22pm UTC](https://community.particle.io/t/sleep-2-0-question-systemsleepresult-or-sleepresult/55676/5 "2020-04-14T15:22:52Z")

</div>

Is there a reason for the enumerator to be in this class SystemSleepWakeupReason::BY\_GPIO rather than as before WAKEUP\_REASON\_PIN?

---

<div class="post-metadata">

### Author: ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)
#### Post date: [April 14, 2020, 3:32pm UTC](https://community.particle.io/t/sleep-2-0-question-systemsleepresult-or-sleepresult/55676/6 "2020-04-14T15:32:25Z")

</div>

Newer definitions are in an `enum class` like:

```auto
enum class SystemSleepWakeupReason: uint16_t {
    UNKNOWN = HAL_WAKEUP_SOURCE_TYPE_UNKNOWN,
    BY_GPIO = HAL_WAKEUP_SOURCE_TYPE_GPIO,
    BY_ADC = HAL_WAKEUP_SOURCE_TYPE_ADC, 

```

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.

```cpp
SystemSleepConfiguration config;
config.mode(SystemSleepMode::STOP)
      .gpio(D2, FALLING)
      .duration(30s);
SystemSleepResult result = System.sleep(config);
if (result.wakeupReason() == SystemSleepWakeupReason::BY_GPIO) {
  // Waken by pin 
  pin_t whichPin = result.wakeupPin();
}

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/6/4/64635adccc35238caa19e9b553ec3e98b163d026.png) [@system](https://community.particle.io/u/system)
#### Post date: [October 14, 2020, 3:32am UTC](https://community.particle.io/t/sleep-2-0-question-systemsleepresult-or-sleepresult/55676/7 "2020-10-14T03:32:27Z")

</div>

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