-
Notifications
You must be signed in to change notification settings - Fork 7.6k
General examples updates #7727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
General examples updates #7727
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e1f49f8
Remove inline code comments for the struct description
PilnyTomas 714e919
Renamed ESPNow examples
PilnyTomas 3d8348c
Changed example from C++ class to C struct
PilnyTomas 1cad7c1
Updated MultiHomedServers
PilnyTomas 9eae97b
Merge branch 'espressif:master' into example_update
PilnyTomas fc3fe6a
Updated BT Serial examples
PilnyTomas 420f290
Added short overview of exaples - missing Enterprise
PilnyTomas 372cedc
Added draft of Enterprise header note
PilnyTomas 75e4d81
Fixed note in README
PilnyTomas 4f2b58f
Fixed compilation error
PilnyTomas a2dd31a
Changed FunctionalInterrupt example
PilnyTomas ae99c71
Fixes
PilnyTomas 387e562
Returned FunctionalInterrupts to original state + added modified vers…
PilnyTomas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 56 additions & 27 deletions
83
libraries/BluetoothSerial/examples/SerialToSerialBTM/SerialToSerialBTM.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
58 changes: 25 additions & 33 deletions
58
libraries/ESP32/examples/GPIO/FunctionalInterrupt/FunctionalInterrupt.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,39 @@ | ||
#include <Arduino.h> | ||
#include <FunctionalInterrupt.h> | ||
|
||
#define BUTTON1 16 | ||
#define BUTTON2 17 | ||
|
||
class Button | ||
{ | ||
public: | ||
Button(uint8_t reqPin) : PIN(reqPin){ | ||
pinMode(PIN, INPUT_PULLUP); | ||
attachInterrupt(PIN, std::bind(&Button::isr,this), FALLING); | ||
}; | ||
~Button() { | ||
detachInterrupt(PIN); | ||
} | ||
|
||
void ARDUINO_ISR_ATTR isr() { | ||
numberKeyPresses += 1; | ||
pressed = true; | ||
} | ||
|
||
void checkPressed() { | ||
if (pressed) { | ||
Serial.printf("Button on pin %u has been pressed %u times\n", PIN, numberKeyPresses); | ||
pressed = false; | ||
} | ||
} | ||
|
||
private: | ||
const uint8_t PIN; | ||
volatile uint32_t numberKeyPresses; | ||
volatile bool pressed; | ||
struct Button { | ||
uint8_t PIN; | ||
volatile uint32_t numberKeyPresses; | ||
volatile int pressed; | ||
}; | ||
|
||
Button button1(BUTTON1); | ||
Button button2(BUTTON2); | ||
void isr(void* param) { | ||
struct Button *button = (struct Button*) param; | ||
button->numberKeyPresses += 1; | ||
button->pressed = 1; | ||
} | ||
|
||
void checkPressed(struct Button* button) { | ||
if(button->pressed) { | ||
Serial.printf("Button on pin %u has been pressed %u times\n", button->PIN, button->numberKeyPresses); | ||
button->pressed = 0; | ||
} | ||
} | ||
|
||
struct Button button1 = {BUTTON1, 0, 0}; | ||
struct Button button2 = {BUTTON2, 0, 0}; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
Serial.begin(115200); | ||
pinMode(button1.PIN, INPUT_PULLUP); | ||
pinMode(button2.PIN, INPUT_PULLUP); | ||
attachInterruptArg(button1.PIN, isr, (void*)&button1, FALLING); | ||
attachInterruptArg(button2.PIN, isr, (void*)&button2, FALLING); | ||
} | ||
|
||
void loop() { | ||
button1.checkPressed(); | ||
button2.checkPressed(); | ||
checkPressed(&button1); | ||
checkPressed(&button2); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While your changes provide simpler code, the original example shows how to attach an interrupt to a class method (and that is often asked), so I suggest to keep the old way and use
class
instead ofstruct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pedrominatel could you please explain why we went from c++ to c?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was just a matter of getting consistency across many examples in C, and not in C++.
I would prefer to keep the
FunctionalInterrupt
example as is and add a new one using a simpler code, as you already did.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we agree that the example with
class Button
should stay and a new one withstruct Button
should be added?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Is that ok for you @PilnyTomas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PilnyTomas this is still left to be done