-
-
Notifications
You must be signed in to change notification settings - Fork 345
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
Make Delegators Compatible with Lambdas and std::function - issue 1337 #1361
Make Delegators Compatible with Lambdas and std::function - issue 1337 #1361
Conversation
``` Timer& IRAM_ATTR initializeMs(uint32_t milliseconds, TimerDelegateStdFunction delegateFunction = nullptr); // Init in Milliseconds. ``` For the moment the others can stay. This allows for easier comment and review. The sample code Basic_Delegate has example calls for old style delegates, plainOldOrdinaryFunctions, memberFunctions and lamdas. The defines for min and max in SmingCore.h have been moved into ArduinoCompat.h This allows the use of the <algorithm> header which has std::max and std::min.
Sming/Services/DateTime/DateTime.cpp
Outdated
@@ -8,7 +8,7 @@ | |||
*/ | |||
|
|||
#include "DateTime.h" | |||
#include <Arduino.h> | |||
//#include <Arduino.h> |
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.
Please, remove the commented line.
Sming/SmingCore/Timer.h
Outdated
@@ -59,16 +60,31 @@ class Timer | |||
* @param milliseconds Duration of timer in milliseconds | |||
* @param delegateFunction Function to call when timer triggers | |||
* @note Delegate callback method | |||
*/ | |||
* @Deprecated Use initializeMs(xx, TimerDelegateStdFunction); instead. |
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.
Fix the indentation to this line and the one below. Use lowercase D: ex: @deprecated ...
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.
Timer.h has spaces for indentation, while Timer.cpp has tabs, - what is the standard?
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.
Actually only the comments in Timer.h use spaces - not very consistent!
Sming/SmingCore/Timer.h
Outdated
Timer& IRAM_ATTR initializeMs(uint32_t milliseconds, TimerDelegate delegateFunction = NULL); // Init in Milliseconds. | ||
|
||
/** @brief Initialise microsecond timer | ||
* @param microseconds Duration of timer in milliseconds | ||
* @param delegateFunction Function to call when timer triggers | ||
* @note Delegate callback method | ||
* @Deprecated Use initializeMs(xx, TimerDelegateStdFunction); instead. |
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.
Fix indentation and lower case D
Sming/SmingCore/Timer.h
Outdated
@@ -142,6 +163,7 @@ class Timer | |||
uint64_t interval = 0; | |||
InterruptCallback callback = nullptr; | |||
TimerDelegate delegate_func = nullptr; | |||
TimerDelegateStdFunction delegate_stdfunc = nullptr; |
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.
Fix indentation...
@@ -9,19 +15,85 @@ public : | |||
pinMode(ledPin, OUTPUT); | |||
}; | |||
bool setTimer(int reqInterval) { | |||
if (reqInterval <= 0) return false; | |||
if (reqInterval <= 0) |
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.
Add curly braces around the if condition.
myLed2.setTimer(500); | ||
myLed2.blink(true); | ||
myLed2.blinkOldDelegate(true); | ||
|
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.
Be consistent with the line spacing between the different groups of commands.
@@ -25,5 +25,15 @@ void yield(); | |||
} | |||
#endif | |||
|
|||
#define abs(x) ((x)>0?(x):-(x)) |
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.
Just for my understanding: Why you add those definitions here and remove them from WConstants.h
? Why not just leave them in WConstants.h
?
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 tried them there, but I had trouble getting things to compile. It would be good to get rid of those macros altogether but I understand we need to support the older style Arduino code. Happy to see them move to a better place.
@@ -9,19 +15,87 @@ public : | |||
pinMode(ledPin, OUTPUT); | |||
}; | |||
bool setTimer(int reqInterval) { | |||
if (reqInterval <= 0) return false; | |||
if (reqInterval <= 0) | |||
{ |
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.
Just to be consistent with the rest of the code, please, move the opening CB at the end of the previous line.
() // No parameters to the callback | ||
{ | ||
debugf("lamda Callback "); | ||
if (foo > 123) |
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.
Braces around if.
() // No parameters to the callback | ||
{ | ||
debugf("lamda Callback "); | ||
if (foo > 123) { |
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.
@frankdownunder In the if condition shouldn't there be an equal sign instead of bigger ?
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.
Ive fixed that now.
@frankdownunder I like the idea of moving min/max macros to AruinoCompat.h and will do it in a separate PR. Once merged, please rebase your PR and try the following: Simplify the example as much as possible
|
…s. (SmingHub#1368) The old Arduino libs can still continue to use the macros.
``` Timer& IRAM_ATTR initializeMs(uint32_t milliseconds, TimerDelegateStdFunction delegateFunction = nullptr); // Init in Milliseconds. ``` For the moment the others can stay. This allows for easier comment and review. The sample code Basic_Delegate has example calls for old style delegates, plainOldOrdinaryFunctions, memberFunctions and lamdas. The defines for min and max in SmingCore.h have been moved into ArduinoCompat.h This allows the use of the <algorithm> header which has std::max and std::min.
…b.com/frankdownunder/Sming into feature/DelegatorsAndStdFunction_1337 # Conflicts: # samples/Basic_Delegates/app/application.cpp
@slaff I had a great deal of trouble dealing with rebase. I do not know if I did it correctly or not. Pls check carefully |
Save somewhere your modified samples/Basic_Delegates/app/application.cpp, Timer.cpp and Timer.h. Get the latest version from OR You can read "Rebase if needed" from CONTRIBUTING.md. Basically what you have to do is: git checkout develop
git pull # make sure to get the latest develop version
git checkout feature/DelegatorsAndStdFunction_1337
git merge develop
git mergetool # if needed use your merge tool
# Once you are ready with the merge commit the changes, if that is not already the case.
git status # will tell you what you should do next.
# Now put your changes on top
git rebase develop
git mergetool # if needed use your merge tool
git status # will tell you what you should do next.
# once ready do
git push -f # to push the changes to the remote repo. |
@slaff Is there anything more I need to do on this? Did I do the rebase corectly? |
@frankdownunder I don't see any rebase ( https://github.com/SmingHub/Sming/pull/1361/files ) or recent change from your side. Can you please check if you forgot to |
This PR has been superseded by #1378 |
For the moment the others can stay.
This allows for easier comment and review.
The sample code Basic_Delegate has example calls for old style delegates,
plainOldOrdinaryFunctions, memberFunctions and lamdas.
The defines for min and max in SmingCore.h have been moved into ArduinoCompat.h
This allows the use of the header which has std::max and std::min.
Macros are nasty, especially those with the same names as standard functions. I can see those macros are needed for code that comes form the Arduino world, and they are still available by including Arduino.h