From 9feaa99511c29ae3f11ea29040e8e60bbf3d619e Mon Sep 17 00:00:00 2001 From: Marcus Nowotny Date: Wed, 31 Oct 2012 11:57:03 +0100 Subject: [PATCH 1/2] adding some delay routines to pause the metro --- Metro.cpp | 16 +++++++++++++--- Metro.h | 6 +++--- README.md | 8 ++++++++ keywords.txt | 2 ++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Metro.cpp b/Metro.cpp index 31816e3..86bcdac 100755 --- a/Metro.cpp +++ b/Metro.cpp @@ -25,7 +25,7 @@ Metro::Metro(unsigned long interval_millis) Metro::Metro(unsigned long interval_millis, uint8_t autoreset) { - this->autoreset = autoreset; + this->autoreset = autoreset; interval(interval_millis); reset(); } @@ -35,6 +35,14 @@ void Metro::interval(unsigned long interval_millis) this->interval_millis = interval_millis; } +void Metro::delay(unsigned long delay_millis) { + this->previous_millis += delay_millis; +} + +void Metro::delayFromNow(unsigned long delay_millis) { + this->previous_millis = millis()+delay_millis; +} + // Benjamin.soelberg's check behavior: // When a check is true, add the interval to the internal counter. // This should guarantee a better overall stability. @@ -45,7 +53,9 @@ void Metro::interval(unsigned long interval_millis) char Metro::check() { - if (millis() - this->previous_millis >= this->interval_millis) { + unsigned long now_millis = millis(); + if (this->previous_millisprevious_millis >= this->interval_millis)) { // As suggested by benjamin.soelberg@gmail.com, the following line // this->previous_millis = millis(); // was changed to @@ -53,7 +63,7 @@ char Metro::check() // If the interval is set to 0 we revert to the original behavior if (this->interval_millis <= 0 || this->autoreset ) { - this->previous_millis = millis(); + this->previous_millis = now_millis; } else { this->previous_millis += this->interval_millis; } diff --git a/Metro.h b/Metro.h index 4e1b446..7e9fe39 100755 --- a/Metro.h +++ b/Metro.h @@ -1,6 +1,4 @@ -/* -For license and instructions, please read Readme.md. -*/ + #ifndef Metro_h #define Metro_h @@ -14,6 +12,8 @@ class Metro Metro(unsigned long interval_millis); Metro(unsigned long interval_millis, uint8_t autoreset); void interval(unsigned long interval_millis); + void delay(unsigned long delay_millis); + void delayFromNow(unsigned long delay_millis); char check(); void reset(); diff --git a/README.md b/README.md index 7bde615..798b3f6 100644 --- a/README.md +++ b/README.md @@ -58,3 +58,11 @@ Changes the interval in milliseconds. Restarts/resets the Metro. +# void delay(long millis) + +delays the triggering of the next successful check() for the specified amount of milliseconds. + +# void delayFromNow(long millis) + +delays the triggering of the next successful check() for the specified amount of milliseconds after now. +After millis() + the specified milliseconds the Metro goes back to normal operation diff --git a/keywords.txt b/keywords.txt index 62ca8a2..4c384e7 100755 --- a/keywords.txt +++ b/keywords.txt @@ -14,6 +14,8 @@ Metro KEYWORD1 check KEYWORD2 interval KEYWORD2 +delay KEYWORD2 +delayFromNow KEYWORD2 ####################################### # Instances (KEYWORD2) From 0c3f3f200e624ddd6f09f88021dc125ee9b946f2 Mon Sep 17 00:00:00 2001 From: Marcus Nowotny Date: Wed, 31 Oct 2012 12:01:41 +0100 Subject: [PATCH 2/2] thou shalt not delete header infos --- Metro.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Metro.h b/Metro.h index 7e9fe39..3d6152e 100755 --- a/Metro.h +++ b/Metro.h @@ -1,4 +1,6 @@ - +/* + For license and instructions, please read Readme.md. + */ #ifndef Metro_h #define Metro_h