SystemSleepResult result, How to use in setup

Im using the new Sleep2.0 and am wondering how I can use the SystemSleepResult in the setup function at the start of the firmware.
see below

Using the below code, and when woken up the SystemSleepResult should return GPIO but it only responds to UNKNOWN.

#include "Particle.h"

SystemSleepConfiguration config;
SystemSleepResult sleepResult;

SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(MANUAL);
void changeRGBColor(uint8_t brightness, uint8_t red, uint8_t green, uint8_t blue, uint16_t blinkCycle) ;

void setup() {
RGB.control(true);

if (sleepResult.wakeupReason() == SystemSleepWakeupReason::BY_GPIO) {
        changeRGBColor(255, 0, 0, 255, 0);
        delay(3000);
        changeRGBColor(255, 255, 255, 0, 0);
    }
}

void loop() {
config.mode(SystemSleepMode::HIBERNATE)
      .gpio(D2, RISING);
sleepResult = System.sleep(config);
}

//Control LED COLOR
void changeRGBColor(uint8_t brightness, uint8_t red, uint8_t green, uint8_t blue, uint16_t blinkCycle) {
    static uint32_t prevBlinkMillis = 0;
    static bool ledOn = true;

    RGB.brightness(brightness);
    if (blinkCycle == 0) {
        RGB.color(red, green, blue);
        return;
    }

    if (millis() - prevBlinkMillis >= blinkCycle) {
        if (ledOn) {
            RGB.color(red, green, blue);
            ledOn = false;
        } else {
            RGB.color(0, 0, 0);
            ledOn = true;
        }
        prevBlinkMillis = millis();
    }
}

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