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;
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 but this type has different options for the result codes.
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?
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();
}