初始化提交
This commit is contained in:
1
arduino-cli/libraries/RBD_Timer-master/.gitignore
vendored
Normal file
1
arduino-cli/libraries/RBD_Timer-master/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.DS_Store
|
||||
21
arduino-cli/libraries/RBD_Timer-master/LICENSE
Normal file
21
arduino-cli/libraries/RBD_Timer-master/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2015 Alex Taujenis
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
12
arduino-cli/libraries/RBD_Timer-master/README.md
Normal file
12
arduino-cli/libraries/RBD_Timer-master/README.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# Arduino Timer Library v1.4.0 [](https://github.com/alextaujenis/RBD_Timer/blob/master/extras/unit_test/unit_test.ino)
|
||||
Manage many timed events.
|
||||
|
||||
* [Documentation](http://robotsbigdata.com/docs-arduino-timer.html)
|
||||
* [Project Website](http://robotsbigdata.com)
|
||||
* [Release Notes](https://github.com/alextaujenis/RBD_Timer/releases)
|
||||
* [Comments, Questions, or Issues](https://github.com/alextaujenis/RBD_Timer/issues/new)*
|
||||
|
||||
\**Please include your Arduino make/model and IDE version when reporting an issue with this library.*
|
||||
|
||||
# License
|
||||
Copyright (c) 2015 Alex Taujenis - MIT License
|
||||
@@ -0,0 +1,19 @@
|
||||
// Arduino RBD Timer Library v1.4.0 Example - A three second interval timer that prints to serial.
|
||||
// https://github.com/alextaujenis/RBD_Timer
|
||||
// Copyright (c) 2015 Alex Taujenis - MIT License
|
||||
|
||||
#include <RBD_Timer.h> // https://github.com/alextaujenis/RBD_Timer
|
||||
|
||||
RBD::Timer timer;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
timer.setTimeout(3000);
|
||||
timer.restart();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if(timer.onRestart()) {
|
||||
Serial.println("Three seconds passed");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,420 @@
|
||||
// Arduino RBD Timer Library v1.4.0 - Unit test coverage.
|
||||
// https://github.com/alextaujenis/RBD_Timer
|
||||
// Copyright (c) 2015 Alex Taujenis - MIT License
|
||||
|
||||
#include <ArduinoUnit.h> // https://github.com/mmurdoch/arduinounit
|
||||
#include <RBD_Timer.h> // https://github.com/alextaujenis/RBD_Timer
|
||||
|
||||
RBD::Timer timer;
|
||||
RBD::Timer timer_untouched;
|
||||
RBD::Timer timer_timeout(100);
|
||||
RBD::Timer timer_zero;
|
||||
|
||||
// constructor
|
||||
test(constructor_should_begin_expired) {
|
||||
assertTrue(timer_untouched.isExpired());
|
||||
assertFalse(timer_untouched.isActive());
|
||||
}
|
||||
|
||||
test(constructor_should_set_the_default_timeout_to_zero_milliseconds) {
|
||||
assertEqual(timer_untouched.getTimeout(), 0);
|
||||
}
|
||||
|
||||
// overloaded constructor
|
||||
test(overloaded_constructor_should_set_the_timeout_in_milliseconds) {
|
||||
assertEqual(timer_timeout.getTimeout(), 100);
|
||||
}
|
||||
|
||||
// setTimeout
|
||||
test(setTimeout_should_set_the_timeout_in_milliseconds) {
|
||||
timer.setTimeout(100);
|
||||
|
||||
assertEqual(timer.getTimeout(), 100);
|
||||
}
|
||||
|
||||
test(setTimeout_should_set_the_timeout_in_long_milliseconds) {
|
||||
timer.setTimeout(100000L); // trailing 'L' is important for 'long' literal
|
||||
|
||||
assertEqual(timer.getTimeout(), 100000L);
|
||||
}
|
||||
|
||||
test(setTimeout_should_constrain_the_lower_bounds_to_one_millisecond) {
|
||||
timer.setTimeout(0);
|
||||
|
||||
assertEqual(timer.getTimeout(), 1);
|
||||
}
|
||||
|
||||
// getTimeout
|
||||
test(getTimeout_should_return_the_timeout_in_milliseconds) {
|
||||
timer.setTimeout(42);
|
||||
|
||||
assertEqual(timer.getTimeout(), 42);
|
||||
}
|
||||
|
||||
// setHertz
|
||||
test(setHertz_should_set_the_refresh_rate_per_second) {
|
||||
timer.setHertz(10);
|
||||
|
||||
assertEqual(timer.getTimeout(), 100); // ten times per second
|
||||
}
|
||||
|
||||
test(setHertz_should_constrain_the_lower_bounds_to_one_if_provided_zero) {
|
||||
timer.setHertz(0);
|
||||
|
||||
assertEqual(timer.getHertz(), 1);
|
||||
}
|
||||
|
||||
test(setHertz_should_constrain_the_lower_bounds_to_one_if_provided_a_negative_number) {
|
||||
timer.setHertz(-1);
|
||||
|
||||
assertEqual(timer.getHertz(), 1);
|
||||
}
|
||||
|
||||
test(setHertz_should_constrain_the_upper_bounds_to_one_thousand_if_provided_a_large_number) {
|
||||
timer.setHertz(1234);
|
||||
|
||||
assertEqual(timer.getHertz(), 1000);
|
||||
}
|
||||
|
||||
test(setHertz_should_properly_set_a_value_on_the_lower_bounds_of_the_threshold) {
|
||||
timer.setHertz(1);
|
||||
|
||||
assertEqual(timer.getHertz(), 1);
|
||||
}
|
||||
|
||||
test(setHertz_should_properly_set_a_value_on_the_upper_bounds_of_the_threshold) {
|
||||
timer.setHertz(1000);
|
||||
|
||||
assertEqual(timer.getHertz(), 1000);
|
||||
}
|
||||
|
||||
// getHertz
|
||||
test(getHerts_should_return_the_hertz_value) {
|
||||
timer.setHertz(42);
|
||||
|
||||
assertEqual(timer.getHertz(), 42);
|
||||
}
|
||||
|
||||
// restart
|
||||
test(restart_should_make_it_active) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
|
||||
assertTrue(timer.isActive());
|
||||
}
|
||||
|
||||
test(restart_should_make_it_not_expired) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
|
||||
assertFalse(timer.isExpired());
|
||||
}
|
||||
|
||||
test(restart_should_make_it_not_stopped) {
|
||||
timer.setTimeout(1);
|
||||
timer.stop();
|
||||
timer.restart();
|
||||
|
||||
assertFalse(timer.isStopped());
|
||||
}
|
||||
|
||||
// expire
|
||||
test(isExpired_and_onExpired_should_return_true_after_expire) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
timer.expire();
|
||||
|
||||
assertTrue(timer.isExpired());
|
||||
assertTrue(timer.onExpired());
|
||||
}
|
||||
|
||||
test(isActive_and_onActive_should_return_false_after_expire) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
timer.expire();
|
||||
|
||||
assertFalse(timer.isActive());
|
||||
assertFalse(timer.onActive());
|
||||
}
|
||||
|
||||
test(onRestart_should_return_true_after_expire) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
timer.expire();
|
||||
|
||||
assertTrue(timer.onRestart());
|
||||
}
|
||||
|
||||
test(isStopped_should_return_false_after_expire) {
|
||||
timer.setTimeout(1);
|
||||
timer.stop();
|
||||
timer.expire();
|
||||
|
||||
assertFalse(timer.isStopped());
|
||||
}
|
||||
|
||||
// isActive
|
||||
test(isActive_should_return_true_if_time_is_available) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
|
||||
assertTrue(timer.isActive());
|
||||
}
|
||||
|
||||
test(isActive_should_return_false_if_time_has_run_out) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
delay(2);
|
||||
|
||||
assertFalse(timer.isActive());
|
||||
}
|
||||
|
||||
test(isActive_should_remain_false_on_timer_rollover) {
|
||||
timer.setTimeout(10);
|
||||
timer.restart();
|
||||
|
||||
delay(11);
|
||||
assertFalse(timer.isActive());
|
||||
|
||||
timer.setTimeout(20); // make it active again without calling restart: almost like timer rollover
|
||||
|
||||
assertFalse(timer.isActive());
|
||||
}
|
||||
|
||||
// isExpired
|
||||
test(isExpired_should_return_false_if_time_is_available) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
|
||||
assertFalse(timer.isExpired());
|
||||
}
|
||||
|
||||
test(isExpired_should_return_true_if_time_has_run_out) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
delay(1);
|
||||
|
||||
assertTrue(timer.isExpired());
|
||||
}
|
||||
|
||||
test(isExpired_should_remain_true_on_timer_rollover) {
|
||||
timer.setTimeout(10);
|
||||
timer.restart();
|
||||
|
||||
delay(11);
|
||||
assertTrue(timer.isExpired());
|
||||
|
||||
timer.setTimeout(20); // make it active again without calling restart: almost like timer rollover
|
||||
|
||||
assertTrue(timer.isExpired());
|
||||
}
|
||||
|
||||
// isStopped
|
||||
test(isStopped_should_return_true_if_stopped) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
timer.stop();
|
||||
|
||||
assertTrue(timer.isStopped());
|
||||
}
|
||||
|
||||
test(isStopped_should_return_false_if_active) {
|
||||
timer.setTimeout(5);
|
||||
timer.restart();
|
||||
|
||||
assertTrue(timer.isActive());
|
||||
assertFalse(timer.isStopped());
|
||||
}
|
||||
|
||||
test(isStopped_should_return_false_if_expired) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
delay(1);
|
||||
|
||||
assertTrue(timer.isExpired());
|
||||
assertFalse(timer.isStopped());
|
||||
}
|
||||
|
||||
test(isStopped_should_remain_true_on_timer_rollover) {
|
||||
timer.setTimeout(10);
|
||||
timer.restart();
|
||||
|
||||
delay(11);
|
||||
assertTrue(timer.isExpired());
|
||||
timer.stop();
|
||||
|
||||
timer.setTimeout(20); // make it active again without calling restart: almost like timer rollover
|
||||
|
||||
assertTrue(timer.isStopped());
|
||||
}
|
||||
|
||||
// onRestart
|
||||
test(onRestart_should_return_true_if_the_timer_expires) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
delay(1);
|
||||
|
||||
assertTrue(timer.onRestart());
|
||||
}
|
||||
|
||||
test(onRestart_should_return_false_the_second_time_after_the_timer_expires) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
delay(1);
|
||||
timer.onRestart();
|
||||
|
||||
assertFalse(timer.onRestart());
|
||||
}
|
||||
|
||||
// onActive
|
||||
test(onActive_should_return_false_if_the_timer_has_not_been_restarted) {
|
||||
timer.setTimeout(1);
|
||||
|
||||
assertFalse(timer.onActive());
|
||||
}
|
||||
|
||||
test(onActive_should_return_true_after_the_timer_is_restarted) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
|
||||
assertTrue(timer.onActive());
|
||||
}
|
||||
|
||||
test(onActive_should_return_false_the_second_time_after_the_timer_is_restarted) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
timer.onActive();
|
||||
|
||||
assertFalse(timer.onActive());
|
||||
}
|
||||
|
||||
test(onActive_should_return_false_on_timer_rollover) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
|
||||
assertTrue(timer.onActive());
|
||||
assertFalse(timer.onActive());
|
||||
|
||||
timer.setTimeout(5); // make it active again without calling restart: almost like timer rollover
|
||||
|
||||
assertFalse(timer.onActive());
|
||||
}
|
||||
|
||||
// onExpired
|
||||
test(onExpired_should_return_true_after_the_timer_expires) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
delay(1);
|
||||
|
||||
assertTrue(timer.onExpired());
|
||||
}
|
||||
|
||||
test(onExpired_should_return_false_the_second_time_after_the_timer_is_restarted) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
delay(1);
|
||||
timer.onExpired();
|
||||
|
||||
assertFalse(timer.onExpired());
|
||||
}
|
||||
|
||||
test(onExpired_should_return_false_on_timer_rollover) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
delay(1);
|
||||
|
||||
assertTrue(timer.onExpired());
|
||||
assertFalse(timer.onExpired());
|
||||
|
||||
timer.setTimeout(5); // make it active again without calling restart, then wait for it to expire: almost like timer rollover
|
||||
delay(5);
|
||||
|
||||
assertFalse(timer.onExpired());
|
||||
}
|
||||
|
||||
// stop
|
||||
test(isActive_and_onActive_should_return_false_after_stop) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
timer.stop();
|
||||
|
||||
assertFalse(timer.isActive());
|
||||
assertFalse(timer.onActive());
|
||||
}
|
||||
|
||||
test(isExpired_and_onExpired_should_return_false_after_stop) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
timer.stop();
|
||||
delay(1);
|
||||
|
||||
assertFalse(timer.isExpired());
|
||||
assertFalse(timer.onExpired());
|
||||
}
|
||||
|
||||
test(onRestart_should_return_false_after_stop) {
|
||||
timer.setTimeout(1);
|
||||
timer.restart();
|
||||
timer.stop();
|
||||
delay(1);
|
||||
|
||||
assertFalse(timer.onRestart());
|
||||
}
|
||||
|
||||
// getValue
|
||||
test(getValue_should_return_the_time_passed_since_restart) {
|
||||
timer.setTimeout(5);
|
||||
timer.restart();
|
||||
delay(1);
|
||||
|
||||
assertEqual(timer.getValue(), 1);
|
||||
}
|
||||
|
||||
// getInverseValue
|
||||
test(getInverseValue_should_return_the_time_left_until_timeout) {
|
||||
timer.setTimeout(5);
|
||||
timer.restart();
|
||||
delay(2);
|
||||
|
||||
assertEqual(timer.getInverseValue(), 3);
|
||||
}
|
||||
|
||||
// getPercentValue
|
||||
test(getPercentValue_should_return_the_percentage_of_time_passed) {
|
||||
timer.setTimeout(100);
|
||||
timer.restart();
|
||||
delay(40);
|
||||
|
||||
assertEqual(timer.getPercentValue(), 40);
|
||||
}
|
||||
|
||||
test(getPercentValue_should_not_divide_by_zero) {
|
||||
timer_zero.restart();
|
||||
|
||||
assertEqual(timer_zero.getPercentValue(), 0);
|
||||
}
|
||||
|
||||
// getInversePercentValue
|
||||
test(getInversePercentValue_should_return_the_percentage_of_time_remaining) {
|
||||
timer.setTimeout(100);
|
||||
timer.restart();
|
||||
delay(40);
|
||||
|
||||
assertEqual(timer.getInversePercentValue(), 60);
|
||||
}
|
||||
|
||||
test(getInversePercentValue_should_not_divide_by_zero) {
|
||||
timer_zero.restart();
|
||||
|
||||
assertEqual(timer_zero.getInversePercentValue(), 100);
|
||||
}
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while(!Serial);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Test::run();
|
||||
}
|
||||
18
arduino-cli/libraries/RBD_Timer-master/keywords.txt
Normal file
18
arduino-cli/libraries/RBD_Timer-master/keywords.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
Timer KEYWORD1
|
||||
setTimeout KEYWORD2
|
||||
setHertz KEYWORD2
|
||||
restart KEYWORD2
|
||||
stop KEYWORD2
|
||||
expire KEYWORD2
|
||||
isActive KEYWORD2
|
||||
isExpired KEYWORD2
|
||||
isStopped KEYWORD2
|
||||
onRestart KEYWORD2
|
||||
onActive KEYWORD2
|
||||
onExpired KEYWORD2
|
||||
getTimeout KEYWORD2
|
||||
getHertz KEYWORD2
|
||||
getValue KEYWORD2
|
||||
getInverseValue KEYWORD2
|
||||
getPercentValue KEYWORD2
|
||||
getInversePercentValue KEYWORD2
|
||||
@@ -0,0 +1,9 @@
|
||||
name=RBD_Timer
|
||||
version=1.4.0
|
||||
author=Alex Taujenis <alex.taujenis@gmail.com>
|
||||
maintainer=Alex Taujenis <alex.taujenis@gmail.com>
|
||||
sentence=Manage many timed events.
|
||||
paragraph=The Arduino real-time loop stops advancing when you write delay() or use interrupts in your sketch. You can keep the real-time loop moving by using millis() to track time and create delay, but it is more complicated and soon becomes messy to manage. This lightweight library manages time the same way you would by setting a waypoint and calculating elapsed millis(). It is a simple replacement to manage your timed events with english instead of math.
|
||||
category=Timing
|
||||
url=https://github.com/alextaujenis/RBD_Timer
|
||||
architectures=*
|
||||
109
arduino-cli/libraries/RBD_Timer-master/src/RBD_Timer.cpp
Normal file
109
arduino-cli/libraries/RBD_Timer-master/src/RBD_Timer.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
// Arduino RBD Timer Library v1.4.0 - Manage many timed events.
|
||||
// https://github.com/alextaujenis/RBD_Timer
|
||||
// Copyright (c) 2015 Alex Taujenis - MIT License
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <RBD_Timer.h> // https://github.com/alextaujenis/RBD_Timer
|
||||
|
||||
namespace RBD {
|
||||
Timer::Timer() {}
|
||||
|
||||
Timer::Timer(unsigned long value) {
|
||||
setTimeout(value);
|
||||
}
|
||||
|
||||
void Timer::setTimeout(unsigned long value) {
|
||||
_timeout = (value > 0) ? value : 1;
|
||||
}
|
||||
|
||||
unsigned long Timer::getTimeout() {
|
||||
return _timeout;
|
||||
}
|
||||
|
||||
void Timer::setHertz(int value) {
|
||||
// possible to do: manage setHertz in micros() for higher resolution
|
||||
_hertz = constrain(value, 1, 1000);
|
||||
_timeout = (unsigned long)(1000 / _hertz);
|
||||
}
|
||||
|
||||
int Timer::getHertz() {
|
||||
return _hertz;
|
||||
}
|
||||
|
||||
void Timer::restart() {
|
||||
_waypoint = millis();
|
||||
_state = ACTIVE;
|
||||
_has_been_active = false;
|
||||
_has_been_expired = false;
|
||||
}
|
||||
|
||||
void Timer::stop() {
|
||||
_state = STOPPED;
|
||||
}
|
||||
|
||||
void Timer::expire() {
|
||||
_state = EXPIRED;
|
||||
}
|
||||
|
||||
bool Timer::isActive() {
|
||||
_updateState();
|
||||
return _state == ACTIVE;
|
||||
}
|
||||
|
||||
bool Timer::isExpired() {
|
||||
_updateState();
|
||||
return _state == EXPIRED;
|
||||
}
|
||||
|
||||
bool Timer::isStopped() {
|
||||
return _state == STOPPED;
|
||||
}
|
||||
|
||||
bool Timer::onRestart() {
|
||||
if(isExpired()) {
|
||||
restart();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Timer::onActive() {
|
||||
if(!_has_been_active && isActive()) {
|
||||
return _has_been_active = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Timer::onExpired() {
|
||||
if(!_has_been_expired && isExpired()) {
|
||||
return _has_been_expired = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned long Timer::getValue() {
|
||||
return millis() - _waypoint;
|
||||
}
|
||||
|
||||
unsigned long Timer::getInverseValue() {
|
||||
return _timeout - getValue();
|
||||
}
|
||||
|
||||
int Timer::getPercentValue() {
|
||||
if(_timeout == 0) {return 0;}
|
||||
return getValue() / float(_timeout) * 100;
|
||||
}
|
||||
|
||||
int Timer::getInversePercentValue() {
|
||||
return 100 - getPercentValue();
|
||||
}
|
||||
|
||||
|
||||
// private
|
||||
|
||||
void Timer::_updateState() {
|
||||
if(_state == ACTIVE && getValue() >= _timeout) {
|
||||
_state = EXPIRED;
|
||||
}
|
||||
}
|
||||
}
|
||||
42
arduino-cli/libraries/RBD_Timer-master/src/RBD_Timer.h
Normal file
42
arduino-cli/libraries/RBD_Timer-master/src/RBD_Timer.h
Normal file
@@ -0,0 +1,42 @@
|
||||
// Arduino RBD Timer Library v1.4.0 - Manage many timed events.
|
||||
// https://github.com/alextaujenis/RBD_Timer
|
||||
// Copyright (c) 2015 Alex Taujenis - MIT License
|
||||
|
||||
#ifndef RBD_TIMER_H
|
||||
#define RBD_TIMER_H
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
namespace RBD {
|
||||
class Timer {
|
||||
public:
|
||||
Timer(); // constructor with zero timeout, starts in "expired" state by default
|
||||
Timer(unsigned long value); // overloaded constructor: provide a setTimeout in milliseconds, starts in "expired" state by default
|
||||
void setTimeout(unsigned long value); // set/change how long the timer will run until it expires in milliseconds
|
||||
void setHertz(int value); // set/change how many times onRestart will return true in one second
|
||||
void restart(); // reset and start the timer
|
||||
void stop(); // stop the timer
|
||||
void expire(); // expire the timer without changing the timeout
|
||||
bool isActive(); // check if time is left
|
||||
bool isExpired(); // returns true if time has run out
|
||||
bool isStopped(); // returns true if the timer is stopped
|
||||
bool onRestart(); // returns true if the timer is expired and restarts the timer automatically
|
||||
bool onActive(); // returns true once the timer is active, then waits for it to expire and go active again
|
||||
bool onExpired(); // returns true once the timer is expired, then waits for it to go active and expire again
|
||||
unsigned long getTimeout(); // returns the value of setTimeout, which is how long the timer will run until it expires in milliseconds
|
||||
int getHertz(); // returns the value of setHertz, which is how many times onRestart will return true in one second
|
||||
unsigned long getValue(); // how many milliseconds that have passed since the start of the timer
|
||||
unsigned long getInverseValue(); // how many milliseconds the timer has until finished
|
||||
int getPercentValue(); // how much time has passed as a percentage of the interval
|
||||
int getInversePercentValue(); // how much time is left as a percentage of the interval
|
||||
private:
|
||||
unsigned long _timeout = 0; // how long this timer should run for
|
||||
unsigned long _waypoint = 0; // the point in time the timer was started or reset
|
||||
int _hertz = 0; // the value given to setHertz
|
||||
bool _has_been_active = false; // helps fire the onActive event only once
|
||||
bool _has_been_expired = false; // helps fire the onExpired event only once
|
||||
void _updateState(); // maintains timer current state, helps eliminate rollover issues
|
||||
enum {ACTIVE, EXPIRED, STOPPED} _state = EXPIRED; // timer internal states, constructed in "expired" state by default
|
||||
};
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user