Podrobnejsi popis v readme, doplnen reload.
This commit is contained in:
@ -10,19 +10,19 @@ extern "C" {
|
||||
uint32_t Interval::remains(void)
|
||||
{
|
||||
|
||||
return timeout - (millis() - timefrom);
|
||||
return _timeout - (millis() - _timefrom);
|
||||
}
|
||||
|
||||
uint32_t Interval::elapsed(void)
|
||||
{
|
||||
|
||||
return millis() - timefrom;
|
||||
return millis() - _timefrom;
|
||||
}
|
||||
|
||||
bool Interval::expired(void)
|
||||
{
|
||||
|
||||
if ((millis() - timefrom) >= timeout)
|
||||
if ((millis() - _timefrom) >= _timeout)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
@ -31,6 +31,14 @@ bool Interval::expired(void)
|
||||
void Interval::set(uint32_t tmout)
|
||||
{
|
||||
|
||||
timefrom = millis();
|
||||
timeout = tmout;
|
||||
_reload = tmout;
|
||||
_timefrom = millis();
|
||||
_timeout = _reload;
|
||||
}
|
||||
|
||||
void Interval::reload(void)
|
||||
{
|
||||
|
||||
_timefrom = millis();
|
||||
_timeout = _reload;
|
||||
}
|
||||
|
@ -3,13 +3,9 @@
|
||||
#define interval_h
|
||||
|
||||
/* Interval
|
||||
* Copyright (C) 2014, 2016 Pavel Brychta http://www.xpablo.cz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses
|
||||
* Copyright (C) 2014, 2016, 2018 Pavel Brychta http://www.xpablo.cz
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the MIT License
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
@ -17,11 +13,13 @@
|
||||
class Interval
|
||||
{
|
||||
protected:
|
||||
uint32_t timefrom;
|
||||
uint32_t timeout;
|
||||
uint32_t _timefrom;
|
||||
uint32_t _timeout;
|
||||
uint32_t _reload;
|
||||
public:
|
||||
bool expired(void);
|
||||
void set(uint32_t tmout);
|
||||
void reload(void);
|
||||
uint32_t elapsed(void);
|
||||
uint32_t remains(void);
|
||||
};
|
||||
|
Reference in New Issue
Block a user