-
-
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
Changes from 2 commits
aa53c75
dbcce0f
78da89e
89fa419
84399c0
cd7a1d3
ff7fb1e
f4d65fa
81913e1
d0e492b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
#ifndef min | ||
#define min(a,b) ((a)<(b)?(a):(b)) | ||
#endif | ||
#ifndef max | ||
#define max(a,b) ((a)>(b)?(a):(b)) | ||
#endif | ||
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) | ||
|
||
|
||
|
||
#endif /* SMINGCORE_ARDUINOCOMPAT_H_ */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
#ifndef _SMING_CORE_Timer_H_ | ||
#define _SMING_CORE_Timer_H_ | ||
|
||
|
||
#include <functional> | ||
#include "../SmingCore/Interrupts.h" | ||
#include "../SmingCore/Delegate.h" | ||
#include "../Wiring/WiringFrameworkDependencies.h" | ||
|
@@ -25,6 +25,7 @@ | |
#define MAX_OS_TIMER_INTERVAL_US 268435000 | ||
|
||
typedef Delegate<void()> TimerDelegate; | ||
typedef std::function<void()> TimerDelegateStdFunction; | ||
|
||
class Timer | ||
{ | ||
|
@@ -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 commentThe 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: There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Actually only the comments in Timer.h use spaces - not very consistent! |
||
*/ | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Fix indentation and lower case D |
||
*/ | ||
Timer& IRAM_ATTR initializeUs(uint32_t microseconds, TimerDelegate delegateFunction = NULL); // Init in Microseconds. | ||
|
||
/** @brief Initialise millisecond timer | ||
* @param milliseconds Duration of timer in milliseconds | ||
* @param delegateFunction Function to call when timer triggers | ||
* @note Delegate callback method | ||
*/ | ||
Timer& IRAM_ATTR initializeMs(uint32_t milliseconds, TimerDelegateStdFunction delegateFunction = nullptr); // 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 | ||
*/ | ||
Timer& IRAM_ATTR initializeUs(uint32_t microseconds, TimerDelegateStdFunction delegateFunction = nullptr); // Init in Microseconds. | ||
/** @brief Start timer running | ||
* @param repeating Set to true for repeating timer. Set to false for one-shot. | ||
*/ | ||
|
@@ -120,11 +136,16 @@ class Timer | |
*/ | ||
void IRAM_ATTR setCallback(InterruptCallback interrupt = NULL); | ||
|
||
/** @brief Set timer trigger function | ||
* @param delegateFunction Function to be called on timer trigger | ||
* @note Delegate callback method | ||
*/ | ||
void IRAM_ATTR setCallback(TimerDelegate delegateFunction); | ||
/** @brief Set timer trigger function | ||
* @param delegateFunction Function to be called on timer trigger | ||
* @note Delegate callback method | ||
*/ | ||
void IRAM_ATTR setCallback(TimerDelegate delegateFunction); | ||
/** @brief Set timer trigger function | ||
* @param delegateFunction Function to be called on timer trigger | ||
* @note Delegate callback method | ||
*/ | ||
void IRAM_ATTR setCallback(const TimerDelegateStdFunction& delegateFunction); | ||
|
||
|
||
protected: | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Fix indentation... |
||
bool repeating = false; | ||
bool started = false; | ||
|
||
|
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.