Skip to content

Commit 579940e

Browse files
committed
Rename FunctionalInterrupt to ScheduledInterrupts. This was a review result in another PR.
1 parent 92900d2 commit 579940e

File tree

8 files changed

+150
-153
lines changed

8 files changed

+150
-153
lines changed

libraries/FunctionalInterrupt/examples/Functional/Functional.ino

-71
This file was deleted.

libraries/FunctionalInterrupt/examples/ScheduledFunctional/ScheduledFunctional.ino

-75
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include <ScheduledInterrupts.h>
2+
3+
#ifndef IRAM_ATTR
4+
#define IRAM_ATTR ICACHE_RAM_ATTR
5+
#endif
6+
7+
#if defined(ESP32)
8+
#define BUTTON1 16
9+
#define BUTTON2 17
10+
#elif defined(ARDUINO_ESP8266_WEMOS_D1MINI)
11+
#define BUTTON1 D4
12+
#define BUTTON2 D3
13+
#else
14+
#define BUTTON1 2
15+
#define BUTTON2 0
16+
#endif
17+
18+
class Button {
19+
public:
20+
Button(const uint8_t reqPin) : _PIN(reqPin) {
21+
pinMode(_PIN, INPUT_PULLUP);
22+
attachInterrupt(_PIN, std::bind(&Button::buttonIsr, this), FALLING);
23+
};
24+
~Button() {
25+
detachInterrupt(_PIN);
26+
}
27+
28+
void IRAM_ATTR buttonIsr() {
29+
_numberKeyPresses += 1;
30+
_pressed = true;
31+
}
32+
33+
uint32_t testResetPressed() {
34+
if (_pressed) {
35+
Serial.printf("Button on pin %u has been pressed %u times\n", _PIN, _numberKeyPresses);
36+
_pressed = false;
37+
}
38+
return _numberKeyPresses;
39+
}
40+
41+
private:
42+
const uint8_t _PIN;
43+
volatile uint32_t _numberKeyPresses = 0;
44+
volatile bool _pressed = false;
45+
};
46+
47+
// Pointers and "new" in setup() are used in this example to simply test
48+
// and demonstrate how an ISR object can be constructed and destructed at runtime,
49+
// including the detach of the ISR from the GPIO.
50+
Button* button1 = nullptr;
51+
Button* button2 = nullptr;
52+
53+
void setup() {
54+
Serial.begin(115200);
55+
Serial.println("ScheduledInterrupts test/example");
56+
57+
button1 = new Button(BUTTON1);
58+
button2 = new Button(BUTTON2);
59+
60+
Serial.println("setup() complete");
61+
}
62+
63+
void loop() {
64+
button1->testResetPressed();
65+
if (nullptr != button2 && 10 < button2->testResetPressed()) {
66+
delete button2;
67+
button2 = nullptr;
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include <ScheduledInterrupts.h>
2+
3+
#ifndef IRAM_ATTR
4+
#define IRAM_ATTR ICACHE_RAM_ATTR
5+
#endif
6+
7+
#if defined(ESP32)
8+
#define BUTTON1 16
9+
#define BUTTON2 17
10+
#elif defined(ARDUINO_ESP8266_WEMOS_D1MINI)
11+
#define BUTTON1 D4
12+
#define BUTTON2 D3
13+
#else
14+
#define BUTTON1 2
15+
#define BUTTON2 0
16+
#endif
17+
18+
class Button {
19+
public:
20+
Button(const uint8_t reqPin) : _PIN(reqPin) {
21+
pinMode(_PIN, INPUT_PULLUP);
22+
attachScheduledInterrupt(_PIN, [this](const InterruptInfo & ii) {
23+
Serial.print("Pin ");
24+
Serial.println(ii.pin);
25+
buttonIsr();
26+
}, FALLING); // works on ESP8266
27+
};
28+
~Button() {
29+
detachInterrupt(_PIN);
30+
}
31+
32+
void IRAM_ATTR buttonIsr() {
33+
_numberKeyPresses += 1;
34+
_pressed = true;
35+
}
36+
37+
uint32_t testResetPressed() {
38+
if (_pressed) {
39+
Serial.printf("Button on pin %u has been pressed %u times\n", _PIN, _numberKeyPresses);
40+
_pressed = false;
41+
}
42+
return _numberKeyPresses;
43+
}
44+
45+
private:
46+
const uint8_t _PIN;
47+
volatile uint32_t _numberKeyPresses = 0;
48+
volatile bool _pressed = false;
49+
};
50+
51+
// Pointers and "new" in setup() are used in this example to simply test
52+
// and demonstrate how an ISR object can be constructed and destructed at runtime,
53+
// including the detach of the ISR from the GPIO.
54+
Button* button1;
55+
Button* button2;
56+
57+
58+
void setup() {
59+
Serial.begin(115200);
60+
Serial.println("ScheduledInterrupts test/example");
61+
62+
button1 = new Button(BUTTON1);
63+
button2 = new Button(BUTTON2);
64+
65+
Serial.println("setup() complete");
66+
}
67+
68+
void loop() {
69+
button1->testResetPressed();
70+
if (nullptr != button2 && 10 < button2->testResetPressed()) {
71+
delete button2;
72+
button2 = nullptr;
73+
}
74+
}

libraries/FunctionalInterrupt/library.properties renamed to libraries/ScheduledInterrupts/library.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
name=FunctionalInterrupt
1+
name=ScheduledInterrupts
22
version=1.0
33
author=hreintke <[email protected]>
44
maintainer=hreintke <[email protected]>
5-
sentence=C++ functional and scheduled interrupt handling
5+
sentence=C++ functional, scheduled interrupt handling
66
paragraph=
77
category=Other
88
url=https://github.com/esp8266/Arduino

libraries/FunctionalInterrupt/src/FunctionalInterrupt.cpp renamed to libraries/ScheduledInterrupts/src/ScheduledInterrupts.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include <FunctionalInterrupt.h>
1+
#include "ScheduledInterrupts.h"
22
#include <Schedule.h>
3-
#include "Arduino.h"
3+
#include <Arduino.h>
44

55
// Duplicate typedefs from core_esp8266_wiring_digital_c
66
typedef void (*voidFuncPtr)(void);

libraries/FunctionalInterrupt/src/FunctionalInterrupt.h renamed to libraries/ScheduledInterrupts/src/ScheduledInterrupts.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef FUNCTIONALINTERRUPT_H
2-
#define FUNCTIONALINTERRUPT_H
1+
#ifndef SCHEDULEDINTERRUPTS_H
2+
#define SCHEDULEDINTERRUPTS_H
33

44
#include <stddef.h>
55
#include <stdint.h>
@@ -31,4 +31,4 @@ struct ArgStructure {
3131
void attachInterrupt(uint8_t pin, std::function<void(void)> intRoutine, int mode);
3232
void attachScheduledInterrupt(uint8_t pin, std::function<void(InterruptInfo)> scheduledIntRoutine, int mode);
3333

34-
#endif //FUNCTIONALINTERRUPT_H
34+
#endif // SCHEDULEDINTERRUPTS_H

0 commit comments

Comments
 (0)