Skip to content

Commit d2ec37c

Browse files
committed
Always apply astyle to examples.
1 parent dea2382 commit d2ec37c

File tree

5 files changed

+89
-60
lines changed

5 files changed

+89
-60
lines changed

libraries/ESP32/examples/GPIO/FunctionalInterrupt/FunctionalInterrupt.ino

+7-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ class Button {
1818
Button(uint8_t reqPin) : PIN(reqPin) {
1919
pinMode(PIN, INPUT_PULLUP);
2020
// Arduino C API:
21-
attachInterruptArg(PIN, [](void* self) { static_cast<Button*>(self)->isr(); }, this, FALLING); // works on ESP32; fails on ESP8266: "ISR not in IRAM"
21+
attachInterruptArg(PIN, [](void* self) {
22+
static_cast<Button*>(self)->isr();
23+
}, this, FALLING); // works on ESP32; fails on ESP8266: "ISR not in IRAM"
2224
//attachInterruptArg(PIN, reinterpret_cast<void(*)(void*)>(&isr_static), this, FALLING); // works on ESP32; works on ESP8266
2325
// FunctionalInterrupts API:
2426
//attachInterrupt(PIN, [this]() { isr(); }, FALLING); // works on ESP32; works on ESP8266
@@ -44,7 +46,7 @@ class Button {
4446
static void IRAM_ATTR isr_static(Button* const self)
4547
#endif
4648
{
47-
self->isr();
49+
self->isr();
4850
}
4951

5052
void checkPressed() {
@@ -66,7 +68,9 @@ Button* button2;
6668

6769
void setup() {
6870
Serial.begin(115200);
69-
schedule_function([]() { Serial.println("Scheduled function"); });
71+
schedule_function([]() {
72+
Serial.println("Scheduled function");
73+
});
7074
Serial.println("FunctionalInterrupt test/example");
7175

7276
button1 = new Button(BUTTON1);

libraries/ESP32/examples/GPIO/FunctionalInterrupt/FunctionalInterrupts.cpp

+49-37
Original file line numberDiff line numberDiff line change
@@ -4,65 +4,77 @@
44

55
void ICACHE_RAM_ATTR interruptFunctional(void* arg)
66
{
7-
ArgStructure* localArg = static_cast<ArgStructure*>(arg);
8-
if (localArg->interruptInfo)
9-
{
10-
localArg->interruptInfo->value = digitalRead(localArg->interruptInfo->pin);
11-
localArg->interruptInfo->micro = micros();
12-
}
13-
if (localArg->functionInfo->reqScheduledFunction)
14-
{
15-
schedule_function(
16-
[reqScheduledFunction = localArg->functionInfo->reqScheduledFunction,
17-
interruptInfo = *localArg->interruptInfo]() { reqScheduledFunction(interruptInfo); });
18-
}
19-
else if (localArg->functionInfo->reqFunction)
20-
{
21-
localArg->functionInfo->reqFunction();
22-
}
7+
ArgStructure* localArg = static_cast<ArgStructure*>(arg);
8+
if (localArg->interruptInfo)
9+
{
10+
localArg->interruptInfo->value = digitalRead(localArg->interruptInfo->pin);
11+
localArg->interruptInfo->micro = micros();
12+
}
13+
if (localArg->functionInfo->reqScheduledFunction)
14+
{
15+
schedule_function(
16+
[reqScheduledFunction = localArg->functionInfo->reqScheduledFunction,
17+
interruptInfo = *localArg->interruptInfo]()
18+
{
19+
reqScheduledFunction(interruptInfo);
20+
});
21+
}
22+
else if (localArg->functionInfo->reqFunction)
23+
{
24+
localArg->functionInfo->reqFunction();
25+
}
2326
}
2427

2528
void cleanupFunctional(void* arg)
2629
{
27-
ArgStructure* localArg = static_cast<ArgStructure*>(arg);
28-
delete localArg;
30+
ArgStructure* localArg = static_cast<ArgStructure*>(arg);
31+
delete localArg;
2932
}
3033

3134
void attachInterrupt(uint8_t pin, std::function<void(void)> intRoutine, int mode)
3235
{
33-
// use the local interrupt routine which takes the ArgStructure as argument
36+
// use the local interrupt routine which takes the ArgStructure as argument
3437

35-
void* localArg = detachInterruptArg(pin);
36-
if (localArg) cleanupFunctional(localArg);
38+
void* localArg = detachInterruptArg(pin);
39+
if (localArg)
40+
{
41+
cleanupFunctional(localArg);
42+
}
3743

38-
FunctionInfo* fi = new FunctionInfo;
39-
fi->reqFunction = intRoutine;
44+
FunctionInfo* fi = new FunctionInfo;
45+
fi->reqFunction = intRoutine;
4046

41-
ArgStructure* as = new ArgStructure;
42-
as->functionInfo = fi;
47+
ArgStructure* as = new ArgStructure;
48+
as->functionInfo = fi;
4349

44-
attachInterruptArg (pin, interruptFunctional, as, mode);
50+
attachInterruptArg(pin, interruptFunctional, as, mode);
4551
}
4652

4753
void attachScheduledInterrupt(uint8_t pin, std::function<void(InterruptInfo)> scheduledIntRoutine, int mode)
4854
{
49-
void* localArg = detachInterruptArg(pin);
50-
if (localArg) cleanupFunctional(localArg);
55+
void* localArg = detachInterruptArg(pin);
56+
if (localArg)
57+
{
58+
cleanupFunctional(localArg);
59+
}
5160

52-
InterruptInfo* ii = new InterruptInfo(pin);
61+
InterruptInfo* ii = new InterruptInfo(pin);
5362

54-
FunctionInfo* fi = new FunctionInfo;
55-
fi->reqScheduledFunction = scheduledIntRoutine;
63+
FunctionInfo* fi = new FunctionInfo;
64+
fi->reqScheduledFunction = scheduledIntRoutine;
5665

57-
ArgStructure* as = new ArgStructure;
58-
as->interruptInfo = ii;
59-
as->functionInfo = fi;
66+
ArgStructure* as = new ArgStructure;
67+
as->interruptInfo = ii;
68+
as->functionInfo = fi;
6069

61-
attachInterruptArg(pin, interruptFunctional, as, mode);
70+
attachInterruptArg(pin, interruptFunctional, as, mode);
6271
}
6372

6473
void detachFunctionalInterrupt(uint8_t pin)
6574
{
66-
void* localArg = detachInterruptArg(pin);
67-
if (localArg) cleanupFunctional(localArg);
75+
void* localArg = detachInterruptArg(pin);
76+
if (localArg)
77+
{
78+
cleanupFunctional(localArg);
79+
}
6880
}

libraries/ESP32/examples/GPIO/FunctionalInterrupt/FunctionalInterrupts.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@
55

66
// Structures for communication
77

8-
struct InterruptInfo {
8+
struct InterruptInfo
9+
{
910
InterruptInfo(uint8_t _pin) : pin(_pin) {}
1011
const uint8_t pin;
1112
uint8_t value = 0;
1213
uint32_t micro = 0;
1314
};
1415

15-
struct FunctionInfo {
16+
struct FunctionInfo
17+
{
1618
std::function<void(void)> reqFunction = nullptr;
1719
std::function<void(InterruptInfo)> reqScheduledFunction = nullptr;
1820
};
1921

20-
struct ArgStructure {
22+
struct ArgStructure
23+
{
2124
~ArgStructure()
2225
{
2326
delete functionInfo;

libraries/ESP32/examples/GPIO/FunctionalInterrupt/Schedule.cpp

+23-13
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@ static scheduled_fn_t* sLastUnused = 0;
1414

1515
static int sCount = 0;
1616

17-
static scheduled_fn_t* get_fn() {
17+
static scheduled_fn_t* get_fn()
18+
{
1819
scheduled_fn_t* result = NULL;
1920
// try to get an item from unused items list
20-
if (sFirstUnused) {
21+
if (sFirstUnused)
22+
{
2123
result = sFirstUnused;
2224
sFirstUnused = result->mNext;
23-
if (sFirstUnused == NULL) {
25+
if (sFirstUnused == NULL)
26+
{
2427
sLastUnused = NULL;
2528
}
2629
}
2730
// if no unused items, and count not too high, allocate a new one
28-
else if (sCount != SCHEDULED_FN_MAX_COUNT) {
31+
else if (sCount != SCHEDULED_FN_MAX_COUNT)
32+
{
2933
result = new scheduled_fn_t;
3034
result->mNext = NULL;
3135
++sCount;
@@ -35,10 +39,12 @@ static scheduled_fn_t* get_fn() {
3539

3640
static void recycle_fn(scheduled_fn_t* fn)
3741
{
38-
if (!sLastUnused) {
42+
if (!sLastUnused)
43+
{
3944
sFirstUnused = fn;
4045
}
41-
else {
46+
else
47+
{
4248
sLastUnused->mNext = fn;
4349
}
4450
fn->mNext = NULL;
@@ -48,15 +54,18 @@ static void recycle_fn(scheduled_fn_t* fn)
4854
bool schedule_function(std::function<void(void)> fn)
4955
{
5056
scheduled_fn_t* item = get_fn();
51-
if (!item) {
57+
if (!item)
58+
{
5259
return false;
5360
}
5461
item->mFunc = fn;
5562
item->mNext = NULL;
56-
if (!sFirst) {
63+
if (!sFirst)
64+
{
5765
sFirst = item;
5866
}
59-
else {
67+
else
68+
{
6069
sLast->mNext = item;
6170
}
6271
sLast = item;
@@ -65,10 +74,11 @@ bool schedule_function(std::function<void(void)> fn)
6574

6675
void run_scheduled_functions()
6776
{
68-
scheduled_fn_t* rFirst = sFirst;
69-
sFirst = NULL;
70-
sLast = NULL;
71-
while (rFirst) {
77+
scheduled_fn_t* rFirst = sFirst;
78+
sFirst = NULL;
79+
sLast = NULL;
80+
while (rFirst)
81+
{
7282
scheduled_fn_t* item = rFirst;
7383
rFirst = item->mNext;
7484
item->mFunc();

libraries/ESP32/examples/GPIO/FunctionalInterrupt/Schedule.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
#define SCHEDULED_FN_MAX_COUNT 32
77
#define SCHEDULED_FN_INITIAL_COUNT 4
88

9-
// Warning
10-
// This API is not considered stable.
9+
// Warning
10+
// This API is not considered stable.
1111
// Function signatures will change.
1212
// You have been warned.
1313

14-
// Run given function next time `loop` function returns,
14+
// Run given function next time `loop` function returns,
1515
// or `run_scheduled_functions` is called.
1616
// Use std::bind to pass arguments to a function, or call a class member function.
1717
// Note: there is no mechanism for cancelling scheduled functions.
1818
// Keep that in mind when binding functions to objects which may have short lifetime.
1919
// Returns false if the number of scheduled functions exceeds SCHEDULED_FN_MAX_COUNT.
2020
bool schedule_function(std::function<void(void)> fn);
2121

22-
// Run all scheduled functions.
22+
// Run all scheduled functions.
2323
// Use this function if your are not using `loop`, or `loop` does not return
2424
// on a regular basis.
2525
void run_scheduled_functions();

0 commit comments

Comments
 (0)