It could look like this:
int wakeInSeconds = secondsUntilNextEvent(); // Figure out how long to sleep
config.mode(SystemSleepMode::ULTRA_LOW_POWER)
.gpio(D2, FALLING)
.duration(wakeInSeconds* 1000L); // Set seconds until wake
// Ready to sleep
SystemSleepResult result = System.sleep(config); // Device sleeps here
if (result.wakeupPin() == D2) { // Woke by pin interrupt
// pin wake code here
}
else { // Woke by time
// time wake code here
}
Hope this helps.
Chip