diff --git a/library.json b/library.json index 3292c33..f247876 100644 --- a/library.json +++ b/library.json @@ -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": "jon@stejsoftware.com", - "url": "http://stejsoftware.com" - }], - "frameworks": [ - "arduino" + "authors": [ + { + "name": "Jonathan Meyer", + "email": "jon@stejsoftware.com", + "url": "https://github.com/stejsoftware/Arduino-Timer" + } ], - "platforms": [ - "atmelavr" - ] + "version": "2.0.0", + "frameworks": "arduino", + "platforms": ["atmelavr", "espressif"] } diff --git a/library.properties b/library.properties index fbba520..3b73e90 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ -name=STEJ Timer -version=0.1.0 -author=STEJ +name=ArduinoTimer +version=2.0.0 +author=Jonathan Meyer maintainer=Jonathan Meyer sentence=A simple software timer -paragraph= +paragraph=A simple software timer category=Timing url=https://github.com/stejsoftware/Arduino-Timer architectures=* diff --git a/src/List.h b/src/List.h index db3c1cf..1170420 100644 --- a/src/List.h +++ b/src/List.h @@ -4,18 +4,17 @@ * */ - #ifndef __List_h_ +#ifndef __List_h_ #define __List_h_ -#include "Arduino.h" +#include -template +template class Node { public: - Node(T item) : - next(NULL), - _item(item) + Node(T item) : next(NULL), + _item(item) { } @@ -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 +template class List { public: @@ -56,7 +55,7 @@ class List bool push(T item) { - Node * node = new Node(item); + Node *node = new Node(item); if (node != NULL) { @@ -69,7 +68,7 @@ class List else { // find the end of the list - Node * end = m_begin; + Node *end = m_begin; while (end->next != NULL) { @@ -85,9 +84,9 @@ class List return false; } - bool pop(T & item) + bool pop(T &item) { - Node * node = m_begin; + Node *node = m_begin; if (node != NULL) { @@ -103,11 +102,10 @@ class List } private: - List(const List&rhs); - List & operator=(const List&rhs); - - Node * m_begin; + List(const List &rhs); + List &operator=(const List &rhs); + Node *m_begin; }; #endif // __List_h_ diff --git a/src/Timer.cpp b/src/Timer.cpp index a8b1f25..995359d 100644 --- a/src/Timer.cpp +++ b/src/Timer.cpp @@ -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() @@ -56,7 +53,7 @@ TimerClass::TimerClass() TimerClass::~TimerClass() { - Alarm * alarm = NULL; + Alarm *alarm = NULL; while (m_alarms.pop(alarm)) { @@ -64,17 +61,17 @@ TimerClass::~TimerClass() } } -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; @@ -82,7 +79,7 @@ Alarm * TimerClass::delay(TimerEventHandler handler, uint16_t timeout) void TimerClass::run() { - Alarm * alarm = NULL; + Alarm *alarm = NULL; if (m_alarms.pop(alarm)) { diff --git a/src/Timer.h b/src/Timer.h index 619cdd1..5f8e46b 100644 --- a/src/Timer.h +++ b/src/Timer.h @@ -7,7 +7,7 @@ #ifndef __Timer_h_ #define __Timer_h_ -#include "Arduino.h" +#include #include "List.h" typedef void (*TimerEventHandler)(); @@ -15,7 +15,7 @@ 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(); @@ -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; }; @@ -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 m_alarms; + List m_alarms; }; extern TimerClass Timer;