Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-meyer committed Jan 7, 2018
1 parent 23e6d50 commit e53f61b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 61 deletions.
23 changes: 11 additions & 12 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
{
"name": "STEJ Timer",
"name": "ArduinoTimer",
"keywords": "timer, callback",
"description": "A simple software timer",
"repository": {
"type": "git",
"url": "https://github.com/stejsoftware/Arduino-Timer"
"url": "https://github.com/stejsoftware/Arduino-Timer.git"
},
"authors": [{
"name": "Jonathan Meyer",
"email": "[email protected]",
"url": "http://stejsoftware.com"
}],
"frameworks": [
"arduino"
"authors": [
{
"name": "Jonathan Meyer",
"email": "[email protected]",
"url": "https://github.com/stejsoftware/Arduino-Timer"
}
],
"platforms": [
"atmelavr"
]
"version": "2.0.0",
"frameworks": "arduino",
"platforms": ["atmelavr", "espressif"]
}
8 changes: 4 additions & 4 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=STEJ Timer
version=0.1.0
author=STEJ
name=ArduinoTimer
version=2.0.0
author=Jonathan Meyer <[email protected]>
maintainer=Jonathan Meyer <[email protected]>
sentence=A simple software timer
paragraph=
paragraph=A simple software timer
category=Timing
url=https://github.com/stejsoftware/Arduino-Timer
architectures=*
34 changes: 16 additions & 18 deletions src/List.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
*
*/

#ifndef __List_h_
#ifndef __List_h_
#define __List_h_

#include "Arduino.h"
#include <Arduino.h>

template<class T>
template <class T>
class Node
{
public:
Node(T item) :
next(NULL),
_item(item)
Node(T item) : next(NULL),
_item(item)
{
}

Expand All @@ -28,16 +27,16 @@ class Node
return _item;
}

Node * next;
Node *next;

private:
Node(const Node & rhs);
Node & operator=(const Node & rhs);
Node(const Node &rhs);
Node &operator=(const Node &rhs);

T _item;
};

template<class T>
template <class T>
class List
{
public:
Expand All @@ -56,7 +55,7 @@ class List

bool push(T item)
{
Node<T> * node = new Node<T>(item);
Node<T> *node = new Node<T>(item);

if (node != NULL)
{
Expand All @@ -69,7 +68,7 @@ class List
else
{
// find the end of the list
Node<T> * end = m_begin;
Node<T> *end = m_begin;

while (end->next != NULL)
{
Expand All @@ -85,9 +84,9 @@ class List
return false;
}

bool pop(T & item)
bool pop(T &item)
{
Node<T> * node = m_begin;
Node<T> *node = m_begin;

if (node != NULL)
{
Expand All @@ -103,11 +102,10 @@ class List
}

private:
List(const List&rhs);
List & operator=(const List&rhs);

Node<T> * m_begin;
List(const List &rhs);
List &operator=(const List &rhs);

Node<T> *m_begin;
};

#endif // __List_h_
23 changes: 10 additions & 13 deletions src/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@

#include "Timer.h"

Alarm::Alarm(TimerEventHandler handler, uint16_t interval, bool repeat) :
m_handler(handler),
m_repeat(repeat),
m_interval(interval),
m_timeout(0)
Alarm::Alarm(TimerEventHandler handler, uint32_t interval, bool repeat) : m_handler(handler),
m_repeat(repeat),
m_interval(interval),
m_timeout(0)
{
// Serial.println("Alarm");
}

Alarm::~Alarm()
{
// Serial.println("~Alarm");
}

void Alarm::reset()
Expand Down Expand Up @@ -56,33 +53,33 @@ TimerClass::TimerClass()

TimerClass::~TimerClass()
{
Alarm * alarm = NULL;
Alarm *alarm = NULL;

while (m_alarms.pop(alarm))
{
delete alarm;
}
}

Alarm * TimerClass::repeat(TimerEventHandler handler, uint16_t interval)
Alarm *TimerClass::repeat(TimerEventHandler handler, uint32_t interval)
{
Alarm * alarm = new Alarm(handler, interval, true);
Alarm *alarm = new Alarm(handler, interval, true);
alarm->reset();
m_alarms.push(alarm);
return alarm;
}

Alarm * TimerClass::delay(TimerEventHandler handler, uint16_t timeout)
Alarm *TimerClass::delay(TimerEventHandler handler, uint32_t timeout)
{
Alarm * alarm = new Alarm(handler, timeout, false);
Alarm *alarm = new Alarm(handler, timeout, false);
alarm->reset();
m_alarms.push(alarm);
return alarm;
}

void TimerClass::run()
{
Alarm * alarm = NULL;
Alarm *alarm = NULL;

if (m_alarms.pop(alarm))
{
Expand Down
24 changes: 10 additions & 14 deletions src/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
#ifndef __Timer_h_
#define __Timer_h_

#include "Arduino.h"
#include <Arduino.h>
#include "List.h"

typedef void (*TimerEventHandler)();

class Alarm
{
public:
Alarm(TimerEventHandler handler, uint16_t interval, bool repeat);
Alarm(TimerEventHandler handler, uint32_t interval, bool repeat);
~Alarm();

void reset();
Expand All @@ -26,12 +26,12 @@ class Alarm
void execute() const;

private:
Alarm(const Alarm & rhs);
Alarm & operator=(const Alarm & rhs);
Alarm(const Alarm &rhs);
Alarm &operator=(const Alarm &rhs);

TimerEventHandler m_handler;
bool m_repeat;
uint16_t m_interval;
uint32_t m_interval;
uint32_t m_timeout;
};

Expand All @@ -41,20 +41,16 @@ class TimerClass
TimerClass();
~TimerClass();

// creates a Timer that executes at the given interval
Alarm * repeat(TimerEventHandler handler, uint16_t interval);

// creates a Timer that executes once after the given timeout
Alarm * delay(TimerEventHandler handler, uint16_t timeout);
Alarm *repeat(TimerEventHandler handler, uint32_t interval);
Alarm *delay(TimerEventHandler handler, uint32_t timeout);

// should be placed in the loop() function to check of a timer has elapsed.
void run();

private:
TimerClass(const TimerClass & rhs);
TimerClass & operator=(const TimerClass & rhs);
TimerClass(const TimerClass &rhs);
TimerClass &operator=(const TimerClass &rhs);

List<Alarm*> m_alarms;
List<Alarm *> m_alarms;
};

extern TimerClass Timer;
Expand Down

0 comments on commit e53f61b

Please sign in to comment.