Skip to content

Commit

Permalink
QueuedTimer trial
Browse files Browse the repository at this point in the history
  • Loading branch information
hreintke committed Jun 27, 2016
1 parent 825f259 commit c2251e0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions sming/sming/core/QueuedDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "../include/sming_global.h"
#include "Delegate.h"
#include "../include/freertos_includes.h"

template<typename ParamType>
class QueuedDelegate
Expand Down
2 changes: 1 addition & 1 deletion sming/sming/core/QueuedInterrupt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
QueuedInterrupt::QueuedInterrupt(int reqPin, GPIO_INT_TYPE reqInterruptType,QueuedInterruptDelegate reqDelegate)
: QueuedDelegate(reqDelegate), interruptPin(reqPin), interruptType(reqInterruptType)
{
attachInterrupt(interruptPin,Delegate<void()>(&QueuedInterrupt::delegatedInterrupt,this), (GPIO_INT_TYPE)GPIO_PIN_INTR_ANYEDGE);
attachInterrupt(interruptPin,Delegate<void()>(&QueuedInterrupt::delegatedInterrupt,this), reqInterruptType);
}

QueuedInterrupt::~QueuedInterrupt() {
Expand Down
21 changes: 21 additions & 0 deletions sming/sming/core/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@

Timer::Timer()
{
qd = new QueuedDelegate<QueuedTimerMessage>(QueuedTimerDelegate(&Timer::queueHandler,this));
}

Timer::~Timer()
{
stop();
delete qd;
}

Timer& Timer::initializeMs(uint32_t milliseconds, InterruptCallback callback/* = NULL*/)
Expand Down Expand Up @@ -189,6 +191,13 @@ void Timer::processing(void *arg)
}
}

if ((ptimer->callback) || (ptimer->delegate_func))
{
QueuedTimerMessage queuedTimerMessage;
queuedTimerMessage.timerMicros = 0; // should be micros()
ptimer->qd->sendQueue(queuedTimerMessage);
}
/*
if (ptimer->callback)
{
ptimer->callback();
Expand All @@ -197,6 +206,18 @@ void Timer::processing(void *arg)
{
ptimer->delegate_func();
}
*/
}
}

void Timer::queueHandler(QueuedTimerMessage queuedTimerMessage)
{
if (callback)
{
callback();
}
else if (delegate_func)
{
delegate_func();
}
}
12 changes: 12 additions & 0 deletions sming/sming/core/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "../wiring/WiringFrameworkDependencies.h"
#include "../include/sming_global.h"
#include "espressif/esp_timer.h"
#include "QueuedDelegate.h"



Expand All @@ -27,6 +28,14 @@

typedef Delegate<void()> TimerDelegate;

typedef struct
{
uint32 timerMicros;
} QueuedTimerMessage;

typedef Delegate<void(QueuedTimerMessage)> QueuedTimerDelegate;


class Timer
{
public:
Expand Down Expand Up @@ -78,6 +87,9 @@ class Timer
Timer& IRAM_ATTR initializeUs(uint32_t microseconds, InterruptCallback callback = NULL); // Init in Microseconds.
Timer& IRAM_ATTR initializeUs(uint32_t microseconds, TimerDelegate delegateFunction = NULL); // Init in Microseconds.

QueuedDelegate<QueuedTimerMessage> * qd;
void queueHandler(QueuedTimerMessage queuedTimerMessage);

};

#endif /* _SMING_CORE_Timer_H_ */

0 comments on commit c2251e0

Please sign in to comment.