Skip to content

Commit 6252680

Browse files
committed
Code style fixes.
1 parent dd6ea93 commit 6252680

File tree

1 file changed

+55
-55
lines changed

1 file changed

+55
-55
lines changed

libraries/esp8266/examples/ForcedLightSleep/ForcedLightSleep.ino

+55-55
Original file line numberDiff line numberDiff line change
@@ -26,77 +26,77 @@
2626
// you can use any GPIO for WAKE_UP_PIN except for D0/GPIO16 as it doesn't support interrupts
2727

2828
void IRAM_ATTR wakeupPinIsr() {
29-
// For edge-triggered IRQ.
30-
detachInterrupt(WAKE_UP_PIN);
31-
schedule_function([]() {
32-
Serial.println("GPIO went from HI to LO");
33-
});
29+
// For edge-triggered IRQ.
30+
detachInterrupt(WAKE_UP_PIN);
31+
schedule_function([]() {
32+
Serial.println("GPIO went from HI to LO");
33+
});
3434
}
3535

3636
void IRAM_ATTR wakeupPinIsrWE() {
37-
// Wakeup IRQs are available as level-triggered only.
38-
detachInterrupt(WAKE_UP_PIN);
39-
schedule_function([]() {
40-
Serial.println("GPIO wakeup IRQ");
41-
});
42-
wakeupPinIsr();
43-
// reattach falling edge IRQ in loop
37+
// Wakeup IRQs are available as level-triggered only.
38+
detachInterrupt(WAKE_UP_PIN);
39+
schedule_function([]() {
40+
Serial.println("GPIO wakeup IRQ");
41+
});
42+
wakeupPinIsr();
43+
// reattach falling edge IRQ in loop
4444
}
4545

4646
void wakeupCallback() {
47-
schedule_function([]() {
48-
Serial.println("wakeup callback was performed");
49-
});
50-
// return to falling edge IRQ, otherwise level-triggered IRQ with wakeup
51-
// would get called unexpectedly while awake.
52-
attachInterrupt(WAKE_UP_PIN, wakeupPinIsr, FALLING);
47+
schedule_function([]() {
48+
Serial.println("wakeup callback was performed");
49+
});
50+
// return to falling edge IRQ, otherwise level-triggered IRQ with wakeup
51+
// would get called unexpectedly while awake.
52+
attachInterrupt(WAKE_UP_PIN, wakeupPinIsr, FALLING);
5353
}
5454

5555
void setup() {
56-
Serial.begin(74880);
57-
while (!Serial)
58-
;
59-
delay(100);
60-
pinMode(LED_BUILTIN, OUTPUT); // activity and status indicator
61-
digitalWrite(LED_BUILTIN, LOW); // turn on the LED
62-
pinMode(WAKE_UP_PIN, INPUT_PULLUP); // polled to advance tests, interrupt for Forced Light Sleep
63-
attachInterrupt(WAKE_UP_PIN, wakeupPinIsr, FALLING);
56+
Serial.begin(74880);
57+
while (!Serial)
58+
;
59+
delay(100);
60+
pinMode(LED_BUILTIN, OUTPUT); // activity and status indicator
61+
digitalWrite(LED_BUILTIN, LOW); // turn on the LED
62+
pinMode(WAKE_UP_PIN, INPUT_PULLUP); // polled to advance tests, interrupt for Forced Light Sleep
63+
attachInterrupt(WAKE_UP_PIN, wakeupPinIsr, FALLING);
6464
}
6565

6666
using oneShotYieldMs = esp8266::polledTimeout::timeoutTemplate<false, esp8266::polledTimeout::YieldPolicy::YieldOrSkip>;
6767
oneShotYieldMs gotoSleep(2000);
6868

6969
void loop() {
70-
if (gotoSleep) {
71-
// No new timers, no delay(), while RAII ForcedLightSleepToken exists.
72-
// Only ONLOW_WE or ONHIGH_WE interrupts work, no edge, that's an SDK or CPU limitation.
73-
// If the GPIO is in the state that will cause a wakeup on attaching the interrupt,
74-
// it cannot trigger a wakeup later, but any sleep duration will be honored.
75-
bool wakeupPinIsHigh = digitalRead(WAKE_UP_PIN);
76-
{
77-
ESPForcedLightSleepToken token(10 * 1000 * 1000, wakeupCallback);
78-
if (token) { // if true, run user code to set up forced light sleep details
79-
// debouncing the wake up pin
80-
delayMicroseconds(5000);
81-
wakeupPinIsHigh &= digitalRead(WAKE_UP_PIN);
82-
delayMicroseconds(5000);
83-
wakeupPinIsHigh &= digitalRead(WAKE_UP_PIN);
84-
// the GPIO might still bounce to LOW after this but before sleep is full engaged,
85-
// disabling wakeup after all
86-
if (wakeupPinIsHigh) {
87-
attachInterrupt(WAKE_UP_PIN, wakeupPinIsrWE, ONLOW_WE);
88-
}
89-
digitalWrite(LED_BUILTIN, HIGH); // turn the LED off so they know the CPU isn't running
90-
if (!wakeupPinIsHigh) token.cancel();
91-
}
92-
// RAII token gets destructed, going to sleep if all went well
93-
}
94-
digitalWrite(LED_BUILTIN, LOW); // turn on the LED
95-
// retry immediately if the GPIO was found not ready for entering sleep
70+
if (gotoSleep) {
71+
// No new timers, no delay(), while RAII ForcedLightSleepToken exists.
72+
// Only ONLOW_WE or ONHIGH_WE interrupts work, no edge, that's an SDK or CPU limitation.
73+
// If the GPIO is in the state that will cause a wakeup on attaching the interrupt,
74+
// it cannot trigger a wakeup later, but any sleep duration will be honored.
75+
bool wakeupPinIsHigh = digitalRead(WAKE_UP_PIN);
76+
{
77+
ESPForcedLightSleepToken token(10 * 1000 * 1000, wakeupCallback);
78+
if (token) { // if true, run user code to set up forced light sleep details
79+
// debouncing the wake up pin
80+
delayMicroseconds(5000);
81+
wakeupPinIsHigh &= digitalRead(WAKE_UP_PIN);
82+
delayMicroseconds(5000);
83+
wakeupPinIsHigh &= digitalRead(WAKE_UP_PIN);
84+
// the GPIO might still bounce to LOW after this but before sleep is full engaged,
85+
// disabling wakeup after all
9686
if (wakeupPinIsHigh) {
97-
gotoSleep.reset();
87+
attachInterrupt(WAKE_UP_PIN, wakeupPinIsrWE, ONLOW_WE);
9888
}
99-
// restore falling edge IRQ
100-
attachInterrupt(WAKE_UP_PIN, wakeupPinIsr, FALLING);
89+
digitalWrite(LED_BUILTIN, HIGH); // turn the LED off so they know the CPU isn't running
90+
if (!wakeupPinIsHigh) token.cancel();
91+
}
92+
// RAII token gets destructed, going to sleep if all went well
10193
}
94+
digitalWrite(LED_BUILTIN, LOW); // turn on the LED
95+
// retry immediately if the GPIO was found not ready for entering sleep
96+
if (wakeupPinIsHigh) {
97+
gotoSleep.reset();
98+
}
99+
// restore falling edge IRQ
100+
attachInterrupt(WAKE_UP_PIN, wakeupPinIsr, FALLING);
101+
}
102102
}

0 commit comments

Comments
 (0)