Skip to content

Commit e53f61b

Browse files
update
1 parent 23e6d50 commit e53f61b

File tree

5 files changed

+51
-61
lines changed

5 files changed

+51
-61
lines changed

library.json

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
{
2-
"name": "STEJ Timer",
2+
"name": "ArduinoTimer",
33
"keywords": "timer, callback",
44
"description": "A simple software timer",
55
"repository": {
66
"type": "git",
7-
"url": "https://github.com/stejsoftware/Arduino-Timer"
7+
"url": "https://github.com/stejsoftware/Arduino-Timer.git"
88
},
9-
"authors": [{
10-
"name": "Jonathan Meyer",
11-
"email": "[email protected]",
12-
"url": "http://stejsoftware.com"
13-
}],
14-
"frameworks": [
15-
"arduino"
9+
"authors": [
10+
{
11+
"name": "Jonathan Meyer",
12+
"email": "[email protected]",
13+
"url": "https://github.com/stejsoftware/Arduino-Timer"
14+
}
1615
],
17-
"platforms": [
18-
"atmelavr"
19-
]
16+
"version": "2.0.0",
17+
"frameworks": "arduino",
18+
"platforms": ["atmelavr", "espressif"]
2019
}

library.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name=STEJ Timer
2-
version=0.1.0
3-
author=STEJ
1+
name=ArduinoTimer
2+
version=2.0.0
3+
author=Jonathan Meyer <[email protected]>
44
maintainer=Jonathan Meyer <[email protected]>
55
sentence=A simple software timer
6-
paragraph=
6+
paragraph=A simple software timer
77
category=Timing
88
url=https://github.com/stejsoftware/Arduino-Timer
99
architectures=*

src/List.h

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@
44
*
55
*/
66

7-
#ifndef __List_h_
7+
#ifndef __List_h_
88
#define __List_h_
99

10-
#include "Arduino.h"
10+
#include <Arduino.h>
1111

12-
template<class T>
12+
template <class T>
1313
class Node
1414
{
1515
public:
16-
Node(T item) :
17-
next(NULL),
18-
_item(item)
16+
Node(T item) : next(NULL),
17+
_item(item)
1918
{
2019
}
2120

@@ -28,16 +27,16 @@ class Node
2827
return _item;
2928
}
3029

31-
Node * next;
30+
Node *next;
3231

3332
private:
34-
Node(const Node & rhs);
35-
Node & operator=(const Node & rhs);
33+
Node(const Node &rhs);
34+
Node &operator=(const Node &rhs);
3635

3736
T _item;
3837
};
3938

