Sleep 2.0 Question: SystemSleepResult or SleepResult

Newer definitions are in an enum class like:

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.

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();
}
1 Like