40-
template<class T>
39+
template <class T>
4140
class List
4241
{
4342
public:
@@ -56,7 +55,7 @@ class List
5655

5756
bool push(T item)
5857
{
59-
Node<T> * node = new Node<T>(item);
58+
Node<T> *node = new Node<T>(item);
6059

6160
if (node != NULL)
6261
{
@@ -69,7 +68,7 @@ class List
6968
else
7069
{
7170
// find the end of the list
72-
Node<T> * end = m_begin;
71+
Node<T> *end = m_begin;
7372

7473
while (end->next != NULL)
7574
{
@@ -85,9 +84,9 @@ class List
8584
return false;
8685
}
8786

88-
bool pop(T & item)
87+
bool pop(T &item)
8988
{
90-
Node<T> * node = m_begin;
89+
Node<T> *node = m_begin;
9190

9291
if (node != NULL)
9392
{
@@ -103,11 +102,10 @@ class List
103102
}
104103

105104
private:
106-
List(const List&rhs);
107-
List & operator=(const List&rhs);
108-
109-
Node<T> * m_begin;
105+
List(const List &rhs);
106+
List &operator=(const List &rhs);
110107

108+
Node<T> *m_begin;
111109
};
112110

113111
#endif // __List_h_

src/Timer.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,15 @@
66

77
#include "Timer.h"
88

9-
Alarm::Alarm(TimerEventHandler handler, uint16_t interval, bool repeat) :
10-
m_handler(handler),
11-
m_repeat(repeat),
12-
m_interval(interval),
13-
m_timeout(0)
9+
Alarm::Alarm(TimerEventHandler handler, uint32_t interval, bool repeat) : m_handler(handler),
10+
m_repeat(repeat),
11+
m_interval(interval),
12+
m_timeout(0)
1413
{
15-
// Serial.println("Alarm");
1614
}
1715

1816
Alarm::~Alarm()
1917
{
20-
// Serial.println("~Alarm");
2118
}
2219

2320
void Alarm::reset()
@@ -56,33 +53,33 @@ TimerClass::TimerClass()
5653

5754
TimerClass::~TimerClass()
5855
{
59-
Alarm * alarm = NULL;
56+
Alarm *alarm = NULL;
6057

6158
while (m_alarms.pop(alarm))
6259
{
6360
delete alarm;
6461
}
6562
}
6663

67-
Alarm * TimerClass::repeat(TimerEventHandler handler, uint16_t interval)
64+
Alarm *TimerClass::repeat(TimerEventHandler handler, uint32_t interval)
6865
{
69-
Alarm * alarm = new Alarm(handler, interval, true);
66+
Alarm *alarm = new Alarm(handler, interval, true);
7067
alarm->reset();
7168
m_alarms.push(alarm);
7269
return alarm;
7370
}
7471

75-
Alarm * TimerClass::delay(TimerEventHandler handler, uint16_t timeout)
72+
Alarm *TimerClass::delay(TimerEventHandler handler, uint32_t timeout)
7673
{
77-
Alarm * alarm = new Alarm(handler, timeout, false);
74+
Alarm *alarm = new Alarm(handler, timeout, false);
7875
alarm->reset();
7976
m_alarms.push(alarm);
8077
return alarm;
8178
}
8279

8380
void TimerClass::run()
8481
{
85-
Alarm * alarm = NULL;
82+
Alarm *alarm = NULL;
8683

8784
if (m_alarms.pop(alarm))
8885
{

src/Timer.h

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
#ifndef __Timer_h_
88
#define __Timer_h_
99

10-
#include "Arduino.h"
10+
#include <Arduino.h>
1111
#include "List.h"
1212

1313
typedef void (*TimerEventHandler)();
1414

1515
class Alarm
1616
{
1717
public:
18-
Alarm(TimerEventHandler handler, uint16_t interval, bool repeat);
18+
Alarm(TimerEventHandler handler, uint32_t interval, bool repeat);
1919
~Alarm();
2020

2121
void reset();
@@ -26,12 +26,12 @@ class Alarm
2626
void execute() const;
2727

2828
private:
29-
Alarm(const Alarm & rhs);
30-
Alarm & operator=(const Alarm & rhs);
29+
Alarm(const Alarm &rhs);
30+
Alarm &operator=(const Alarm &rhs);
3131

3232
TimerEventHandler m_handler;
3333
bool m_repeat;
34-
uint16_t m_interval;
34+
uint32_t m_interval;
3535
uint32_t m_timeout;
3636
};
3737

@@ -41,20 +41,16 @@ class TimerClass
4141
TimerClass();
4242
~TimerClass();
4343

44-
// creates a Timer that executes at the given interval
45-
Alarm * repeat(TimerEventHandler handler, uint16_t interval);
46-
47-
// creates a Timer that executes once after the given timeout
48-
Alarm * delay(TimerEventHandler handler, uint16_t timeout);
44+
Alarm *repeat(TimerEventHandler handler, uint32_t interval);
45+
Alarm *delay(TimerEventHandler handler, uint32_t timeout);
4946

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

5349
private:
54-
TimerClass(const TimerClass & rhs);
55-
TimerClass & operator=(const TimerClass & rhs);
50+
TimerClass(const TimerClass &rhs);
51+
TimerClass &operator=(const TimerClass &rhs);
5652

57-
List<Alarm*> m_alarms;
53+
List<Alarm *> m_alarms;
5854
};
5955

6056
extern TimerClass Timer;

0 commit comments

Comments
 (0)